FEATURE #2048: prepare routes for ACL, add some more permissions
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Permissions;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Permission extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $fillable = [
|
||||
'string_id',
|
||||
'parent_id',
|
||||
'group',
|
||||
'name',
|
||||
'default'
|
||||
];
|
||||
protected $casts = [
|
||||
'default' => 'boolean'
|
||||
];
|
||||
|
||||
/**
|
||||
* Assign observer for this model for logging
|
||||
*/
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::observe(PermissionObserver::class);
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->hasOne(Permission::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function subpermissions()
|
||||
{
|
||||
return $this->hasMany(Permission::class, 'parent_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Permissions;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class PermissionObserver
|
||||
{
|
||||
/**
|
||||
* Sets default permissions when creating new
|
||||
*
|
||||
* @param Permission $permission
|
||||
*/
|
||||
public function created(Permission $permission)
|
||||
{
|
||||
if ($permission->default) {
|
||||
$users = User::where('role', '!=', User::ROLE_VISITOR)
|
||||
->get();
|
||||
|
||||
foreach ($users as $user) {
|
||||
$user->permissions()
|
||||
->attach($permission->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user