debian-mirror-gitlab/lib/api/settings.rb

36 lines
939 B
Ruby
Raw Normal View History

2015-09-11 14:41:01 +05:30
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
2016-11-24 13:41:30 +05:30
# Modify application settings
2015-09-11 14:41:01 +05:30
#
# Example Request:
# PUT /application/settings
put "application/settings" do
2016-11-24 13:41:30 +05:30
attributes = ["repository_storage"] + current_settings.attributes.keys - ["id"]
2015-09-11 14:41:01 +05:30
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