fix : 권한관리 기능 추가 (각 기능 확인 필요)
- 메뉴관리 - 역할관리 - 부서관리 - 메뉴, 부서, 역할, 유저 - 권한 연동
This commit is contained in:
52
app/Models/Commons/Department.php
Normal file
52
app/Models/Commons/Department.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Commons;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use App\Traits\ModelTrait;
|
||||
|
||||
class Department extends Model
|
||||
{
|
||||
use SoftDeletes, BelongsToTenant, ModelTrait;
|
||||
|
||||
protected $table = 'departments';
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id','code','name','description','is_active','sort_order',
|
||||
'created_by','updated_by','deleted_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'tenant_id' => 'integer',
|
||||
'is_active' => 'integer',
|
||||
'sort_order'=> 'integer',
|
||||
];
|
||||
|
||||
/** Relations */
|
||||
public function departmentUsers()
|
||||
{
|
||||
return $this->hasMany(DepartmentUser::class, 'department_id');
|
||||
}
|
||||
|
||||
public function users()
|
||||
{
|
||||
// User 네임스페이스가 다르면 여기만 맞춰줘.
|
||||
return $this->belongsToMany(\App\Models\User::class, 'department_user', 'department_id', 'user_id')
|
||||
->withPivot(['tenant_id','is_primary','joined_at','left_at','created_at','updated_at','deleted_at'])
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function departmentPermissions()
|
||||
{
|
||||
return $this->hasMany(DepartmentPermission::class, 'department_id');
|
||||
}
|
||||
|
||||
public function permissions()
|
||||
{
|
||||
return $this->belongsToMany(\Spatie\Permission\Models\Permission::class, 'department_permissions', 'department_id', 'permission_id')
|
||||
->withPivot(['tenant_id','menu_id','is_allowed','created_at','updated_at','deleted_at'])
|
||||
->withTimestamps();
|
||||
}
|
||||
}
|
||||
37
app/Models/Commons/DepartmentPermission.php
Normal file
37
app/Models/Commons/DepartmentPermission.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Commons;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use App\Traits\ModelTrait;
|
||||
|
||||
class DepartmentPermission extends Model
|
||||
{
|
||||
use SoftDeletes, BelongsToTenant, ModelTrait;
|
||||
|
||||
protected $table = 'department_permissions';
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id','department_id','permission_id','menu_id','is_allowed',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'tenant_id' => 'integer',
|
||||
'department_id' => 'integer',
|
||||
'permission_id' => 'integer',
|
||||
'menu_id' => 'integer',
|
||||
'is_allowed' => 'integer',
|
||||
];
|
||||
|
||||
public function department()
|
||||
{
|
||||
return $this->belongsTo(Department::class, 'department_id');
|
||||
}
|
||||
|
||||
public function permission()
|
||||
{
|
||||
return $this->belongsTo(\Spatie\Permission\Models\Permission::class, 'permission_id');
|
||||
}
|
||||
}
|
||||
38
app/Models/Commons/DepartmentUser.php
Normal file
38
app/Models/Commons/DepartmentUser.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Commons;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use App\Traits\ModelTrait;
|
||||
|
||||
class DepartmentUser extends Model
|
||||
{
|
||||
use SoftDeletes, BelongsToTenant, ModelTrait;
|
||||
|
||||
protected $table = 'department_user';
|
||||
protected $fillable = [
|
||||
'tenant_id','department_id','user_id','is_primary','joined_at','left_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'tenant_id' => 'integer',
|
||||
'department_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'is_primary' => 'integer',
|
||||
'joined_at' => 'datetime',
|
||||
'left_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function department()
|
||||
{
|
||||
return $this->belongsTo(Department::class, 'department_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
// User 네임스페이스가 다르면 여기만 맞춰줘.
|
||||
return $this->belongsTo(\App\Models\User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,14 @@
|
||||
namespace App\Models\Commons;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Menu extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id', 'parent_id', 'name', 'url', 'is_active', 'sort_order',
|
||||
'tenant_id', 'parent_id', 'slug', 'name', 'url', 'is_active', 'sort_order',
|
||||
'hidden', 'is_external', 'external_url', 'icon'
|
||||
];
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Models\Members;
|
||||
|
||||
use App\Models\Commons\Role;
|
||||
use App\Models\Commons\File;
|
||||
use App\Models\Tenants\Tenant;
|
||||
use App\Traits\ModelTrait;
|
||||
@@ -13,10 +12,15 @@
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
use Spatie\Permission\Models\Role as SpatieRole;
|
||||
use App\Models\Commons\Role as CommonRole;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, Notifiable, SoftDeletes, ModelTrait, HasRoles;
|
||||
|
||||
protected $guard_name = 'api'; // ★ 중요: 권한/역할 가드 통일
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'name',
|
||||
@@ -56,9 +60,10 @@ public function userRoles()
|
||||
return $this->hasMany(UserRole::class);
|
||||
}
|
||||
|
||||
public function roles()
|
||||
public function orgRoles()
|
||||
{
|
||||
return $this->belongsToMany(Role::class, 'user_roles')->withPivot('tenant_id', 'assigned_at');
|
||||
return $this->belongsToMany(CommonRole::class, 'user_roles')
|
||||
->withPivot(['tenant_id', 'assigned_at']);
|
||||
}
|
||||
|
||||
public function userTenantById($tenantId)
|
||||
|
||||
Reference in New Issue
Block a user