-
Notifications
You must be signed in to change notification settings - Fork 502
Add basic API #1766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
dhh
wants to merge
59
commits into
main
Choose a base branch
from
basic-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+938
−46
Draft
Add basic API #1766
Changes from 17 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
d787971
Add API to boards
dhh 60cd429
Merge branch 'main' into basic-api
dhh 237f02b
Add access token authentication via HTTP AUTHORIZATION bearer header
dhh 155bd0b
Merge branch 'main' into basic-api
dhh 982a1dd
Test the boards API
dhh 27fca3e
API index for cards
dhh 95708c7
Correct
dhh a7464f6
Tie access token directly to session
dhh 4db45db
Add developer section to user profile
jzimdars 95f89bf
List, create, and revoke access tokens
jzimdars 367f45b
Authenticate api requests without needing a session
dhh 350d349
Merge branch 'main' into basic-api
dhh 88ea7d1
Drop the need for access tokens to have a session
dhh 05f301f
Handle everything in the same method
dhh 5067a36
Inline now anemic helper methods
dhh 3ac7c82
Clarify
dhh a47c8f4
The magic of it is not needing to manually yield it!
dhh a47bd51
This had gotten stripped
dhh 1b84b69
Smooth out the finder API
dhh b512c8c
Access tokens are strictly personal
dhh db226a7
Inline anemic partial
dhh d2b849c
Only allow new token to be viewed within 10 seconds
dhh 9db0b84
Polish
dhh d889127
Awaiting JZ's design
dhh 25ca9ea
Only allow writing when the access token has permission
dhh eefbf58
Allow API JSON requests to sidestep csrf protection
dhh 9832b1f
Creating a new board will return the location header
dhh c4feffa
Return json URLs for API actions
dhh 89f5e73
Create cards via API
dhh f608bfd
Design show view
jzimdars 684ec3d
Complete the view transition loop
jzimdars 0c60e27
Use built-in authenticate_or_request_with_http_token
dhh 3bfce80
Add API support for users
jayohms 673e06e
Add top-level API index support for tags
jayohms d3cdb01
Merge branch 'main' into basic-api
dhh cbc24e7
Merge branch 'main' into basic-api
dhh 71ba999
Excess whitespace
dhh 9567a07
Only authenticate with bearer token if the header is present
dhh 13a471b
Compact
dhh bd5b46b
Publish any API card as soon as it is created
dhh 748be87
Include card description and tags
dhh 9d89967
Fix quoting
dhh be4f9ff
Add an /identity.json endpoint to obtain the identity accounts and users
jayohms 528258b
Fix identity tests
monorkin 7866537
Fix Current not setting a session in some contexts
monorkin 591f290
Move tests into their controller tests
monorkin 21b1075
Add card update & delete actions
monorkin 0db9614
Add API for assigning cards
monorkin 2fe4891
Add API for mobing cards between boards
monorkin ac656fe
Add API for closing and opening cards
monorkin 8d53b3d
Add API for comments CRUD
monorkin 4e55b04
Add API for gilding cards
monorkin 2a3c529
Add API for removing card images
monorkin 803d9cd
Add API for postponing cards
monorkin f0e6258
Add API for CRUD actions on steps
monorkin 44d8051
Add API for tagging cards
monorkin ec1348f
Add API for card triage
monorkin 0d96d35
Add API for watching cards
monorkin 5019bb5
Add API for reactions
monorkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| .access_tokens_table { | ||
| border-collapse: collapse; | ||
| inline-size: 100%; | ||
|
|
||
| td, th { | ||
| border-block-end: 1px solid var(--color-ink-light); | ||
| padding-inline: var(--inline-space); | ||
| text-align: start; | ||
| } | ||
|
|
||
| th { | ||
| font-size: var(--text-x-small); | ||
| text-transform: uppercase; | ||
| } | ||
|
|
||
| tr:nth-of-type(even) { | ||
| background-color: var(--color-ink-lightest); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| class Users::AccessTokensController < ApplicationController | ||
| before_action :set_user | ||
| before_action :set_access_token, except: %i[ index new create ] | ||
|
|
||
| def index | ||
| set_page_and_extract_portion_from @user.identity.access_tokens.order(created_at: :desc) | ||
| end | ||
|
|
||
| def new | ||
| @access_token = @user.identity.access_tokens.new | ||
| end | ||
|
|
||
| def create | ||
| @access_token = @user.identity.access_tokens.create!(access_token_params) | ||
| redirect_to user_access_tokens_path(@user) | ||
| end | ||
|
|
||
| def destroy | ||
| @access_token.destroy! | ||
| redirect_to user_access_tokens_path(@user) | ||
| end | ||
|
|
||
| private | ||
| def set_user | ||
| @user = Current.account.users.active.find(params[:user_id]) | ||
| end | ||
|
|
||
| def set_access_token | ||
| @access_token = @user.identity.access_tokens.find(params[:id]) | ||
| end | ||
|
|
||
| def access_token_params | ||
| params.expect(access_token: [ :description, :permission ]) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| class Identity::AccessToken < ApplicationRecord | ||
| belongs_to :identity | ||
|
|
||
| has_secure_token | ||
| enum :permission, %w[ read write ].index_by(&:itself), default: :read | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| json.array! @boards, partial: "boards/board", as: :board |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| json.partial! "boards/board", board: @board |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| json.array! @page.records, partial: "cards/card", as: :card | ||
|
|
||
| json.next_page_url cards_path(@board, page: @page.next_param) unless @page.last? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <div class="flex flex-column align-center gap margin-block-start-double"> | ||
| <header class="full-width"> | ||
| <h2 class="divider txt-large margin-none-block">Developer</h2> | ||
| </header> | ||
|
|
||
| <div class="flex align-center gap txt-normal"> | ||
| <%= link_to "Personal access tokens", user_access_tokens_path(user), class: "btn" %> | ||
| </div> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <tr> | ||
| <td><strong><%= access_token.description %></strong></td> | ||
| <td><%= access_token.permission.humanize %></td> | ||
| <td><%= local_datetime_tag access_token.created_at, style: :datetime %></td> | ||
| <td> | ||
| <%= button_to user_access_token_path(@user, access_token), method: :delete, | ||
| class: "btn txt-negative btn--circle txt-x-small borderless fill-transparent", | ||
| data: { turbo_confirm: "Are you sure you want to permanently revoke this access token?" } do %> | ||
| <%= icon_tag "trash" %> | ||
| <span class="for-screen-reader">Edit this token</span> | ||
| <% end %> | ||
| </td> | ||
| </tr> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <% @page_title = "Personal access tokens" %> | ||
|
|
||
| <% content_for :header do %> | ||
| <div class="header__actions header__actions--start"> | ||
| <%= back_link_to "My profile", user_path(@user), "keydown.left@document->hotkey#click keydown.esc@document->hotkey#click" %> | ||
| </div> | ||
|
|
||
| <h1 class="header__title"><%= @page_title %></h1> | ||
| <% end %> | ||
|
|
||
| <section class="panel panel--wide shadow center webhooks"> | ||
| <% if @page.used? %> | ||
| <p class="margin-none-block-start">Tokens you have generated that can be used to access the Fizzy API.</p> | ||
| <table class="access_tokens_table margin-block-end-double max-width txt-small"> | ||
| <thead> | ||
| <tr> | ||
| <th>Description</th> | ||
| <th>Permission</th> | ||
| <th>Created</th> | ||
| <th></th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <%= with_automatic_pagination :access_tokens, @page do %> | ||
| <%= render partial: "users/access_tokens/access_token", collection: @page.records %> | ||
| <% end %> | ||
| </tbody> | ||
| </table> | ||
| <% else %> | ||
| <p class="margin-none-block-start">Personal access tokens can be used like a password to access the Fizzy developer API. You can have as many tokens as you need and revoke access to each one at any time.</p> | ||
| <% end %> | ||
|
|
||
| <%= link_to new_user_access_token_path(@user), class: "btn btn--link" do %> | ||
| <%= icon_tag "add" %> | ||
| <span>Generate a new access token</span> | ||
| <% end %> | ||
| </section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <% @page_title = "Generate a personal access token" %> | ||
|
|
||
| <% content_for :header do %> | ||
| <div class="header__actions header__actions--start"> | ||
| <%= back_link_to "tokens", user_access_tokens_path(@user), "keydown.left@document->hotkey#click keydown.esc@document->hotkey#click" %> | ||
| </div> | ||
|
|
||
| <h1 class="header__title"><%= @page_title %></h1> | ||
| <% end %> | ||
|
|
||
| <article class="panel panel--wide shadow center txt-align-start" style="view-transition-name: <%= dom_id(@access_token) %>"> | ||
| <%= form_with model: @access_token, url: user_access_tokens_path(@user), scope: :access_token, data: { controller: "form" }, html: { class: "flex flex-column gap" } do |form| %> | ||
| <div class="flex flex-column gap-half"> | ||
| <strong><%= form.label :description, "Access token description" %></strong> | ||
| <%= form.text_field :description, required: true, autofocus: true, class: "input", placeholder: "e.g. Github", data: { action: "keydown.esc@document->form#cancel" } %> | ||
| </div> | ||
|
|
||
| <div class="flex flex-column gap-half"> | ||
| <strong><%= form.label :permission %></strong> | ||
| <%= form.select :permission, options_for_select(access_token_permission_options), {}, class: "input input--select" %> | ||
| </div> | ||
|
|
||
| <%= form.button type: :submit, class: "btn btn--link center txt-medium" do %> | ||
| <span>Generate access token</span> | ||
| <% end %> | ||
|
|
||
| <%= link_to "Cancel and go back", user_access_tokens_path(@user), data: { form_target: "cancel" }, hidden: true %> | ||
| <% end %> | ||
| </article> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
db/migrate/20251201132341_create_identity_access_tokens.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| class CreateIdentityAccessTokens < ActiveRecord::Migration[8.2] | ||
| def change | ||
| create_table :identity_access_tokens, id: :uuid do |t| | ||
| t.uuid :identity_id, null: false | ||
| t.string :token | ||
| t.string :permission | ||
| t.text :description | ||
|
|
||
| t.timestamps | ||
|
|
||
| t.index ["identity_id"], name: "index_access_token_on_identity_id" | ||
| end | ||
| end | ||
| end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.