Skip to content

Commit

Permalink
Archiving Users
Browse files Browse the repository at this point in the history
 * you can now archive users
WIP:
 * make it so that you can see the archived users
 * move the delete / impersonate functions to the User edit screen
  • Loading branch information
rnhurt committed Oct 30, 2010
1 parent 799d106 commit d64513f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
16 changes: 10 additions & 6 deletions app/controllers/users_controller.rb
@@ -1,6 +1,6 @@
class UsersController < ApplicationController
before_filter :require_user
before_filter :decode_user_type, :except => "modify_users"
before_filter :decode_user_type, :except => "archive"

append_before_filter :authorized?
include SortHelper
Expand All @@ -9,7 +9,7 @@ def index
sort_init 'last_name'
sort_update
params[:sort_clause] = sort_clause
@users = @user_type.search(params)
@users = @user_type.active.search(params)
end


Expand Down Expand Up @@ -80,11 +80,15 @@ def impersonate
end
end

def modify_users
debugger
# Archive users
def archive
# The list of users is sent to this method using the "on" value. Therefor we grab all the
# elements in the params array that has a value of "on" and process them.
params.reject{|k,v| v !="on" }.keys.each do |id|
User.find(id).archive
end

puts "I got #{params[:change_to]}"
render :nothing => true
redirect_to users_url
end

private
Expand Down
7 changes: 7 additions & 0 deletions app/models/user.rb
Expand Up @@ -18,6 +18,7 @@ class User < ActiveRecord::Base
validates_existence_of :site

named_scope :active, :conditions => { :active => true }
scope :archived, :conditions => { :active => false }

# Search for a user using the 'will_paginate' plugin
def self.search(params)
Expand All @@ -34,6 +35,7 @@ def self.user_types
types = []
types << {'All (active)' => nil} << {'Students' => Student}
types << {'Teachers' => Teacher} << {'Teacher Assistants' => TeacherAssistant}
types << {'Archived' => nil}
end

# Display the user's full name.
Expand All @@ -48,4 +50,9 @@ def full_name=(name)
self.last_name = split.last
end

# Archive a user by setting its "active" bit to false
def archive
self.active = false
self.save!
end
end
53 changes: 25 additions & 28 deletions app/views/users/_user_list.html.erb
@@ -1,5 +1,3 @@
<% auth_token = url_encode(form_authenticity_token) %>

<table id="users" class="master">
<thead>
<tr>
Expand All @@ -14,32 +12,30 @@

<th><%= text_field_tag :search, params[:search],
:size => 10, :class => "focus search" %></th>
<% end %>

<th>
<select id="options" onchange="this.ids=$$('input:checked').invoke('identify').join(',');<%= remote_function(
:url => { :action => :modify_users, :id => 0 }, :with=>"'change_to='+this.value+':'+this.ids") %>">
<option value="">Action...</option>
<option value="archive">Archive</option>
<option value="impersonate">Impersonate</option>
<option value="delete">Delete</option>
</select>
</th>
<form method="post" action="/users/0/archive">
<input name="authenticity_token" type="hidden" value="<%= form_authenticity_token %>" />
<th><%= submit_tag "Archive" %></th>

<% end %>
</tr>
</thead>
<tbody>
<% for u in users %>
<tr class="<%= cycle('odd', 'even') %>" nclick="location.href='<%= url_for(u)+'/edit' %>'">
<%= content_tag :td, u.login %>
<td><%= link_to u.first_name, url_for(u)+'/edit' %></td>
<td><%= link_to u.last_name, url_for(u)+'/edit' %></td>
<%= content_tag :td, u.homeroom %>
<%= content_tag :td, u.site.name %>
<%= content_tag :td, u.class_of %>
<%= content_tag :td, u.email, :colspan => "2" %>

<td><input type="checkbox" name="<%= u.id %>" id="<%= u.id %>" class="checkbox" /></td>
</thead>
<tbody>
<% for u in users %>
<tr class="<%= cycle('odd', 'even') %>" nclick="location.href='<%= url_for(u)+'/edit' %>'">
<%= content_tag :td, u.login %>
<td><%= link_to u.first_name, url_for(u)+'/edit' %></td>
<td><%= link_to u.last_name, url_for(u)+'/edit' %></td>
<%= content_tag :td, u.homeroom %>
<%= content_tag :td, u.site.name %>
<%= content_tag :td, u.class_of %>
<%= content_tag :td, u.email, :colspan => "2" %>

<td>
<% unless u.is_admin? %>
<input type="checkbox" name="<%= u.id %>" class="checkbox" />
<% end %>
</td>

<%#= button_to 'Delete', u, :method => :delete,
:confirm => "Are you sure you want to delete\n\n '" + u.full_name + "'?",
Expand All @@ -48,9 +44,10 @@
:confirm => "Are you sure you want to impersonate\n\n '" + u.full_name + "'?",
:class => 'btn negative sml' %>

</tr>
<% end %>
</tbody>
</tr>
<% end %>
</form>
</tbody>
</table>

<span class="paginate">
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -6,7 +6,7 @@

# Since we subclass the Users into different types,
# we need to build routes for them.
map.resources :users, :member => { :modify_users => :post }
map.resources :users, :member => { :archive => :post }
map.namespace :users do |u|
u.resources :students, :name_prefix => nil
u.resources :teachers, :name_prefix => nil
Expand Down

0 comments on commit d64513f

Please sign in to comment.