Commit 52ab5d7f423004db43163a0e4ce72c1f7c06fd28

Authored by Gabriela Navarro
Committed by Tallys Martins
1 parent 242a3479

user_registration: Creates task for the admin to process and cucumber test.

(ActionItem3036)

Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Signed-off-by: Wilton Rodrigues <braynwilton@gmail.com>
app/controllers/public/account_controller.rb
... ... @@ -65,7 +65,6 @@ class AccountController &lt; ApplicationController
65 65 render :text => { :ok=>true, :key=>key }.to_json
66 66 end
67 67  
68   - # action to register an user to the application
69 68 def signup
70 69 if @plugins.dispatch(:allow_user_registration).include?(false)
71 70 redirect_back_or_default(:controller => 'home')
... ... @@ -85,29 +84,40 @@ class AccountController &lt; ApplicationController
85 84 @user.return_to = session[:return_to]
86 85 @person = Person.new(params[:profile_data])
87 86 @person.environment = @user.environment
88   - if request.post?
89   - if may_be_a_bot
90   - set_signup_start_time_for_now
91   - @block_bot = true
92   - session[:may_be_a_bot] = true
93   - else
94   - if session[:may_be_a_bot]
95   - return false unless verify_recaptcha :model=>@user, :message=>_('Captcha (the human test)')
96   - end
97   - @user.community_to_join = session[:join]
98   - @user.signup!
99   - owner_role = Role.find_by_name('owner')
100   - @user.person.affiliate(@user.person, [owner_role]) if owner_role
101   - invitation = Task.find_by_code(@invitation_code)
102   - if invitation
103   - invitation.update_attributes!({:friend => @user.person})
104   - invitation.finish
105   - end
106   - if @user.activated?
107   - self.current_user = @user
108   - check_join_in_community(@user)
109   - go_to_signup_initial_page
  87 + unless @user.environment.enabled?('admin_must_approve_new_users')
  88 + if request.post?
  89 + if may_be_a_bot
  90 + set_signup_start_time_for_now
  91 + @block_bot = true
  92 + session[:may_be_a_bot] = true
110 93 else
  94 + if session[:may_be_a_bot]
  95 + return false unless verify_recaptcha :model=>@user, :message=>_('Captcha (the human test)')
  96 + end
  97 + @user.community_to_join = session[:join]
  98 + @user.signup!
  99 + owner_role = Role.find_by_name('owner')
  100 + @user.person.affiliate(@user.person, [owner_role]) if owner_role
  101 + invitation = Task.find_by_code(@invitation_code)
  102 + if invitation
  103 + invitation.update_attributes!({:friend => @user.person})
  104 + invitation.finish
  105 + end
  106 + if @user.activated?
  107 + self.current_user = @user
  108 + go_to_signup_initial_page
  109 + else
  110 + @register_pending = true
  111 + end
  112 + end
  113 + end
  114 + else
  115 + @task = CreateUser.new(params[:user])
  116 + if request.post?
  117 + @task.target = @user.environment
  118 + @task.name = @person.name
  119 + if @task.save
  120 + session[:notice] = _('Thanks for registering. The administrators were notified.')
