Add board settings fields to board JSON responses (#2788)
* Add board settings fields to board JSON responses * Move public_description fields to board partial, gate on published * Add index test for public_description fields on published boards * Update app/views/boards/show.json.jbuilder Prefer `unless` to `if !` --------- Co-authored-by: Mike Dalessio <mike.dalessio@gmail.com>
This commit is contained in:
@@ -6,5 +6,9 @@ json.cache! board do
|
||||
|
||||
json.creator board.creator, partial: "users/user", as: :user
|
||||
|
||||
json.public_url published_board_url(board) if board.published?
|
||||
if board.published?
|
||||
json.public_description board.public_description.to_plain_text
|
||||
json.public_description_html board.public_description.to_s
|
||||
json.public_url published_board_url(board)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
json.partial! "boards/board", board: @board
|
||||
json.user_ids @board.users.ids unless @board.all_access?
|
||||
|
||||
@@ -40,7 +40,7 @@ __Response:__
|
||||
{
|
||||
"id": "03f5v9zkft4hj9qq0lsn9ohcm",
|
||||
"name": "Fizzy",
|
||||
"all_access": true,
|
||||
"all_access": false,
|
||||
"created_at": "2025-12-05T19:36:35.534Z",
|
||||
"auto_postpone_period_in_days": 30,
|
||||
"url": "http://fizzy.localhost:3006/897362094/boards/03f5v9zkft4hj9qq0lsn9ohcm",
|
||||
@@ -53,11 +53,17 @@ __Response:__
|
||||
"created_at": "2025-12-05T19:36:35.401Z",
|
||||
"url": "http://fizzy.localhost:3006/897362094/users/03f5v9zjw7pz8717a4no1h8a7"
|
||||
},
|
||||
"public_description": "Follow along with public product updates.",
|
||||
"public_description_html": "<div class=\"trix-content\"><p>Follow along with public product updates.</p></div>",
|
||||
"user_ids": [
|
||||
"03f5v9zjw7pz8717a4no1h8a7",
|
||||
"03f5v9zppzlksuj4mxba2nbzn"
|
||||
],
|
||||
"public_url": "http://fizzy.localhost:3006/897362094/public/boards/aB3dEfGhIjKlMnOp"
|
||||
}
|
||||
```
|
||||
|
||||
The `public_url` field is only present when the board is published.
|
||||
The `public_description`, `public_description_html`, and `public_url` fields are only present when the board is published. The `user_ids` field is only present when `all_access` is `false`; use `GET /:account_slug/users` to resolve those IDs to user records if needed.
|
||||
|
||||
## `POST /:account_slug/boards`
|
||||
|
||||
|
||||
@@ -217,6 +217,19 @@ class BoardsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal users(:kevin).boards.count, @response.parsed_body.count
|
||||
end
|
||||
|
||||
test "index as JSON includes public_description fields for published boards" do
|
||||
board = boards(:writebook)
|
||||
board.publish
|
||||
board.update!(public_description: "<p>Public board description.</p>")
|
||||
|
||||
get boards_path, as: :json
|
||||
assert_response :success
|
||||
|
||||
published_board = @response.parsed_body.find { |b| b["id"] == board.id }
|
||||
assert_equal board.public_description.to_plain_text, published_board["public_description"]
|
||||
assert_equal board.public_description.to_s, published_board["public_description_html"]
|
||||
end
|
||||
|
||||
test "index as JSON paginates and preserves recently-accessed order" do
|
||||
account = accounts("37s")
|
||||
kevin = users(:kevin)
|
||||
@@ -261,6 +274,43 @@ class BoardsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal boards(:writebook).auto_postpone_period_in_days, @response.parsed_body["auto_postpone_period_in_days"]
|
||||
end
|
||||
|
||||
test "show as JSON includes public_description fields when published" do
|
||||
board = boards(:writebook)
|
||||
board.publish
|
||||
board.update!(public_description: "<p>This is a <strong>public</strong> note.</p>")
|
||||
|
||||
get board_path(board), as: :json
|
||||
assert_response :success
|
||||
assert_equal board.public_description.to_plain_text, @response.parsed_body["public_description"]
|
||||
assert_equal board.public_description.to_s, @response.parsed_body["public_description_html"]
|
||||
end
|
||||
|
||||
test "show as JSON excludes public_description fields when not published" do
|
||||
board = boards(:writebook)
|
||||
board.update!(public_description: "<p>This is a <strong>public</strong> note.</p>")
|
||||
assert_not board.published?
|
||||
|
||||
get board_path(board), as: :json
|
||||
assert_response :success
|
||||
assert_nil @response.parsed_body["public_description"]
|
||||
assert_nil @response.parsed_body["public_description_html"]
|
||||
end
|
||||
|
||||
test "show as JSON includes granted user_ids when board is not all access" do
|
||||
board = boards(:private)
|
||||
board.accesses.revise granted: users(:david, :jz), revoked: []
|
||||
|
||||
get board_path(board), as: :json
|
||||
assert_response :success
|
||||
assert_equal board.users.ids.sort, @response.parsed_body["user_ids"].sort
|
||||
end
|
||||
|
||||
test "show as JSON excludes user_ids when board is all access" do
|
||||
get board_path(boards(:writebook)), as: :json
|
||||
assert_response :success
|
||||
assert_nil @response.parsed_body["user_ids"]
|
||||
end
|
||||
|
||||
test "show as JSON includes public_url when published" do
|
||||
board = boards(:writebook)
|
||||
board.publish
|
||||
|
||||
Reference in New Issue
Block a user