public
Fork of courtenay/altered_beast
Description: Ground-up rewrite of Beast, a Ruby on Rails forum.
Homepage: http://activereload.lighthouseapp.com/projects/7537-altered-beast/
Clone URL: git://github.com/technoweenie/altered_beast.git
move user-edit to user-settings and make edit an admin function. cleanup 
suspend functionality
courtenay (author)
Sun Feb 10 16:06:34 -0800 2008
commit  e7c17074f6751578cfccfa6f222f91e50d1131d4
tree    cef3ede13805eaef88111e196cf7e2b29e7d82cb
parent  a564e663055d930ade08184c6ed6605b07fa038d
...
1
2
3
4
 
 
 
5
6
7
...
24
25
26
27
28
29
30
 
31
 
 
 
 
 
32
33
34
35
 
36
37
38
 
39
40
41
...
56
57
58
 
59
60
61
62
63
 
64
65
66
...
76
77
78
79
 
 
 
 
 
80
81
82
83
 
84
85
...
1
 
 
 
2
3
4
5
6
7
...
24
25
26
 
 
 
 
27
28
29
30
31
32
33
34
35
36
 
37
38
39
 
40
41
42
43
...
58
59
60
61
62
63
64
65
66
67
68
69
70
...
80
81
82
 
83
84
85
86
87
88
89
90
 
91
92
93
0
@@ -1,7 +1,7 @@
0
 class UsersController < ApplicationController
0
- before_filter :admin_required, :only => [:suspend, :unsuspend, :destroy, :purge]
0
- before_filter :find_user, :only => [:update, :show, :suspend, :unsuspend, :destroy, :purge]
0
- before_filter :login_required, :only => [:edit, :update]
0
+ before_filter :admin_required, :only => [:suspend, :unsuspend, :destroy, :purge, :edit]
0
+ before_filter :find_user, :only => [:update, :show, :edit, :suspend, :unsuspend, :destroy, :purge]
0
+ before_filter :login_required, :only => [:settings, :update]
0
   
0
   def index
0
     @users = current_site.users.paginate :all, :page => current_page
0
@@ -24,18 +24,20 @@ class UsersController < ApplicationController
0
     end
0
   end
0
 
0
- def edit
0
- if params[:id]
0
- redirect_to settings_path and return
0
- end
0
+ def settings
0
     @user = current_user
0
+ render :action => "edit"
0
+ end
0
+
0
+ def edit
0
+ @user = find_user
0
   end
0
 
0
   def update
0
- @user = current_user
0
+ @user = admin? ? find_user : current_user
0
     respond_to do |format|
0
       if @user.update_attributes(params[:user])
0
- flash[:notice] = 'Forum was successfully updated.'
0
+ flash[:notice] = 'User account was successfully updated.'
0
         format.html { redirect_to(settings_path) }
0
         format.xml { head :ok }
0
       else
0
@@ -56,11 +58,13 @@ class UsersController < ApplicationController
0
 
0
   def suspend
0
     @user.suspend!
0
+ flash[:notice] = "User was suspended."
0
     redirect_to users_path
0
   end
0
 
0
   def unsuspend
0
     @user.unsuspend!
0
+ flash[:notice] = "User was unsuspended."
0
     redirect_to users_path
0
   end
0
 
0
@@ -76,10 +80,14 @@ class UsersController < ApplicationController
0
 
0
 protected
0
   def find_user
0
- @user = current_site.users.find_by_permalink(params[:id])
0
+ @user = if admin?
0
+ current_site.all_users.find_by_permalink(params[:id])
0
+ else
0
+ current_site.users.find_by_permalink(params[:id])
0
+ end or raise ActiveRecord::RecordNotFound
0
   end
0
   
0
   def authorized?
0
- params[:id].blank? || @user == current_user
0
+ admin? || params[:id].blank? || @user == current_user
0
   end
0
 end
...
15
16
17
18
 
 
 
19
20
21
...
15
16
17
 
18
19
20
21
22
23
0
@@ -15,7 +15,9 @@ class Forum < ActiveRecord::Base
0
 
0
   # this is used to see if a forum is "fresh"... we can't use topics because it puts
0
   # stickies first even if they are not the most recently modified
