From c2ee6862c8538c967ba04fa72b702198f31f876c Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 3 Jul 2015 16:50:21 +0200 Subject: API to set application settings for admin Signed-off-by: Dmitriy Zaporozhets --- lib/api/settings.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/api/settings.rb (limited to 'lib/api/settings.rb') 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 -- cgit v1.2.1 From b28714b6a9bf71fac64a0423091fb7eab244fd7f Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 6 Jul 2015 15:53:08 +0200 Subject: Add docs and empty specs for applicaiton settings API Signed-off-by: Dmitriy Zaporozhets --- lib/api/settings.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/api/settings.rb') diff --git a/lib/api/settings.rb b/lib/api/settings.rb index 28c7a05c629..4aa81bf8bab 100644 --- a/lib/api/settings.rb +++ b/lib/api/settings.rb @@ -1,7 +1,6 @@ module API class Settings < Grape::API - before { authenticate! } - before { authorize_admin_project } + before { authenticated_as_admin! } helpers do def current_settings -- cgit v1.2.1 From 603ceea21a0144ff1900106efa0c17e759eeceef Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 6 Jul 2015 16:47:19 +0200 Subject: Add tests and improve logic Signed-off-by: Dmitriy Zaporozhets --- lib/api/settings.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/api/settings.rb') diff --git a/lib/api/settings.rb b/lib/api/settings.rb index 4aa81bf8bab..c885fcd7ea3 100644 --- a/lib/api/settings.rb +++ b/lib/api/settings.rb @@ -4,7 +4,8 @@ module API helpers do def current_settings - @current_setting ||= ApplicationSetting.current + @current_setting ||= + (ApplicationSetting.current || ApplicationSetting.create_from_defaults) end end -- cgit v1.2.1