chore: update document approval workflow and bug fixes

This commit is contained in:
2026-05-25 13:05:20 +08:00
parent d573c02893
commit 39a8e1d4cd
910 changed files with 49994 additions and 1010 deletions

View File

@@ -2,31 +2,112 @@
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Traits\BelongsToTenant;
use App\Traits\HasPublicIdentifier;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Modules\UserManagement\Models\CustomerProfile;
use Modules\UserManagement\Models\EmployeeProfile;
use Spatie\Permission\Traits\HasRoles;
#[Fillable(['name', 'email', 'password'])]
#[Hidden(['password', 'remember_token'])]
class User extends Authenticatable
{
/** @use HasFactory<UserFactory> */
use HasFactory, Notifiable;
use BelongsToTenant, HasFactory, HasPublicIdentifier, HasRoles, Notifiable;
protected $fillable = [
'name',
'email',
'password',
'user_type',
'status',
'userable_type',
'userable_id',
'contractor_id',
'must_change_password',
];
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'must_change_password' => 'boolean',
];
}
public function userable(): MorphTo
{
return $this->morphTo();
}
public function employeeProfile()
{
return $this->hasOne(EmployeeProfile::class);
}
public function customerProfile()
{
return $this->hasOne(CustomerProfile::class);
}
public function contractor(): BelongsTo
{
return $this->belongsTo(\Modules\ContractorManagement\Models\Contractor::class);
}
public function isAdmin(): bool
{
return $this->user_type === 'admin';
}
public function isPlatformAdmin(): bool
{
return is_null($this->contractor_id) && $this->isAdmin();
}
public function isContractorAdmin(): bool
{
return ! is_null($this->contractor_id)
&& $this->hasRole('Contractor');
}
public function isContractorUser(): bool
{
return ! is_null($this->contractor_id);
}
public function isEmployee(): bool
{
return in_array($this->user_type, ['admin', 'employee']);
}
public function isCustomer(): bool
{
return $this->user_type === 'customer';
}
public function isActive(): bool
{
return $this->status === 'active';
}
public function scopeActive($query)
{
return $query->where('status', 'active');
}
public function scopeOfType($query, string $type)
{
return $query->where('user_type', $type);
}
}