diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-01-08 11:22:50 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-01-08 11:22:50 +0300 |
commit | 8589b4e137f50293952923bb07e2814257d7784d (patch) | |
tree | 45e96152606d36a906f5a8d54ad1c245987c3b9e /app | |
parent | d02a22ba21f91d2aa4f9cf716dc3aefcf7e7495e (diff) |
Init ApplicationSettings resource with defaults from config file
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin/application_settings_controller.rb | 31 | ||||
-rw-r--r-- | app/controllers/registrations_controller.rb | 4 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 8 | ||||
-rw-r--r-- | app/helpers/application_settings_helper.rb | 2 | ||||
-rw-r--r-- | app/models/application_setting.rb | 5 | ||||
-rw-r--r-- | app/services/gravatar_service.rb | 2 | ||||
-rw-r--r-- | app/views/admin/application_settings/_form.html.haml | 29 | ||||
-rw-r--r-- | app/views/admin/application_settings/edit.html.haml | 5 | ||||
-rw-r--r-- | app/views/admin/application_settings/show.html.haml | 18 | ||||
-rw-r--r-- | app/views/devise/sessions/new.html.haml | 2 | ||||
-rw-r--r-- | app/views/devise/shared/_signin_box.html.haml | 6 |
11 files changed, 106 insertions, 6 deletions
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb new file mode 100644 index 00000000000..d6e950b0007 --- /dev/null +++ b/app/controllers/admin/application_settings_controller.rb @@ -0,0 +1,31 @@ +class Admin::ApplicationSettingsController < Admin::ApplicationController + before_filter :set_application_setting + + def show + end + + def edit + end + + def update + @application_setting.update_attributes(application_setting_params) + + redirect_to admin_application_settings_path + end + + private + + def set_application_setting + @application_setting = ApplicationSetting.last + end + + def application_setting_params + params.require(:application_setting).permit( + :default_projects_limit, + :signup_enabled, + :signin_enabled, + :gravatar_enabled, + :sign_in_text, + ) + end +end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 6d3214b70a8..7c15eab4345 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -26,7 +26,9 @@ class RegistrationsController < Devise::RegistrationsController private def signup_enabled? - redirect_to new_user_session_path unless Gitlab.config.gitlab.signup_enabled + unless ApplicationSetting.current.signup_enabled + redirect_to new_user_session_path + end end def sign_up_params diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f21b0bd1f50..c339b3597ec 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -310,4 +310,12 @@ module ApplicationHelper request.env['rack.session']['user_return_to'] == '/' end + + def signup_enabled? + ApplicationSetting.current.signup_enabled + end + + def signin_enabled? + ApplicationSetting.current.signin_enabled + end end diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb new file mode 100644 index 00000000000..bb39a3cf4f0 --- /dev/null +++ b/app/helpers/application_settings_helper.rb @@ -0,0 +1,2 @@ +module ApplicationSettingsHelper +end diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb new file mode 100644 index 00000000000..4b885461cbb --- /dev/null +++ b/app/models/application_setting.rb @@ -0,0 +1,5 @@ +class ApplicationSetting < ActiveRecord::Base + def self.current + ApplicationSetting.last + end +end diff --git a/app/services/gravatar_service.rb b/app/services/gravatar_service.rb index a69c7c78377..d8c9436aaa5 100644 --- a/app/services/gravatar_service.rb +++ b/app/services/gravatar_service.rb @@ -1,6 +1,6 @@ class GravatarService def execute(email, size = nil) - if gravatar_config.enabled && email.present? + if ApplicationSetting.current.gravatar_enabled && email.present? size = 40 if size.nil? || size <= 0 sprintf gravatar_url, diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml new file mode 100644 index 00000000000..846d74d433d --- /dev/null +++ b/app/views/admin/application_settings/_form.html.haml @@ -0,0 +1,29 @@ += form_for @application_setting, url: admin_application_settings_path, html: { class: 'form-horizontal fieldset-form' } do |f| + - if @application_setting.errors.any? + #error_explanation + .alert.alert-danger + - @application_setting.errors.full_messages.each do |msg| + %p= msg + + .form-group + = f.label :default_projects_limit, class: 'control-label' + .col-sm-10 + = f.number_field :default_projects_limit, class: 'form-control' + .form-group + = f.label :signup_enabled, class: 'control-label' + .col-sm-10 + = f.check_box :signup_enabled, class: 'checkbox' + .form-group + = f.label :signin_enabled, class: 'control-label' + .col-sm-10 + = f.check_box :signin_enabled, class: 'checkbox' + .form-group + = f.label :gravatar_enabled, class: 'control-label' + .col-sm-10 + = f.check_box :gravatar_enabled, class: 'checkbox' + .form-group + = f.label :sign_in_text, class: 'control-label' + .col-sm-10 + = f.text_area :sign_in_text, class: 'form-control' + .form-actions + = f.submit 'Save', class: 'btn btn-primary' diff --git a/app/views/admin/application_settings/edit.html.haml b/app/views/admin/application_settings/edit.html.haml new file mode 100644 index 00000000000..62c0617ca4f --- /dev/null +++ b/app/views/admin/application_settings/edit.html.haml @@ -0,0 +1,5 @@ +%h1 Editing application_setting + += render 'form' + += link_to 'Back', admin_application_settings_path diff --git a/app/views/admin/application_settings/show.html.haml b/app/views/admin/application_settings/show.html.haml new file mode 100644 index 00000000000..1c77886546d --- /dev/null +++ b/app/views/admin/application_settings/show.html.haml @@ -0,0 +1,18 @@ +%table.table + %tr + %td Default projects limit: + %td= @application_setting.default_projects_limit + %tr + %td Signup enabled: + %td= @application_setting.signup_enabled + %tr + %td Signin enabled: + %td= @application_setting.signin_enabled + %tr + %td Gravatar enabled: + %td= @application_setting.gravatar_enabled + %tr + %td Sign in text: + %td= @application_setting.sign_in_text + += link_to 'Edit', edit_admin_application_settings_path diff --git a/app/views/devise/sessions/new.html.haml b/app/views/devise/sessions/new.html.haml index 5e31d8e818a..6d8415613d1 100644 --- a/app/views/devise/sessions/new.html.haml +++ b/app/views/devise/sessions/new.html.haml @@ -5,7 +5,7 @@ .prepend-top-20 = render 'devise/shared/oauth_box' - - if gitlab_config.signup_enabled + - if signup_enabled? .prepend-top-20 = render 'devise/shared/signup_box' diff --git a/app/views/devise/shared/_signin_box.html.haml b/app/views/devise/shared/_signin_box.html.haml index 3f2161ff6a4..70587329033 100644 --- a/app/views/devise/shared/_signin_box.html.haml +++ b/app/views/devise/shared/_signin_box.html.haml @@ -7,18 +7,18 @@ - @ldap_servers.each_with_index do |server, i| %li{class: (:active if i.zero?)} = link_to server['label'], "#tab-#{server['provider_name']}", 'data-toggle' => 'tab' - - if gitlab_config.signin_enabled + - if signin_enabled? %li = link_to 'Standard', '#tab-signin', 'data-toggle' => 'tab' .tab-content - @ldap_servers.each_with_index do |server, i| %div.tab-pane{id: "tab-#{server['provider_name']}", class: (:active if i.zero?)} = render 'devise/sessions/new_ldap', provider: server['provider_name'] - - if gitlab_config.signin_enabled + - if signin_enabled? %div#tab-signin.tab-pane = render 'devise/sessions/new_base' - - elsif gitlab_config.signin_enabled + - elsif signin_enabled? = render 'devise/sessions/new_base' - else %div |