Commit 32968c83e976e3ffbb3e074685d0174aa6ae5035

Authored by Victor Costa
2 parents 7f7efef1 f9358611

Merge branch 'master' into rails3_stable

app/controllers/public/account_controller.rb
... ... @@ -15,11 +15,23 @@ class AccountController < ApplicationController
15 15  
16 16 def activate
17 17 @user = User.find_by_activation_code(params[:activation_code]) if params[:activation_code]
18   - if @user and @user.activate
19   - @message = _("Your account has been activated, now you can log in!")
20   - check_redirection
21   - session[:join] = params[:join] unless params[:join].blank?
22   - render :action => 'login', :userlogin => @user.login
  18 + if @user
  19 + unless @user.environment.enabled?('admin_must_approve_new_users')
  20 + if @user.activate
  21 + @message = _("Your account has been activated, now you can log in!")
  22 + check_redirection
  23 + session[:join] = params[:join] unless params[:join].blank?
  24 + render :action => 'login', :userlogin => @user.login
  25 + end
  26 + else
  27 + if @user.create_moderate_task
  28 + session[:notice] = _('Thanks for registering. The administrators were notified.')
  29 + @register_pending = true
  30 + @user.activation_code = nil
  31 + @user.save!
  32 + redirect_to :controller => :home
  33 + end
  34 + end
23 35 else
24 36 session[:notice] = _("It looks like you're trying to activate an account. Perhaps have already activated this account?")
25 37 redirect_to :controller => :home
... ... @@ -108,6 +120,7 @@ class AccountController < ApplicationController
108 120 check_join_in_community(@user)
109 121 go_to_signup_initial_page
110 122 else
  123 + session[:notice] = _('Thanks for registering!')
111 124 @register_pending = true
112 125 end
113 126 end
... ...
app/models/environment.rb
... ... @@ -124,6 +124,7 @@ class Environment < ActiveRecord::Base
124 124 'organizations_are_moderated_by_default' => _("Organizations have moderated publication by default"),
125 125 'enable_organization_url_change' => _("Allow organizations to change their URL"),
126 126 'admin_must_approve_new_communities' => _("Admin must approve creation of communities"),
  127 + 'admin_must_approve_new_users' => _("Admin must approve registration of new users"),
