Class: People::AdminController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/people/admin_controller.rb

Overview

COPYRIGHT:

Copyright (c) 2005-2009 North Carolina State University
Developed with funding for the National eXtension Initiative.

LICENSE:

BSD(-compatible)
see LICENSE file or view at http://about.extension.org/wiki/LICENSE

Instance Method Summary (collapse)

Instance Method Details

- (Object) activity



151
152
153
154
155
156
157
158
# File 'app/controllers/people/admin_controller.rb', line 151

def activity
  if (!params[:days] or (params[:days].to_i == 0))
    @days = AppConfig.configtable['recent_activity_delta']
  else
    @days = params[:days].to_i
  end
  @eventslist = UserEvent.paginate(:all, :order => 'created_at desc', :conditions => "created_at > date_sub(curdate(), interval #{@days} day)",:page => params[:page])      
end

- (Object) adminevents


Sudo Actions




20
21
22
# File 'app/controllers/people/admin_controller.rb', line 20

def adminevents
  @admineventslist = AdminEvent.paginate(:all, :order => 'created_at DESC', :page => params[:page])
end

- (Object) adminusers



24
25
26
27
28
29
30
31
# File 'app/controllers/people/admin_controller.rb', line 24

def adminusers
  labels = Hash.new
  findopts = Hash.new
  labels[:page_title] = "Admin Users"
  findopts[:order] = 'last_name asc'
  findopts[:conditions] = "is_admin = 1"
  userlist(false,'admin_users',labels,findopts)
end

- (Object) agreements



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'app/controllers/people/admin_controller.rb', line 160

def agreements
  labels = Hash.new
  findopts = Hash.new
  case params[:type]
  when "accepts"
    labels[:time_column_label] = "agreement entered at"
    labels[:time_column_field] = User::TIMECOLUMN_CONTRIBUTOR_AGREEMENT_AT
    labels[:page_title] = "Users accepting Agreement:"
    findopts[:order] = 'contributor_agreement_at desc'
    findopts[:conditions] = "contributor_agreement = 1"
  when "noaccepts"
    labels[:time_column_label] = "agreement entered at"
    labels[:time_column_field] = User::TIMECOLUMN_CONTRIBUTOR_AGREEMENT_AT
    labels[:page_title] = "Users not acccepting Agreement:"
    findopts[:order] = 'contributor_agreement_at desc'
    findopts[:conditions] = "contributor_agreement = 0"
  when "pending"
    labels[:page_title] = "Users with pending Agreement reviews:"
    findopts[:order] = 'last_name'
    findopts[:conditions] = "contributor_agreement is NULL"
  else
    # uh?
  end
  
  userlist(true,'agreements',labels,findopts,{:type => @type})    
      
end

- (Object) alias_list


End - Sudo Actions




37
38
39
# File 'app/controllers/people/admin_controller.rb', line 37

def alias_list
  @alias_list = EmailAlias.all(:conditions => "alias_type IN (#{EmailAlias::INDIVIDUAL_ALIAS},#{EmailAlias::SYSTEM_ALIAS},#{EmailAlias::SYSTEM_FORWARD})", :order => 'mail_alias ASC')
end

- (Object) confirmaccount_users



299
300
301
302
303
304
305
306
307
# File 'app/controllers/people/admin_controller.rb', line 299

def confirmaccount_users
  labels = Hash.new
  findopts = Hash.new
  
  labels[:page_title] = "Users that have not confirmed their account"
  findopts[:order] = 'updated_at desc'
  findopts[:conditions] = "account_status = #{User::STATUS_SIGNUP} and retired = 0"
  userlist(false,'confirmaccount_users',labels,findopts)
end

- (Object) confirmemail_users



288
289
290
291
292
293
294
295
296
# File 'app/controllers/people/admin_controller.rb', line 288

def confirmemail_users
  labels = Hash.new
  findopts = Hash.new
  
  labels[:page_title] = "Users that have not confirmed their email address"
  findopts[:order] = 'updated_at desc'
  findopts[:conditions] = "emailconfirmed = 0 and retired = 0 and account_status != #{User::STATUS_SIGNUP}"
  userlist(false,'confirmemail_users',labels,findopts)
