From 52ab5d7f423004db43163a0e4ce72c1f7c06fd28 Mon Sep 17 00:00:00 2001 From: Gabriela Navarro Date: Tue, 1 Apr 2014 08:39:45 -0300 Subject: [PATCH] user_registration: Creates task for the admin to process and cucumber test. --- app/controllers/public/account_controller.rb | 56 +++++++++++++++++++++++++++++++++----------------------- app/models/create_user.rb | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ features/signup.feature | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 23 deletions(-) create mode 100644 app/models/create_user.rb diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index a02b28b..d8434e6 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -65,7 +65,6 @@ class AccountController < ApplicationController render :text => { :ok=>true, :key=>key }.to_json end - # action to register an user to the application def signup if @plugins.dispatch(:allow_user_registration).include?(false) redirect_back_or_default(:controller => 'home') @@ -85,29 +84,40 @@ class AccountController < ApplicationController @user.return_to = session[:return_to] @person = Person.new(params[:profile_data]) @person.environment = @user.environment - if request.post? - if may_be_a_bot - set_signup_start_time_for_now - @block_bot = true - session[:may_be_a_bot] = true - else - if session[:may_be_a_bot] - return false unless verify_recaptcha :model=>@user, :message=>_('Captcha (the human test)') - end - @user.community_to_join = session[:join] - @user.signup! - owner_role = Role.find_by_name('owner') - @user.person.affiliate(@user.person, [owner_role]) if owner_role - invitation = Task.find_by_code(@invitation_code) - if invitation - invitation.update_attributes!({:friend => @user.person}) - invitation.finish - end - if @user.activated? - self.current_user = @user - check_join_in_community(@user) - go_to_signup_initial_page + unless @user.environment.enabled?('admin_must_approve_new_users') + if request.post? + if may_be_a_bot + set_signup_start_time_for_now + @block_bot = true + session[:may_be_a_bot] = true else + if session[:may_be_a_bot] + return false unless verify_recaptcha :model=>@user, :message=>_('Captcha (the human test)') + end + @user.community_to_join = session[:join] + @user.signup! + owner_role = Role.find_by_name('owner') + @user.person.affiliate(@user.person, [owner_role]) if owner_role + invitation = Task.find_by_code(@invitation_code) + if invitation + invitation.update_attributes!({:friend => @user.person}) + invitation.finish + end + if @user.activated? + self.current_user = @user + go_to_signup_initial_page + else + @register_pending = true + end + end + end + else + @task = CreateUser.new(params[:user]) + if request.post? + @task.target = @user.environment + @task.name = @person.name + if @task.save + session[:notice] = _('Thanks for registering. The administrators were notified.') @register_pending = true end end diff --git a/app/models/create_user.rb b/app/models/create_user.rb new file mode 100644 index 0000000..5a44126 --- /dev/null +++ b/app/models/create_user.rb @@ -0,0 +1,69 @@ +class CreateUser < Task + + settings_items :email, :type => String + settings_items :name, :type => String + settings_items :author_name, :type => String + + after_create :schedule_spam_checking + + alias :environment :target + alias :environment= :target= + + DATA_FIELDS = Person.fields + ['name', 'email', 'login', 'author_name', 'password', 'password_confirmation'] + DATA_FIELDS.each do |field| + settings_items field.to_sym + end + + def schedule_spam_checking + self.delay.check_for_spam + end + + include Noosfero::Plugin::HotSpot + + def sender + "#{name} (#{email})" + end + + def perform + user = User.new + author_name = user.name + user_data = self.data.reject do |key, value| + ! DATA_FIELDS.include?(key.to_s) + end + + user.update_attributes(user_data) + user.environment = self.environment + user.save! + end + + def title + _("New user") + end + + def subject + name + end + + def information + { :message => _('%{sender} wants to register.'), + :variables => {:sender => sender} } + end + + def icon + result = {:type => :defined_image, :src => '/images/icons-app/person-minor.png', :name => name} + end + + def target_notification_description + _('%{sender} tried to register.') % + {:sender => sender} + end + + def target_notification_message + target_notification_description + "\n\n" + + _('You need to login on %{system} in order to approve or reject this user.') % { :environment => self.environment } + end + + def target_notification_message + _("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 } + end +end \ No newline at end of file diff --git a/features/signup.feature b/features/signup.feature index da6fa8f..4b57f73 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -298,3 +298,57 @@ Feature: signup And wait for the captcha signup time And I press "Create my account" Then "José da Silva" should be a member of "Free Software" + + @selenium + Scenario: user registration moderate option avaliable on features panel + Given I am logged in as admin + When I follow "Administration" + And I follow "Features" + Then I should see "Admin must approve registration of new users" + + @selenium + Scenario: user registration is moderated by admin + Given feature "admin_must_approve_new_users" is enabled on environment + And feature "skip_new_user_email_confirmation" is enabled on environment + And I go to /account/signup + And I fill in "Username" with "teste" + And I fill in "Password" with "1234" + And I fill in "Password confirmation" with "1234" + And I fill in "e-Mail" with "teste@teste.com" + And I fill in "Full name" with "Teste da Silva" + And I press "Create my account" + And I am logged in as admin + And I follow "Control panel" + And I follow "Tasks" + And I choose "Accept" + And I press "Apply!" + And I follow "Logout" + And I follow "Login" + And I fill in "Username / Email" with "teste" + And I fill in "Password" with "1234" + And I press "Log in" + Then I should see "teste" + + + @selenium + Scenario: user registration is not accepted by the admin + Given feature "admin_must_approve_new_users" is enabled on environment + And feature "skip_new_user_email_confirmation" is enabled on environment + And I go to /account/signup + And I fill in "Username" with "teste" + And I fill in "Password" with "1234" + And I fill in "Password confirmation" with "1234" + And I fill in "e-Mail" with "teste@teste.com" + And I fill in "Full name" with "Teste da Silva" + And I press "Create my account" + And I am logged in as admin + And I follow "Control panel" + And I follow "Tasks" + And I choose "Reject" + And I press "Apply!" + And I follow "Logout" + And I follow "Login" + And I fill in "Username / Email" with "teste" + And I fill in "Password" with "1234" + And I press "Log in" + Then I should not see "teste" \ No newline at end of file -- libgit2 0.21.2