public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Added tools to make user deactivation easier
Michael Hartl (author)
Mon May 19 16:04:11 -0700 2008
commit  ba2f3496e9aac914cb8045415dac330fc81f09ba
tree    4dbbf4981976703084c6bf45473b768a4b134065
parent  5d5f889ba4d680cc0966862474b79a21e80a0dc3
...
8
9
10
11
12
 
 
13
14
15
 
16
17
18
 
19
20
21
22
...
8
9
10
 
 
11
12
13
14
 
15
16
17
 
18
19
20
21
22
0
@@ -8,14 +8,14 @@ class Admin::PeopleController < ApplicationController
0
 
0
   def update
0
     @person = Person.find(params[:id])
0
- if @person.last_admin?
0
- flash[:error] = "Action failed&mdash;you're the last admin."
0
+ if current_person?(@person)
0
+ flash[:error] = "Action failed."
0
     else
0
       @person.toggle!(params[:task])
0
- flash[:success] = "#{CGI.escapeHTML @person.name} updated"
0
+ flash[:success] = "#{CGI.escapeHTML @person.name} updated."
0
     end
0
     respond_to do |format|
0
- format.html { redirect_to admin_people_url }
0
+ format.html { redirect_to :back }
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
16
17
18
19
 
20
21
22
...
16
17
18
 
19
20
21
22
0
@@ -16,7 +16,7 @@ class PeopleController < ApplicationController
0
   
0
   def show
0
     @person = Person.find(params[:id], :include => :activities)
0
- if @person.deactivated?
0
+ if @person.deactivated? and not current_person.admin?
0
       flash[:error] = "That person is not activated"
0
       redirect_to home_url and return
0
     end
...
119
120
121
122
 
123
124
125
...
119
120
121
 
122
123
124
125
0
@@ -119,7 +119,7 @@ class Person < ActiveRecord::Base
0
       query = options[:q]
0
       return [].paginate if query.blank? or query == "*"
0
       # This is inefficient. We'll fix it when we move to Sphinx.
0
- conditions = conditions_for_inactive
0
+ conditions = conditions_for_active
0
       results = find_by_contents(query, {}, :conditions => conditions)
0
       results[0...SEARCH_LIMIT].paginate(:page => options[:page],
0
                                          :per_page => SEARCH_PER_PAGE)
...
3
4
5
6
7
 
 
8
9
10
...
13
14
15
16
 
17
 
18
19
...
3
4
5
 
6
7
8
9
10
11
...
14
15
16
 
17
18
19
20
21
0
@@ -3,8 +3,9 @@
0
   <div class="profile-image">
0
     <%= image_link person %>
0
   </div>
0
- <p><%= person_link person, :class => "url fn" %></p>
0
   <p>
0
+ <%= person_link person, :class => "url fn" %>
0
+ |
0
     <%- activity = person.deactivated? ? "activate" : "deactivate" -%>
0
     <%= link_to activity,
0
                 admin_person_path(person, :task => "deactivated"),
0
@@ -13,6 +14,7 @@
0
     <%- activity = person.admin? ? "unadmin" : "admin" -%>
0
     <%= link_to activity,
0
                 admin_person_path(person, :task => "admin"),
0
- :method => :put %>
0
+ :method => :put %>
0
   </p>
0
+ <%= display person.description %>
0
 </li>
0
\ No newline at end of file
...
44
45
46
 
 
 
 
 
 
 
 
47
48
49
...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
0
@@ -44,6 +44,14 @@
0
         <%- end -%>
0
           <li><%= link_to "#{h @person.name}'s blog",
0
                   blog_path(@person.blog) %></li>
0
+ <%- if current_person.admin? -%>
0
+ <li>
0
+ <%- activity = @person.deactivated? ? "activate" : "deactivate" -%>
0
+ <%= link_to activity,
0
+ admin_person_path(@person, :task => "deactivated"),
0
+ :method => :put %>
0
+ </li>
0
+ <%- end -%>
0
         </ul>
0
       <%- end -%>
0
       
...
3
4
5
 
 
 
 
6
7
8
...
47
48
49
50
51
52
53
54
55
56
57
58
 
59
60
61
62
63
64
65
66
67
68
69
70
 
71
72
73
74
75
76
77
78
79
80
 
81
...
3
4
5
6
7
8
9
10
11
12
...
51
52
53
 
 
 
 
 
 
 
 
 
54
55
 
56
57
 
 
 
 
 
58
59
 
60
61
62
 
 
 
 
63
64
 
 
65
66
0
@@ -3,6 +3,10 @@ require File.dirname(__FILE__) + '/../../spec_helper'
0
 describe Admin::PeopleController do
0
   integrate_views
0
   
0
+ before(:each) do
0
+ request.env['HTTP_REFERER'] = "http://test.host/previous/page"
0
+ end
0
+
0
   it "should redirect a non-logged-in user" do
0
     get :index
0
     response.should be_redirect
0
@@ -47,35 +51,16 @@ describe Admin::PeopleController do
0
       @person.reload.should_not be_deactivated
0
     end
0
     
0
-
0
- it "should allow an admin to deactivate himself" do
0
- @person.toggle!(:admin)
0
- put :update, :id => @admin, :task => "deactivated"
0
- @admin.reload.should be_deactivated
0
- end
0
-
0
- it "should not deactivation if no other admins are active" do
0
- # Add an admin, but deactivate him.
0
+ it "should not allow an admin to deactivate himself" do
0
       @person.toggle!(:admin)
0
- @person.toggle!(:deactivated)
0
       put :update, :id => @admin, :task => "deactivated"
0
       @admin.reload.should_not be_deactivated
0
- end
0
-
0
- it "should not allow last admin to deactivate himself" do
0
- put :update, :id => @admin, :task => "deactivated"
0
- @admin.should_not be_deactivated
0
     end
0
     
0
- it "should allow an admin to un-admin himself" do
0
+ it "should not allow an admin to un-admin himself" do
0
       @person.toggle!(:admin)
0
       put :update, :id => @admin, :task => "admin"
0
- @admin.reload.should_not be_admin
0
- end
0
- it "should not allow the last admin to un-admin himself" do
0
- put :update, :id => @admin, :task => "admin"
0
       @admin.reload.should be_admin
0
     end
0
- end
0
-
0
+ end
0
 end

Comments

    No one has commented yet.