0
- has_many :recent_topics, :class_name => 'Topic', :order => "#{Topic.table_name}.last_updated_at DESC"
0
+ has_many :recent_topics, :class_name => 'Topic', :include => [:user],
0
+ :order => "#{Topic.table_name}.last_updated_at DESC",
0
+ :conditions => ["users.state == ?", "active"]
0
   has_one :recent_topic, :class_name => 'Topic', :order => "#{Topic.table_name}.last_updated_at DESC"
0
 
0
   has_many :posts, :order => "#{Post.table_name}.created_at DESC", :dependent => :delete_all
...
15
16
17
18
 
19
20
21
...
48
49
50
 
 
 
 
51
52
...
15
16
17
 
18
19
20
21
...
48
49
50
51
52
53
54
55
56
0
@@ -15,7 +15,7 @@ class User
0
   end
0
   
0
   event :suspend do
0
- transitions :from => [:passive, :pending, :active], :to => :suspended
0
+ transitions :from => [:passive, :pending, :active], :to => :suspended, :guard => :remove_moderatorships
0
   end
0
   
0
   event :delete do
0
@@ -48,4 +48,8 @@ protected
0
     self.activated_at = Time.now.utc
0
     self.deleted_at = self.activation_code = nil
0
   end
0
+
0
+ def remove_moderatorships
0
+ moderatorships.delete_all
0
+ end
0
 end
0
\ No newline at end of file
...
88
89
90
91
 
92
93
94
95
96
 
 
97
98
99
...
118
119
120
121
 
 
 
 
 
122
123
124
...
88
89
90
 
91
92
93
94
95
96
97
98
99
100
101
...
120
121
122
 
123
124
125
126
127
128
129
130
0
@@ -88,12 +88,14 @@
0
 
0
     <%= avatar_for post.user %>
0
     <span class="fn"><%= link_to truncate(h(post.user.display_name), 15), user_path(post.user), :class => (post.user == @posts.first.user ? "threadauthor" : nil) %></span>
0
- <% if post.user.admin? || post.forum.moderators.include?(post.user) %>
0
+ <% if post.user.admin? || post.forum.moderators.include?(post.user) || !post.user.active? %>
0
     <span class="admin">
0
       <% if post.user.admin? %>
0
       <%= 'Administator'[:administrator_title] %>
0
       <% elsif post.forum.moderators.include?(post.user) %>
0
       <%= 'Moderator'[:moderator_title] %>
0
+ <% elsif post.user.suspended? %>
0
+ <%=h post.user.state %>
0
       <% end %>
0
     </span>
0
     <% end %>
0
@@ -118,7 +120,11 @@
0
 <!--
0
     <%= link_to_function image_tag('clearbits/comment.gif', :class => 'icon reply'), "$('reply').toggle()" if logged_in? %>
0
 -->
0
- <%= post.body_html %>
0
+ <% if post.user.active? %>
0
+ <%= post.body_html %>
0
+ <% else %>
0
+ <p><% "(This post has been removed)"[:suspended_user_post] %></p>
0
+ <% end %>
0
   </td>
0
 </tr>
0
 
...
2
3
4
5
6
 
 
 
7
8
 
9
10
 
11
12
13
14
15
16
17
18
19
 
 
 
 
 
 
 
 
20
21
22
23
24
25
26
 
 
 
 
 
 
27
28
 
29
30
31
32
33
34
 
 
 
 
 
 
 
 
 
 
 
35
36
37
...
2
3
4
 
 
5
6
7
8
 
9
10
 
11
12
 
 
 
 
 
 
 
 
13
14
15
16
17
18
19
20
21
 
 
 
 
 
 
22
23
24
25
26
27
28
 
29
30
 
 
 
 
 
31
32
33
34
35
36
37
38
39
40
41
42
43
44
0
@@ -2,36 +2,43 @@
0
 
0
 <% content_for :right do -%>
0
 <% if admin? %>
0
-<% form_for @user.moderatorships.build, :html => {:class => "xdialog"} do |f| -%>
0
- <h6><%= 'Admin &amp; Moderation'[:admin_and_moderation] %></h6>
0
+<% if @user.active? %>
0
+ <% form_for @user.moderatorships.build do |f| -%>
0
+ <h6><%= 'Admin &amp; Moderation'[:admin_and_moderation] %></h6>
0
 
0
- <% unless @user.forums.empty? -%>
0
+ <% unless @user.forums.empty? -%>
0
 
0
- <p><%= 'This user can moderate the following forums. Click one to remove.'[:remove_moderated_forum] %></p>
0
+ <p><%= 'This user can moderate the following forums. Click one to remove.'[:remove_moderated_forum] %></p>
0
 