end

- (Object) enable



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/people/admin_controller.rb', line 69

def enable
  if not params[:id].nil?
    @showuser = User.(params[:id])
    if @showuser
      if request.post?
        if params[:reason].nil? or params[:reason].empty?
          flash.now[:failure] = 'A reason for enabling this eXtensionID is required'      
          @showuser.errors.add("A reason for enabling this eXtensionID is required")
        else
          if @showuser.enable
            AdminEvent.log_event(@currentuser, AdminEvent::ENABLE_ACCOUNT,{:extensionid => @showuser., :reason => params[:reason]})
            UserEvent.log_event(:etype => UserEvent::PROFILE,:user => @showuser,:description => "account enabled by #{@currentuser.}")
          else
            flash.now[:failure] = 'Failed to enable user, reported status may not be correct'      
          end
          @events = UserEvent.find(:all, :order => 'created_at desc', :conditions => ['login = :login or login = :email', { :login => @showuser., :email => @showuser.email }])
          render :template => 'people/admin/showuser'
        end
      else
        # show form
      end
    else
      flash.now[:warning] = 'User not found.'      
      render :template => 'people/admin/showuser'
    end
  else
    flash.now[:warning] = 'Missing user.'      
    render :template => 'people/admin/showuser'
  end    
end

- (Object) finduser



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'app/controllers/people/admin_controller.rb', line 332

def finduser
  
  if (params[:searchterm].nil? or params[:searchterm].empty?)
    flash[:warning] = "Empty search term"
    return redirect_to(:action => 'index')
  end


  @userlist = User.patternsearch(params[:searchterm]).paginate({:order => 'last_name,first_name', :page => params[:page]})
        
  if @userlist.nil? || @userlist.length == 0
    flash[:warning] = "No user was found that matches your search term"
    redirect_to :action => 'index'
  else
    if @userlist.length == 1
      redirect_to :action => :showuser, :id => @userlist[0].
    end
  end

end

- (Object) fixemail



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'app/controllers/people/admin_controller.rb', line 353

def fixemail
  # using "showuser" because we include the common/profile view
  @showuser = User.(params[:id])
  if @showuser
    if request.post?
      success = @showuser.fix_email(params[:email],@currentuser)
      if(success)
        @showuser.reload
        flash.now[:success] = 'Email address changed, confirmation email sent to ' + @showuser.email + '.'
      else
        flash.now[:success] = 'Unable to change email address for ' + @showuser. + '.'
      end
      @events = UserEvent.find(:all, :order => 'created_at desc', :conditions => ['login = :login or login = :email', { :login => @showuser., :email => @showuser.email }])
      render :template => 'people/admin/showuser'
    end
  else
    flash.now[:warning] = 'User not found.'      
    render :template => 'people/admin/index'
  end  
end

- (Object) index



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'app/controllers/people/admin_controller.rb', line 131

def index
  @recent_users = User.notsystem_or_admin.validusers.count(:conditions => "created_at > date_sub(curdate(), interval #{AppConfig.configtable['recent_account_delta']} day)")
  @recent_logins = User.notsystem_or_admin.validusers.count(:conditions => "last_login_at > date_sub(curdate(), interval #{AppConfig.configtable['recent_login_delta']} day)")

  @review_users = User.count(:conditions => ["vouched = 0 AND retired = 0 AND emailconfirmed = 1"])
  @retired_accounts = User.count(:conditions => ["retired = 1"])
  @confirmemail_users = User.count(:conditions => ["emailconfirmed = 0 and retired = 0 and account_status != #{User::STATUS_SIGNUP}"])
  @confirmaccount_users = User.count(:conditions => ["account_status = #{User::STATUS_SIGNUP} and retired = 0"])
  @invalidemail_users = User.count(:conditions => ["(account_status = #{User::STATUS_INVALIDEMAIL} or account_status = #{User::STATUS_INVALIDEMAIL_FROM_SIGNUP}) AND retired = 0"])
  
  # @agreement_accepts = User.notsystem_or_admin.validusers.count(:conditions => "contributor_agreement = 1")
  # @agreement_noaccepts = User.notsystem_or_admin.validusers.count(:conditions => "contributor_agreement = 0")
  # @agreement_pending = User.notsystem_or_admin.validusers.count(:conditions => "contributor_agreement is NULL")
  
  @missing = Hash.new
  @missing['location'] = User.notsystem_or_admin.validusers.count(:conditions => "location_id = 0 or location_id is NULL")
  @missing['position'] = User.notsystem_or_admin.validusers.count(:conditions => "position_id = 0 or position_id is NULL")
  
