Class UsersController
In: app/controllers/users_controller.rb
Parent: ApplicationController

Methods

Constants

FLASH_REPORT_SENT = "Report sent!"
FLASH_FAILED_TO_RESEND_PW = "New password could not be saved!"
FLASH_NO_LONGER_CADMIN = "You are no longer the central administrator"

Public Instance methods

[Source]

    # File app/controllers/users_controller.rb, line 61
61:   def account
62:     select_user
63:     #@version_pages, @versions = paginate :version, :per_page => 5, :order => 'created_on DESC', :conditions => ['user_id = ? and version <> 0', @user.id ]
64:   end

[Source]

     # File app/controllers/users_controller.rb, line 98
 98:   def admin
 99:     @user = User.find(params[:id])
100:     @user.user = session['user'] # used for authorisation
101:     @user.admin = params[:admin]
102:     if  @user.save
103:       flash['success'] = ::FLASH_RECORD_UPDATED
104:     end
105:     redirect_to :action => 'list'
106:   end

[Source]

     # File app/controllers/users_controller.rb, line 140
140:   def adminmessage
141:     @admin_message = AdminMessage.find(params[:id])
142:     if request.get?
143:     else
144:       @admin_message.update_attributes(params[:admin_message])
145:     end
146:   end

[Source]

    # File app/controllers/users_controller.rb, line 90
90:   def cadmin
91:     @cadmin = User.find(session['user'].id) # about to become 'ordinary' admin
92:     @user = User.find(params[:id]) # about to become cadmin
93:     User.cadmin(@cadmin,@user)
94:     flash['notice'] = FLASH_NO_LONGER_CADMIN 
95:     redirect_to :action => 'list'
96:   end

[Source]

    # File app/controllers/users_controller.rb, line 80
80:   def destroy
81:     #--
82:     # TODO Cannot destroy user with versions and comments, 
83:     # we should also do something with version and comments. Aassign versions 
84:     # and comments to admin user, and do a flash notice
85:     #++
86:     User.find(params[:id]).destroy
87:     redirect_to :action => 'list'
88:   end

[Source]

    # File app/controllers/users_controller.rb, line 66
66:   def edit
67:     @user = User.find(params[:id])
68:     if request.get?
69:     else
70:       if  mine?(@user) || cadmin?
71:         if @user.update_attributes(params[:user].merge(:user => session['user']))
72:           flash.now['success'] = ::FLASH_RECORD_UPDATED
73:         end
74:       else
75:         flash.now['error'] = ::FLASH_NOT_OWNER        
76:       end
77:     end
78:   end

[Source]

    # File app/controllers/users_controller.rb, line 30
30:   def index
31:     redirect_to :action => 'list'
32:   end

[Source]

    # File app/controllers/users_controller.rb, line 34
34:   def list
35:     @admins = User.find_all_by_admin('Y')
36:     @users = User.find_all_by_admin('N')
37:     @cadmin = User.find_central_admin
38:   end

Action notification creates or deletes (toggles) a notification of a certain type for a Page and Site

[Source]

     # File app/controllers/users_controller.rb, line 122
122:   def notification
123:     @user = User.find(params[:user_id])
124:     @site = Site.find(params[:site_id])
125:     @page = Page.find(params[:page_id])
126:     @type = params[:notification_type]
127:     if session['user'] == @user || cadmin?
128:       n = Notification.find(:first, :conditions => ["user_id=? and page_id=? and notification_type=?", @user.id, @page.id, @type])
129:       if  n
130:         n.destroy
131:       else
132:         n = Notification.create(:user => session['user'], :page => @page, :notification_type => @type)
133:       end
134:       render :inline => "<%= link_to_notification_toggle(@page, @type, @user)%>"
135:     else
136:       render :inline => "<%= link_to_notification_toggle(@page, @type, @user)%>"
137:     end
138:   end

[Source]

    # File app/controllers/users_controller.rb, line 40
40:   def send_report
41:     Notifier::deliver_summary(params.merge(:user => session['user']))
42:     flash['success'] = FLASH_REPORT_SENT
43:     redirect_to :action => 'account', :id => session['user'].id
44:   end

TODO caching of this page

[Source]

    # File app/controllers/users_controller.rb, line 47
47:   def show
48:     @user = User.find(params[:id])
49:     @versions = UserVersion.find(:all, :order => 'created_on DESC', :conditions => ['user_id=?',@user.id])
50:     @comments = Comment.find(:all, :order => 'created_on DESC', :conditions => ['user_id=?',@user.id])
51:     @uploads = Upload.find(:all, :order => 'created_on DESC', :conditions => ['user_id=?',@user.id])
52:     @pages = WikiPage.find(:all, :order => 'created_on DESC', :conditions => ['tool=? and user_id=?','Wiki', @user.id])
53:     @tabitems = []
54:     @tabitems << {:text => "General", :id => 'general'} 
55:     @tabitems << {:text => "Comments (#{@comments.size.to_s})", :id => 'discussion'} 
56:     @tabitems << {:text => "Changes (#{@versions.size.to_s})", :id => 'changes'} 
57:     @tabitems << {:text => "Uploads (#{@uploads.size.to_s})", :id => 'uploads'}     
58:     @tabitems << {:text => "New Pages (#{@pages.size.to_s})", :id => 'new_pages'}   
59:   end

[Source]

     # File app/controllers/users_controller.rb, line 108
108:   def toggle_change_report_notification
109:     @user = User.find(params[:user_id])
110:     if  mine?(@user) || cadmin?
111:       @user.notify_daily = (@user.notify_daily - 1).abs  if params[:type] == 'D'
112:       @user.notify_weekly = (@user.notify_weekly - 1).abs  if params[:type] == 'W'
113:       @user.notify_monthly = (@user.notify_monthly - 1).abs  if params[:type] == 'M'
114:       @user.notify_immediate = (@user.notify_immediate - 1).abs  if params[:type] == 'I'
115:       #user.notify_dialy = 1
116:       @user.save!
117:     end
118:     render :inline => "<%= link_to_change_report_notification_toggle(params[:type], @user) %>"
119:   end

Protected Instance methods

[Source]

     # File app/controllers/users_controller.rb, line 149
149:   def select_user #:doc:
150:     if params[:id]
151:       @user = User.find(params[:id])
152:     else
153:       @user = session['user']
154:     end
155:     if  !cadmin? && !mine?(@user)
156:       @user = session['user']
157:       flash['notice'] = LoginController::FLASH_UNOT_ADMIN 
158:     end
159:   end

[Validate]