Commit 2c83b2f8b01e083f5e68f6a340e05008a266c276
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 | 1 | class OauthClientPluginAdminController < AdminController |
| 2 | 2 | |
| 3 | 3 | def index |
| 4 | - @config = OauthClientPlugin::Config.instance | |
| 4 | + @config = OauthClientPlugin::Configuration.instance | |
| 5 | 5 | end |
| 6 | 6 | |
| 7 | 7 | def new |
| ... | ... | @@ -15,7 +15,7 @@ class OauthClientPluginAdminController < AdminController |
| 15 | 15 | end |
| 16 | 16 | |
| 17 | 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 | 19 | redirect_to :action => 'index' |
| 20 | 20 | end |
| 21 | 21 | ... | ... |
plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb
| ... | ... | @@ -33,7 +33,6 @@ class OauthClientPluginPublicController < PublicController |
| 33 | 33 | person = OauthClientPlugin::OauthExternalPerson.find_or_create_by( |
| 34 | 34 | identifier: auth_data.info.nickname || user.login, |
| 35 | 35 | name: auth_data.info.name, |
| 36 | - created_at: Time.now, | |
| 37 | 36 | source: provider.site || auth_data.provider, |
| 38 | 37 | email: user.email |
| 39 | 38 | ) | ... | ... |
plugins/oauth_client/db/migrate/20160714113820_create_oauth_client_plugin_config.rb
plugins/oauth_client/lib/ext/environment.rb
| 1 | 1 | require_dependency 'environment' |
| 2 | 2 | |
| 3 | 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 | 5 | has_many :oauth_providers, :class_name => 'OauthClientPlugin::Provider' |
| 6 | 6 | end | ... | ... |
plugins/oauth_client/models/oauth_client_plugin/config.rb
| ... | ... | @@ -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 @@ |
| 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 | 1 | class OauthClientPlugin::OauthExternalPerson < ExternalPerson |
| 2 | 2 | |
| 3 | + before_save :add_timestamp | |
| 4 | + | |
| 3 | 5 | has_one :oauth_auth, as: :profile, class_name: 'OauthClientPlugin::Auth', dependent: :destroy |
| 4 | 6 | has_one :oauth_provider, through: :oauth_auth, source: :provider |
| 5 | 7 | |
| ... | ... | @@ -32,4 +34,9 @@ class OauthClientPlugin::OauthExternalPerson < ExternalPerson |
| 32 | 34 | URI(@oauth_auth.image_url(size)) |
| 33 | 35 | end |
| 34 | 36 | end |
| 37 | + | |
| 38 | + protected | |
| 39 | + def add_timestamp | |
| 40 | + self.created_at = Time.now | |
| 41 | + end | |
| 35 | 42 | end | ... | ... |
plugins/oauth_client/views/auth/_oauth_login.html.erb
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | <div> |
| 6 | 6 | <%= render :partial => 'auth/generate_providers_links', :locals => {:providers => providers, :action => ""} %> |
| 7 | 7 | </div> |
| 8 | - <% if OauthClientPlugin::Config.instance.allow_external_login %> | |
| 8 | + <% if OauthClientPlugin::Configuration.instance.allow_external_login %> | |
| 9 | 9 | <%= _('Login with:') %> |
| 10 | 10 | <div> |
| 11 | 11 | <%= render :partial => 'auth/generate_providers_links', :locals => {:providers => providers, :action => "external_login"} %> | ... | ... |