127 128 'show_balloon_with_profile_links_when_clicked' => _('Show a balloon with profile links when a profile image is clicked'),
128 129 'xmpp_chat' => _('XMPP/Jabber based chat'),
129 130 'show_zoom_button_on_article_images' => _('Show a zoom link on all article images'),
... ...
app/models/moderate_user_registration.rb 0 → 100644
... ... @@ -0,0 +1,59 @@
  1 +class ModerateUserRegistration < Task
  2 +
  3 + settings_items :user_id, :type => String
  4 + settings_items :name, :type => String
  5 + settings_items :author_name, :type => String
  6 + settings_items :email, :type => String
  7 +
  8 + after_create :schedule_spam_checking
  9 +
  10 + alias :environment :target
  11 + alias :environment= :target=
  12 +
  13 + def schedule_spam_checking
  14 + self.delay.check_for_spam
  15 + end
  16 +
  17 + include Noosfero::Plugin::HotSpot
  18 +
  19 + def sender
  20 + "#{name} (#{email})"
  21 + end
  22 +
  23 + def perform
  24 + user=environment.users.find_by_id(user_id)
  25 + user.activate
  26 + end
  27 +
  28 + def title
  29 + _("New user")
  30 + end
  31 +
  32 + def subject
  33 + name
  34 + end
  35 +
  36 + def information
  37 + { :message => _('%{sender} wants to register.'),
  38 + :variables => {:sender => sender} }
  39 + end
  40 +
  41 + def icon
  42 + result = {:type => :defined_image, :src => '/images/icons-app/person-minor.png', :name => name}
  43 + end
  44 +
  45 + def target_notification_description
  46 + _('%{sender} tried to register.') %
  47 + {:sender => sender}
  48 + end
  49 +
  50 + def target_notification_message
  51 + target_notification_description + "\n\n" +
  52 + _('You need to login on %{system} in order to approve or reject this user.') % { :environment => self.environment }
  53 + end
  54 +
  55 + def target_notification_message
  56 + _("User \"%{user}\" just requested to register. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :user => self.name }
  57 + end
  58 +
  59 +end
0 60 \ No newline at end of file
... ...
app/models/user.rb
... ... @@ -48,8 +48,12 @@ class User &lt; ActiveRecord::Base
48 48  
49 49 user.person = p
50 50 end
51   - if user.environment.enabled?('skip_new_user_email_confirmation')
52   - user.activate
  51 + if user.environment.enabled?('skip_new_user_email_confirmation')
  52 + if user.environment.enabled?('admin_must_approve_new_users')
  53 + create_moderate_task
  54 + else
  55 + user.activate
  56 + end
53 57 end
54 58 end
55 59 after_create :deliver_activation_code
... ... @@ -150,6 +154,15 @@ class User &lt; ActiveRecord::Base
150 154 end
151 155 end
152 156  
  157 + def create_moderate_task
  158 + @task = ModerateUserRegistration.new
  159 + @task.user_id = self.id
  160 + @task.name = self.name
  161 + @task.email = self.email
  162 + @task.target = self.environment
  163 + @task.save
  164 + end
  165 +
153 166 def activated?
154 167 self.activation_code.nil? && !self.activated_at.nil?
155 168 end
... ...
app/views/account/signup.html.erb
... ... @@ -2,18 +2,36 @@
2 2 <div id='thanks-for-signing'>
3 3 <% if environment.has_custom_welcome_screen? %>
4 4 <%= environment.settings[:signup_welcome_screen_body].html_safe %>
5   - <% else %>
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>
8   - <p><%= _("Firstly, some tips for getting started:") %></p>
9   - <h4><%= _("Confirm your account!") %></h4>
  5 + <% elsif environment.enabled?('admin_must_approve_new_users')%>
  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>
  8 + <p><%= _("Firstly, some tips for getting started:") %></p>
  9 + <% unless environment.enabled?('skip_new_user_email_confirmation') %>
  10 + <h4><%= _("Confirm your account and wait for admin approvement!") %></h4>
10 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>
11   - <p><%= _("You won't appear as %s until your account is confirmed.") % link_to(_('user'), {:controller => :search, :action => :people, :filter => 'more_recent'}, :target => '_blank') %></p>
12   - <h4><%= _("What to do next?") %></h4>
13   - <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>
14   - <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>
15   - <p><%= _("%s your Gmail, Yahoo and Hotmail contacts!") % link_to(_('Invite and find'), {:controller => 'doc', :section => 'user', :topic => 'invite-contacts'}, :target => '_blank') %></p>
16   - <p><%= _("Start exploring and have fun!") %></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 %>
  18 + <h4><%= _("What to do next?") %></h4>
  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>
  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>
  21 + <p><%= _("%s your Gmail, Yahoo and Hotmail contacts!") % link_to(_('Invite and find'), {:controller => 'doc', :section => 'user', :topic => 'invite-contacts'}, :target => '_blank') %></p>
  22 + <p><%= _("Start exploring and have fun!") %></p>
  23 + <% else %>
  24 + <h1><%= _("Welcome to %s!") % environment.name %></h1>
  25 + <h3><%= _("Thanks for signing up, we're thrilled to have you on our social network!") %></h3>
  26 + <p><%= _("Firstly, some tips for getting started:") %></p>
  27 + <h4><%= _("Confirm your account!") %></h4>
  28 + <p><%= _("You should receive a welcome email from us shortly. Please take a second to follow the link within to confirm your account.") %></p>
  29 + <p><%= _("You won't appear as %s until your account is confirmed.") % link_to(_('user'), {:controller => :search, :action => :people, :filter => 'more_recent'}, :target => '_blank') %></p>
  30 + <h4><%= _("What to do next?") %></h4>
  31 + <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>
  32 + <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>
  33 + <p><%= _("%s your Gmail, Yahoo and Hotmail contacts!") % link_to(_('Invite and find'), {:controller => 'doc', :section => 'user', :topic => 'invite-contacts'}, :target => '_blank') %></p>
  34 + <p><%= _("Start exploring and have fun!") %></p>
17 35 <% end %>
18 36 </div>
19 37 <% else %>
... ...
config/initializers/passenger.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +if defined? PhusionPassenger
  2 +
  3 + # from http://russbrooks.com/2010/10/20/rails-cache-memcache-on-passenger-with-smart-spawning
  4 + PhusionPassenger.on_event :starting_worker_process do |forked|
  5 + if forked
  6 + Rails.cache.instance_variable_get(:@data).reset if Rails.cache.class == ActiveSupport::Cache::MemCacheStore
  7 + end
  8 + end
  9 +end
... ...
features/signup.feature
... ... @@ -298,3 +298,55 @@ Feature: signup
298 298 And wait for the captcha signup time
299 299 And I press "Create my account"
300 300 Then "José da Silva" should be a member of "Free Software"
  301 +
  302 + @selenium
  303 + Scenario: user registration is moderated by admin
  304 + Given feature "admin_must_approve_new_users" is enabled on environment
  305 + And feature "skip_new_user_email_confirmation" is disabled on environment
  306 + And I go to /account/signup
  307 + And I fill in "Username" with "teste"
  308 + And I fill in "Password" with "123456"
  309 + And I fill in "Password confirmation" with "123456"
  310 + And I fill in "e-Mail" with "teste@teste.com"
  311 + And I fill in "Full name" with "Teste da Silva"
  312 + And wait for the captcha signup time
  313 + And I press "Create my account"
  314 + And I go to teste's confirmation URL
  315 + And I am logged in as admin
  316 + And I follow "Control panel"
  317 + And I follow "Tasks"
  318 + And I choose "Accept"
  319 + And I press "Apply!"
  320 + And I follow "Logout"
  321 + And Teste da Silva's account is activated
  322 + And I follow "Login"
  323 + And I fill in "Username / Email" with "teste"
  324 + And I fill in "Password" with "123456"
  325 + And I press "Log in"
  326 + Then I should see "teste"
  327 +
  328 +
  329 + @selenium
  330 + Scenario: user registration is not accepted by the admin
  331 + Given feature "admin_must_approve_new_users" is enabled on environment
  332 + And feature "skip_new_user_email_confirmation" is disabled on environment
  333 + And I go to /account/signup
  334 + And I fill in "Username" with "teste"
  335 + And I fill in "Password" with "123456"
  336 + And I fill in "Password confirmation" with "123456"
  337 + And I fill in "e-Mail" with "teste@teste.com"
  338 + And I fill in "Full name" with "Teste da Silva"
  339 + And wait for the captcha signup time
  340 + And I press "Create my account"
  341 + And I go to teste's confirmation URL
  342 + And I am logged in as admin
  343 + And I follow "Control panel"
  344 + And I follow "Tasks"
  345 + And I choose "Reject"
  346 + And I press "Apply!"
  347 + And I follow "Logout"
  348 + And I follow "Login"
  349 + And I fill in "Username / Email" with "teste"
  350 + And I fill in "Password" with "123456"
  351 + And I press "Log in"
  352 + Then I should not see "teste"
301 353 \ No newline at end of file
... ...
po/pt/noosfero.po
... ... @@ -13,7 +13,7 @@ msgid &quot;&quot;
13 13 msgstr ""
14 14 "Project-Id-Version: noosfero 0.47.1\n"
15 15 "POT-Creation-Date: 2014-06-05 20:27-0000\n"
16   -"PO-Revision-Date: 2014-08-19 10:30-0300\n"
  16 +"PO-Revision-Date: 2014-08-22 11:19-0300\n"
17 17 "Last-Translator: Rodrigo Souto <rodrigo@colivre.coop.br>\n"
18 18 "Language-Team: Noosfero Develeopers <noosfero-dev@listas.softwarelivre.org>\n"
19 19 "Language: pt\n"
... ... @@ -8925,7 +8925,7 @@ msgstr &quot;Boas vindas ao ambiente %s&quot;
8925 8925 msgid ""
8926 8926 "Thanks for signing up, we're thrilled to have you on our social network!"
8927 8927 msgstr ""
8928   -"Obrigado por se registrar! Agora verifique seu e-mail para ativar sua conta!"
  8928 +"Obrigado por se registrar, estamos empolgados de ter você na nossa rede social!"
8929 8929  
8930 8930 #: app/views/account/signup.rhtml:5
8931 8931 msgid "Firstly, some tips for getting started:"
... ...
test/unit/moderate_user_registration_test.rb 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +# encoding: UTF-8
  2 +require File.dirname(__FILE__) + '/../test_helper'
  3 +
  4 +class ModerateUserRegistrationTest < ActiveSupport::TestCase
  5 + fixtures :users, :environments
  6 +
  7 + def test_should_on_perform_activate_user
  8 + user = User.new(:login => 'lalala', :email => 'lalala@example.com', :password => 'test', :password_confirmation => 'test')
  9 + user.save!
  10 + environment = Environment.default
  11 + t= ModerateUserRegistration.new
  12 + t.user_id = user.id
  13 + t.name = user.name
  14 + t.author_name = user.name
  15 + t.email = user.email
  16 + t.target= environment
  17 + t.save!
  18 + assert !user.activated?
  19 + t.perform
  20 + assert environment.users.find_by_id(user.id).activated?
  21 + end
  22 +end
... ...
vendor/plugins/delayed_job/lib/delayed/command.rb
... ... @@ -97,7 +97,7 @@ module Delayed
97 97 Dir.chdir(Rails.root)
98 98  
99 99 Delayed::Worker.after_fork
100   - Delayed::Worker.logger ||= Logger.new(File.join(Rails.root, 'log', 'delayed_job.log'))
  100 + Delayed::Worker.logger = Logger.new(File.join(Rails.root, 'log', "#{Rails.env}_delayed_job.log"))
101 101  
102 102 worker = Delayed::Worker.new(@options)
103 103 worker.name_prefix = "#{worker_name} "
... ...