end

- (Object) invalidemail



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/controllers/people/admin_controller.rb', line 100

def invalidemail
  if not params[:id].nil?
    @showuser = User.(params[:id])
    if @showuser
        if request.post?
          if params[:reason].nil? or params[:reason].empty?
            flash.now[:failure] = 'A reason for marking this email address invalid is required'      
            @showuser.errors.add("A reason for marking this email address invalid is required")
          else
            if @showuser.invalidemail
              AdminEvent.log_event(@currentuser, AdminEvent::ACCOUNT_INVALIDEMAIL,{:extensionid => @showuser., :reason => params[:reason]})
              UserEvent.log_event(:etype => UserEvent::PROFILE,:user => @showuser,:description => "email marked invalid by #{@currentuser.}")                                                                            
            else
              flash.now[:failure] = 'Failed to mark email invalid, reported status may not be correct'      
            end
            @events = UserEvent.find(:all, :order => 'created_at desc', :conditions => ['login = :login or login = :email', { :login => @showuser., :email => @showuser.email }])
            render :template => 'people/admin/showuser'
          end
        else
          # show form
        end
    else
      flash.now[:warning] = 'User not found.'      
      render :template => 'people/admin/showuser'
    end
  else
    flash.now[:warning] = 'Missing user.'      
    render :template => 'people/admin/showuser'
  end    
end

- (Object) invalidemail_users



278
279
280
281
282
283
284
285
286
# File 'app/controllers/people/admin_controller.rb', line 278

def invalidemail_users
  labels = Hash.new
  findopts = Hash.new
  
  labels[:page_title] = "Users with invalid email addresses"
  findopts[:order] = 'updated_at desc'
  findopts[:conditions] = "(account_status = #{User::STATUS_INVALIDEMAIL} or account_status = #{User::STATUS_INVALIDEMAIL_FROM_SIGNUP}) and retired = 0"
  userlist(false,'invalidemail_users',labels,findopts)
end

- (Object) missing_institution



238
239
240
241
242
243
244
245
246
# File 'app/controllers/people/admin_controller.rb', line 238

def missing_institution
  labels = Hash.new
  findopts = Hash.new
  
  labels[:page_title] = "Users not specifying a institution"
  findopts[:order] = 'last_name'
  findopts[:conditions] = "institution_id = 0 or institution_id is NULL"
  userlist(true,'missing_institution',labels,findopts)
end

- (Object) missing_location



248
249
250
251
252
253
254
255
256
# File 'app/controllers/people/admin_controller.rb', line 248

def missing_location
  labels = Hash.new
  findopts = Hash.new
  
  labels[:page_title] = "Users not specifying a location"
  findopts[:order] = 'last_name'
  findopts[:conditions] = "location_id = 0 or location_id is NULL"
  userlist(true,'missing_location',labels,findopts)
end

- (Object) missing_position



258
259
260
261
262
263
264
265
266
# File 'app/controllers/people/admin_controller.rb', line 258

def missing_position
  labels = Hash.new
  findopts = Hash.new
  
  labels[:page_title] = "Users not specifying a position"
  findopts[:order] = 'last_name'
  findopts[:conditions] = "position_id = 0 or position_id is NULL"
  userlist(true,'missing_position',labels,findopts)
end

- (Object) openidusage



188
189
190
# File 'app/controllers/people/admin_controller.rb', line 188

