Commit 8af1ea81f636672014be28b45eaad4edcb7e32b9

Authored by Tallys Martins
1 parent fa585a8c

AI3036 Fixed bugs on User Moderation

Solved code duplication that creates the Task for moderation.
Fixed the signup page to show the correct messages in case of any combination of the features "Admin Must Approve New Users" and "Skip Email Activation"

Signed-off-by: Hebert Douglas <hebertdougl@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
app/controllers/public/account_controller.rb
@@ -24,12 +24,7 @@ class AccountController &lt; ApplicationController @@ -24,12 +24,7 @@ class AccountController &lt; ApplicationController
24 render :action => 'login', :userlogin => @user.login 24 render :action => 'login', :userlogin => @user.login
25 end 25 end
26 else 26 else
27 - @task = CreateUser.new  
28 - @task.user_id = @user.id  
29 - @task.name = @user.name  
30 - @task.email =@user.email  
31 - @task.target = @user.environment  
32 - if @task.save 27 + if @user.create_moderate_task
33 session[:notice] = _('Thanks for registering. The administrators were notified.') 28 session[:notice] = _('Thanks for registering. The administrators were notified.')
34 @register_pending = true 29 @register_pending = true
35 @user.activation_code = nil 30 @user.activation_code = nil
@@ -124,10 +119,8 @@ class AccountController &lt; ApplicationController @@ -124,10 +119,8 @@ class AccountController &lt; ApplicationController
124 self.current_user = @user 119 self.current_user = @user
125 check_join_in_community(@user) 120 check_join_in_community(@user)
126 go_to_signup_initial_page 121 go_to_signup_initial_page
127 - elsif environment.enabled?('skip_new_user_email_confirmation') && environment.enabled?('admin_must_approve_new_users')  
128 - session[:notice] = _('Thanks for registering. The administrators were notified.')  
129 - redirect_to :controller => 'home', :action => 'index'  
130 else 122 else
  123 + session[:notice] = _('Thanks for registering!')
131 @register_pending = true 124 @register_pending = true
132 end 125 end
133 end 126 end
app/models/create_user.rb
@@ -21,7 +21,7 @@ class CreateUser &lt; Task @@ -21,7 +21,7 @@ class CreateUser &lt; Task
21 end 21 end
22 22
23 def perform 23 def perform
24 - user=User.find_by_id(user_id) 24 + user=environment.users.find_by_id(user_id)
25 user.activate 25 user.activate
26 end 26 end
27 27
app/models/user.rb
@@ -51,12 +51,7 @@ class User &lt; ActiveRecord::Base @@ -51,12 +51,7 @@ class User &lt; ActiveRecord::Base
51 unless user.environment.enabled?('admin_must_approve_new_users') 51 unless user.environment.enabled?('admin_must_approve_new_users')
52 user.activate 52 user.activate
53 else 53 else
54 - @task = CreateUser.new  
55 - @task.user_id = user.id  
56 - @task.name = user.name  
57 - @task.email = user.email  
58 - @task.target = user.environment  
59 - @task.save 54 + create_moderate_task
60 end 55 end
61 end 56 end
62 end 57 end
@@ -146,6 +141,15 @@ class User &lt; ActiveRecord::Base @@ -146,6 +141,15 @@ class User &lt; ActiveRecord::Base
146 end 141 end
147 end 142 end
148 143
  144 + def create_moderate_task
  145 + @task = CreateUser.new
  146 + @task.user_id = self.id
  147 + @task.name = self.name
  148 + @task.email = self.email
  149 + @task.target = self.environment
  150 + @task.save
  151 + end
  152 +
149 def activated? 153 def activated?
150 self.activation_code.nil? && !self.activated_at.nil? 154 self.activation_code.nil? && !self.activated_at.nil?
151 end 155 end
app/views/account/signup.html.erb
@@ -3,13 +3,18 @@ @@ -3,13 +3,18 @@
3 <% if environment.has_custom_welcome_screen? %> 3 <% if environment.has_custom_welcome_screen? %>
4 <%= environment.settings[:signup_welcome_screen_body].html_safe %> 4 <%= environment.settings[:signup_welcome_screen_body].html_safe %>
5 <% elsif environment.enabled?('admin_must_approve_new_users')%> 5 <% elsif environment.enabled?('admin_must_approve_new_users')%>
6 - <h1><%= _("Welcome to %s!") % environment.name %></h1> 6 + <h1><%= _("Welcome to %s!") % environment.name %></h1>
7 <h3><%= _("Thanks for signing up, we're thrilled to have you on our social network!") %></h3> 7 <h3><%= _("Thanks for signing up, we're thrilled to have you on our social network!") %></h3>
8 <p><%= _("Firstly, some tips for getting started:") %></p> 8 <p><%= _("Firstly, some tips for getting started:") %></p>
9 - <h4><%= _("Confirm your account!") %></h4>  
10 - <p><%= _("You should receive a welcome email from us shortly. Please take a second to follow the link within to confirm your account.") %></p>  
11 - <p><%= _("After your confirmation the administrators will be able to approve your signup request.") %></p>  
12 - <p><%= _("You won't appear as %s until your account is confirmed and approved.") % link_to(_('user'), {:controller => :search, :action => :people, :filter => 'more_recent'}, :target => '_blank') %></p> 9 + <% unless environment.enabled?('skip_new_user_email_confirmation') %>
  10 + <h4><%= _("Confirm your account and wait for admin approvement!") %></h4>
  11 + <p><%= _("You should receive a welcome email from us shortly. Please take a second to follow the link within to confirm your account.") %></p>
  12 + <p><%= _("You won't appear as %s until your account is confirmed and approved.") % link_to(_('user'), {:controller => :search, :action => :people, :filter => 'more_recent'}, :target => '_blank') %></p>
  13 + <% else %>
  14 + <h4><%= _("Wait for admin approvement!") %></h4>
  15 + <p><%= _("The administrators will evaluate your signup request for approvement.") %></p>
  16 + <p><%= _("You won't appear as %s until your account is approved.") % link_to(_('user'), {:controller => :search, :action => :people, :filter => 'more_recent'}, :target => '_blank') %></p>
  17 + <% end %>
13 <h4><%= _("What to do next?") %></h4> 18 <h4><%= _("What to do next?") %></h4>
14 <p><%= _("%s. Upload an avatar and let your friends find you easily :)") % link_to(_('Customize your profile'), {:controller => 'doc', :section => 'user', :topic => 'editing-person-info'}, :target => '_blank') %></p> 19 <p><%= _("%s. Upload an avatar and let your friends find you easily :)") % link_to(_('Customize your profile'), {:controller => 'doc', :section => 'user', :topic => 'editing-person-info'}, :target => '_blank') %></p>
15 <p><%= _("Learn the guidelines. Read the %s for more details on how to use this social network!") % link_to(_('Documentation'), {:controller => 'doc'}, :target => '_blank') %></p> 20 <p><%= _("Learn the guidelines. Read the %s for more details on how to use this social network!") % link_to(_('Documentation'), {:controller => 'doc'}, :target => '_blank') %></p>