public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
allow setting of site admins

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2209 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Mon Sep 18 01:54:06 -0700 2006
commit  79943b8c0199d594f3455dca87979345b1ef5d7f
tree    5f9e87812c6e9cbddb0560674b985b170de94cf5
parent  f8d6671da882bca212cafb9662c389965bbe02ee
...
1
2
3
4
 
5
6
7
...
34
35
36
37
38
39
 
 
40
41
42
...
44
45
46
 
 
 
 
 
 
47
48
49
...
1
2
3
 
4
5
6
7
...
34
35
36
 
 
 
37
38
39
40
41
...
43
44
45
46
47
48
49
50
51
52
53
54
0
@@ -1,7 +1,7 @@
0
 class Admin::UsersController < Admin::BaseController
0
   MEMBER_ACTIONS = %w(show update).freeze unless const_defined?(:MEMBER_ACTIONS)
0
   before_filter :find_all_users, :only => [:index, :show, :new]
0
- before_filter :find_user, :only => [:show, :update, :enable]
0
+ before_filter :find_user, :only => [:show, :update, :enable, :admin, :destroy]
0
 
0
   def index
0
     @enabled, @disabled = @users.partition { |u| u.deleted_at.nil? }
0
@@ -34,9 +34,8 @@ class Admin::UsersController < Admin::BaseController
0
   end
0
 
0
   def destroy
0
- @user = site.user(params[:id])
0
- @user.destroy
0
- @user = site.user_with_deleted(params[:id]) # reload
0
+ @user.deleted_at = Time.now.utc
0
+ @user.save!
0
   end
0
 
0
   def enable
0
@@ -44,6 +43,12 @@ class Admin::UsersController < Admin::BaseController
0
     @user.save!
0
   end
0
   
0
+ def admin
0
+ @membership = Membership.find_or_initialize_by_site_id_and_user_id(site.id, @user.id)
0
+ @membership.admin = !@membership.admin?
0
+ @membership.save!
0
+ end
0
+
0
   protected
0
     def find_all_users
0
       @users = site.users_with_deleted
...
11
12
13
14
 
15
16
17
...
11
12
13
 
14
15
16
17
0
@@ -11,7 +11,7 @@ class ApplicationController < ActionController::Base
0
     helper_method :admin?
0
     
0
     def admin?
0
- logged_in? && current_user.admin? || current_user.site_admin?
0
+ logged_in? && (current_user.admin? || current_user.site_admin?)
0
     end
0
   
0
     # so not the best place for this...
...
30
31
32
33
34
35
36
...
46
47
48
49
 
50
51
 
52
53
54
...
30
31
32
 
33
34
35
...
45
46
47
 
48
49
 
50
51
52
53
0
@@ -30,7 +30,6 @@
0
 </div>
0
 <!-- /end overview -->
0
 
0
-
0
 <% content_for :sidebar do %>
0
   <% if @articles.any? -%>
0
   <div class="sgroup">
0
@@ -46,9 +45,9 @@
0
   <div class="sgroup">
0
     <h3>Recent activity</h3>
0
     <ul class="slist" id="activity">
0
- <% for user in @users %>
0
+ <% @users.each do |user| -%>
0
         <li style="clear:right;"><%= avatar_for user %><%= link_to who(user.login), :controller => 'users', :action => 'show', :id => user %><br /> showed up <%= distance_of_time_in_words_to_now(user.updated_at) %> ago</li>
0
- <% end %>
0
+ <% end -%>
0
     </ul>
0
   </div>
0
 <% end %>
...
10
11
12
13
14
15
16
17
18
19
...
10
11
12
 
 
 
 
13
14
15
0
@@ -10,10 +10,6 @@
0
     </dd>
0
     <dt><label for="user_email">Email address</label></dt>
0
     <dd><%= f.text_field :email %></dd>
0
- <% unless @user == current_user %>
0
- <dt><label for="user_deleted_at">Allow this user to login?</label></dt>
0
- <dd><label><%= f.check_box :deleted_at, {}, @user.deleted_at.nil? %> Yes, allow this user to login.</label></dd>
0
- <% end %>
0
   </dl>
0
 </div>
0
 
...
2
3
4
5
6
7
8
9
10
11
 
12
13
...
2
3
4
 
 
 
 
 
 
 
5
6
7
0
@@ -2,11 +2,5 @@
0
     <%= avatar_for user %>
0
     <h3><%= link_to user.login, :action => 'show', :id => user %></h3>
0
     <%= user.email %>
0
- <% unless user == current_user -%>
0
- <p>
0
- <%= check_box_tag user.dom_id(:user_toggle), user.id, user.deleted_at.nil?, :onclick => "UserForm.toggle(this);" %>
0
- <strong><label for="<%= user.dom_id(:user_toggle) %>">Allow this user to login</label></strong>
0
- <%= image_tag 'mephisto/progress.gif', :size => '10x10', :style => 'display:none', :id => "#{user.dom_id}-progress" %>
0
- </p>
0
- <% end -%>
0
+<%= render :partial => "toggles", :locals => { :user => user } %>
0
 </li>
0
\ No newline at end of file
...
1
2
3
 
 
 
 
 
 
4
...
1
 
2
3
4
5
6
7
8
9
0
@@ -1,2 +1,7 @@
0
 page.call 'Flash.notice', "#{@user.login} was disabled."
0
-page["#{@user.dom_id}-progress"].hide
0
\ No newline at end of file
0
+page["#{@user.dom_id}-progress"].hide
0
+page << 'function foo() {'
0
+page[@user.dom_id].remove
0
+page.insert_html :bottom, :disabled_users, :partial => 'disabled', :locals => { :user => @user }
0
+page << '}'
0
+page[@user.dom_id].visual_effect :drop_out, :afterFinish => ActiveSupport::JSON::Variable.new("foo")
0
\ No newline at end of file
...
1
2
3
 
 
 
 
 
 
4
...
1
 
