Skip to content

Commit eebb196

Browse files
committed
Add JSON response format to board publication toggle
Allows programmatic clients to publish and unpublish boards via the API, returning the shareable key and URL on publish.
1 parent 646b552 commit eebb196

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

app/controllers/boards/publications_controller.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ class Boards::PublicationsController < ApplicationController
55

66
def create
77
@board.publish
8+
9+
respond_to do |format|
10+
format.turbo_stream
11+
format.json { render json: { key: @board.publication.key, url: published_board_url(@board) }, status: :created }
12+
end
813
end
914

1015
def destroy
1116
@board.unpublish
1217
@board.reload
18+
19+
respond_to do |format|
20+
format.turbo_stream
21+
format.json { head :no_content }
22+
end
1323
end
1424
end

docs/API.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,37 @@ __Response:__
502502

503503
Returns `204 No Content` on success.
504504

505+
## Board Publications
506+
507+
Publishing a board makes it publicly accessible via a shareable link, without requiring authentication. Only board administrators can publish or unpublish a board.
508+
509+
### `POST /:account_slug/boards/:board_id/publication`
510+
511+
Publishes a board, generating a shareable public link.
512+
513+
__Response:__
514+
515+
```
516+
HTTP/1.1 201 Created
517+
```
518+
519+
```json
520+
{
521+
"key": "aB3dEfGhIjKlMnOp",
522+
"url": "https://app.fizzy.do/1234567/public/boards/aB3dEfGhIjKlMnOp"
523+
}
524+
```
525+
526+
If the board is already published, the existing publication is returned.
527+
528+
### `DELETE /:account_slug/boards/:board_id/publication`
529+
530+
Unpublishes a board, removing public access.
531+
532+
__Response:__
533+
534+
Returns `204 No Content` on success.
535+
505536
## Cards
506537

507538
Cards are tasks or items of work on a board. They can be organized into columns, tagged, assigned to users, and have comments.

test/controllers/boards/publications_controller_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ class Boards::PublicationsControllerTest < ActionDispatch::IntegrationTest
2727
assert_turbo_stream action: :replace, target: dom_id(@board, :publication)
2828
end
2929

30+
test "publish a board via JSON" do
31+
assert_not @board.published?
32+
33+
assert_changes -> { @board.reload.published? }, from: false, to: true do
34+
post board_publication_path(@board), as: :json
35+
end
36+
37+
assert_response :created
38+
body = @response.parsed_body
39+
assert_equal @board.reload.publication.key, body["key"]
40+
assert_includes body["url"], body["key"]
41+
end
42+
43+
test "unpublish a board via JSON" do
44+
@board.publish
45+
assert @board.published?
46+
47+
assert_changes -> { @board.reload.published? }, from: true, to: false do
48+
delete board_publication_path(@board), as: :json
49+
end
50+
51+
assert_response :no_content
52+
end
53+
3054
test "publish requires board admin permission" do
3155
logout_and_sign_in_as :jz
3256

0 commit comments

Comments
 (0)