2015-07-03 10:50:21 -04:00
|
|
|
module API
|
|
|
|
class Settings < Grape::API
|
2015-07-06 09:53:08 -04:00
|
|
|
before { authenticated_as_admin! }
|
2015-07-03 10:50:21 -04:00
|
|
|
|
|
|
|
helpers do
|
|
|
|
def current_settings
|
2015-07-06 10:47:19 -04:00
|
|
|
@current_setting ||=
|
|
|
|
(ApplicationSetting.current || ApplicationSetting.create_from_defaults)
|
2015-07-03 10:50:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Get current applicaiton settings
|
|
|
|
#
|
|
|
|
# Example Request:
|
|
|
|
# GET /application/settings
|
|
|
|
get "application/settings" do
|
|
|
|
present current_settings, with: Entities::ApplicationSetting
|
|
|
|
end
|
|
|
|
|
2016-11-03 10:12:20 -04:00
|
|
|
# Modify application settings
|
2015-07-03 10:50:21 -04:00
|
|
|
#
|
|
|
|
# Example Request:
|
|
|
|
# PUT /application/settings
|
|
|
|
put "application/settings" do
|
2016-11-03 10:12:20 -04:00
|
|
|
attributes = ["repository_storage"] + current_settings.attributes.keys - ["id"]
|
2015-07-03 10:50:21 -04:00
|
|
|
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
|