Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/controllers/boards/publications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ class Boards::PublicationsController < ApplicationController

def create
@board.publish

respond_to do |format|
format.turbo_stream
format.json { render json: { key: @board.publication.key, url: published_board_url(@board) }, status: :created }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON response should typically be the entity created. Would add a partial for the board publication, include it in boards/_board (if published), and then choose whether to render the publication itself or the entire board in response here.

end
end

def destroy
@board.unpublish
@board.reload

respond_to do |format|
format.turbo_stream
format.json { head :no_content }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the default Rails response anyway? Can it be omitted?

end
end
end
31 changes: 31 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,37 @@ __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
{
"key": "aB3dEfGhIjKlMnOp",
"url": "https://app.fizzy.do/1234567/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.
Expand Down
24 changes: 24 additions & 0 deletions test/controllers/boards/publications_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ 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
assert_equal @board.reload.publication.key, body["key"]
assert_includes body["url"], body["key"]
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

Expand Down