fix : 부서관리 기능 수정
- Route, Controller, Service, Swagger, DB 수정 - 모델 위치 이동
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Commons;
|
||||
|
||||
use App\Models\Members\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use App\Traits\ModelTrait;
|
||||
|
||||
/**
|
||||
* @mixin IdeHelperDepartment
|
||||
*/
|
||||
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',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'deleted_by','deleted_at'
|
||||
];
|
||||
|
||||
/** Relations */
|
||||
public function departmentUsers()
|
||||
{
|
||||
return $this->hasMany(DepartmentUser::class, 'department_id');
|
||||
}
|
||||
|
||||
public function users()
|
||||
{
|
||||
// User 네임스페이스가 다르면 여기만 맞춰줘.
|
||||
return $this->belongsToMany(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();
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Commons;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use App\Traits\ModelTrait;
|
||||
|
||||
/**
|
||||
* @mixin IdeHelperDepartmentPermission
|
||||
*/
|
||||
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');
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,8 @@
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @mixin IdeHelperUser
|
||||
*/
|
||||
@@ -37,7 +33,7 @@ class User extends Authenticatable
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'last_login_at' => 'datetime',
|
||||
'options' => 'array',
|
||||
'options' => 'array',
|
||||
'deleted_at' => 'datetime',
|
||||
'password' => 'hashed', // ← 이걸 쓰면 자동 해싱
|
||||
];
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Models\Members;
|
||||
|
||||
use App\Models\Commons\Role;
|
||||
use App\Models\Permissions\Role;
|
||||
use App\Models\Tenants\Tenant;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
40
app/Models/Permissions/PermissionOverride.php
Normal file
40
app/Models/Permissions/PermissionOverride.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Permissions;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\Permission\Models\Permission as SpatiePermission;
|
||||
|
||||
class PermissionOverride extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'permission_overrides';
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $casts = [
|
||||
'tenant_id' => 'int',
|
||||
'model_id' => 'int',
|
||||
'permission_id' => 'int',
|
||||
'effect' => 'int', // 1=ALLOW, -1=DENY
|
||||
'effective_from' => 'datetime',
|
||||
'effective_to' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* 예외가 걸린 주체(User, Department 등)
|
||||
* model_type, model_id를 사용하는 morphTo
|
||||
*/
|
||||
public function model()
|
||||
{
|
||||
// morphTo(relationshipName, type, id)
|
||||
return $this->morphTo('model', 'model_type', 'model_id');
|
||||
}
|
||||
|
||||
/** 연결된 Spatie Permission */
|
||||
public function permission()
|
||||
{
|
||||
return $this->belongsTo(SpatiePermission::class, 'permission_id');
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Commons;
|
||||
namespace App\Models\Permissions;
|
||||
|
||||
use App\Models\Commons\IdeHelperRole;
|
||||
use App\Models\Members\UserRole;
|
||||
use App\Models\Tenants\Tenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Commons;
|
||||
namespace App\Models\Permissions;
|
||||
|
||||
use App\Models\Commons\IdeHelperRoleMenuPermission;
|
||||
use App\Models\Commons\Menu;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
65
app/Models/Tenants/Department.php
Normal file
65
app/Models/Tenants/Department.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Tenants;
|
||||
|
||||
use App\Models\Members\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
use App\Traits\ModelTrait;
|
||||
use App\Models\Tenants\Pivots\DepartmentUser;
|
||||
use App\Models\Permissions\PermissionOverride;
|
||||
|
||||
class Department extends Model
|
||||
{
|
||||
use HasRoles, ModelTrait; // 부서도 권한/역할을 가짐
|
||||
|
||||
protected $table = 'departments';
|
||||
protected $guarded = ['id'];
|
||||
protected $casts = [
|
||||
'tenant_id' => 'int',
|
||||
'parent_id' => 'int',
|
||||
'is_active' => 'bool',
|
||||
'sort_order'=> 'int',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'deleted_by','deleted_at'
|
||||
];
|
||||
|
||||
// 스파티 가드명(프로젝트 설정에 맞게 조정)
|
||||
protected string $guard_name = 'web';
|
||||
|
||||
/** 상위/하위 부서 */
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(self::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(self::class, 'parent_id');
|
||||
}
|
||||
|
||||
/** 부서-사용자 N:N (추가 컬럼 포함 Pivot) */
|
||||
public function users()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'department_user')
|
||||
->using(DepartmentUser::class)
|
||||
->withTimestamps()
|
||||
->withPivot(['tenant_id','is_primary','joined_at','left_at']);
|
||||
}
|
||||
|
||||
/** 부서의 권한 오버라이드(DENY/임시허용) */
|
||||
public function permissionOverrides(): MorphMany
|
||||
{
|
||||
return $this->morphMany(PermissionOverride::class, 'model');
|
||||
}
|
||||
|
||||
/** 부서-사용자 매핑 로우들(피벗 테이블의 레코드들) */
|
||||
public function departmentUsers()
|
||||
{
|
||||
return $this->hasMany(DepartmentUser::class, 'department_id');
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Commons;
|
||||
namespace App\Models\Tenants\Pivots;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Models\Commons\IdeHelperDepartmentUser;
|
||||
use App\Models\Members\User;
|
||||
use App\Models\Tenants\Department;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use App\Traits\ModelTrait;
|
||||
use App\Models\Members\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* @mixin IdeHelperDepartmentUser
|
||||
@@ -36,7 +38,6 @@ public function department()
|
||||
|
||||
public function user()
|
||||
{
|
||||
// User 네임스페이스가 다르면 여기만 맞춰줘.
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Models\Tenants;
|
||||
|
||||
use App\Models\Commons\Role;
|
||||
use App\Models\Commons\File;
|
||||
use App\Models\Members\User;
|
||||
use App\Models\Members\UserRole;
|
||||
use App\Models\Members\UserTenant;
|
||||
use App\Models\Permissions\Role;
|
||||
use App\Traits\ModelTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Models\Tenants;
|
||||
|
||||
use App\Models\Members\User;
|
||||
use App\Models\Commons\Department;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user