- Create Account model as Cashier Billable entity (stripe, plan, subscription) - Account owns workspaces and has an owner_id (User) - User belongs to one Account via account_id - Workspace belongs to Account via account_id, no longer has billing fields - Remove Brand model entirely (workspaces serve as grouping) - Rename brand_limit to workspace_limit in plans - Workspace roles simplified: admin/member/viewer (owner via Account) - Invites now belong to Account with workspaces JSON array - Pennant features scope changed from Workspace to Account - EnsureSubscribed middleware checks Account subscription - All controllers updated: BillingController, OnboardingController, WorkspaceInviteController, SocialController, StripeEventListener - Frontend: extract GoogleAuthButton component, create WorkspaceRole enum for type-safe role checks, fix all views for new architecture - All 1101 tests passing
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Resources\App\HandleInertiaRequests;
|
|
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
|
|
class AuthWorkspaceResource
|
|
{
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public static function make(Workspace $workspace, ?User $user = null): array
|
|
{
|
|
return [
|
|
'id' => $workspace->id,
|
|
'name' => $workspace->name,
|
|
'timezone' => $workspace->timezone,
|
|
'logo_url' => $workspace->logo_url,
|
|
'created_at' => $workspace->created_at->toIso8601String(),
|
|
'role' => $user ? self::resolveRole($workspace, $user) : null,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public static function summary(Workspace $workspace): array
|
|
{
|
|
return [
|
|
'id' => $workspace->id,
|
|
'name' => $workspace->name,
|
|
'logo_url' => $workspace->logo_url,
|
|
];
|
|
}
|
|
|
|
private static function resolveRole(Workspace $workspace, User $user): ?string
|
|
{
|
|
if ($user->isAccountOwner() && $workspace->account_id === $user->account_id) {
|
|
return 'owner';
|
|
}
|
|
|
|
return $workspace->members()
|
|
->where('users.id', $user->id)
|
|
->first()
|
|
?->pivot
|
|
?->role;
|
|
}
|
|
}
|