Commit 1400bce512c89493ee0d94680fb6b4b7ba766f34
Exists in
staging
and in
2 other branches
Merge branch 'master' into staging
Conflicts: plugins/oauth_client/Gemfile plugins/oauth_client/lib/ext/user.rb
Showing
5 changed files
with
37 additions
and
42 deletions
Show diff stats
app/views/shared/_organization_custom_fields.html.erb
... | ... | @@ -30,6 +30,4 @@ |
30 | 30 | <%= optional_field(profile, 'foundation_year', f.text_field(:foundation_year)) %> |
31 | 31 | <% end %> |
32 | 32 | |
33 | -<%= render :partial => 'shared/custom_fields', :locals => {:f => f, :profile => profile, :signup => true} %> | |
34 | - | |
35 | 33 | <%= javascript_include_tag('city_state_validation') %> | ... | ... |
plugins/oauth_client/Gemfile
plugins/oauth_client/lib/ext/user.rb
... | ... | @@ -6,15 +6,28 @@ class User |
6 | 6 | has_many :oauth_providers, through: :oauth_auths, source: :provider |
7 | 7 | |
8 | 8 | after_create :activate_oauth_user |
9 | + after_create :store_oauth_providers | |
10 | + | |
11 | + def initialize_with_oauth_client(attributes = {}, options = {}) | |
12 | + @oauth_providers = attributes.delete(:oauth_providers) || [] | |
13 | + initialize_without_oauth_client(attributes, options) | |
14 | + end | |
15 | + alias_method_chain :initialize, :oauth_client | |
16 | + | |
17 | + def store_oauth_providers | |
18 | + @oauth_providers.each do |provider| | |
19 | + self.person.oauth_auths.create!(profile: self.person, provider: provider, enabled: true) | |
20 | + end | |
21 | + end | |
9 | 22 | |
10 | 23 | def activate_oauth_user |
11 | - self.activate if oauth_providers.present? | |
24 | + self.activate if oauth_providers.present? || @oauth_providers.present? | |
12 | 25 | end |
13 | 26 | |
14 | 27 | def password_required_with_oauth? |
15 | 28 | # user creation through api does not set oauth_providers |
16 | 29 | check_providers |
17 | - password_required_without_oauth? && oauth_providers.empty? | |
30 | + password_required_without_oauth? && oauth_providers.empty? && @oauth_providers.blank? | |
18 | 31 | end |
19 | 32 | |
20 | 33 | def oauth_data |
... | ... | @@ -29,37 +42,21 @@ class User |
29 | 42 | @oauth_signup_token |
30 | 43 | end |
31 | 44 | |
32 | - alias_method_chain :password_required?, :oauth | |
33 | - | |
34 | - after_create :activate_oauth_user | |
35 | - | |
36 | 45 | # user creation through api does not set oauth_providers |
37 | 46 | # so it is being shared through a distributed cache |
38 | 47 | def check_providers |
39 | 48 | if oauth_providers.empty? && oauth_signup_token.present? |
40 | 49 | #check if is oauth user, reading oauth_data recorded at cache store |
41 | 50 | @oauth_data = OauthClientPlugin::SignupDataStore.get_oauth_data(self.email, self.oauth_signup_token) |
42 | - if @oauth_data | |
43 | - provider_id = @oauth_data.delete(:provider_id) | |
44 | - self.oauth_providers = [OauthClientPlugin::Provider.find(provider_id)] | |
45 | - end | |
51 | + provider_id = (@oauth_data || {}).delete(:provider_id) | |
52 | + @oauth_providers = [OauthClientPlugin::Provider.find(provider_id)] if provider_id.present? | |
46 | 53 | end |
47 | 54 | end |
48 | 55 | |
49 | - def activate_oauth_user | |
50 | - self.oauth_providers.each do |provider| | |
51 | - OauthClientPlugin::Auth.create! do |user_provider| | |
52 | - user_provider.profile = self.person | |
53 | - user_provider.provider = provider | |
54 | - user_provider.enabled = true | |
55 | - user_provider.oauth_data = oauth_data | |
56 | - end | |
57 | - end | |
58 | - activate unless oauth_providers.empty? | |
59 | - end | |
56 | + alias_method_chain :password_required?, :oauth | |
60 | 57 | |
61 | 58 | def make_activation_code_with_oauth |
62 | - self.oauth_providers.blank? ? make_activation_code_without_oauth : nil | |
59 | + @oauth_providers.blank? && oauth_providers.blank? ? make_activation_code_without_oauth : nil | |
63 | 60 | end |
64 | 61 | |
65 | 62 | alias_method_chain :make_activation_code, :oauth | ... | ... |
plugins/oauth_client/test/unit/user_test.rb
... | ... | @@ -11,6 +11,11 @@ class UserTest < ActiveSupport::TestCase |
11 | 11 | User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [provider]) |
12 | 12 | end |
13 | 13 | |
14 | + should 'associate the oauth provider with the created user' do | |
15 | + user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [provider]) | |
16 | + assert_equal user.oauth_providers.reload, [provider] | |
17 | + end | |
18 | + | |
14 | 19 | should 'password is required if there is a oauth provider' do |
15 | 20 | user = User.new(:email => 'testoauth@example.com', :login => 'testoauth') |
16 | 21 | user.save | ... | ... |
plugins/recent_content/features/add_recent_content.feature
... | ... | @@ -27,24 +27,21 @@ Background: |
27 | 27 | And I am logged in as "joaosilva" |
28 | 28 | Given I go to joaosilva's control panel |
29 | 29 | And I follow "Edit sideboxes" |
30 | - And I follow "Add a block" | |
31 | - And I choose "Recent content" | |
32 | - And I press "Add" | |
33 | 30 | |
34 | 31 | Scenario: the block is being displayed |
35 | 32 | Then I should see "This is the recent content block. Please edit it to show the content you want." |
36 | 33 | |
37 | 34 | Scenario: a user should be redirected to the post page when the link is clicked |
38 | - When I follow "Edit" within ".recent-content-block" | |
35 | + When I follow "Edit" within ".block.recent-content-block" | |
39 | 36 | And I select "JSilva blog" from "Choose which blog should be displayed" |
40 | 37 | And I select "Title only" from "Choose how the content should be displayed" |
41 | 38 | And I fill in "Choose how many items will be displayed" with "3" |
42 | 39 | And I press "Save" |
43 | - And I follow "post #4" within ".recent-content-block" | |
40 | + And I follow "post #4" within ".block.recent-content-block" | |
44 | 41 | Then I should be on /joaosilva/jsilva-blog/post-4 |
45 | 42 | |
46 | 43 | Scenario: a user should be redirected to the blog page when the "view all" is clicked |
47 | - When I follow "Edit" within ".recent-content-block" | |
44 | + When I follow "Edit" within ".block.recent-content-block" | |
48 | 45 | And I select "JSilva blog" from "Choose which blog should be displayed" |
49 | 46 | And I select "Title only" from "Choose how the content should be displayed" |
50 | 47 | And I fill in "Choose how many items will be displayed" with "2" |
... | ... | @@ -53,39 +50,38 @@ Background: |
53 | 50 | Then I should be on /joaosilva/jsilva-blog |
54 | 51 | |
55 | 52 | Scenario: a user should see only titles if the block was configured for it |
56 | - When I follow "Edit" within ".recent-content-block" | |
53 | + When I follow "Edit" within ".block.recent-content-block" | |
57 | 54 | And I select "JSilva blog" from "Choose which blog should be displayed" |
58 | 55 | And I select "Title only" from "Choose how the content should be displayed" |
59 | 56 | And I fill in "Choose how many items will be displayed" with "3" |
60 | 57 | And I press "Save" |
61 | - Then I should see "post #6" within ".recent-content-block" | |
58 | + Then I should see "post #6" within ".block.recent-content-block" | |
62 | 59 | |
63 | 60 | Scenario: a user should see titles and abstract if the block was configured for it |
64 | - When I follow "Edit" within ".recent-content-block" | |
61 | + When I follow "Edit" within ".block.recent-content-block" | |
65 | 62 | And I select "JSilva blog" from "Choose which blog should be displayed" |
66 | 63 | And I select "Title and abstract" from "Choose how the content should be displayed" |
67 | 64 | And I fill in "Choose how many items will be displayed" with "6" |
68 | 65 | And I press "Save" |
69 | - Then I should see "Resumo 5" within ".recent-content-block" | |
66 | + Then I should see "Resumo 5" within ".block.recent-content-block" | |
70 | 67 | |
71 | 68 | Scenario: a user should see full content if the block was configured for it |
72 | - When I follow "Edit" within ".recent-content-block" | |
69 | + When I follow "Edit" within ".block.recent-content-block" | |
73 | 70 | And I select "JSilva blog" from "Choose which blog should be displayed" |
74 | 71 | And I select "Full content" from "Choose how the content should be displayed" |
75 | 72 | And I fill in "Choose how many items will be displayed" with "6" |
76 | 73 | And I press "Save" |
77 | - Then I should see "Quinto post do joao silva" within ".recent-content-block" | |
74 | + Then I should see "Quinto post do joao silva" within ".block.recent-content-block" | |
78 | 75 | |
79 | - # the step for attaching a file on the input only works with capybara 1.1.2, but it requires rails 1.9.3 | |
80 | - @selenium-fixme | |
81 | 76 | Scenario: the user should see the blog cover image if configured and the image is available |
82 | 77 | Given I go to joaosilva's control panel |
83 | 78 | And I follow "Configure blog" |
79 | + And I follow "Edit" within "tr[title='JSilva blog']" | |
84 | 80 | And I attach the file "public/images/rails.png" to "Uploaded data" |
85 | 81 | And I press "Save" |
86 | 82 | When I go to joaosilva's control panel |
87 | 83 | And I follow "Edit sideboxes" |
88 | - And I follow "Edit" within ".recent-content-block" | |
84 | + And I follow "Edit" within ".block.recent-content-block" | |
89 | 85 | And I select "JSilva blog" from "Choose which blog should be displayed" |
90 | 86 | And I select "Title only" from "Choose how the content should be displayed" |
91 | 87 | And I fill in "Choose how many items will be displayed" with "3" | ... | ... |