Add JSON response format to board publication toggle (#2663)

This commit is contained in:
Rob Zolkos
2026-03-05 20:48:03 -05:00
committed by GitHub
parent e27c0c5fa1
commit e47f2d93eb
5 changed files with 103 additions and 1 deletions
@@ -5,10 +5,20 @@ class Boards::PublicationsController < ApplicationController
def create
@board.publish
respond_to do |format|
format.turbo_stream
format.json { render partial: "boards/board", locals: { board: @board }, status: :created }
end
end
def destroy
@board.unpublish
@board.reload
respond_to do |format|
format.turbo_stream
format.json { head :no_content }
end
end
end
+2
View File
@@ -4,4 +4,6 @@ json.cache! board do
json.url board_url(board)
json.creator board.creator, partial: "users/user", as: :user
json.public_url published_board_url(board) if board.published?
end
+48 -1
View File
@@ -469,10 +469,13 @@ __Response:__
"email_address": "david@example.com",
"created_at": "2025-12-05T19:36:35.401Z",
"url": "http://fizzy.localhost:3006/897362094/users/03f5v9zjw7pz8717a4no1h8a7"
}
},
"public_url": "http://fizzy.localhost:3006/897362094/public/boards/aB3dEfGhIjKlMnOp"
}
```
The `public_url` field is only present when the board is published.
### `POST /:account_slug/boards`
Creates a new Board in the account.
@@ -544,6 +547,50 @@ __Response:__
Returns `204 No Content` on success.
## Board Publications
Publishing a board makes it publicly accessible via a shareable link, without requiring authentication. Only board administrators can publish or unpublish a board.
### `POST /:account_slug/boards/:board_id/publication`
Publishes a board, generating a shareable public link.
__Response:__
```
HTTP/1.1 201 Created
```
```json
{
"id": "03f5v9zkft4hj9qq0lsn9ohcm",
"name": "Fizzy",
"all_access": true,
"created_at": "2025-12-05T19:36:35.534Z",
"url": "http://fizzy.localhost:3006/897362094/boards/03f5v9zkft4hj9qq0lsn9ohcm",
"creator": {
"id": "03f5v9zjw7pz8717a4no1h8a7",
"name": "David Heinemeier Hansson",
"role": "owner",
"active": true,
"email_address": "david@example.com",
"created_at": "2025-12-05T19:36:35.401Z",
"url": "http://fizzy.localhost:3006/897362094/users/03f5v9zjw7pz8717a4no1h8a7"
},
"public_url": "http://fizzy.localhost:3006/897362094/public/boards/aB3dEfGhIjKlMnOp"
}
```
If the board is already published, the existing publication is returned.
### `DELETE /:account_slug/boards/:board_id/publication`
Unpublishes a board, removing public access.
__Response:__
Returns `204 No Content` on success.
## Cards
Cards are tasks or items of work on a board. They can be organized into columns, tagged, assigned to users, and have comments.
@@ -27,6 +27,31 @@ class Boards::PublicationsControllerTest < ActionDispatch::IntegrationTest
assert_turbo_stream action: :replace, target: dom_id(@board, :publication)
end
test "publish a board via JSON" do
assert_not @board.published?
assert_changes -> { @board.reload.published? }, from: false, to: true do
post board_publication_path(@board), as: :json
end
assert_response :created
body = @response.parsed_body
@board.reload
assert_equal @board.name, body["name"]
assert_equal published_board_url(@board), body["public_url"]
end
test "unpublish a board via JSON" do
@board.publish
assert @board.published?
assert_changes -> { @board.reload.published? }, from: true, to: false do
delete board_publication_path(@board), as: :json
end
assert_response :no_content
end
test "publish requires board admin permission" do
logout_and_sign_in_as :jz
@@ -250,6 +250,24 @@ class BoardsControllerTest < ActionDispatch::IntegrationTest
assert_equal boards(:writebook).name, @response.parsed_body["name"]
end
test "show as JSON includes public_url when published" do
board = boards(:writebook)
board.publish
get board_path(board), as: :json
assert_response :success
assert_equal published_board_url(board), @response.parsed_body["public_url"]
end
test "show as JSON excludes public_url when not published" do
board = boards(:writebook)
assert_not board.published?
get board_path(board), as: :json
assert_response :success
assert_nil @response.parsed_body["public_url"]
end
test "create as JSON" do
assert_difference -> { Board.count }, +1 do
post boards_path, params: { board: { name: "My new board" } }, as: :json