[Git][noosfero/noosfero][master] 2 commits: make environments and profiles endpoints accept parameters
Leandro Nunes
gitlab at mg.gitlab.com
Tue Jun 26 14:03:50 BRT 2018
Leandro Nunes pushed to branch master at Noosfero / noosfero
Commits:
2b62be4c by Leandro Nunes dos Santos at 2018-06-26T16:13:51Z
make environments and profiles endpoints accept parameters
- - - - -
e6a0b2cf by Leandro Nunes at 2018-06-26T17:03:43Z
Merge branch 'accept-paramters-in-endpoints' into 'master'
make environments and profiles endpoints accept parameters
See merge request noosfero/noosfero!1558
- - - - -
8 changed files:
- app/api/v1/environments.rb
- app/api/v1/profiles.rb
- app/models/block.rb
- app/models/menu_block.rb
- test/api/environment_test.rb
- test/api/profiles_test.rb
- test/unit/block_test.rb
- test/unit/menu_block_test.rb
Changes:
=====================================
app/api/v1/environments.rb
=====================================
--- a/app/api/v1/environments.rb
+++ b/app/api/v1/environments.rb
@@ -28,7 +28,7 @@ module Api
return forbidden! unless is_admin?(environment)
begin
environment.update_attributes!(params[:environment])
- present_partial environment, with: Entities::Environment, is_admin: is_admin?(environment), current_person: current_person
+ present_partial environment, with: Entities::Environment, is_admin: is_admin?(environment), current_person: current_person, params: params
rescue ActiveRecord::RecordInvalid
render_model_errors!(environment.errors)
end
=====================================
app/api/v1/profiles.rb
=====================================
--- a/app/api/v1/profiles.rb
+++ b/app/api/v1/profiles.rb
@@ -51,7 +51,7 @@ module Api
begin
profile_params = asset_with_image(params[:profile])
profile.update_attributes!(asset_with_custom_image(:top_image, profile_params))
- present profile, :with => Entities::Profile, :current_person => current_person
+ present profile, :with => Entities::Profile, :current_person => current_person, :params => params
rescue ActiveRecord::RecordInvalid
render_model_errors!(profile.errors)
end
=====================================
app/models/block.rb
=====================================
--- a/app/models/block.rb
+++ b/app/models/block.rb
@@ -322,6 +322,8 @@ class Block < ApplicationRecord
end
def api_content=(values = {})
+ settings[:display] = values[:display]
+ settings[:display_user] = values[:display_user]
end
def display_api_content_by_default?
=====================================
app/models/menu_block.rb
=====================================
--- a/app/models/menu_block.rb
+++ b/app/models/menu_block.rb
@@ -40,6 +40,7 @@ class MenuBlock < Block
end
def api_content=(values = {})
+ super
settings[:enabled_links] = values[:enabled_items]
end
=====================================
test/api/environment_test.rb
=====================================
--- a/test/api/environment_test.rb
+++ b/test/api/environment_test.rb
@@ -133,6 +133,15 @@ class EnvironmentTest < ActiveSupport::TestCase
assert_equal "leftbar", environment.reload.layout_template
end
+ should "update environment accept optional fields" do
+ login_api
+ environment = Environment.default
+ environment.add_admin(person)
+ post "/api/v1/environments/#{environment.id}?#{params.merge({:optional_fields => [:boxes]}).to_query}"
+ json = JSON.parse(last_response.body)
+ assert json.has_key?('boxes')
+ end
+
should "test_should_forbid_update_for_non_admin_users_for_environments" do
login_api
environment = Environment.default
=====================================
test/api/profiles_test.rb
=====================================
--- a/test/api/profiles_test.rb
+++ b/test/api/profiles_test.rb
@@ -312,6 +312,15 @@ class ProfilesTest < ActiveSupport::TestCase
assert_equal "Another Header", profile.reload.custom_header
end
+ should "update #{klass.name} accept optional_fields" do
+ login_api
+ profile = fast_create(klass)
+ profile.add_admin(person)
+ post "/api/v1/profiles/#{profile.id}?#{params.merge({:optional_fields => [:boxes]}).to_query}"
+ json = JSON.parse(last_response.body)
+ assert json.has_key?('boxes')
+ end
+
should "not update a #{klass.name} if user does not have permission" do
login_api
profile = fast_create(klass)
@@ -338,6 +347,13 @@ class ProfilesTest < ActiveSupport::TestCase
assert_equal "Another Header", person.reload.custom_header
end
+ should "update person accept optional_fields" do
+ login_api
+ post "/api/v1/profiles/#{person.id}?#{params.merge({:optional_fields => [:boxes]}).to_query}"
+ json = JSON.parse(last_response.body)
+ assert json.has_key?('boxes')
+ end
+
should 'not update person information if user does not have permission' do
login_api
profile = fast_create(Person)
=====================================
test/unit/block_test.rb
=====================================
--- a/test/unit/block_test.rb
+++ b/test/unit/block_test.rb
@@ -2,9 +2,34 @@ require_relative "../test_helper"
class BlockTest < ActiveSupport::TestCase
+ ALL_BLOCKS = Block.descendants
+
+ ALL_BLOCKS.map do |block_type|
+ should "#{block_type.name} describe itself" do
+ assert_kind_of String, block_type.description
+ end
+
+ should "#{block_type.name} api_content= set display settings values" do
+ block = block_type.new
+ assert_nil block.settings[:display]
+ block.api_content= { display: 'always' }
+ assert_equal 'always', block.settings[:display]
+ end
+
+ should "#{block_type.name} api_content= set display_user settings values" do
+ block = block_type.new
+ assert_nil block.settings[:display_user]
+ block.api_content= { display_user: 'all' }
+ assert_equal 'all', block.settings[:display_user]
+ end
+
+ should "#{block_type.name} api_content= set display_user settings if exist display value at the same time" do
+ block = block_type.new
+ assert_nil block.settings[:display_user]
+ block.api_content= { display_user: 'all', display: 'always' }
+ assert_equal 'all', block.settings[:display_user]
+ end
- should 'describe itself' do
- assert_kind_of String, Block.description
end
should 'access owner through box' do
=====================================
test/unit/menu_block_test.rb
=====================================
--- a/test/unit/menu_block_test.rb
+++ b/test/unit/menu_block_test.rb
@@ -54,4 +54,35 @@ class MenuBlockTest < ActiveSupport::TestCase
links = block.enabled_links_for(person)
assert_equal ['Activities', 'About', 'Communities', 'People', 'Control Panel'], links.map { |l| l[:title] }
end
+
+ should 'api_content= set display settings values' do
+ block = MenuBlock.new
+ assert_nil block.settings[:display]
+ block.api_content= { display: 'always' }
+ assert_equal 'always', block.settings[:display]
+ end
+
+ should 'api_content= set display_user settings values' do
+ block = MenuBlock.new
+ assert_nil block.settings[:display_user]
+ block.api_content= { display_user: 'all' }
+ block.valid?
+ assert_equal 'all', block.settings[:display_user]
+ end
+
+ should 'api_content= set enabled_links to settings' do
+ block = MenuBlock.new
+ assert_nil block.settings[:enabled_links]
+ value = { controller: 'SomeController'}
+ block.api_content= { enabled_items: value }
+ assert_equal value, block.settings[:enabled_links]
+ end
+
+ should 'api_content= set display_user settings if exist display value at the same time' do
+ block = MenuBlock.new
+ assert_nil block.settings[:display_user]
+ block.api_content= { display_user: 'all', display: 'always' }
+ assert_equal 'all', block.settings[:display_user]
+ end
+
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/503438a27e3b98918607b3486eb849ea5234b09b...e6a0b2cf452094f827112f13740652fe802aa67b
--
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/503438a27e3b98918607b3486eb849ea5234b09b...e6a0b2cf452094f827112f13740652fe802aa67b
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20180626/acceeb9c/attachment-0001.html>
More information about the Noosfero-dev
mailing list