diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-07-03 17:50:21 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-07-03 17:50:21 +0300 |
commit | c2ee6862c8538c967ba04fa72b702198f31f876c (patch) | |
tree | be7e7a908ce4ef49ccc2ec5c31d8c533de59ad83 /lib/api/settings.rb | |
parent | a6a0792e9d2a2ffa6bda06b7e171cd4d61097bca (diff) |
API to set application settings for admin
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'lib/api/settings.rb')
-rw-r--r-- | lib/api/settings.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/api/settings.rb b/lib/api/settings.rb new file mode 100644 index 00000000000..28c7a05c629 --- /dev/null +++ b/lib/api/settings.rb @@ -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 |