Commit 57a65ede authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve application settings and write tests

parent 8589b4e1
...@@ -4,13 +4,13 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController ...@@ -4,13 +4,13 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
def show def show
end end
def edit
end
def update def update
@application_setting.update_attributes(application_setting_params) if @application_setting.update_attributes(application_setting_params)
redirect_to admin_application_settings_path,
redirect_to admin_application_settings_path notice: 'Application settings saved successfully'
else
render :show
end
end end
private private
......
require 'gon' require 'gon'
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
include Gitlab::CurrentSettings
before_filter :authenticate_user_from_token! before_filter :authenticate_user_from_token!
before_filter :authenticate_user! before_filter :authenticate_user!
before_filter :reject_blocked! before_filter :reject_blocked!
...@@ -13,7 +15,7 @@ class ApplicationController < ActionController::Base ...@@ -13,7 +15,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception protect_from_forgery with: :exception
helper_method :abilities, :can? helper_method :abilities, :can?, :current_application_settings
rescue_from Encoding::CompatibilityError do |exception| rescue_from Encoding::CompatibilityError do |exception|
log_exception(exception) log_exception(exception)
......
...@@ -26,8 +26,8 @@ class RegistrationsController < Devise::RegistrationsController ...@@ -26,8 +26,8 @@ class RegistrationsController < Devise::RegistrationsController
private private
def signup_enabled? def signup_enabled?
unless ApplicationSetting.current.signup_enabled if current_application_settings.signup_enabled?
redirect_to new_user_session_path redirect_to(new_user_session_path)
end end
end end
......
class SessionsController < Devise::SessionsController class SessionsController < Devise::SessionsController
def new def new
redirect_path = if request.referer.present? && (params['redirect_to_referer'] == 'yes') redirect_path =
if request.referer.present? && (params['redirect_to_referer'] == 'yes')
referer_uri = URI(request.referer) referer_uri = URI(request.referer)
if referer_uri.host == Gitlab.config.gitlab.host if referer_uri.host == Gitlab.config.gitlab.host
referer_uri.path referer_uri.path
......
...@@ -310,12 +310,4 @@ module ApplicationHelper ...@@ -310,12 +310,4 @@ 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 module ApplicationSettingsHelper
def signup_enabled?
current_application_settings.signup_enabled
end
def signin_enabled?
current_application_settings.signin_enabled
end
def extra_sign_in_text
current_application_settings.sign_in_text
end
end end
...@@ -51,14 +51,15 @@ require 'file_size_validator' ...@@ -51,14 +51,15 @@ require 'file_size_validator'
class User < ActiveRecord::Base class User < ActiveRecord::Base
include Gitlab::ConfigHelper include Gitlab::ConfigHelper
extend Gitlab::ConfigHelper
include TokenAuthenticatable include TokenAuthenticatable
extend Gitlab::ConfigHelper
extend Gitlab::CurrentSettings
default_value_for :admin, false default_value_for :admin, false
default_value_for :can_create_group, gitlab_config.default_can_create_group default_value_for :can_create_group, gitlab_config.default_can_create_group
default_value_for :can_create_team, false default_value_for :can_create_team, false
default_value_for :hide_no_ssh_key, false default_value_for :hide_no_ssh_key, false
default_value_for :projects_limit, gitlab_config.default_projects_limit default_value_for :projects_limit, current_application_settings.default_projects_limit
default_value_for :theme_id, gitlab_config.default_theme default_value_for :theme_id, gitlab_config.default_theme
devise :database_authenticatable, :lockable, :async, devise :database_authenticatable, :lockable, :async,
......
class BaseService class BaseService
include Gitlab::CurrentSettings
attr_accessor :project, :current_user, :params attr_accessor :project, :current_user, :params
def initialize(project, user, params = {}) def initialize(project, user, params = {})
...@@ -29,6 +31,10 @@ class BaseService ...@@ -29,6 +31,10 @@ class BaseService
SystemHooksService.new SystemHooksService.new
end end
def current_application_settings
ApplicationSetting.current
end
private private
def error(message) def error(message)
......
class GravatarService class GravatarService
include Gitlab::CurrentSettings
def execute(email, size = nil) def execute(email, size = nil)
if ApplicationSetting.current.gravatar_enabled && email.present? if current_application_settings.gravatar_enabled? && email.present?
size = 40 if size.nil? || size <= 0 size = 40 if size.nil? || size <= 0
sprintf gravatar_url, sprintf gravatar_url,
......
...@@ -5,10 +5,8 @@ ...@@ -5,10 +5,8 @@
- @application_setting.errors.full_messages.each do |msg| - @application_setting.errors.full_messages.each do |msg|
%p= msg %p= msg
.form-group %fieldset
= f.label :default_projects_limit, class: 'control-label' %legend Features
.col-sm-10
= f.number_field :default_projects_limit, class: 'form-control'
.form-group .form-group
= f.label :signup_enabled, class: 'control-label' = f.label :signup_enabled, class: 'control-label'
.col-sm-10 .col-sm-10
...@@ -21,6 +19,12 @@ ...@@ -21,6 +19,12 @@
= f.label :gravatar_enabled, class: 'control-label' = f.label :gravatar_enabled, class: 'control-label'
.col-sm-10 .col-sm-10
= f.check_box :gravatar_enabled, class: 'checkbox' = f.check_box :gravatar_enabled, class: 'checkbox'
%fieldset
%legend Misc
.form-group
= f.label :default_projects_limit, class: 'control-label'
.col-sm-10
= f.number_field :default_projects_limit, class: 'form-control'
.form-group .form-group
= f.label :sign_in_text, class: 'control-label' = f.label :sign_in_text, class: 'control-label'
.col-sm-10 .col-sm-10
......
%h1 Editing application_setting
= render 'form'
= link_to 'Back', admin_application_settings_path
%table.table %h3.page-title Application settings
%tr %hr
%td Default projects limit: = render 'form'
%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
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
Perform code reviews and enhance collaboration with merge requests. Perform code reviews and enhance collaboration with merge requests.
Each project can also have an issue tracker and a wiki. Each project can also have an issue tracker and a wiki.
- if extra_config.has_key?('sign_in_text') - if extra_sign_in_text.present?
= markdown(extra_config.sign_in_text) = markdown(extra_sign_in_text)
%hr %hr
.container .container
......
...@@ -40,3 +40,8 @@ ...@@ -40,3 +40,8 @@
%span %span
Background Jobs Background Jobs
= nav_link(controller: :application_settings) do
= link_to admin_application_settings_path do
%i.fa.fa-cogs
%span
Settings
...@@ -109,7 +109,7 @@ Gitlab::Application.routes.draw do ...@@ -109,7 +109,7 @@ Gitlab::Application.routes.draw do
end end
end end
resource :application_settings resource :application_settings, only: [:show, :update]
root to: "dashboard#index" root to: "dashboard#index"
end end
......
@admin
Feature: Admin Settings
Background:
Given I sign in as an admin
And I visit admin settings page
Scenario: Change application settings
When I disable gravatars and save form
Then I should be see gravatar disabled
class Spinach::Features::AdminSettings < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
include SharedAdmin
include Gitlab::CurrentSettings
step 'I disable gravatars and save form' do
uncheck 'Gravatar enabled'
click_button 'Save'
end
step 'I should be see gravatar disabled' do
current_application_settings.gravatar_enabled.should be_false
page.should have_content 'Application settings saved successfully'
end
end
...@@ -167,6 +167,10 @@ module SharedPaths ...@@ -167,6 +167,10 @@ module SharedPaths
visit admin_teams_path visit admin_teams_path
end end
step 'I visit admin settings page' do
visit admin_application_settings_path
end
# ---------------------------------------- # ----------------------------------------
# Generic Project # Generic Project
# ---------------------------------------- # ----------------------------------------
......
module Gitlab
module CurrentSettings
def current_application_settings
ApplicationSetting.current
end
end
end
require 'spec_helper'
describe ApplicationSetting, models: true do
describe 'should exists on start' do
it { ApplicationSetting.count.should_not be_zero }
end
end
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