API to set application settings for admin
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
a6a0792e9d
commit
c2ee6862c8
3 changed files with 58 additions and 0 deletions
|
@ -49,5 +49,6 @@ module API
|
|||
mount Namespaces
|
||||
mount Branches
|
||||
mount Labels
|
||||
mount Settings
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
35
lib/api/settings.rb
Normal file
35
lib/api/settings.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
module API
|
||||
class Settings < Grape::API
|
||||
before { authenticate! }
|
||||
before { authorize_admin_project }
|
||||
|
||||
helpers do
|
||||
def current_settings
|
||||
@current_setting ||= ApplicationSetting.current
|
||||
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
|
Loading…
Reference in a new issue