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
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,47 @@ GET /projects/{project}/items/{item}/ai
/projects/1-bugs/items/2-bug-in-sites-overview/ai?format=yml&include[comments]=1
```

## Read API and webhooks

### Read API

Create an API token in the admin panel under **Manage > API tokens** (not tied to a user, shown only once) and send it as `Authorization: Bearer <token>`. Private projects, items and comments are included.

```
GET /api/v1/projects
GET /api/v1/items?project_id=1
GET /api/v1/comments?item_id=1
```

| Parameter | Description |
|---|---|
| `updated_since` | Only records updated at or after this date, e.g. `2026-01-01T00:00:00Z` |
| `per_page` | 1-100, defaults to 50 |
| `page` | Page number; responses include `data`, `links` and `meta` |

Deleted records are not listed, use the `*.deleted` webhooks for those. `updated_since` accepts a time zone offset. Responses are always JSON.

### Webhooks

Admins manage webhooks in the admin panel under **Manage > Webhooks**: a URL, a secret and the events to receive. The URL must use `https` and resolve to a public address, redirects are not followed.

| Event | Sent when |
|---|---|
| `item.created` | an item is created |
| `item.updated` | an item is changed |
| `item.status_changed` | an item moves to another board (adds `previous_board_id`) |
| `item.deleted` | an item is deleted |
| `comment.created` | a comment is placed |
| `comment.updated` | the content or visibility of a comment is changed |
| `comment.deleted` | a comment is deleted |
| `project.created` | a project is created |
| `project.updated` | a project is changed |
| `project.deleted` | a project is deleted |

Requests are `POST` with a JSON body `{"event", "delivery_id", "created_at", "data"}`, where `data` has the same shape as the API resources. `created_at` is the time the event happened. Changes to the vote count alone do not send `item.updated`. Comments that are removed together with their item or user do not send `comment.deleted`, use `item.deleted` for that. Requests are sent through the queue (make sure a worker is running, with `QUEUE_CONNECTION=sync` they are sent after the response and failures are only logged) and retried up to 5 times with increasing delays when the endpoint does not answer with a 2xx status.

Verify a request by computing `sha256=` + `HMAC_SHA256(secret, X-Roadmap-Timestamp + "." + raw body)` and comparing it with the `X-Roadmap-Signature` header. Reject requests with an old timestamp to prevent replays.

## Docker Support

### Getting up and running...
Expand Down
25 changes: 25 additions & 0 deletions app/Enums/WebhookEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Enums;

enum WebhookEvent: string
{
case ItemCreated = 'item.created';
case ItemUpdated = 'item.updated';
case ItemStatusChanged = 'item.status_changed';
case ItemDeleted = 'item.deleted';
case CommentCreated = 'comment.created';
case CommentUpdated = 'comment.updated';
case CommentDeleted = 'comment.deleted';
case ProjectCreated = 'project.created';
case ProjectUpdated = 'project.updated';
case ProjectDeleted = 'project.deleted';

/**
* @return array<string, string>
*/
public static function options(): array
{
return collect(self::cases())->mapWithKeys(fn (self $event) => [$event->value => $event->value])->all();
}
}
89 changes: 89 additions & 0 deletions app/Filament/Resources/ApiTokens/ApiTokenResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace App\Filament\Resources\ApiTokens;

use App\Models\ApiToken;
use Filament\Tables\Table;
use Filament\Schemas\Schema;
use Filament\Resources\Resource;
use Filament\Actions\DeleteAction;
use Filament\Actions\DeleteBulkAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Forms\Components\TextInput;
use App\Filament\Resources\ApiTokens\Pages\ListApiTokens;
use App\Filament\Resources\ApiTokens\Pages\CreateApiToken;

class ApiTokenResource extends Resource

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Blocking (security): this resource has no policy, canAccess() or shouldRegisterNavigation() guard. User::canAccessPanel() lets both Admins and Employees in, so an Employee can open Manage > API tokens, create a token and read every private project, item and comment through /api/v1.

The rest of the admin-only area restricts this explicitly. Settings and System check hasRole(UserRole::Admin), and UserPolicy does the same. The README also says "Admins manage webhooks". The tests only log in as an Admin, so nothing covers this.

Suggestion: add an ApiTokenPolicy (and a WebhookEndpointPolicy) that only allows UserRole::Admin, plus a test that an Employee gets a 403.

{
protected static ?string $model = ApiToken::class;

protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-key';

protected static ?int $navigationSort = 1400;

public static function shouldRegisterNavigation(): bool

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: now that the policy is in place, this override isn't needed. Filament v5's HasNavigation::registerNavigationItems() already returns early when ! static::canAccess(). Same in WebhookResource.php:33.

{
return static::canAccess();
}

public static function getNavigationGroup(): ?string
{
return trans('nav.manage');
}

public static function getNavigationLabel(): string
{
return trans('nav.api-tokens');
}

public static function getModelLabel(): string
{
return trans('resources.api-token.label');
}

public static function getPluralModelLabel(): string
{
return trans('resources.api-token.label-plural');
}

public static function form(Schema $schema): Schema
{
return $schema->components([
TextInput::make('name')
->label(trans('resources.api-token.name'))
->maxLength(255)
->required(),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->label(trans('resources.api-token.name'))
->searchable(),
TextColumn::make('last_used_at')
->label(trans('resources.api-token.last-used-at'))
->since()
->placeholder('-'),
TextColumn::make('created_at')
->label(trans('resources.created-at'))
->dateTime(),
])
->recordActions([
DeleteAction::make(),
])
->toolbarActions([
DeleteBulkAction::make(),
]);
}

public static function getPages(): array
{
return [
'index' => ListApiTokens::route('/'),
'create' => CreateApiToken::route('/create'),
];
}
}
38 changes: 38 additions & 0 deletions app/Filament/Resources/ApiTokens/Pages/CreateApiToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Filament\Resources\ApiTokens\Pages;

use App\Models\ApiToken;
use Illuminate\Database\Eloquent\Model;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\CreateRecord;
use App\Filament\Resources\ApiTokens\ApiTokenResource;

class CreateApiToken extends CreateRecord
{
protected static string $resource = ApiTokenResource::class;

protected function handleRecordCreation(array $data): Model
{
[$token, $plainTextToken] = ApiToken::generate($data['name']);

Notification::make()
->title(trans('resources.api-token.created-title'))
->body(trans('resources.api-token.created-body', ['token' => $plainTextToken]))
->success()
->persistent()
->send();

return $token;
}

protected function getCreatedNotification(): ?Notification
{
return null;
}

protected function getRedirectUrl(): string
{
return static::getResource()::getUrl('index');
}
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/ApiTokens/Pages/ListApiTokens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\ApiTokens\Pages;

use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
use App\Filament\Resources\ApiTokens\ApiTokenResource;

class ListApiTokens extends ListRecords
{
protected static string $resource = ApiTokenResource::class;

protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}
11 changes: 11 additions & 0 deletions app/Filament/Resources/Webhooks/Pages/CreateWebhook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Filament\Resources\Webhooks\Pages;

use Filament\Resources\Pages\CreateRecord;
use App\Filament\Resources\Webhooks\WebhookResource;

class CreateWebhook extends CreateRecord
{
protected static string $resource = WebhookResource::class;
}
27 changes: 27 additions & 0 deletions app/Filament/Resources/Webhooks/Pages/EditWebhook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Filament\Resources\Webhooks\Pages;

use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
use App\Filament\Resources\Webhooks\WebhookResource;

class EditWebhook extends EditRecord
{
protected static string $resource = WebhookResource::class;

protected function mutateFormDataBeforeFill(array $data): array
{
// `secret` is hidden on the model, so Filament would otherwise leave the field empty.
$data['secret'] = $this->record->secret;

return $data;
}

protected function getHeaderActions(): array
{
return [
DeleteAction::make(),
];
}
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/Webhooks/Pages/ListWebhooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\Webhooks\Pages;

use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
use App\Filament\Resources\Webhooks\WebhookResource;

class ListWebhooks extends ListRecords
{
protected static string $resource = WebhookResource::class;

protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}
Loading
Loading