def openidusage
  @opieapprovals = OpieApproval.find(:all)
end

- (Object) recent_logins



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'app/controllers/people/admin_controller.rb', line 211

def recent_logins
  labels = Hash.new
  findopts = Hash.new
  
  if (!params[:days] or (params[:days].to_i == 0))
    @days = AppConfig.configtable['recent_login_delta']
  else
    @days = params[:days].to_i
  end
  labels[:time_column_label] = "last login at"
  labels[:time_column_field] = User::TIMECOLUMN_LAST_LOGIN_AT
  labels[:page_title] = "Recent Logins"
  findopts[:order] = 'last_login_at desc'
  findopts[:conditions] = "last_login_at > date_sub(curdate(), interval #{@days} day)"
  userlist(true,'recent_logins',labels,findopts)
end

- (Object) recent_users



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'app/controllers/people/admin_controller.rb', line 193

def recent_users
  labels = Hash.new
  findopts = Hash.new
  
  if (!params[:days] or (params[:days].to_i == 0))
    @days = AppConfig.configtable['recent_account_delta']
  else
    @days = params[:days].to_i
  end

  labels[:time_column_label] = "created at"
  labels[:time_column_field] = User::TIMECOLUMN_CREATED_AT
  labels[:page_title] = "Recent Users"
  findopts[:order] = 'created_at desc'
  findopts[:conditions] = "created_at > date_sub(curdate(), interval #{@days} day)"
  userlist(true,'recent_users',labels,findopts)    
end

- (Object) retire



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/people/admin_controller.rb', line 41

def retire
  if not params[:id].nil?
    @showuser = User.(params[:id])
    if @showuser
      if request.post?
        if params[:reason].nil? or params[:reason].empty?
          flash.now[:failure] = 'A reason for disabling this eXtensionID is required'      
          @showuser.errors.add("A reason for disabling this eXtensionID is required")
        else
          if(!@showuser.retire(@currentuser,params[:reason]))
            flash.now[:failure] = 'Failed to retire user, reported status may not be correct'      
          end
          @events = UserEvent.find(:all, :order => 'created_at desc', :conditions => ['login = :login or login = :email', { :login => @showuser., :email => @showuser.email }])
          render :template => 'people/admin/showuser'
        end
      else
        # show form
      end
    else
      flash.now[:warning] = 'User not found.'      
      render :template => 'people/admin/showuser'
    end
  else
    flash.now[:warning] = 'Missing user.'      
    render :template => 'people/admin/showuser'
  end    
end

- (Object) retired_accounts



268
269
270
271
272
273
274
275
276
# File 'app/controllers/people/admin_controller.rb', line 268

def retired_accounts
  labels = Hash.new
  findopts = Hash.new
  
  labels[:page_title] = "Retired accounts"
  findopts[:order] = 'updated_at desc'
  findopts[:conditions] = "retired = 1"
  userlist(false,'retired_accounts',labels,findopts)
end

- (Object) review_users



228
229
230
231
232
233
234
235
236
# File 'app/controllers/people/admin_controller.rb', line 228

def review_users
  labels = Hash.new
  findopts = Hash.new
  
  labels[:page_title] = "Users pending review"
  findopts[:order] = 'updated_at desc'
  findopts[:conditions] = "vouched = 0 AND retired = 0 AND emailconfirmed = 1"
  userlist(false,'review_users',labels,findopts)
end

- (Object) showuser



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'app/controllers/people/admin_controller.rb', line 309

def showuser
  if(!params[:id].nil?)
    if(params[:id].to_i != 0)
      @showuser = User.find_by_id(params[:id])
    else
      @showuser = User.(params[:id])
    end
    
    if @showuser   
      @events = UserEvent.find(:all, :order => 'created_at desc', 
        :conditions => ['login = :login or login = :email', { :login => @showuser., :email => @showuser.email }])
    else
      flash[:warning] = 'User not found.'      
      render :template => 'people/admin/showuser'
    end
  else
    flash[:warning] = 'Missing user.'      
    render :template => 'people/admin/showuser'
  end
end