feat: roles system backend
This commit is contained in:
1 parent
44cca46d5e
commit
8c6c6456da
50 files changed
+2578
-22
No files matched your search
@@ -0,0 +1,45 @@
|
||||
package mappers
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/role"
|
||||
"RenewCMS/internal/infrastructure/persistence/models"
|
||||
)
|
||||
|
||||
func RoleToDomain(m models.Role, grants []models.RolePermission) role.Role {
|
||||
return role.Role{
|
||||
ID: m.ID,
|
||||
Name: m.Name,
|
||||
Description: m.Description,
|
||||
BuiltIn: m.BuiltIn,
|
||||
Locked: m.Locked,
|
||||
Version: m.Version,
|
||||
Grants: GrantsToDomain(grants),
|
||||
}
|
||||
}
|
||||
|
||||
func RoleToModel(r role.Role) models.Role {
|
||||
return models.Role{
|
||||
ID: r.ID,
|
||||
Name: r.Name,
|
||||
Description: r.Description,
|
||||
BuiltIn: r.BuiltIn,
|
||||
Locked: r.Locked,
|
||||
Version: r.Version,
|
||||
}
|
||||
}
|
||||
|
||||
func GrantsToDomain(rows []models.RolePermission) []role.Grant {
|
||||
grants := make([]role.Grant, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
grants = append(grants, role.Grant{Key: row.Key, Scope: role.Scope(row.Scope)})
|
||||
}
|
||||
return grants
|
||||
}
|
||||
|
||||
func GrantsToModel(roleID uint32, grants []role.Grant) []models.RolePermission {
|
||||
rows := make([]models.RolePermission, 0, len(grants))
|
||||
for _, grant := range grants {
|
||||
rows = append(rows, models.RolePermission{RoleID: roleID, Key: grant.Key, Scope: string(grant.Scope)})
|
||||
}
|
||||
return rows
|
||||
}
|
||||
Reference in new issue
Block a user