0
- <ul class="flat">
0
- <% @user.forums.find(:all, :select => "#{Forum.table_name}.*, #{Moderatorship.table_name}.id as moderatorship_id").each do |forum| -%>
0
- <li>
0
- <%= link_to forum.name, moderatorship_path(forum.moderatorship_id), :method => :delete, :confirm => "#{'Remove user as moderator for'[:remove_user_as_moderator]} #{forum.name}?" %>
0
- </li>
0
- <% end -%>
0
- </ul>
0
- <% end -%>
0
+ <ul class="flat">
0
+ <% @user.forums.find(:all, :select => "#{Forum.table_name}.*, #{Moderatorship.table_name}.id as moderatorship_id").each do |forum| -%>
0
+ <li>
0
+ <%= link_to forum.name, moderatorship_path(forum.moderatorship_id), :method => :delete, :confirm => "#{'Remove user as moderator for'[:remove_user_as_moderator]} #{forum.name}?" %>
0
+ </li>
0
+ <% end -%>
0
+ </ul>
0
+ <% end -%>
0
 
0
- <% unless @user.available_forums.empty? -%>
0
- <p>
0
- <label><%= 'Add as moderator'[] %></label><br />
0
- <%= f.select :forum_id, @user.available_forums.collect { |forum| [forum.name, forum.id] }, :include_blank => " - " %>
0
- </p>
0
- <% end -%>
0
+ <% unless @user.available_forums.empty? -%>
0
+ <p>
0
+ <label><%= 'Add as moderator'[] %></label><br />
0
+ <%= f.select :forum_id, @user.available_forums.collect { |forum| [forum.name, forum.id] }, :include_blank => " - " %>
0
+ </p>
0
+ <% end -%>
0
 
0
- <p><label><%= check_box_tag :admin, @user.admin? %> <%= 'User is an administrator'[] %></label></p>
0
+ <p><label><%= check_box_tag :admin, @user.admin? %> <%= 'User is an administrator'[] %></label></p>
0
 
0
- <p>
0
- <%= f.submit 'Save'[:save_title] %>
0
- <%= f.hidden_field :user_id %>
0
- </p>
0
-<% end -%>
0
+ <p>
0
+ <%= f.submit 'Save'[:save_title] %>
0
+ <%= f.hidden_field :user_id %>
0
+ </p>
0
+ <% end -%>
0
+ <p><%= link_to "Suspend user account", suspend_user_path(@user), :method => :put %></p>
0
+<% else %>
0
+ <p><%= "User account is suspended."[] %> <%= link_to "Unsuspend user account", unsuspend_user_path(@user), :method => :put %></p>
0
+
0
+<% end %>
0
+<p><%= link_to "Edit user account"[], edit_user_path(@user) %></p>
0
 <% end -%>
0
 <% end -%>
0
 
...
12
13
14
 
15
16
17
...
20
21
22
23
 
24
25
26
...
12
13
14
15
16
17
18
...
21
22
23
 
24
25
26
27
0
@@ -12,6 +12,7 @@ ActionController::Routing::Routes.draw do |map|
0
   map.resources :posts, :collection => {:search => :get}
0
 
0
   map.resources :users, :member => { :suspend => :put,
0
+ :settings => :get,
0
                                      :unsuspend => :put,
0
                                      :purge => :delete },
0
                         :has_many => [:posts]
0
@@ -20,7 +21,7 @@ ActionController::Routing::Routes.draw do |map|
0
   map.signup '/signup', :controller => 'users', :action => 'new'
0
   map.login '/login', :controller => 'sessions', :action => 'new'
0
   map.logout '/logout', :controller => 'sessions', :action => 'destroy'
0
- map.settings '/settings', :controller => 'users', :action => 'edit'
0
+ map.settings '/settings', :controller => 'users', :action => 'settings'
0
   map.resource :session
0
   map.root :controller => 'forums', :action => 'index'
0
 end
...
68
69
70
71
 
72
73
74
...
68
69
70
 
71
72
73
74
0
@@ -68,7 +68,7 @@ module AuthenticatedSystem
0
     end
0
     
0
     def admin_required
0
- (admin? && authorized?) || access_denied
0
+ admin? || access_denied
0
     end
0
 
0
     # Redirect as appropriate when an access request fails.

Comments

    No one has commented yet.