Commit cd9d8da619477c8803df159ac4f0c61efe4848f8
Committed by
Matheus Miranda Lacerda
1 parent
642d0fb0
Adding attribute for creating account with external login
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: Victor Navarro <victor.matias.navarro@gmail.com> Signed-off-by: Vitor Barbosa <vitornga15@gmail.com>
Showing
4 changed files
with
19 additions
and
6 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 | end | 5 | end |
5 | 6 | ||
6 | def new | 7 | def new |
@@ -13,6 +14,11 @@ class OauthClientPluginAdminController < AdminController | @@ -13,6 +14,11 @@ class OauthClientPluginAdminController < AdminController | ||
13 | redirect_to :action => 'index' | 14 | redirect_to :action => 'index' |
14 | end | 15 | end |
15 | 16 | ||
17 | + def update_configs | ||
18 | + OauthClientPlugin::Config.instance.update_attributes(params[:oauth_client_config]) | ||
19 | + redirect_to :action => 'index' | ||
20 | + end | ||
21 | + | ||
16 | def edit | 22 | def edit |
17 | @provider = params[:id] ? environment.oauth_providers.find(params[:id]) : environment.oauth_providers.new | 23 | @provider = params[:id] ? environment.oauth_providers.find(params[:id]) : environment.oauth_providers.new |
18 | if request.post? | 24 | if request.post? |
plugins/oauth_client/lib/ext/environment.rb
1 | require_dependency 'environment' | 1 | require_dependency 'environment' |
2 | 2 | ||
3 | class Environment | 3 | class Environment |
4 | - | 4 | + has_one :oauth_client_plugin_configs, :class_name => 'OauthClientPlugin::Config' |
5 | has_many :oauth_providers, :class_name => 'OauthClientPlugin::Provider' | 5 | has_many :oauth_providers, :class_name => 'OauthClientPlugin::Provider' |
6 | - | ||
7 | end | 6 | end |
plugins/oauth_client/models/oauth_client_plugin/config.rb
1 | class OauthClientPlugin::Config < ApplicationRecord | 1 | class OauthClientPlugin::Config < ApplicationRecord |
2 | 2 | ||
3 | belongs_to :environment | 3 | belongs_to :environment |
4 | + attr_accessible :create_account_for_login, :environment_id | ||
4 | 5 | ||
5 | - attr_accessible :create_account_for_login | 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 | ||
6 | 14 | ||
7 | end | 15 | end |
plugins/oauth_client/views/oauth_client_plugin_admin/index.html.erb
1 | <h1><%= _('Oauth Client Settings') %></h1> | 1 | <h1><%= _('Oauth Client Settings') %></h1> |
2 | 2 | ||
3 | -<%= labelled_form_for("") do |f| %> | 3 | +<%= labelled_form_for @config, url: { action: "update_configs" } do |f| %> |
4 | <table> | 4 | <table> |
5 | <tr> | 5 | <tr> |
6 | - <%= hidden_field_tag('environment[enabled_features][]', '') %> | 6 | + <%= hidden_field_tag "oauth_client_config[create_account_for_login]", false %> |
7 | <td><%= _('Only allow login with creation of new account') %></td> | 7 | <td><%= _('Only allow login with creation of new account') %></td> |
8 | - <td><%= check_box_tag "environment[enabled_features][]","" ,"" %></td> | 8 | + <td><%= check_box_tag "oauth_client_config[create_account_for_login]", true, @config.create_account_for_login %></td> |
9 | </tr> | 9 | </tr> |
10 | </table> | 10 | </table> |
11 | 11 |