diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-07-07 10:57:41 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-07-07 10:57:41 +0000 |
commit | f76092c06dd1f3b40a6d32ad3d62ea09bf32d1a0 (patch) | |
tree | 31b0ead46e605f7d3c4ede969f0c1c933b6cc471 /lib | |
parent | 41e6b8d8d8bb183e9313219aa65ea6a786c76133 (diff) | |
parent | 603ceea21a0144ff1900106efa0c17e759eeceef (diff) | |
download | gitlab-ce-f76092c06dd1f3b40a6d32ad3d62ea09bf32d1a0.tar.gz |
Merge branch 'settings-via-api' into 'master'
API to set application settings for admin
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
See merge request !934
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/api.rb | 1 | ||||
-rw-r--r-- | lib/api/entities.rb | 22 | ||||
-rw-r--r-- | lib/api/settings.rb | 35 |
3 files changed, 58 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index d2a35c78fc1..eebd44ea5b6 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -49,5 +49,6 @@ module API mount Namespaces mount Branches mount Labels + mount Settings end end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 14a8f929d76..31202fa8c1f 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -277,5 +277,27 @@ module API class BroadcastMessage < Grape::Entity expose :message, :starts_at, :ends_at, :color, :font end + + class ApplicationSetting < Grape::Entity + expose :id + expose :default_projects_limit + expose :signup_enabled + expose :signin_enabled + expose :gravatar_enabled + expose :sign_in_text + expose :created_at + expose :updated_at + expose :home_page_url + expose :default_branch_protection + expose :twitter_sharing_enabled + expose :restricted_visibility_levels + expose :max_attachment_size + expose :session_expire_delay + expose :default_project_visibility + expose :default_snippet_visibility + expose :restricted_signup_domains + expose :user_oauth_applications + expose :after_sign_out_path + end end end diff --git a/lib/api/settings.rb b/lib/api/settings.rb new file mode 100644 index 00000000000..c885fcd7ea3 --- /dev/null +++ b/lib/api/settings.rb @@ -0,0 +1,35 @@ +module API + class Settings < Grape::API + before { authenticated_as_admin! } + + helpers do + def current_settings + @current_setting ||= + (ApplicationSetting.current || ApplicationSetting.create_from_defaults) + end + end + + # Get current applicaiton settings + # + # Example Request: + # GET /application/settings + get "application/settings" do + present current_settings, with: Entities::ApplicationSetting + end + + # Modify applicaiton settings + # + # Example Request: + # PUT /application/settings + put "application/settings" do + attributes = current_settings.attributes.keys - ["id"] + attrs = attributes_for_keys(attributes) + + if current_settings.update_attributes(attrs) + present current_settings, with: Entities::ApplicationSetting + else + render_validation_error!(current_settings) + end + end + end +end |