Commit dbc4a6e4ad835488c6f20422fb651fa01abaeda6
1 parent
e56e2fd3
Bug fixes on oauth_client plugin
- Changed oauth client configuration table name - Set automatic timestamp from login method for federated user Signed-off-by: Matheus Miranda <matheusmirandalacerda@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com> Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: Jessica Cristina <jessica.cris1127@gmail.com>
Showing
8 changed files
with
27 additions
and
21 deletions
Show diff stats
plugins/oauth_client/controllers/oauth_client_plugin_admin_controller.rb
1 | class OauthClientPluginAdminController < AdminController | 1 | class OauthClientPluginAdminController < AdminController |
2 | 2 | ||
3 | def index | 3 | def index |
4 | - @config = OauthClientPlugin::Config.instance | 4 | + @config = OauthClientPlugin::Configuration.instance |
5 | end | 5 | end |
6 | 6 | ||
7 | def new | 7 | def new |
@@ -15,7 +15,7 @@ class OauthClientPluginAdminController < AdminController | @@ -15,7 +15,7 @@ class OauthClientPluginAdminController < AdminController | ||
15 | end | 15 | end |
16 | 16 | ||
17 | def update_configs | 17 | def update_configs |
18 | - OauthClientPlugin::Config.instance.update_attributes(params[:oauth_client_config]) | 18 | + OauthClientPlugin::Configuration.instance.update_attributes(params[:oauth_client_config]) |
19 | redirect_to :action => 'index' | 19 | redirect_to :action => 'index' |
20 | end | 20 | end |
21 | 21 |
plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb
@@ -33,7 +33,6 @@ class OauthClientPluginPublicController < PublicController | @@ -33,7 +33,6 @@ class OauthClientPluginPublicController < PublicController | ||
33 | person = OauthClientPlugin::OauthExternalPerson.find_or_create_by( | 33 | person = OauthClientPlugin::OauthExternalPerson.find_or_create_by( |
34 | identifier: auth_data.info.nickname || user.login, | 34 | identifier: auth_data.info.nickname || user.login, |
35 | name: auth_data.info.name, | 35 | name: auth_data.info.name, |
36 | - created_at: Time.now, | ||
37 | source: provider.site || auth_data.provider, | 36 | source: provider.site || auth_data.provider, |
38 | email: user.email | 37 | email: user.email |
39 | ) | 38 | ) |
plugins/oauth_client/db/migrate/20160714113820_create_oauth_client_plugin_config.rb
1 | class CreateOauthClientPluginConfig < ActiveRecord::Migration | 1 | class CreateOauthClientPluginConfig < ActiveRecord::Migration |
2 | 2 | ||
3 | def change | 3 | def change |
4 | - create_table :oauth_client_plugin_configs do |t| | 4 | + create_table :oauth_client_plugin_configurations do |t| |
5 | t.belongs_to :environment | 5 | t.belongs_to :environment |
6 | t.boolean :allow_external_login, :default => false | 6 | t.boolean :allow_external_login, :default => false |
7 | end | 7 | end |
plugins/oauth_client/lib/ext/environment.rb
1 | require_dependency 'environment' | 1 | require_dependency 'environment' |
2 | 2 | ||
3 | class Environment | 3 | class Environment |
4 | - has_one :oauth_client_plugin_configs, :class_name => 'OauthClientPlugin::Config' | 4 | + has_one :oauth_client_plugin_configuration, :class_name => 'OauthClientPlugin::Configuration' |
5 | has_many :oauth_providers, :class_name => 'OauthClientPlugin::Provider' | 5 | has_many :oauth_providers, :class_name => 'OauthClientPlugin::Provider' |
6 | end | 6 | end |
plugins/oauth_client/models/oauth_client_plugin/config.rb
@@ -1,15 +0,0 @@ | @@ -1,15 +0,0 @@ | ||
1 | -class OauthClientPlugin::Config < ApplicationRecord | ||
2 | - | ||
3 | - belongs_to :environment | ||
4 | - attr_accessible :allow_external_login, :environment_id | ||
5 | - | ||
6 | - class << self | ||
7 | - def instance | ||
8 | - environment = Environment.default | ||
9 | - environment.oauth_client_plugin_configs || create(environment_id: environment.id) | ||
10 | - end | ||
11 | - | ||
12 | - private :new | ||
13 | - end | ||
14 | - | ||
15 | -end |
plugins/oauth_client/models/oauth_client_plugin/configuration.rb
0 → 100644
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +class OauthClientPlugin::Configuration < ApplicationRecord | ||
2 | + | ||
3 | + belongs_to :environment | ||
4 | + attr_accessible :allow_external_login, :environment_id | ||
5 | + | ||
6 | + class << self | ||
7 | + def instance | ||
8 | + environment = Environment.default | ||
9 | + environment.oauth_client_plugin_configuration || create(environment_id: environment.id) | ||
10 | + end | ||
11 | + | ||
12 | + private :new | ||
13 | + end | ||
14 | + | ||
15 | +end |
plugins/oauth_client/models/oauth_client_plugin/oauth_external_person.rb
1 | class OauthClientPlugin::OauthExternalPerson < ExternalPerson | 1 | class OauthClientPlugin::OauthExternalPerson < ExternalPerson |
2 | 2 | ||
3 | + before_save :add_timestamp | ||
4 | + | ||
3 | has_one :oauth_auth, as: :profile, class_name: 'OauthClientPlugin::Auth', dependent: :destroy | 5 | has_one :oauth_auth, as: :profile, class_name: 'OauthClientPlugin::Auth', dependent: :destroy |
4 | has_one :oauth_provider, through: :oauth_auth, source: :provider | 6 | has_one :oauth_provider, through: :oauth_auth, source: :provider |
5 | 7 | ||
@@ -32,4 +34,9 @@ class OauthClientPlugin::OauthExternalPerson < ExternalPerson | @@ -32,4 +34,9 @@ class OauthClientPlugin::OauthExternalPerson < ExternalPerson | ||
32 | URI(@oauth_auth.image_url(size)) | 34 | URI(@oauth_auth.image_url(size)) |
33 | end | 35 | end |
34 | end | 36 | end |
37 | + | ||
38 | + protected | ||
39 | + def add_timestamp | ||
40 | + self.created_at = Time.now | ||
41 | + end | ||
35 | end | 42 | end |
plugins/oauth_client/views/auth/_oauth_login.html.erb
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | <div> | 5 | <div> |
6 | <%= render :partial => 'auth/generate_providers_links', :locals => {:providers => providers, :action => ""} %> | 6 | <%= render :partial => 'auth/generate_providers_links', :locals => {:providers => providers, :action => ""} %> |
7 | </div> | 7 | </div> |
8 | - <% if OauthClientPlugin::Config.instance.allow_external_login %> | 8 | + <% if OauthClientPlugin::Configuration.instance.allow_external_login %> |
9 | <%= _('Login with:') %> | 9 | <%= _('Login with:') %> |
10 | <div> | 10 | <div> |
11 | <%= render :partial => 'auth/generate_providers_links', :locals => {:providers => providers, :action => "external_login"} %> | 11 | <%= render :partial => 'auth/generate_providers_links', :locals => {:providers => providers, :action => "external_login"} %> |