Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
gitlab-ce
Commits
57a65ede
Commit
57a65ede
authored
Jan 08, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve application settings and write tests
parent
8589b4e1
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
123 additions
and
77 deletions
+123
-77
app/controllers/admin/application_settings_controller.rb
app/controllers/admin/application_settings_controller.rb
+6
-6
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+3
-1
app/controllers/registrations_controller.rb
app/controllers/registrations_controller.rb
+2
-2
app/controllers/sessions_controller.rb
app/controllers/sessions_controller.rb
+11
-11
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+0
-8
app/helpers/application_settings_helper.rb
app/helpers/application_settings_helper.rb
+11
-0
app/models/user.rb
app/models/user.rb
+3
-2
app/services/base_service.rb
app/services/base_service.rb
+6
-0
app/services/gravatar_service.rb
app/services/gravatar_service.rb
+3
-1
app/views/admin/application_settings/_form.html.haml
app/views/admin/application_settings/_form.html.haml
+24
-20
app/views/admin/application_settings/edit.html.haml
app/views/admin/application_settings/edit.html.haml
+0
-5
app/views/admin/application_settings/show.html.haml
app/views/admin/application_settings/show.html.haml
+3
-18
app/views/layouts/devise.html.haml
app/views/layouts/devise.html.haml
+2
-2
app/views/layouts/nav/_admin.html.haml
app/views/layouts/nav/_admin.html.haml
+5
-0
config/routes.rb
config/routes.rb
+1
-1
features/admin/settings.feature
features/admin/settings.feature
+9
-0
features/steps/admin/settings.rb
features/steps/admin/settings.rb
+16
-0
features/steps/shared/paths.rb
features/steps/shared/paths.rb
+4
-0
lib/gitlab/current_settings.rb
lib/gitlab/current_settings.rb
+7
-0
spec/models/application_setting_spec.rb
spec/models/application_setting_spec.rb
+7
-0
No files found.
app/controllers/admin/application_settings_controller.rb
View file @
57a65ede
...
@@ -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
...
...
app/controllers/application_controller.rb
View file @
57a65ede
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
)
...
...
app/controllers/registrations_controller.rb
View file @
57a65ede
...
@@ -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
...
...
app/controllers/sessions_controller.rb
View file @
57a65ede
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
=
referer_uri
=
URI
(
request
.
referer
)
if
request
.
referer
.
present?
&&
(
params
[
'redirect_to_referer'
]
==
'yes'
)
if
referer_uri
.
host
==
Gitlab
.
config
.
gitlab
.
host
referer_uri
=
URI
(
request
.
referer
)
referer_uri
.
path
if
referer_uri
.
host
==
Gitlab
.
config
.
gitlab
.
host
else
referer_uri
.
path
request
.
fullpath
else
end
request
.
fullpath
else
end
request
.
fullpath
else
end
request
.
fullpath
end
# Prevent a 'you are already signed in' message directly after signing:
# Prevent a 'you are already signed in' message directly after signing:
# we should never redirect to '/users/sign_in' after signing in successfully.
# we should never redirect to '/users/sign_in' after signing in successfully.
...
...
app/helpers/application_helper.rb
View file @
57a65ede
...
@@ -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
app/helpers/application_settings_helper.rb
View file @
57a65ede
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
app/models/user.rb
View file @
57a65ede
...
@@ -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
,
...
...
app/services/base_service.rb
View file @
57a65ede
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
)
...
...
app/services/gravatar_service.rb
View file @
57a65ede
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
,
...
...
app/views/admin/application_settings/_form.html.haml
View file @
57a65ede
...
@@ -5,25 +5,29 @@
...
@@ -5,25 +5,29 @@
-
@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
.form-group
=
f
.
number_field
:default_projects_limit
,
class:
'form-control'
=
f
.
label
:signup_enabled
,
class:
'control-label'
.form-group
.col-sm-10
=
f
.
label
:signup_enabled
,
class:
'control-label'
=
f
.
check_box
:signup_enabled
,
class:
'checkbox'
.col-sm-10
.form-group
=
f
.
check_box
:signup_enabled
,
class:
'checkbox'
=
f
.
label
:signin_enabled
,
class:
'control-label'
.form-group
.col-sm-10
=
f
.
label
:signin_enabled
,
class:
'control-label'
=
f
.
check_box
:signin_enabled
,
class:
'checkbox'
.col-sm-10
.form-group
=
f
.
check_box
:signin_enabled
,
class:
'checkbox'
=
f
.
label
:gravatar_enabled
,
class:
'control-label'
.form-group
.col-sm-10
=
f
.
label
:gravatar_enabled
,
class:
'control-label'
=
f
.
check_box
:gravatar_enabled
,
class:
'checkbox'
.col-sm-10
%fieldset
=
f
.
check_box
:gravatar_enabled
,
class:
'checkbox'
%legend
Misc
.form-group
.form-group
=
f
.
label
:sign_in_text
,
class:
'control-label'
=
f
.
label
:default_projects_limit
,
class:
'control-label'
.col-sm-10
.col-sm-10
=
f
.
text_area
:sign_in_text
,
class:
'form-control'
=
f
.
number_field
:default_projects_limit
,
class:
'form-control'
.form-group
=
f
.
label
:sign_in_text
,
class:
'control-label'
.col-sm-10
=
f
.
text_area
:sign_in_text
,
class:
'form-control'
.form-actions
.form-actions
=
f
.
submit
'Save'
,
class:
'btn btn-primary'
=
f
.
submit
'Save'
,
class:
'btn btn-primary'
app/views/admin/application_settings/edit.html.haml
deleted
100644 → 0
View file @
8589b4e1
%h1
Editing application_setting
=
render
'form'
=
link_to
'Back'
,
admin_application_settings_path
app/views/admin/application_settings/show.html.haml
View file @
57a65ede
%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
app/views/layouts/devise.html.haml
View file @
57a65ede
...
@@ -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
...
...
app/views/layouts/nav/_admin.html.haml
View file @
57a65ede
...
@@ -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
config/routes.rb
View file @
57a65ede
...
@@ -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
...
...
features/admin/settings.feature
0 → 100644
View file @
57a65ede
@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
features/steps/admin/settings.rb
0 → 100644
View file @
57a65ede
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
features/steps/shared/paths.rb
View file @
57a65ede
...
@@ -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
# ----------------------------------------
# ----------------------------------------
...
...
lib/gitlab/current_settings.rb
0 → 100644
View file @
57a65ede
module
Gitlab
module
CurrentSettings
def
current_application_settings
ApplicationSetting
.
current
end
end
end
spec/models/application_setting_spec.rb
0 → 100644
View file @
57a65ede
require
'spec_helper'
describe
ApplicationSetting
,
models:
true
do
describe
'should exists on start'
do
it
{
ApplicationSetting
.
count
.
should_not
be_zero
}
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment