MCP: workspace settings, viewer read access, and token access (#241)
* Add workspace MCP settings and token access controls.
Ship MCP settings UI, OAuth revoke/list helpers, Passport deploy wiring,
and workspace.token:mcp gating so assistants can connect without pulling
in welcome/onboarding from the parent epic.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Type MCP client config shapes instead of string checks.
Encode http/config-root on each advanced client and tighten primary
client ids so snippet generation does not branch on magic strings.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Polish MCP settings follow-ups from review.
Translate Ukrainian MCP copy, deep-link ChatGPT into connector
creation, drop an unused asset and revoke arg, and assert PATs are
rejected on the MCP endpoint.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Harden MCP connected clients, revoke scope, and OAuth consent.
List recoverable sessions with live refresh tokens, revoke only PATs,
throttle registration alone, and block viewers from authorizing MCP.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Simplify MCP OAuth route throttling to a single middleware group.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Allow workspace viewers read-only MCP access with web policy writes.
Mirror the web app: MCP connects on view + OAuth mcp:use, write tools
enforce createPost/update/delete/manageAccounts/manageTeam, and demotion
to Viewer keeps grants. Cover role denials, consent, and disconnect.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Harden MCP tool authz with shared workspace helpers.
Route ApiKey tools through AuthorizesMcpTool, fail closed on null user
or policy argument, and resolve the current workspace before mutating.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Drop redundant string casts on validated request data.
Enum::from and validated() fields are already strings, so the casts
add noise without changing behavior.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Show only the current user's MCP connections in settings.
Match API keys privacy: list and disconnect your own OAuth clients,
not teammates' across the account.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Cover LoadWorkspaceFromToken gaps and harden AuthorizesMcpTool tests.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Drop redundant is_string guard before UpdatePostTool find.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Refactor AppSidebar to always show MCP link and simplify route middleware definition in ai.php. The MCP link is now consistently displayed regardless of the current workspace state, and the route middleware syntax has been streamlined.
* Refresh MCP connected clients with Inertia usePoll.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Bump laravel/mcp to 0.9.1 and add the TryPost server icon.
Requires laravel/boost 2.5 for the Icon attribute; expose images/trypost/icon.png on TryPostServer.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Drop no-op ReflectionClass import in TryPostServerTest.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-06 12:54:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Enums\SocialAccount\Platform;
|
|
|
|
|
use App\Enums\UserWorkspace\Role;
|
|
|
|
|
use App\Mcp\Servers\TryPostServer;
|
feat: Asset Library list, preview, and attach via API and MCP (#282)
* feat: list, preview, and attach Asset Library media via API and MCP
Let API and MCP clients reuse workspace assets instead of re-uploading, sharing the same scoped query, signed preview, and idempotent attach path.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Align Asset Library API and MCP with main media patterns.
Drop the signed-preview stack, return Storage URLs and PostResource like existing attach flows, and query medias by morph owner instead of getMedia().
Co-authored-by: Cursor <cursoragent@cursor.com>
* Paginate workspace assets with the app default page size.
Keep list pagination in the action via config('app.pagination.default') instead of a hardcoded API page size.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Move asset API and MCP input rules into FormRequests.
Keep controllers and tools free of inline field validation; MCP tools reuse the request rule definitions.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Document asset MCP tools with explicit parameters and constraints.
Spell out workspace scope, return fields, sibling tools, and rejection cases so agents can call list/get/attach without guessing.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Harden asset attach against races and keep library metadata on the post.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Relock the library asset on attach so a deleted file cannot land on the post.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Document that omitting alt on attach keeps the library alt text.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-16 20:08:20 +00:00
|
|
|
use App\Mcp\Tools\Asset\AttachExistingAssetTool;
|
|
|
|
|
use App\Mcp\Tools\Asset\GetAssetTool;
|
|
|
|
|
use App\Mcp\Tools\Asset\ListAssetsTool;
|
MCP: workspace settings, viewer read access, and token access (#241)
* Add workspace MCP settings and token access controls.
Ship MCP settings UI, OAuth revoke/list helpers, Passport deploy wiring,
and workspace.token:mcp gating so assistants can connect without pulling
in welcome/onboarding from the parent epic.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Type MCP client config shapes instead of string checks.
Encode http/config-root on each advanced client and tighten primary
client ids so snippet generation does not branch on magic strings.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Polish MCP settings follow-ups from review.
Translate Ukrainian MCP copy, deep-link ChatGPT into connector
creation, drop an unused asset and revoke arg, and assert PATs are
rejected on the MCP endpoint.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Harden MCP connected clients, revoke scope, and OAuth consent.
List recoverable sessions with live refresh tokens, revoke only PATs,
throttle registration alone, and block viewers from authorizing MCP.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Simplify MCP OAuth route throttling to a single middleware group.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Allow workspace viewers read-only MCP access with web policy writes.
Mirror the web app: MCP connects on view + OAuth mcp:use, write tools
enforce createPost/update/delete/manageAccounts/manageTeam, and demotion
to Viewer keeps grants. Cover role denials, consent, and disconnect.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Harden MCP tool authz with shared workspace helpers.
Route ApiKey tools through AuthorizesMcpTool, fail closed on null user
or policy argument, and resolve the current workspace before mutating.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Drop redundant string casts on validated request data.
Enum::from and validated() fields are already strings, so the casts
add noise without changing behavior.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Show only the current user's MCP connections in settings.
Match API keys privacy: list and disconnect your own OAuth clients,
not teammates' across the account.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Cover LoadWorkspaceFromToken gaps and harden AuthorizesMcpTool tests.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Drop redundant is_string guard before UpdatePostTool find.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Refactor AppSidebar to always show MCP link and simplify route middleware definition in ai.php. The MCP link is now consistently displayed regardless of the current workspace state, and the route middleware syntax has been streamlined.
* Refresh MCP connected clients with Inertia usePoll.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Bump laravel/mcp to 0.9.1 and add the TryPost server icon.
Requires laravel/boost 2.5 for the Icon attribute; expose images/trypost/icon.png on TryPostServer.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Drop no-op ReflectionClass import in TryPostServerTest.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-06 12:54:51 +00:00
|
|
|
use App\Mcp\Tools\Label\CreateLabelTool;
|
|
|
|
|
use App\Mcp\Tools\Label\DeleteLabelTool;
|
|
|
|
|
use App\Mcp\Tools\Label\ListLabelsTool;
|
|
|
|
|
use App\Mcp\Tools\Label\UpdateLabelTool;
|
|
|
|
|
use App\Mcp\Tools\Post\AttachMediaFromUploadTool;
|
|
|
|
|
use App\Mcp\Tools\Post\AttachMediaFromUrlTool;
|
|
|
|
|
use App\Mcp\Tools\Post\PublishPostTool;
|
|
|
|
|
use App\Mcp\Tools\Post\RequestMediaUploadTool;
|
|
|
|
|
use App\Mcp\Tools\Signature\CreateSignatureTool;
|
|
|
|
|
use App\Mcp\Tools\Signature\DeleteSignatureTool;
|
|
|
|
|
use App\Mcp\Tools\Signature\ListSignaturesTool;
|
|
|
|
|
use App\Mcp\Tools\Signature\UpdateSignatureTool;
|
|
|
|
|
use App\Mcp\Tools\SocialAccount\ListDiscordChannelsTool;
|
|
|
|
|
use App\Mcp\Tools\SocialAccount\ListPinterestBoardsTool;
|
|
|
|
|
use App\Mcp\Tools\SocialAccount\ListSocialAccountsTool;
|
|
|
|
|
use App\Mcp\Tools\SocialAccount\ToggleSocialAccountTool;
|
2026-09-04 15:00:32 +00:00
|
|
|
use App\Mcp\Tools\Webhook\CreateWebhookTool;
|
|
|
|
|
use App\Mcp\Tools\Webhook\ListWebhooksTool;
|
MCP: workspace settings, viewer read access, and token access (#241)
* Add workspace MCP settings and token access controls.
Ship MCP settings UI, OAuth revoke/list helpers, Passport deploy wiring,
and workspace.token:mcp gating so assistants can connect without pulling
in welcome/onboarding from the parent epic.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Type MCP client config shapes instead of string checks.
Encode http/config-root on each advanced client and tighten primary
client ids so snippet generation does not branch on magic strings.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Polish MCP settings follow-ups from review.
Translate Ukrainian MCP copy, deep-link ChatGPT into connector
creation, drop an unused asset and revoke arg, and assert PATs are
rejected on the MCP endpoint.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Harden MCP connected clients, revoke scope, and OAuth consent.
List recoverable sessions with live refresh tokens, revoke only PATs,
throttle registration alone, and block viewers from authorizing MCP.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Simplify MCP OAuth route throttling to a single middleware group.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Allow workspace viewers read-only MCP access with web policy writes.
Mirror the web app: MCP connects on view + OAuth mcp:use, write tools
enforce createPost/update/delete/manageAccounts/manageTeam, and demotion
to Viewer keeps grants. Cover role denials, consent, and disconnect.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Harden MCP tool authz with shared workspace helpers.
Route ApiKey tools through AuthorizesMcpTool, fail closed on null user
or policy argument, and resolve the current workspace before mutating.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Drop redundant string casts on validated request data.
Enum::from and validated() fields are already strings, so the casts
add noise without changing behavior.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Show only the current user's MCP connections in settings.
Match API keys privacy: list and disconnect your own OAuth clients,
not teammates' across the account.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Cover LoadWorkspaceFromToken gaps and harden AuthorizesMcpTool tests.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Drop redundant is_string guard before UpdatePostTool find.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Refactor AppSidebar to always show MCP link and simplify route middleware definition in ai.php. The MCP link is now consistently displayed regardless of the current workspace state, and the route middleware syntax has been streamlined.
* Refresh MCP connected clients with Inertia usePoll.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Bump laravel/mcp to 0.9.1 and add the TryPost server icon.
Requires laravel/boost 2.5 for the Icon attribute; expose images/trypost/icon.png on TryPostServer.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Drop no-op ReflectionClass import in TryPostServerTest.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-06 12:54:51 +00:00
|
|
|
use App\Models\Media;
|
|
|
|
|
use App\Models\Post;
|
|
|
|
|
use App\Models\SocialAccount;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
use App\Models\WorkspaceLabel;
|
|
|
|
|
use App\Models\WorkspaceSignature;
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
use Illuminate\Testing\Fluent\AssertableJson;
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
$this->owner = User::factory()->create();
|
|
|
|
|
$this->workspace = Workspace::factory()->create(['user_id' => $this->owner->id]);
|
|
|
|
|
$this->workspace->members()->attach($this->owner->id, ['role' => Role::Admin->value]);
|
|
|
|
|
$this->owner->update(['current_workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
$this->viewer = User::factory()->create(['account_id' => $this->owner->account_id]);
|
|
|
|
|
$this->workspace->members()->attach($this->viewer->id, ['role' => Role::Viewer->value]);
|
|
|
|
|
$this->viewer->update(['current_workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
$this->member = User::factory()->create(['account_id' => $this->owner->account_id]);
|
|
|
|
|
$this->workspace->members()->attach($this->member->id, ['role' => Role::Member->value]);
|
|
|
|
|
$this->member->update(['current_workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
$this->post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->owner->id,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('viewers can list labels signatures and social accounts via mcp', function () {
|
|
|
|
|
WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
WorkspaceSignature::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::LinkedIn,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(ListLabelsTool::class, [])
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertStructuredContent(fn (AssertableJson $json) => $json->has('labels', 1)->etc());
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(ListSignaturesTool::class, [])
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertStructuredContent(fn (AssertableJson $json) => $json->has('signatures', 1)->etc());
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(ListSocialAccountsTool::class, [])
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertStructuredContent(fn (AssertableJson $json) => $json->has('social_accounts', 1)->etc());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('viewers cannot publish attach media or request uploads via mcp', function () {
|
|
|
|
|
$uploadToken = (string) Str::uuid();
|
|
|
|
|
Media::factory()->create([
|
|
|
|
|
'mediable_type' => (new Workspace)->getMorphClass(),
|
|
|
|
|
'mediable_id' => $this->workspace->id,
|
|
|
|
|
'collection' => 'assets',
|
|
|
|
|
'upload_token' => $uploadToken,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(PublishPostTool::class, ['post_id' => $this->post->id])
|
|
|
|
|
->assertHasErrors(['Not authorized to publish this post.']);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(AttachMediaFromUrlTool::class, [
|
|
|
|
|
'post_id' => $this->post->id,
|
|
|
|
|
'urls' => [['url' => 'https://example.com/photo.jpg']],
|
|
|
|
|
])
|
|
|
|
|
->assertHasErrors(['Not authorized to update this post.']);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(AttachMediaFromUploadTool::class, [
|
|
|
|
|
'post_id' => $this->post->id,
|
|
|
|
|
'upload_token' => $uploadToken,
|
|
|
|
|
])
|
|
|
|
|
->assertHasErrors(['Not authorized to update this post.']);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(RequestMediaUploadTool::class, [])
|
|
|
|
|
->assertHasErrors(['Not authorized to upload media.']);
|
feat: Asset Library list, preview, and attach via API and MCP (#282)
* feat: list, preview, and attach Asset Library media via API and MCP
Let API and MCP clients reuse workspace assets instead of re-uploading, sharing the same scoped query, signed preview, and idempotent attach path.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Align Asset Library API and MCP with main media patterns.
Drop the signed-preview stack, return Storage URLs and PostResource like existing attach flows, and query medias by morph owner instead of getMedia().
Co-authored-by: Cursor <cursoragent@cursor.com>
* Paginate workspace assets with the app default page size.
Keep list pagination in the action via config('app.pagination.default') instead of a hardcoded API page size.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Move asset API and MCP input rules into FormRequests.
Keep controllers and tools free of inline field validation; MCP tools reuse the request rule definitions.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Document asset MCP tools with explicit parameters and constraints.
Spell out workspace scope, return fields, sibling tools, and rejection cases so agents can call list/get/attach without guessing.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Harden asset attach against races and keep library metadata on the post.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Relock the library asset on attach so a deleted file cannot land on the post.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Document that omitting alt on attach keeps the library alt text.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-16 20:08:20 +00:00
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(ListAssetsTool::class, [])
|
|
|
|
|
->assertHasErrors(['Not authorized to view assets.']);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(GetAssetTool::class, ['asset_id' => (string) Str::uuid()])
|
|
|
|
|
->assertHasErrors(['Not authorized to view assets.']);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(AttachExistingAssetTool::class, [
|
|
|
|
|
'post_id' => $this->post->id,
|
|
|
|
|
'asset_id' => (string) Str::uuid(),
|
|
|
|
|
])
|
|
|
|
|
->assertHasErrors(['Not authorized to update this post.']);
|
MCP: workspace settings, viewer read access, and token access (#241)
* Add workspace MCP settings and token access controls.
Ship MCP settings UI, OAuth revoke/list helpers, Passport deploy wiring,
and workspace.token:mcp gating so assistants can connect without pulling
in welcome/onboarding from the parent epic.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Type MCP client config shapes instead of string checks.
Encode http/config-root on each advanced client and tighten primary
client ids so snippet generation does not branch on magic strings.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Polish MCP settings follow-ups from review.
Translate Ukrainian MCP copy, deep-link ChatGPT into connector
creation, drop an unused asset and revoke arg, and assert PATs are
rejected on the MCP endpoint.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Harden MCP connected clients, revoke scope, and OAuth consent.
List recoverable sessions with live refresh tokens, revoke only PATs,
throttle registration alone, and block viewers from authorizing MCP.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Simplify MCP OAuth route throttling to a single middleware group.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Allow workspace viewers read-only MCP access with web policy writes.
Mirror the web app: MCP connects on view + OAuth mcp:use, write tools
enforce createPost/update/delete/manageAccounts/manageTeam, and demotion
to Viewer keeps grants. Cover role denials, consent, and disconnect.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Harden MCP tool authz with shared workspace helpers.
Route ApiKey tools through AuthorizesMcpTool, fail closed on null user
or policy argument, and resolve the current workspace before mutating.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Drop redundant string casts on validated request data.
Enum::from and validated() fields are already strings, so the casts
add noise without changing behavior.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Show only the current user's MCP connections in settings.
Match API keys privacy: list and disconnect your own OAuth clients,
not teammates' across the account.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Cover LoadWorkspaceFromToken gaps and harden AuthorizesMcpTool tests.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Drop redundant is_string guard before UpdatePostTool find.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Refactor AppSidebar to always show MCP link and simplify route middleware definition in ai.php. The MCP link is now consistently displayed regardless of the current workspace state, and the route middleware syntax has been streamlined.
* Refresh MCP connected clients with Inertia usePoll.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Bump laravel/mcp to 0.9.1 and add the TryPost server icon.
Requires laravel/boost 2.5 for the Icon attribute; expose images/trypost/icon.png on TryPostServer.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Drop no-op ReflectionClass import in TryPostServerTest.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-06 12:54:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('viewers cannot manage labels or signatures via mcp', function () {
|
|
|
|
|
$label = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
$signature = WorkspaceSignature::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(CreateLabelTool::class, ['name' => 'Nope', 'color' => '#112233'])
|
|
|
|
|
->assertHasErrors(['Not authorized to manage labels.']);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(UpdateLabelTool::class, [
|
|
|
|
|
'label_id' => $label->id,
|
|
|
|
|
'name' => 'Nope',
|
|
|
|
|
'color' => '#112233',
|
|
|
|
|
])
|
|
|
|
|
->assertHasErrors(['Not authorized to manage labels.']);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(DeleteLabelTool::class, ['label_id' => $label->id])
|
|
|
|
|
->assertHasErrors(['Not authorized to manage labels.']);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(CreateSignatureTool::class, ['name' => 'Nope', 'content' => 'x'])
|
|
|
|
|
->assertHasErrors(['Not authorized to manage signatures.']);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(UpdateSignatureTool::class, [
|
|
|
|
|
'signature_id' => $signature->id,
|
|
|
|
|
'name' => 'Nope',
|
|
|
|
|
'content' => 'x',
|
|
|
|
|
])
|
|
|
|
|
->assertHasErrors(['Not authorized to manage signatures.']);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(DeleteSignatureTool::class, ['signature_id' => $signature->id])
|
|
|
|
|
->assertHasErrors(['Not authorized to manage signatures.']);
|
|
|
|
|
|
|
|
|
|
expect($label->fresh())->not->toBeNull()
|
|
|
|
|
->and($signature->fresh())->not->toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('viewers cannot toggle social accounts or list compose helpers via mcp', function () {
|
|
|
|
|
$linkedin = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::LinkedIn,
|
|
|
|
|
'is_active' => true,
|
|
|
|
|
]);
|
|
|
|
|
$discord = SocialAccount::factory()->discord()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
]);
|
|
|
|
|
$pinterest = SocialAccount::factory()->pinterest()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(ToggleSocialAccountTool::class, ['account_id' => $linkedin->id])
|
|
|
|
|
->assertHasErrors(['Not authorized to manage social accounts.']);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(ListDiscordChannelsTool::class, ['account_id' => $discord->id])
|
|
|
|
|
->assertHasErrors(['Not authorized to manage posts.']);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->viewer)
|
|
|
|
|
->tool(ListPinterestBoardsTool::class, ['account_id' => $pinterest->id])
|
|
|
|
|
->assertHasErrors(['Not authorized to manage posts.']);
|
|
|
|
|
|
|
|
|
|
expect($linkedin->fresh()->is_active)->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('members cannot toggle social accounts via mcp', function () {
|
|
|
|
|
$account = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::LinkedIn,
|
|
|
|
|
'is_active' => true,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->member)
|
|
|
|
|
->tool(ToggleSocialAccountTool::class, ['account_id' => $account->id])
|
|
|
|
|
->assertHasErrors(['Not authorized to manage social accounts.']);
|
|
|
|
|
|
|
|
|
|
expect($account->fresh()->is_active)->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('admins can toggle social accounts via mcp', function () {
|
|
|
|
|
$account = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::LinkedIn,
|
|
|
|
|
'is_active' => true,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->owner)
|
|
|
|
|
->tool(ToggleSocialAccountTool::class, ['account_id' => $account->id])
|
|
|
|
|
->assertOk();
|
|
|
|
|
|
|
|
|
|
expect($account->fresh()->is_active)->toBeFalse();
|
|
|
|
|
});
|
2026-09-04 15:00:32 +00:00
|
|
|
|
|
|
|
|
test('viewers and members cannot list or create webhooks via mcp', function (Role $role) {
|
|
|
|
|
$user = $role === Role::Viewer ? $this->viewer : $this->member;
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($user)
|
|
|
|
|
->tool(ListWebhooksTool::class, [])
|
|
|
|
|
->assertHasErrors(['Not authorized to manage webhooks.']);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($user)
|
|
|
|
|
->tool(CreateWebhookTool::class, [
|
|
|
|
|
'endpoint' => 'https://example.com/webhooks',
|
|
|
|
|
'events' => ['post.published'],
|
|
|
|
|
])
|
|
|
|
|
->assertHasErrors(['Not authorized to manage webhooks.']);
|
|
|
|
|
})->with([
|
|
|
|
|
Role::Viewer,
|
|
|
|
|
Role::Member,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
test('admins can list webhooks via mcp', function () {
|
|
|
|
|
TryPostServer::actingAs($this->owner)
|
|
|
|
|
->tool(ListWebhooksTool::class, [])
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertStructuredContent(fn (AssertableJson $json) => $json->has('webhooks', 0)->etc());
|
|
|
|
|
});
|