BigW Consortium Gitlab

Commit 8589b4e1 by Dmitriy Zaporozhets

Init ApplicationSettings resource with defaults from config file

parent d02a22ba
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
...@@ -26,7 +26,9 @@ class RegistrationsController < Devise::RegistrationsController ...@@ -26,7 +26,9 @@ class RegistrationsController < Devise::RegistrationsController
private private
def signup_enabled? 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 end
def sign_up_params def sign_up_params
......
...@@ -310,4 +310,12 @@ module ApplicationHelper ...@@ -310,4 +310,12 @@ module ApplicationHelper
request.env['rack.session']['user_return_to'] == request.env['rack.session']['user_return_to'] ==
'/' '/'
end end
def signup_enabled?
ApplicationSetting.current.signup_enabled
end
def signin_enabled?
ApplicationSetting.current.signin_enabled
end
end end
module ApplicationSettingsHelper
end
class ApplicationSetting < ActiveRecord::Base
def self.current
ApplicationSetting.last
end
end
class GravatarService class GravatarService
def execute(email, size = nil) 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 size = 40 if size.nil? || size <= 0
sprintf gravatar_url, sprintf gravatar_url,
......
= 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'
%h1 Editing application_setting
= render 'form'
= link_to 'Back', admin_application_settings_path
%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
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
.prepend-top-20 .prepend-top-20
= render 'devise/shared/oauth_box' = render 'devise/shared/oauth_box'
- if gitlab_config.signup_enabled - if signup_enabled?
.prepend-top-20 .prepend-top-20
= render 'devise/shared/signup_box' = render 'devise/shared/signup_box'
......
...@@ -7,18 +7,18 @@ ...@@ -7,18 +7,18 @@
- @ldap_servers.each_with_index do |server, i| - @ldap_servers.each_with_index do |server, i|
%li{class: (:active if i.zero?)} %li{class: (:active if i.zero?)}
= link_to server['label'], "#tab-#{server['provider_name']}", 'data-toggle' => 'tab' = link_to server['label'], "#tab-#{server['provider_name']}", 'data-toggle' => 'tab'
- if gitlab_config.signin_enabled - if signin_enabled?
%li %li
= link_to 'Standard', '#tab-signin', 'data-toggle' => 'tab' = link_to 'Standard', '#tab-signin', 'data-toggle' => 'tab'
.tab-content .tab-content
- @ldap_servers.each_with_index do |server, i| - @ldap_servers.each_with_index do |server, i|
%div.tab-pane{id: "tab-#{server['provider_name']}", class: (:active if i.zero?)} %div.tab-pane{id: "tab-#{server['provider_name']}", class: (:active if i.zero?)}
= render 'devise/sessions/new_ldap', provider: server['provider_name'] = render 'devise/sessions/new_ldap', provider: server['provider_name']
- if gitlab_config.signin_enabled - if signin_enabled?
%div#tab-signin.tab-pane %div#tab-signin.tab-pane
= render 'devise/sessions/new_base' = render 'devise/sessions/new_base'
- elsif gitlab_config.signin_enabled - elsif signin_enabled?
= render 'devise/sessions/new_base' = render 'devise/sessions/new_base'
- else - else
%div %div
......
begin
unless ApplicationSetting.any?
ApplicationSetting.create(
default_projects_limit: Settings.gitlab['default_projects_limit'],
signup_enabled: Settings.gitlab['signup_enabled'],
signin_enabled: Settings.gitlab['signin_enabled'],
gravatar_enabled: Settings.gravatar['enabled'],
sign_in_text: Settings.extra['sign_in_text'],
)
end
rescue
end
...@@ -109,6 +109,8 @@ Gitlab::Application.routes.draw do ...@@ -109,6 +109,8 @@ Gitlab::Application.routes.draw do
end end
end end
resource :application_settings
root to: "dashboard#index" root to: "dashboard#index"
end end
......
class CreateApplicationSettings < ActiveRecord::Migration
def change
create_table :application_settings do |t|
t.integer :default_projects_limit
t.boolean :signup_enabled
t.boolean :signin_enabled
t.boolean :gravatar_enabled
t.text :sign_in_text
t.timestamps
end
end
end
...@@ -11,11 +11,21 @@ ...@@ -11,11 +11,21 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141226080412) do ActiveRecord::Schema.define(version: 20150108073740) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
create_table "application_settings", force: true do |t|
t.integer "default_projects_limit"
t.boolean "signup_enabled"
t.boolean "signin_enabled"
t.boolean "gravatar_enabled"
t.text "sign_in_text"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "broadcast_messages", force: true do |t| create_table "broadcast_messages", force: true do |t|
t.text "message", null: false t.text "message", null: false
t.datetime "starts_at" t.datetime "starts_at"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment