Added the support for generating docs from template doc
This commit is contained in:
@@ -33,6 +33,8 @@ class Document extends Model
|
||||
'preview_path',
|
||||
'preview_mime',
|
||||
'preview_generated_at',
|
||||
'template_id',
|
||||
'template_version',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DocumentSetting extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'file_name_pattern',
|
||||
'date_format',
|
||||
'unresolved_policy',
|
||||
'preview_enabled',
|
||||
'whitelist',
|
||||
'date_formats',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'preview_enabled' => 'boolean',
|
||||
'whitelist' => 'array',
|
||||
'date_formats' => 'array',
|
||||
];
|
||||
|
||||
public static function instance(): self
|
||||
{
|
||||
return static::query()->first() ?? static::create([
|
||||
'file_name_pattern' => config('documents.file_name_pattern'),
|
||||
'date_format' => config('documents.date_format'),
|
||||
'unresolved_policy' => config('documents.unresolved_policy'),
|
||||
'preview_enabled' => config('documents.preview.enabled', true),
|
||||
'whitelist' => config('documents.whitelist'),
|
||||
'date_formats' => [],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class DocumentTemplate extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'slug', 'custom_name', 'description', 'core_entity', 'entities', 'columns', 'tokens', 'version', 'engine', 'file_path', 'file_hash', 'file_size', 'mime_type', 'active', 'created_by', 'updated_by',
|
||||
'output_filename_pattern', 'date_format', 'fail_on_unresolved', 'formatting_options', 'meta', 'action_id', 'decision_id', 'activity_note_template',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'entities' => 'array',
|
||||
'columns' => 'array',
|
||||
'tokens' => 'array',
|
||||
'active' => 'boolean',
|
||||
'version' => 'integer',
|
||||
'fail_on_unresolved' => 'boolean',
|
||||
'formatting_options' => 'array',
|
||||
'meta' => 'array',
|
||||
];
|
||||
|
||||
public function action(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Action::class);
|
||||
}
|
||||
|
||||
public function decision(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Decision::class);
|
||||
}
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
public function updater(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'updated_by');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Permission extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'description',
|
||||
];
|
||||
|
||||
public function roles(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Role::class)
|
||||
->withTimestamps()
|
||||
->select('roles.id', 'roles.name', 'roles.slug');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Role extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'description',
|
||||
];
|
||||
|
||||
public function permissions(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Permission::class)
|
||||
->withTimestamps()
|
||||
->select('permissions.id', 'permissions.name', 'permissions.slug');
|
||||
}
|
||||
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class)
|
||||
->withTimestamps()
|
||||
->select('users.id', 'users.name', 'users.email');
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ class User extends Authenticatable
|
||||
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory;
|
||||
|
||||
use HasProfilePhoto;
|
||||
use Notifiable;
|
||||
use TwoFactorAuthenticatable;
|
||||
@@ -64,4 +65,36 @@ protected function casts(): array
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Roles relationship.
|
||||
*/
|
||||
public function roles()
|
||||
{
|
||||
return $this->belongsToMany(Role::class)
|
||||
->withTimestamps()
|
||||
->select('roles.id', 'roles.name', 'roles.slug');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a flattened collection of permissions via roles.
|
||||
*/
|
||||
public function permissions()
|
||||
{
|
||||
return $this->roles()->with('permissions')->get()->pluck('permissions')->flatten()->unique('id');
|
||||
}
|
||||
|
||||
public function hasRole(string|array $roles): bool
|
||||
{
|
||||
$roles = (array) $roles;
|
||||
|
||||
return $this->roles->pluck('slug')->intersect($roles)->isNotEmpty();
|
||||
}
|
||||
|
||||
public function hasPermission(string|array $permissions): bool
|
||||
{
|
||||
$permissions = (array) $permissions;
|
||||
|
||||
return $this->permissions()->pluck('slug')->intersect($permissions)->isNotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user