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 24 render :action => 'login', :userlogin => @user.login
25 25 end
26 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 28 session[:notice] = _('Thanks for registering. The administrators were notified.')
34 29 @register_pending = true
35 30 @user.activation_code = nil
... ... @@ -124,10 +119,8 @@ class AccountController &lt; ApplicationController
124 119 self.current_user = @user
125 120 check_join_in_community(@user)
126 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 122 else
  123 + session[:notice] = _('Thanks for registering!')
131 124 @register_pending = true
132 125 end
133 126 end
... ...
app/models/create_user.rb
... ... @@ -21,7 +21,7 @@ class CreateUser &lt; Task
21 21 end
22 22  
23 23 def perform
24   - user=User.find_by_id(user_id)
  24 + user=environment.users.find_by_id(user_id)
25 25 user.activate
26 26 end
27 27  
... ...
app/models/user.rb
... ... @@ -51,12 +51,7 @@ class User &lt; ActiveRecord::Base
51 51 unless user.environment.enabled?('admin_must_approve_new_users')
52 52 user.activate
53 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 55 end
61 56 end
62 57 end
... ... @@ -146,6 +141,15 @@ class User &lt; ActiveRecord::Base
146 141 end
147 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 153 def activated?
150 154 self.activation_code.nil? && !self.activated_at.nil?
151 155 end
... ...
app/views/account/signup.html.erb
... ... @@ -3,13 +3,18 @@
3 3 <% if environment.has_custom_welcome_screen? %>
4 4 <%= environment.settings[:signup_welcome_screen_body].html_safe %>
5 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 7 <h3><%= _("Thanks for signing up, we're thrilled to have you on our social network!") %></h3>
8 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 18 <h4><%= _("What to do next?") %></h4>
14 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 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>
... ...