Commit e8398c7d4329070f4b1af2f6e253d1bde1789be5
1 parent
1445c0a7
Exists in
staging
api: accept parameters to build api content for blocks
Showing
3 changed files
with
17 additions
and
0 deletions
Show diff stats
app/api/v1/blocks.rb
| @@ -6,6 +6,7 @@ module Api | @@ -6,6 +6,7 @@ module Api | ||
| 6 | get ':id' do | 6 | get ':id' do |
| 7 | block = Block.find(params["id"]) | 7 | block = Block.find(params["id"]) |
| 8 | return forbidden! unless block.visible_to_user?(current_person) || block.allow_edit?(current_person) | 8 | return forbidden! unless block.visible_to_user?(current_person) || block.allow_edit?(current_person) |
| 9 | + block.api_content_params = params.except("id") | ||
| 9 | present block, :with => Entities::Block, display_api_content: true, current_person: current_person | 10 | present block, :with => Entities::Block, display_api_content: true, current_person: current_person |
| 10 | end | 11 | end |
| 11 | 12 |
app/models/block.rb
test/api/blocks_test.rb
| @@ -141,4 +141,18 @@ class BlocksTest < ActiveSupport::TestCase | @@ -141,4 +141,18 @@ class BlocksTest < ActiveSupport::TestCase | ||
| 141 | json = JSON.parse(last_response.body) | 141 | json = JSON.parse(last_response.body) |
| 142 | assert_includes json["block"]["permissions"], 'allow_edit' | 142 | assert_includes json["block"]["permissions"], 'allow_edit' |
| 143 | end | 143 | end |
| 144 | + | ||
| 145 | + should 'get a block with api content params' do | ||
| 146 | + class MyTestBlock < Block | ||
| 147 | + def api_content | ||
| 148 | + api_content_params | ||
| 149 | + end | ||
| 150 | + end | ||
| 151 | + box = fast_create(Box, :owner_id => environment.id, :owner_type => Environment.name) | ||
| 152 | + block = fast_create(MyTestBlock, box_id: box.id) | ||
| 153 | + params["custom_param"] = "custom_value" | ||
| 154 | + get "/api/v1/blocks/#{block.id}?#{params.to_query}" | ||
| 155 | + json = JSON.parse(last_response.body) | ||
| 156 | + assert_equal "custom_value", json["block"]["api_content"]["custom_param"] | ||
| 157 | + end | ||
| 144 | end | 158 | end |