diff --git a/app/api/v1/blocks.rb b/app/api/v1/blocks.rb index aefa370..6778b6b 100644 --- a/app/api/v1/blocks.rb +++ b/app/api/v1/blocks.rb @@ -6,6 +6,7 @@ module Api get ':id' do block = Block.find(params["id"]) return forbidden! unless block.visible_to_user?(current_person) || block.allow_edit?(current_person) + block.api_content_params = params.except("id") present block, :with => Entities::Block, display_api_content: true, current_person: current_person end diff --git a/app/models/block.rb b/app/models/block.rb index 47d6618..894e6d9 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -320,6 +320,8 @@ class Block < ApplicationRecord false end + attr_accessor :api_content_params + private def home_page_path diff --git a/test/api/blocks_test.rb b/test/api/blocks_test.rb index de63f83..4a4ac29 100644 --- a/test/api/blocks_test.rb +++ b/test/api/blocks_test.rb @@ -141,4 +141,18 @@ class BlocksTest < ActiveSupport::TestCase json = JSON.parse(last_response.body) assert_includes json["block"]["permissions"], 'allow_edit' end + + should 'get a block with api content params' do + class MyTestBlock < Block + def api_content + api_content_params + end + end + box = fast_create(Box, :owner_id => environment.id, :owner_type => Environment.name) + block = fast_create(MyTestBlock, box_id: box.id) + params["custom_param"] = "custom_value" + get "/api/v1/blocks/#{block.id}?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal "custom_value", json["block"]["api_content"]["custom_param"] + end end -- libgit2 0.21.2