2
3
4
5
6
7
8
9
0
@@ -1,2 +1,7 @@
0
 page.call 'Flash.notice', "#{@user.login} was enabled."
0
-page["#{@user.dom_id}-progress"].hide
0
\ No newline at end of file
0
+page["#{@user.dom_id}-progress"].hide
0
+page << 'function foo() {'
0
+page[@user.dom_id].remove
0
+page.insert_html :bottom, :users, :partial => 'user', :object => @user
0
+page << '}'
0
+page[@user.dom_id].visual_effect :drop_out, :afterFinish => ActiveSupport::JSON::Variable.new("foo")
0
\ No newline at end of file
...
9
10
11
12
13
14
 
 
 
 
 
 
 
 
 
 
 
 
 
15
...
9
10
11
 
 
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
0
@@ -9,5 +9,16 @@
0
 <% end %>
0
 
0
 <ul id="users">
0
-<%= render :partial => "user", :collection => @users %>
0
-</ul>
0
\ No newline at end of file
0
+<%= render :partial => "user", :collection => @enabled %>
0
+</ul>
0
+
0
+<% content_for :sidebar do -%>
0
+ <div class="sgroup">
0
+ <h3>Disabled Users</h3>
0
+ <ul class="slist" id="disabled_users">
0
+ <% @disabled.each do |user| -%>
0
+<%= render :partial => "disabled", :locals => { :user => user } %>
0
+ <% end -%>
0
+ </ul>
0
+ </div>
0
+<% end -%>
0
\ No newline at end of file
...
312
313
314
 
 
 
 
315
316
317
...
312
313
314
315
316
317
318
319
320
321
0
@@ -312,6 +312,10 @@ var UserForm = {
0
   toggle: function(chk) {
0
     $('user-' + chk.getAttribute('value') + '-progress').show();
0
     new Ajax.Request('/admin/users/' + (chk.checked ? 'enable' : 'destroy') + '/' + chk.getAttribute('value'));
0
+ },
0
+ toggleAdmin: function(chk) {
0
+ $('user-' + chk.getAttribute('value') + '-progress').show();
0
+ new Ajax.Request('/admin/users/admin/' + chk.getAttribute('value'));
0
   }
0
 }
0
 
...
1030
1031
1032
 
1033
1034
1035
1036
1037
 
1038
1039
1040
...
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
0
@@ -1030,11 +1030,13 @@ img.avatar {
0
   font-weight: bold;
0
 }
0
 
0
+#disabled_users .avatar,
0
 #activity .avatar {
0
   max-width: 30px;
0
   max-height: 30px;
0
 }
0
 
0
+#disabled_users li,
0
 #activity li {
0
   min-height: 40px;
0
   line-height: 125%;
...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
 
 
 
 
 
 
 
 
 
132
133
134
...
139
140
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
143
144
...
118
119
120
 
 
 
 
 
 
 
 
 
 
 
121
122
123
124
125
126
127
128
129
130
131
132
...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
0
@@ -118,17 +118,15 @@ class Admin::UsersControllerTest < Test::Unit::TestCase
0
     login_as :quentin
0
     get :index
0
     assert_equal 4, assigns(:users).size
0
- user_tag = { :tag => 'li', :attributes => { :id => 'user-1', :class => 'clear' } }
0
- normal_tag = { :tag => 'li', :attributes => { :id => 'user-2', :class => 'clear' } }
0
- deleted_tag = { :tag => 'li', :attributes => { :id => 'user-3', :class => 'clear deleted' } }
0
- assert_tag user_tag
0
- assert_tag normal_tag
0
- assert_tag deleted_tag
0
- assert_no_tag 'input', :attributes => { :type => 'checkbox', :id => 'user-toggle-1' }, :ancestor => user_tag
0
- assert_tag 'input', :attributes => { :type => 'checkbox', :id => 'user-toggle-2' }, :ancestor => normal_tag
0
- assert_tag 'input', :attributes => { :type => 'checkbox', :id => 'user-toggle-3' }, :ancestor => deleted_tag
0
- assert_tag 'input', :attributes => { :type => 'checkbox', :id => 'user-toggle-2', :checked => 'checked' }, :ancestor => normal_tag
0
- assert_no_tag 'input', :attributes => { :type => 'checkbox', :id => 'user-toggle-3', :checked => 'checked' }, :ancestor => deleted_tag
0
+ assert_select "#users li[id='user-1']" do
0
+ assert_select "[class='clear']"
0
+ end
0
+ assert_select "#users li[id='user-2']" do
0
+ assert_select "[class='clear']"
0
+ end
0
+ assert_select "#disabled_users li[id='user-3']" do
0
+ assert_select "[class='clear deleted']"
0
+ end
0
   end
0
 
0
   def test_should_not_disable_as_site_member
0
@@ -139,6 +137,21 @@ class Admin::UsersControllerTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+ def test_should_disable_site_admin
0
+ login_as :quentin
0
+ xhr :post, :admin, :id => users(:arthur).id
0
+ assert_response :success
0
+ assert !sites(:first).user(users(:arthur).id).site_admin?
0
+ end
0
+
0
+ def test_should_enable_site_admin
0
+ sites(:first).user_with_deleted(3).update_attribute :deleted_at, nil
0
+ login_as :quentin
0
+ xhr :post, :admin, :id => users(:aaron).id
0
+ assert_response :success
0
+ assert sites(:first).user(users(:aaron).id).site_admin?
0
+ end
0
+
0
   def test_should_disable_user
0
     login_as :quentin
0
     assert_no_difference User, :count_with_deleted do

Comments

    No one has commented yet.