[Git][noosfero/noosfero][master] 2 commits: api: add method to update an environment

Leandro Nunes gitlab at mg.gitlab.com
Thu Dec 1 12:36:26 BRST 2016


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
9b7c6d9a by Victor Costa at 2016-11-30T17:22:09-03:00
api: add method to update an environment

- - - - -
caa05c2b by Leandro Nunes at 2016-12-01T14:33:21+00:00
Merge branch 'api-environment-update' into 'master'

api: add method to update an environment

See merge request !1058
- - - - -


3 changed files:

- app/api/v1/environments.rb
- app/models/environment.rb
- test/api/environment_test.rb


Changes:

=====================================
app/api/v1/environments.rb
=====================================
--- a/app/api/v1/environments.rb
+++ b/app/api/v1/environments.rb
@@ -21,6 +21,15 @@ module Api
           present_partial local_environment, with: Entities::Environment, is_admin: is_admin?(local_environment), current_person: current_person
         end
 
+        desc "Update environment information"
+        post ':id' do
+          authenticate!
+          environment = Environment.find_by(id: params[:id])
+          return forbidden! unless is_admin?(environment)
+          environment.update_attributes!(params[:environment])
+          present_partial environment, with: Entities::Environment, is_admin: is_admin?(environment), current_person: current_person
+        end
+
       end
 
     end


=====================================
app/models/environment.rb
=====================================
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -15,7 +15,7 @@ class Environment < ApplicationRecord
                   :members_whitelist, :highlighted_news_amount,
                   :portal_news_amount, :date_format, :signup_intro,
                   :enable_feed_proxy, :http_feed_proxy, :https_feed_proxy,
-                  :disable_feed_ssl
+                  :disable_feed_ssl, :layout_template
 
   has_many :users
 


=====================================
test/api/environment_test.rb
=====================================
--- a/test/api/environment_test.rb
+++ b/test/api/environment_test.rb
@@ -85,4 +85,21 @@ class EnvironmentTest < ActiveSupport::TestCase
     assert_equal environment.permissions_for(person), json['permissions']
   end
 
+  should 'update environment' do
+    login_api
+    environment = Environment.default
+    environment.add_admin(person)
+    params[:environment] = {layout_template: "leftbar"}
+    post "/api/v1/environment/#{environment.id}?#{params.to_query}"
+    assert_equal "leftbar", environment.reload.layout_template
+  end
+
+  should 'forbid update for non admin users' do
+    login_api
+    environment = Environment.default
+    params[:environment] = {layout_template: "leftbar"}
+    post "/api/v1/environment/#{environment.id}?#{params.to_query}"
+    assert_equal 403, last_response.status
+    assert_equal "default", environment.reload.layout_template
+  end
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/0b2c36697b817414d5c4f4660ca1308109d848c3...caa05c2ba9b5c9c087cce2b07d2ee5e173ac3524
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20161201/8d774ce2/attachment-0001.html>


More information about the Noosfero-dev mailing list