111 121 @register_pending = true
112 122 end
113 123 end
... ...
app/models/create_user.rb 0 → 100644
... ... @@ -0,0 +1,69 @@
  1 +class CreateUser < Task
  2 +
  3 + settings_items :email, :type => String
  4 + settings_items :name, :type => String
  5 + settings_items :author_name, :type => String
  6 +
  7 + after_create :schedule_spam_checking
  8 +
  9 + alias :environment :target
  10 + alias :environment= :target=
  11 +
  12 + DATA_FIELDS = Person.fields + ['name', 'email', 'login', 'author_name', 'password', 'password_confirmation']
  13 + DATA_FIELDS.each do |field|
  14 + settings_items field.to_sym
  15 + end
  16 +
  17 + def schedule_spam_checking
  18 + self.delay.check_for_spam
  19 + end
  20 +
  21 + include Noosfero::Plugin::HotSpot
  22 +
  23 + def sender
  24 + "#{name} (#{email})"
  25 + end
  26 +
  27 + def perform
  28 + user = User.new
  29 + author_name = user.name
  30 + user_data = self.data.reject do |key, value|
  31 + ! DATA_FIELDS.include?(key.to_s)
  32 + end
  33 +
  34 + user.update_attributes(user_data)
  35 + user.environment = self.environment
  36 + user.save!
  37 + end
  38 +
  39 + def title
  40 + _("New user")
  41 + end
  42 +
  43 + def subject
  44 + name
  45 + end
  46 +
  47 + def information
  48 + { :message => _('%{sender} wants to register.'),
  49 + :variables => {:sender => sender} }
  50 + end
  51 +
  52 + def icon
  53 + result = {:type => :defined_image, :src => '/images/icons-app/person-minor.png', :name => name}
  54 + end
  55 +
  56 + def target_notification_description
  57 + _('%{sender} tried to register.') %
  58 + {:sender => sender}
  59 + end
  60 +
  61 + def target_notification_message
  62 + target_notification_description + "\n\n" +
  63 + _('You need to login on %{system} in order to approve or reject this user.') % { :environment => self.environment }
  64 + end
  65 +
  66 + def target_notification_message
  67 + _("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 }
  68 + end
  69 +end
0 70 \ No newline at end of file
... ...
features/signup.feature
... ... @@ -298,3 +298,57 @@ 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 moderate option avaliable on features panel
  304 + Given I am logged in as admin
  305 + When I follow "Administration"
  306 + And I follow "Features"
  307 + Then I should see "Admin must approve registration of new users"
  308 +
  309 + @selenium
  310 + Scenario: user registration is moderated by admin
  311 + Given feature "admin_must_approve_new_users" is enabled on environment
  312 + And feature "skip_new_user_email_confirmation" is enabled on environment
  313 + And I go to /account/signup
  314 + And I fill in "Username" with "teste"
  315 + And I fill in "Password" with "1234"
  316 + And I fill in "Password confirmation" with "1234"
  317 + And I fill in "e-Mail" with "teste@teste.com"
  318 + And I fill in "Full name" with "Teste da Silva"
  319 + And I press "Create my account"
  320 + And I am logged in as admin
  321 + And I follow "Control panel"
  322 + And I follow "Tasks"
  323 + And I choose "Accept"
  324 + And I press "Apply!"
  325 + And I follow "Logout"
  326 + And I follow "Login"
  327 + And I fill in "Username / Email" with "teste"
  328 + And I fill in "Password" with "1234"
  329 + And I press "Log in"
  330 + Then I should see "teste"
  331 +
  332 +
  333 + @selenium
  334 + Scenario: user registration is not accepted by the admin
  335 + Given feature "admin_must_approve_new_users" is enabled on environment
  336 + And feature "skip_new_user_email_confirmation" is enabled on environment
  337 + And I go to /account/signup
  338 + And I fill in "Username" with "teste"
  339 + And I fill in "Password" with "1234"
  340 + And I fill in "Password confirmation" with "1234"
  341 + And I fill in "e-Mail" with "teste@teste.com"
  342 + And I fill in "Full name" with "Teste da Silva"
  343 + And I press "Create my account"
  344 + And I am logged in as admin
  345 + And I follow "Control panel"
  346 + And I follow "Tasks"
  347 + And I choose "Reject"
  348 + And I press "Apply!"
  349 + And I follow "Logout"
  350 + And I follow "Login"
  351 + And I fill in "Username / Email" with "teste"
  352 + And I fill in "Password" with "1234"
  353 + And I press "Log in"
  354 + Then I should not see "teste"
301 355 \ No newline at end of file
... ...