2026-01-15 01:13:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
refactor: settings redesign, Spanish translations, language system, strict_types
Settings pages:
- Redesign layout to match Sendkit (max-w-4xl, space-y-12, Separator sections)
- Merge Members page into Workspace settings with Table, invite Dialog, ConfirmDeleteModal
- Add workspace logo upload/delete routes and controller methods
- Translate all hardcoded strings in Workspace.vue modals
Language system:
- Drop languages table, replace language_id FK with locale string column on users
- Create config/languages.php for available languages and default locale
- Add Spanish (es) translations (13 files)
- Simplify HandleInertiaRequests, ProfileController, RegisteredUserController
Code quality:
- Add declare(strict_types=1) to all PHP files
- Fix MastodonPublisher using wrong attribute (filename -> original_filename)
- Fix HasMediaTest for new has_photo/photo_url accessors
- Fix PublishToSocialPlatformTest type error revealed by strict_types
- Remove orphaned Language model from AppServiceProvider morph map
- Update User TypeScript interface (has_photo, photo_url, locale)
- Eager load media relation on workspaces to prevent N+1
- Add 8 new tests for workspace logo upload/delete
- Update workspace settings test to assert members/invitations props
All 710 tests passing.
2026-03-30 03:20:43 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-01-15 01:13:44 +00:00
|
|
|
namespace App\Models;
|
|
|
|
|
|
feat: notification system with SendNotification job, dialog UI, tests
Backend:
- Create notifications table (user_id, workspace_id, type, channel,
title, body, data JSON, read_at, archived_at)
- Create Notification model with Type enum (post_failed,
account_disconnected, invite_received, member_joined, member_removed)
and Channel enum (email, in_app, both)
- Create SendNotification job: isolated from publish flow, handles
saving in-app notification and sending email independently
- NotificationController: index (excludes archived, scoped to workspace),
markAsRead, markAllAsRead, archiveAll
- Integrate with PublishToSocialPlatform (post failed/partial)
- Integrate with VerifyWorkspaceConnections (batch disconnection)
- Integrate with SocialAccount::markAsDisconnected (single disconnection)
- All use SendNotification::dispatch() instead of direct Mail::to()
Frontend:
- NotificationBell component in sidebar footer with unread badge
- Dialog with notification list, mark as read, mark all read, archive all
- Click navigates to relevant page (post edit, accounts)
- i18n for notifications UI (en, es, pt-BR)
Tests:
- 8 tests for NotificationController (auth, CRUD, workspace scoping)
- 4 tests for SendNotification job (channels, email, data storage)
All 745 tests passing.
2026-03-30 19:47:03 +00:00
|
|
|
use App\Enums\Notification\Channel;
|
|
|
|
|
use App\Enums\Notification\Type;
|
2026-01-17 17:44:37 +00:00
|
|
|
use App\Enums\SocialAccount\Platform as SocialPlatform;
|
|
|
|
|
use App\Enums\SocialAccount\Status;
|
feat: notification system with SendNotification job, dialog UI, tests
Backend:
- Create notifications table (user_id, workspace_id, type, channel,
title, body, data JSON, read_at, archived_at)
- Create Notification model with Type enum (post_failed,
account_disconnected, invite_received, member_joined, member_removed)
and Channel enum (email, in_app, both)
- Create SendNotification job: isolated from publish flow, handles
saving in-app notification and sending email independently
- NotificationController: index (excludes archived, scoped to workspace),
markAsRead, markAllAsRead, archiveAll
- Integrate with PublishToSocialPlatform (post failed/partial)
- Integrate with VerifyWorkspaceConnections (batch disconnection)
- Integrate with SocialAccount::markAsDisconnected (single disconnection)
- All use SendNotification::dispatch() instead of direct Mail::to()
Frontend:
- NotificationBell component in sidebar footer with unread badge
- Dialog with notification list, mark as read, mark all read, archive all
- Click navigates to relevant page (post edit, accounts)
- i18n for notifications UI (en, es, pt-BR)
Tests:
- 8 tests for NotificationController (auth, CRUD, workspace scoping)
- 4 tests for SendNotification job (channels, email, data storage)
All 745 tests passing.
2026-03-30 19:47:03 +00:00
|
|
|
use App\Jobs\SendNotification;
|
2026-01-19 00:49:13 +00:00
|
|
|
use App\Mail\AccountDisconnected;
|
2026-05-15 21:40:07 +00:00
|
|
|
use App\Observers\SocialAccountObserver;
|
2026-03-29 22:24:28 +00:00
|
|
|
use Database\Factories\SocialAccountFactory;
|
2026-05-15 21:40:07 +00:00
|
|
|
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
|
2026-03-31 00:18:07 +00:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2026-01-15 01:13:44 +00:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
|
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2026-01-17 02:46:30 +00:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2026-01-15 01:13:44 +00:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
2026-05-15 21:40:07 +00:00
|
|
|
#[ObservedBy(SocialAccountObserver::class)]
|
2026-01-15 01:13:44 +00:00
|
|
|
class SocialAccount extends Model
|
|
|
|
|
{
|
2026-03-29 22:24:28 +00:00
|
|
|
/** @use HasFactory<SocialAccountFactory> */
|
2026-01-15 01:13:44 +00:00
|
|
|
use HasFactory, HasUuids;
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'workspace_id',
|
|
|
|
|
'platform',
|
|
|
|
|
'platform_user_id',
|
|
|
|
|
'username',
|
|
|
|
|
'display_name',
|
|
|
|
|
'avatar_url',
|
|
|
|
|
'access_token',
|
|
|
|
|
'refresh_token',
|
|
|
|
|
'token_expires_at',
|
|
|
|
|
'scopes',
|
|
|
|
|
'meta',
|
2026-01-17 02:46:30 +00:00
|
|
|
'status',
|
2026-03-31 00:18:07 +00:00
|
|
|
'is_active',
|
2026-01-17 02:46:30 +00:00
|
|
|
'error_message',
|
|
|
|
|
'disconnected_at',
|
2026-05-02 17:15:41 +00:00
|
|
|
'last_used_at',
|
2026-01-15 01:13:44 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $hidden = [
|
|
|
|
|
'access_token',
|
|
|
|
|
'refresh_token',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'platform' => SocialPlatform::class,
|
2026-01-17 02:46:30 +00:00
|
|
|
'status' => Status::class,
|
2026-03-31 00:18:07 +00:00
|
|
|
'is_active' => 'boolean',
|
2026-01-15 01:13:44 +00:00
|
|
|
'access_token' => 'encrypted',
|
|
|
|
|
'refresh_token' => 'encrypted',
|
|
|
|
|
'token_expires_at' => 'datetime',
|
2026-01-17 02:46:30 +00:00
|
|
|
'disconnected_at' => 'datetime',
|
2026-05-02 17:15:41 +00:00
|
|
|
'last_used_at' => 'datetime',
|
2026-01-15 01:13:44 +00:00
|
|
|
'scopes' => 'array',
|
|
|
|
|
'meta' => 'array',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function workspace(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Workspace::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function postPlatforms(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(PostPlatform::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function isTokenExpired(): Attribute
|
|
|
|
|
{
|
|
|
|
|
return Attribute::make(
|
|
|
|
|
get: fn () => $this->token_expires_at && $this->token_expires_at->isPast(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-03 12:18:45 +00:00
|
|
|
protected function isTokenExpiringSoon(): Attribute
|
|
|
|
|
{
|
|
|
|
|
return Attribute::make(
|
|
|
|
|
get: fn () => $this->token_expires_at && $this->token_expires_at->isBefore(now()->addMinutes(15)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the token should be refreshed before use. Rotating-refresh-token
|
|
|
|
|
* platforms are only refreshed once actually expired, to avoid rotating a
|
|
|
|
|
* still-valid single-use refresh_token; extension-model platforms
|
|
|
|
|
* (Instagram/Threads) must be refreshed while still valid because their
|
|
|
|
|
* token can't be extended once expired.
|
|
|
|
|
*/
|
|
|
|
|
public function needsProactiveTokenRefresh(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->is_token_expired
|
|
|
|
|
|| ($this->platform->extendsAccessTokenOnRefresh() && $this->is_token_expiring_soon);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-15 01:13:44 +00:00
|
|
|
protected function avatarUrl(): Attribute
|
|
|
|
|
{
|
|
|
|
|
return Attribute::make(
|
|
|
|
|
get: fn (?string $value) => $value ? Storage::url($value) : null,
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-01-17 02:46:30 +00:00
|
|
|
|
2026-05-02 17:15:41 +00:00
|
|
|
protected function profileUrl(): Attribute
|
|
|
|
|
{
|
|
|
|
|
return Attribute::make(
|
|
|
|
|
get: function (): ?string {
|
|
|
|
|
$username = $this->username;
|
|
|
|
|
$platformUserId = $this->platform_user_id;
|
|
|
|
|
|
|
|
|
|
return match ($this->platform) {
|
|
|
|
|
SocialPlatform::Facebook => ($username || $platformUserId)
|
|
|
|
|
? 'https://facebook.com/'.($username ?: $platformUserId)
|
|
|
|
|
: null,
|
|
|
|
|
SocialPlatform::LinkedIn => $username ? "https://linkedin.com/in/{$username}" : null,
|
|
|
|
|
SocialPlatform::LinkedInPage => $username ? "https://linkedin.com/company/{$username}" : null,
|
|
|
|
|
SocialPlatform::X => $username ? "https://x.com/{$username}" : null,
|
|
|
|
|
SocialPlatform::TikTok => $username ? "https://tiktok.com/@{$username}" : null,
|
|
|
|
|
SocialPlatform::Instagram, SocialPlatform::InstagramFacebook => $username
|
|
|
|
|
? "https://instagram.com/{$username}"
|
|
|
|
|
: null,
|
|
|
|
|
SocialPlatform::YouTube => $username ? "https://youtube.com/@{$username}" : null,
|
|
|
|
|
SocialPlatform::Threads => $username ? "https://threads.net/@{$username}" : null,
|
|
|
|
|
SocialPlatform::Bluesky => $username ? "https://bsky.app/profile/{$username}" : null,
|
|
|
|
|
SocialPlatform::Pinterest => $username ? "https://pinterest.com/{$username}" : null,
|
|
|
|
|
SocialPlatform::Mastodon => ($username && data_get($this->meta, 'instance'))
|
|
|
|
|
? rtrim((string) data_get($this->meta, 'instance'), '/')."/@{$username}"
|
|
|
|
|
: null,
|
Add Telegram publishing (backend foundation)
Register Telegram as a platform: Platform/ContentType enum cases, a
platforms.telegram config block (shared bot token via env), TelegramPublisher
(sendMessage / sendPhoto|Video|Document / sendMediaGroup over the Bot API, HTML
parse mode, 4096 limit with long text split off a 1024 caption), wired into the
publisher dispatch. Add a Telegram ContentSanitizer branch (Telegram-allowed
HTML + ampersand escaping), MediaOptimizer/profile-url/factory support, and the
TelegramPublishException. Tests cover text, single media, album, long-text split,
overflow, API errors, private-channel URLs, and sanitization.
2026-06-14 00:25:31 +00:00
|
|
|
SocialPlatform::Telegram => $username ? "https://t.me/{$username}" : null,
|
2026-05-02 17:15:41 +00:00
|
|
|
default => null,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-17 02:46:30 +00:00
|
|
|
public function markAsDisconnected(string $errorMessage): void
|
|
|
|
|
{
|
2026-05-12 22:11:23 +00:00
|
|
|
$lock = Cache::lock("social_account_status:{$this->id}", 10);
|
2026-01-17 02:46:30 +00:00
|
|
|
|
|
|
|
|
if ($lock->get()) {
|
|
|
|
|
try {
|
|
|
|
|
$this->refresh();
|
|
|
|
|
$wasConnected = $this->status !== Status::Disconnected;
|
|
|
|
|
|
|
|
|
|
$this->update([
|
|
|
|
|
'status' => Status::Disconnected,
|
|
|
|
|
'error_message' => $errorMessage,
|
|
|
|
|
'disconnected_at' => now(),
|
|
|
|
|
]);
|
|
|
|
|
|
feat: notification system with SendNotification job, dialog UI, tests
Backend:
- Create notifications table (user_id, workspace_id, type, channel,
title, body, data JSON, read_at, archived_at)
- Create Notification model with Type enum (post_failed,
account_disconnected, invite_received, member_joined, member_removed)
and Channel enum (email, in_app, both)
- Create SendNotification job: isolated from publish flow, handles
saving in-app notification and sending email independently
- NotificationController: index (excludes archived, scoped to workspace),
markAsRead, markAllAsRead, archiveAll
- Integrate with PublishToSocialPlatform (post failed/partial)
- Integrate with VerifyWorkspaceConnections (batch disconnection)
- Integrate with SocialAccount::markAsDisconnected (single disconnection)
- All use SendNotification::dispatch() instead of direct Mail::to()
Frontend:
- NotificationBell component in sidebar footer with unread badge
- Dialog with notification list, mark as read, mark all read, archive all
- Click navigates to relevant page (post edit, accounts)
- i18n for notifications UI (en, es, pt-BR)
Tests:
- 8 tests for NotificationController (auth, CRUD, workspace scoping)
- 4 tests for SendNotification job (channels, email, data storage)
All 745 tests passing.
2026-03-30 19:47:03 +00:00
|
|
|
if ($wasConnected && $this->workspace->owner) {
|
2026-05-12 22:11:23 +00:00
|
|
|
$placeholders = [
|
|
|
|
|
'platform' => $this->platform->label(),
|
|
|
|
|
'account' => '@'.($this->username ?? $this->display_name),
|
|
|
|
|
];
|
feat: notification system with SendNotification job, dialog UI, tests
Backend:
- Create notifications table (user_id, workspace_id, type, channel,
title, body, data JSON, read_at, archived_at)
- Create Notification model with Type enum (post_failed,
account_disconnected, invite_received, member_joined, member_removed)
and Channel enum (email, in_app, both)
- Create SendNotification job: isolated from publish flow, handles
saving in-app notification and sending email independently
- NotificationController: index (excludes archived, scoped to workspace),
markAsRead, markAllAsRead, archiveAll
- Integrate with PublishToSocialPlatform (post failed/partial)
- Integrate with VerifyWorkspaceConnections (batch disconnection)
- Integrate with SocialAccount::markAsDisconnected (single disconnection)
- All use SendNotification::dispatch() instead of direct Mail::to()
Frontend:
- NotificationBell component in sidebar footer with unread badge
- Dialog with notification list, mark as read, mark all read, archive all
- Click navigates to relevant page (post edit, accounts)
- i18n for notifications UI (en, es, pt-BR)
Tests:
- 8 tests for NotificationController (auth, CRUD, workspace scoping)
- 4 tests for SendNotification job (channels, email, data storage)
All 745 tests passing.
2026-03-30 19:47:03 +00:00
|
|
|
|
|
|
|
|
SendNotification::dispatch(
|
|
|
|
|
user: $this->workspace->owner,
|
|
|
|
|
workspaceId: $this->workspace_id,
|
|
|
|
|
type: Type::AccountDisconnected,
|
|
|
|
|
channel: Channel::Both,
|
2026-05-12 22:11:23 +00:00
|
|
|
title: __('notifications.account_disconnected.title', $placeholders),
|
|
|
|
|
body: __('notifications.account_disconnected.body', $placeholders),
|
feat: notification system with SendNotification job, dialog UI, tests
Backend:
- Create notifications table (user_id, workspace_id, type, channel,
title, body, data JSON, read_at, archived_at)
- Create Notification model with Type enum (post_failed,
account_disconnected, invite_received, member_joined, member_removed)
and Channel enum (email, in_app, both)
- Create SendNotification job: isolated from publish flow, handles
saving in-app notification and sending email independently
- NotificationController: index (excludes archived, scoped to workspace),
markAsRead, markAllAsRead, archiveAll
- Integrate with PublishToSocialPlatform (post failed/partial)
- Integrate with VerifyWorkspaceConnections (batch disconnection)
- Integrate with SocialAccount::markAsDisconnected (single disconnection)
- All use SendNotification::dispatch() instead of direct Mail::to()
Frontend:
- NotificationBell component in sidebar footer with unread badge
- Dialog with notification list, mark as read, mark all read, archive all
- Click navigates to relevant page (post edit, accounts)
- i18n for notifications UI (en, es, pt-BR)
Tests:
- 8 tests for NotificationController (auth, CRUD, workspace scoping)
- 4 tests for SendNotification job (channels, email, data storage)
All 745 tests passing.
2026-03-30 19:47:03 +00:00
|
|
|
data: ['social_account_id' => $this->id],
|
|
|
|
|
mailable: new AccountDisconnected($this),
|
|
|
|
|
);
|
2026-01-17 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
$lock->release();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 21:46:06 +00:00
|
|
|
public function markAsTokenExpired(string $errorMessage, bool $notify = true): void
|
2026-04-01 14:46:51 +00:00
|
|
|
{
|
2026-05-12 22:11:23 +00:00
|
|
|
$lock = Cache::lock("social_account_status:{$this->id}", 10);
|
2026-05-12 21:46:06 +00:00
|
|
|
|
|
|
|
|
if (! $lock->get()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$this->refresh();
|
|
|
|
|
$wasUsable = $this->status === Status::Connected;
|
|
|
|
|
|
|
|
|
|
$this->update([
|
|
|
|
|
'status' => Status::TokenExpired,
|
|
|
|
|
'error_message' => $errorMessage,
|
|
|
|
|
'disconnected_at' => $this->disconnected_at ?? now(),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if ($notify && $wasUsable && $this->workspace->owner) {
|
2026-05-12 22:11:23 +00:00
|
|
|
$placeholders = [
|
|
|
|
|
'platform' => $this->platform->label(),
|
|
|
|
|
'account' => '@'.($this->username ?? $this->display_name),
|
|
|
|
|
];
|
2026-05-12 21:46:06 +00:00
|
|
|
|
|
|
|
|
SendNotification::dispatch(
|
|
|
|
|
user: $this->workspace->owner,
|
|
|
|
|
workspaceId: $this->workspace_id,
|
|
|
|
|
type: Type::AccountDisconnected,
|
|
|
|
|
channel: Channel::Both,
|
2026-05-12 22:11:23 +00:00
|
|
|
title: __('notifications.account_token_expired.title', $placeholders),
|
|
|
|
|
body: __('notifications.account_token_expired.body', $placeholders),
|
2026-05-12 21:46:06 +00:00
|
|
|
data: ['social_account_id' => $this->id],
|
|
|
|
|
mailable: new AccountDisconnected($this),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
$lock->release();
|
|
|
|
|
}
|
2026-04-01 14:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-17 02:46:30 +00:00
|
|
|
public function markAsConnected(): void
|
|
|
|
|
{
|
|
|
|
|
$this->update([
|
|
|
|
|
'status' => Status::Connected,
|
|
|
|
|
'error_message' => null,
|
|
|
|
|
'disconnected_at' => null,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isDisconnected(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->status === Status::Disconnected || $this->status === Status::TokenExpired;
|
|
|
|
|
}
|
2026-03-31 00:18:07 +00:00
|
|
|
|
|
|
|
|
public function scopeActive(Builder $query): Builder
|
|
|
|
|
{
|
|
|
|
|
return $query->where('is_active', true)->orderBy('platform');
|
|
|
|
|
}
|
2026-01-15 01:13:44 +00:00
|
|
|
}
|