Initial commit: CABM-IT (ItGlue-style MSP documentation platform)
Laravel 13 + Livewire/Volt app for managing client organizations, documents, passwords, flexible assets, virtual machines, contacts, domains, todos, shortcuts, and role-based user administration.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Casts\EncryptedField;
|
||||
use App\Contracts\Linkable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
#[Fillable([
|
||||
'organization_id', 'resource_type', 'resource_id', 'name', 'username',
|
||||
'password_ciphertext', 'url', 'notes', 'otp_secret', 'is_favorite',
|
||||
'password_updated_at', 'rotation_due_at', 'created_by',
|
||||
])]
|
||||
class Password extends Model implements Linkable
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'password_ciphertext' => EncryptedField::class,
|
||||
'otp_secret' => EncryptedField::class,
|
||||
'is_favorite' => 'boolean',
|
||||
'password_updated_at' => 'datetime',
|
||||
'rotation_due_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function organization()
|
||||
{
|
||||
return $this->belongsTo(Organization::class);
|
||||
}
|
||||
|
||||
public function resource()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function creator()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
public function auditLogs()
|
||||
{
|
||||
return $this->hasMany(PasswordAuditLog::class);
|
||||
}
|
||||
|
||||
public function logAction(string $action): void
|
||||
{
|
||||
$this->auditLogs()->create([
|
||||
'user_id' => auth()->id(),
|
||||
'action' => $action,
|
||||
'ip_address' => request()->ip(),
|
||||
'user_agent' => (string) request()->userAgent(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function relatedItems()
|
||||
{
|
||||
return RelatedItem::forItem($this);
|
||||
}
|
||||
|
||||
public function linkableKind(): string
|
||||
{
|
||||
return 'Password';
|
||||
}
|
||||
|
||||
public function linkableLabel(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function linkableUrl(): string
|
||||
{
|
||||
return route('organizations.passwords.edit', [$this->organization_id, $this]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user