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.
111 lines
2.6 KiB
PHP
111 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\User\Persona;
|
|
use App\Enums\User\Setup;
|
|
use App\Models\Traits\HasMedia;
|
|
use App\Models\Traits\HasWorkspace;
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Cashier\Billable;
|
|
|
|
class User extends Authenticatable implements MustVerifyEmail
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use Billable, HasFactory, HasMedia, HasUuids, HasWorkspace, Notifiable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'setup',
|
|
'persona',
|
|
'current_workspace_id',
|
|
'locale',
|
|
'email_verified_at',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'two_factor_secret',
|
|
'two_factor_recovery_codes',
|
|
'remember_token',
|
|
];
|
|
|
|
protected $appends = [
|
|
'has_photo',
|
|
'photo_url',
|
|
];
|
|
|
|
public function getHasPhotoAttribute(): bool
|
|
{
|
|
return $this->getFirstMedia('avatar') !== null;
|
|
}
|
|
|
|
public function getPhotoUrlAttribute(): ?string
|
|
{
|
|
return $this->getFirstMediaUrl('avatar');
|
|
}
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'two_factor_confirmed_at' => 'datetime',
|
|
'setup' => Setup::class,
|
|
'persona' => Persona::class,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the user's locale code (e.g. 'en', 'es', 'pt-br').
|
|
*/
|
|
public function getLocaleCode(): string
|
|
{
|
|
return $this->locale ?? 'en';
|
|
}
|
|
|
|
/**
|
|
* Check if user has an active subscription.
|
|
* In self-hosted mode, always returns true (no subscription required).
|
|
*/
|
|
public function hasActiveSubscription(): bool
|
|
{
|
|
if (config('trypost.self_hosted')) {
|
|
return true;
|
|
}
|
|
|
|
return $this->subscribed('default');
|
|
}
|
|
|
|
/**
|
|
* Check if user has ever had a subscription (for trial eligibility).
|
|
*/
|
|
public function hasEverSubscribed(): bool
|
|
{
|
|
return $this->subscriptions()->exists();
|
|
}
|
|
}
|