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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
9e222d6d
Commit
9e222d6d
authored
Jan 08, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'app-settings' into 'master'
Dynamic application settings in database See merge request !1378
parents
d02a22ba
08c9cb4c
Changes
29
Hide whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
230 additions
and
32 deletions
+230
-32
app/controllers/admin/application_settings_controller.rb
app/controllers/admin/application_settings_controller.rb
+31
-0
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+3
-1
app/controllers/registrations_controller.rb
app/controllers/registrations_controller.rb
+3
-1
app/controllers/sessions_controller.rb
app/controllers/sessions_controller.rb
+11
-11
app/helpers/application_settings_helper.rb
app/helpers/application_settings_helper.rb
+17
-0
app/helpers/profile_helper.rb
app/helpers/profile_helper.rb
+1
-1
app/models/application_setting.rb
app/models/application_setting.rb
+15
-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
+33
-0
app/views/admin/application_settings/show.html.haml
app/views/admin/application_settings/show.html.haml
+3
-0
app/views/admin/dashboard/index.html.haml
app/views/admin/dashboard/index.html.haml
+2
-2
app/views/devise/sessions/new.html.haml
app/views/devise/sessions/new.html.haml
+1
-1
app/views/devise/shared/_signin_box.html.haml
app/views/devise/shared/_signin_box.html.haml
+3
-3
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
+2
-0
db/migrate/20150108073740_create_application_settings.rb
db/migrate/20150108073740_create_application_settings.rb
+13
-0
db/schema.rb
db/schema.rb
+11
-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
+22
-0
spec/features/profile_spec.rb
spec/features/profile_spec.rb
+2
-2
spec/features/users_spec.rb
spec/features/users_spec.rb
+1
-1
spec/helpers/application_helper_spec.rb
spec/helpers/application_helper_spec.rb
+1
-1
spec/models/application_setting_spec.rb
spec/models/application_setting_spec.rb
+5
-0
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+2
-2
No files found.
app/controllers/admin/application_settings_controller.rb
0 → 100644
View file @
9e222d6d
class
Admin::ApplicationSettingsController
<
Admin
::
ApplicationController
before_filter
:set_application_setting
def
show
end
def
update
if
@application_setting
.
update_attributes
(
application_setting_params
)
redirect_to
admin_application_settings_path
,
notice:
'Application settings saved successfully'
else
render
:show
end
end
private
def
set_application_setting
@application_setting
=
ApplicationSetting
.
current
end
def
application_setting_params
params
.
require
(
:application_setting
).
permit
(
:default_projects_limit
,
:signup_enabled
,
:signin_enabled
,
:gravatar_enabled
,
:sign_in_text
,
)
end
end
app/controllers/application_controller.rb
View file @
9e222d6d
require
'gon'
class
ApplicationController
<
ActionController
::
Base
include
Gitlab
::
CurrentSettings
before_filter
:authenticate_user_from_token!
before_filter
:authenticate_user!
before_filter
:reject_blocked!
...
...
@@ -13,7 +15,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery
with: :exception
helper_method
:abilities
,
:can?
helper_method
:abilities
,
:can?
,
:current_application_settings
rescue_from
Encoding
::
CompatibilityError
do
|
exception
|
log_exception
(
exception
)
...
...
app/controllers/registrations_controller.rb
View file @
9e222d6d
...
...
@@ -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
current_application_settings
.
signup_enabled?
redirect_to
(
new_user_session_path
)
end
end
def
sign_up_params
...
...
app/controllers/sessions_controller.rb
View file @
9e222d6d
class
SessionsController
<
Devise
::
SessionsController
def
new
redirect_path
=
if
request
.
referer
.
present?
&&
(
params
[
'redirect_to_referer'
]
==
'yes'
)
referer_uri
=
URI
(
request
.
referer
)
if
referer_uri
.
host
==
Gitlab
.
config
.
gitlab
.
host
referer_uri
.
path
else
request
.
fullpath
end
else
request
.
fullpath
end
redirect_path
=
if
request
.
referer
.
present?
&&
(
params
[
'redirect_to_referer'
]
==
'yes'
)
referer_uri
=
URI
(
request
.
referer
)
if
referer_uri
.
host
==
Gitlab
.
config
.
gitlab
.
host
referer_uri
.
path
else
request
.
fullpath
end
else
request
.
fullpath
end
# Prevent a 'you are already signed in' message directly after signing:
# we should never redirect to '/users/sign_in' after signing in successfully.
...
...
app/helpers/application_settings_helper.rb
0 → 100644
View file @
9e222d6d
module
ApplicationSettingsHelper
def
gravatar_enabled?
current_application_settings
.
gravatar_enabled?
end
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
app/helpers/profile_helper.rb
View file @
9e222d6d
...
...
@@ -14,6 +14,6 @@ module ProfileHelper
end
def
show_profile_remove_tab?
gitlab_config
.
signup_enabled
signup_enabled?
end
end
app/models/application_setting.rb
0 → 100644
View file @
9e222d6d
class
ApplicationSetting
<
ActiveRecord
::
Base
def
self
.
current
ApplicationSetting
.
last
end
def
self
.
create_from_defaults
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
end
app/models/user.rb
View file @
9e222d6d
...
...
@@ -51,14 +51,15 @@ require 'file_size_validator'
class
User
<
ActiveRecord
::
Base
include
Gitlab
::
ConfigHelper
extend
Gitlab
::
ConfigHelper
include
TokenAuthenticatable
extend
Gitlab
::
ConfigHelper
extend
Gitlab
::
CurrentSettings
default_value_for
:admin
,
false
default_value_for
:can_create_group
,
gitlab_config
.
default_can_create_group
default_value_for
:can_create_team
,
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
devise
:database_authenticatable
,
:lockable
,
:async
,
...
...
app/services/base_service.rb
View file @
9e222d6d
class
BaseService
include
Gitlab
::
CurrentSettings
attr_accessor
:project
,
:current_user
,
:params
def
initialize
(
project
,
user
,
params
=
{})
...
...
@@ -29,6 +31,10 @@ class BaseService
SystemHooksService
.
new
end
def
current_application_settings
ApplicationSetting
.
current
end
private
def
error
(
message
)
...
...
app/services/gravatar_service.rb
View file @
9e222d6d
class
GravatarService
include
Gitlab
::
CurrentSettings
def
execute
(
email
,
size
=
nil
)
if
gravatar_config
.
enabled
&&
email
.
present?
if
current_application_settings
.
gravatar_enabled?
&&
email
.
present?
size
=
40
if
size
.
nil?
||
size
<=
0
sprintf
gravatar_url
,
...
...
app/views/admin/application_settings/_form.html.haml
0 → 100644
View file @
9e222d6d
=
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
%fieldset
%legend
Features
.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'
%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
=
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'
app/views/admin/application_settings/show.html.haml
0 → 100644
View file @
9e222d6d
%h3
.page-title
Application settings
%hr
=
render
'form'
app/views/admin/dashboard/index.html.haml
View file @
9e222d6d
...
...
@@ -104,7 +104,7 @@
%p
Sign up
%span
.light.pull-right
=
boolean_to_icon
gitlab_config
.
signup_enabled
=
boolean_to_icon
signup_enabled?
%p
LDAP
%span
.light.pull-right
...
...
@@ -112,7 +112,7 @@
%p
Gravatar
%span
.light.pull-right
=
boolean_to_icon
Gitlab
.
config
.
gravatar
.
enabled
=
boolean_to_icon
gravatar_enabled?
%p
OmniAuth
%span
.light.pull-right
...
...
app/views/devise/sessions/new.html.haml
View file @
9e222d6d
...
...
@@ -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'
...
...
app/views/devise/shared/_signin_box.html.haml
View file @
9e222d6d
...
...
@@ -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
...
...
app/views/layouts/devise.html.haml
View file @
9e222d6d
...
...
@@ -25,8 +25,8 @@
Perform code reviews and enhance collaboration with merge requests.
Each project can also have an issue tracker and a wiki.
-
if
extra_
config
.
has_key?
(
'sign_in_text'
)
=
markdown
(
extra_
config
.
sign_in_text
)
-
if
extra_
sign_in_text
.
present?
=
markdown
(
extra_sign_in_text
)
%hr
.container
...
...
app/views/layouts/nav/_admin.html.haml
View file @
9e222d6d
...
...
@@ -40,3 +40,8 @@
%span
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 @
9e222d6d
...
...
@@ -109,6 +109,8 @@ Gitlab::Application.routes.draw do
end
end
resource
:application_settings
,
only:
[
:show
,
:update
]
root
to:
"dashboard#index"
end
...
...
db/migrate/20150108073740_create_application_settings.rb
0 → 100644
View file @
9e222d6d
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
db/schema.rb
View file @
9e222d6d
...
...
@@ -11,11 +11,21 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201
41226080412
)
do
ActiveRecord
::
Schema
.
define
(
version:
201
50108073740
)
do
# These are extensions that must be enabled in order to support this database
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
|
t
.
text
"message"
,
null:
false
t
.
datetime
"starts_at"
...
...
features/admin/settings.feature
0 → 100644
View file @
9e222d6d
@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 @
9e222d6d
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 @
9e222d6d
...
...
@@ -167,6 +167,10 @@ module SharedPaths
visit
admin_teams_path
end
step
'I visit admin settings page'
do
visit
admin_application_settings_path
end
# ----------------------------------------
# Generic Project
# ----------------------------------------
...
...
lib/gitlab/current_settings.rb
0 → 100644
View file @
9e222d6d
module
Gitlab
module
CurrentSettings
def
current_application_settings
if
ActiveRecord
::
Base
.
connection
.
table_exists?
(
'application_settings'
)
ApplicationSetting
.
current
||
ApplicationSetting
.
create_from_defaults
else
fake_application_settings
end
end
def
fake_application_settings
OpenStruct
.
new
(
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
end
end
spec/features/profile_spec.rb
View file @
9e222d6d
...
...
@@ -9,7 +9,7 @@ describe "Profile account page", feature: true do
describe
"when signup is enabled"
do
before
do
Gitlab
.
config
.
gitlab
.
stub
(
:signup_enabled
).
and_return
(
true
)
ApplicationSetting
.
any_instance
.
stub
(
signup_enabled?:
true
)
visit
profile_account_path
end
...
...
@@ -23,7 +23,7 @@ describe "Profile account page", feature: true do
describe
"when signup is disabled"
do
before
do
Gitlab
.
config
.
gitlab
.
stub
(
:signup_enabled
).
and_return
(
false
)
ApplicationSetting
.
any_instance
.
stub
(
signup_enabled?:
false
)
visit
profile_account_path
end
...
...
spec/features/users_spec.rb
View file @
9e222d6d
...
...
@@ -3,7 +3,7 @@ require 'spec_helper'
describe
'Users'
,
feature:
true
do
describe
"GET /users/sign_up"
do
before
do
Gitlab
.
config
.
gitlab
.
stub
(
:signup_enabled
).
and_return
(
true
)
ApplicationSetting
.
any_instance
.
stub
(
signup_enabled?:
true
)
end
it
"should create a new user account"
do
...
...
spec/helpers/application_helper_spec.rb
View file @
9e222d6d
...
...
@@ -87,7 +87,7 @@ describe ApplicationHelper do
let
(
:user_email
)
{
'user@email.com'
}
it
"should return a generic avatar path when Gravatar is disabled"
do
Gitlab
.
config
.
gravatar
.
stub
(
:enabled
).
and_return
(
false
)
ApplicationSetting
.
any_instance
.
stub
(
gravatar_enabled?:
false
)
gravatar_icon
(
user_email
).
should
match
(
'no_avatar.png'
)
end
...
...
spec/models/application_setting_spec.rb
0 → 100644
View file @
9e222d6d
require
'spec_helper'
describe
ApplicationSetting
,
models:
true
do
it
{
ApplicationSetting
.
create_from_defaults
.
should
be_valid
}
end
spec/requests/api/users_spec.rb
View file @
9e222d6d
...
...
@@ -186,7 +186,7 @@ describe API::API, api: true do
describe
"GET /users/sign_up"
do
context
'enabled'
do
before
do
Gitlab
.
config
.
gitlab
.
stub
(
:signup_enabled
).
and_return
(
true
)
ApplicationSetting
.
any_instance
.
stub
(
signup_enabled?:
true
)
end
it
"should return sign up page if signup is enabled"
do
...
...
@@ -197,7 +197,7 @@ describe API::API, api: true do
context
'disabled'
do
before
do
Gitlab
.
config
.
gitlab
.
stub
(
:signup_enabled
).
and_return
(
false
)
ApplicationSetting
.
any_instance
.
stub
(
signup_enabled?:
false
)
end
it
"should redirect to sign in page if signup is disabled"
do
...
...
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