package role import ( "time" "online-back/internal/identity/rbac" "online-back/internal/identity/rbac/perm" ) type RoleDTO struct { Id int64 `json:"id"` Code string `json:"code"` Name string `json:"name"` Scope rbac.Scope `json:"scope"` ScopeName string `json:"scopeName"` IsSuper bool `json:"isSuper"` IsSystem bool `json:"isSystem"` Permissions []perm.Code `json:"permissions"` UsersCount int64 `json:"usersCount"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } func (r RoleDTO) Info() rbac.RoleInfo { return rbac.RoleInfo{ ID: r.Id, Code: r.Code, Scope: r.Scope, IsSuper: r.IsSuper, IsSystem: r.IsSystem, Perms: r.Permissions, } } // CreateRoleDTO: scope is own (clients, only their records), branch (the // user's branch_user branches) or all (every branch). Permissions are // module codes from GET /permissions. type CreateRoleDTO struct { Code string `json:"code" binding:"required,max=64"` Name string `json:"name" binding:"required"` Scope rbac.Scope `json:"scope" binding:"required,oneof=own branch all"` Permissions []perm.Code `json:"permissions" binding:"required"` } // UpdateRoleDTO replaces name, scope and the whole permission set. The code // is fixed at create time. type UpdateRoleDTO struct { Name string `json:"name" binding:"required"` Scope rbac.Scope `json:"scope" binding:"required,oneof=own branch all"` Permissions []perm.Code `json:"permissions" binding:"required"` } type ListFilter struct { RoleName string Page int Limit int } // RoleListItemDTO is the list row; permissions and the rest come from // GET /roles/:id. type RoleListItemDTO struct { Id int64 `json:"id"` Code string `json:"code"` Name string `json:"name"` Scope rbac.Scope `json:"scope"` ScopeName string `json:"scopeName"` UsersCount int64 `json:"usersCount"` } type ListRoleDTO struct { Count int64 `json:"count"` Roles []RoleListItemDTO `json:"roles"` }