From: Jan Provaznik jprovazn@redhat.com
--- src/app/controllers/users_controller.rb | 1 + src/app/services/registration_service.rb | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/app/controllers/users_controller.rb b/src/app/controllers/users_controller.rb index 19828db..b9d290a 100644 --- a/src/app/controllers/users_controller.rb +++ b/src/app/controllers/users_controller.rb @@ -34,6 +34,7 @@ class UsersController < ApplicationController flash[:notice] = "User registered!" redirect_back_or_default user_url(@user) else + flash[:warning] = "user registration failed: #{@registration.error}" render :action => :new end end diff --git a/src/app/services/registration_service.rb b/src/app/services/registration_service.rb index 2083803..37444ad 100644 --- a/src/app/services/registration_service.rb +++ b/src/app/services/registration_service.rb @@ -1,11 +1,16 @@ class RegistrationService + attr_reader :error
def initialize(user) @user = user end
def save - return false unless valid? + unless valid? + @error = "validation failed" + return false + end + begin User.transaction do @user.save! @@ -17,11 +22,17 @@ class RegistrationService @pool.quota_id = @quota.id @pool.save!
+ raise "Role 'Instance Creator and User' doesn't exist" unless + role = Role.find_by_name("Instance Creator and User") + Permission.create!({:user => @user, - :role => Role.find_by_name("Instance Creator and User"), + :role => role, :permission_object => @pool}) end rescue + Rails.logger.error $!.message + Rails.logger.error $!.backtrace.join("\n ") + @error = $!.message false end end
From: Jan Provaznik jprovazn@redhat.com
--- src/features/authentication.feature | 18 ++++++++++++++++++ src/features/step_definitions/authentication.rb | 4 ++++ 2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/src/features/authentication.feature b/src/features/authentication.feature index 12e217b..2527c64 100644 --- a/src/features/authentication.feature +++ b/src/features/authentication.feature @@ -21,6 +21,24 @@ Feature: User authentication And I should see "User registered!" And I should have one private pool named "testuser"
+ @register + Scenario: Register as new user fails even if user is valid + Given I am on the homepage + And there are not any roles + When I follow "Create one now" + Then I should be on the new account page + And I should see "New Account" + When I fill in the following: + | Choose a username | testuser | + | Choose a password | secret | + | Confirm password | secret | + | First name | Joe | + | Last name | Tester | + | Email | testuser@example.com | + And I press "Create Account" + Then I should see "New Account" + And I should see "user registration failed" + Scenario: Log in as registered user Given I am a registered user And I am on the login page diff --git a/src/features/step_definitions/authentication.rb b/src/features/step_definitions/authentication.rb index c0d581d..0c72146 100644 --- a/src/features/step_definitions/authentication.rb +++ b/src/features/step_definitions/authentication.rb @@ -23,6 +23,10 @@ Given /^I am logged in$/ do UserSession.find.should_not == nil end
+Given /^there are not any roles$/ do + Role.destroy_all +end + When /^I forget to enter my password$/ do login(user.login, nil) end
ACK
----- Original Message ----- From: jprovazn@redhat.com To: deltacloud-devel@lists.fedorahosted.org Sent: Tuesday, August 17, 2010 3:25:48 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna Subject: [deltacloud-devel] [PATCH aggregator] Cucumber test: Bug 619838 - display errors when user registration fails
From: Jan Provaznik jprovazn@redhat.com
--- src/features/authentication.feature | 18 ++++++++++++++++++ src/features/step_definitions/authentication.rb | 4 ++++ 2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/src/features/authentication.feature b/src/features/authentication.feature index 12e217b..2527c64 100644 --- a/src/features/authentication.feature +++ b/src/features/authentication.feature @@ -21,6 +21,24 @@ Feature: User authentication And I should see "User registered!" And I should have one private pool named "testuser"
+ @register + Scenario: Register as new user fails even if user is valid + Given I am on the homepage + And there are not any roles + When I follow "Create one now" + Then I should be on the new account page + And I should see "New Account" + When I fill in the following: + | Choose a username | testuser | + | Choose a password | secret | + | Confirm password | secret | + | First name | Joe | + | Last name | Tester | + | Email | testuser@example.com | + And I press "Create Account" + Then I should see "New Account" + And I should see "user registration failed" + Scenario: Log in as registered user Given I am a registered user And I am on the login page diff --git a/src/features/step_definitions/authentication.rb b/src/features/step_definitions/authentication.rb index c0d581d..0c72146 100644 --- a/src/features/step_definitions/authentication.rb +++ b/src/features/step_definitions/authentication.rb @@ -23,6 +23,10 @@ Given /^I am logged in$/ do UserSession.find.should_not == nil end
+Given /^there are not any roles$/ do + Role.destroy_all +end + When /^I forget to enter my password$/ do login(user.login, nil) end
ACK
----- Original Message ----- From: jprovazn@redhat.com To: deltacloud-devel@lists.fedorahosted.org Sent: Tuesday, August 10, 2010 3:20:31 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna Subject: [deltacloud-devel] [PATCH aggregator] Fixed Bug 619838 - display errors when user registration fails
From: Jan Provaznik jprovazn@redhat.com
--- src/app/controllers/users_controller.rb | 1 + src/app/services/registration_service.rb | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/app/controllers/users_controller.rb b/src/app/controllers/users_controller.rb index 19828db..b9d290a 100644 --- a/src/app/controllers/users_controller.rb +++ b/src/app/controllers/users_controller.rb @@ -34,6 +34,7 @@ class UsersController < ApplicationController flash[:notice] = "User registered!" redirect_back_or_default user_url(@user) else + flash[:warning] = "user registration failed: #{@registration.error}" render :action => :new end end diff --git a/src/app/services/registration_service.rb b/src/app/services/registration_service.rb index 2083803..37444ad 100644 --- a/src/app/services/registration_service.rb +++ b/src/app/services/registration_service.rb @@ -1,11 +1,16 @@ class RegistrationService + attr_reader :error
def initialize(user) @user = user end
def save - return false unless valid? + unless valid? + @error = "validation failed" + return false + end + begin User.transaction do @user.save! @@ -17,11 +22,17 @@ class RegistrationService @pool.quota_id = @quota.id @pool.save!
+ raise "Role 'Instance Creator and User' doesn't exist" unless + role = Role.find_by_name("Instance Creator and User") + Permission.create!({:user => @user, - :role => Role.find_by_name("Instance Creator and User"), + :role => role, :permission_object => @pool}) end rescue + Rails.logger.error $!.message + Rails.logger.error $!.backtrace.join("\n ") + @error = $!.message false end end
deltacloud-devel@lists.fedorahosted.org