feat: roles system backend
This commit is contained in:
1 parent
44cca46d5e
commit
8c6c6456da
50 files changed
+2578
-22
No files matched your search
@@ -37,6 +37,7 @@ func ArticleToDomain(m models.Article) article.Article {
|
||||
Body: m.Body,
|
||||
IsOnline: m.IsOnline,
|
||||
SiteID: m.SiteID,
|
||||
CreatedBy: m.CreatedBy,
|
||||
Slug: m.Slug,
|
||||
Excerpt: m.Excerpt,
|
||||
SEOTitle: m.SEOTitle,
|
||||
@@ -60,6 +61,7 @@ func ArticleToModel(a article.Article) models.Article {
|
||||
Body: a.Body,
|
||||
IsOnline: a.IsOnline,
|
||||
SiteID: a.SiteID,
|
||||
CreatedBy: a.CreatedBy,
|
||||
Slug: a.Slug,
|
||||
Excerpt: a.Excerpt,
|
||||
SEOTitle: a.SEOTitle,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -19,6 +19,20 @@ func DomainToNullableString(value string) *string {
|
||||
return &value
|
||||
}
|
||||
|
||||
func nullableIDToDomain(value *uint32) uint32 {
|
||||
if value == nil {
|
||||
return 0
|
||||
}
|
||||
return *value
|
||||
}
|
||||
|
||||
func domainToNullableID(value uint32) *uint32 {
|
||||
if value == 0 {
|
||||
return nil
|
||||
}
|
||||
return &value
|
||||
}
|
||||
|
||||
func UserToDomain(m models.User) user.User {
|
||||
return user.User{
|
||||
ID: m.ID,
|
||||
@@ -29,6 +43,7 @@ func UserToDomain(m models.User) user.User {
|
||||
DisplayName: m.DisplayName,
|
||||
IsVerified: m.IsVerified,
|
||||
Role: user.Role(m.Role),
|
||||
RoleID: nullableIDToDomain(m.RoleID),
|
||||
VerificationCode: nullableStringToDomain(m.VerificationCode),
|
||||
VerificationExpiration: m.VerificationExpiration,
|
||||
PasswordResetExpiration: m.PasswordResetExpiration,
|
||||
@@ -47,6 +62,7 @@ func UserToModel(a user.User) models.User {
|
||||
DisplayName: a.DisplayName,
|
||||
IsVerified: a.IsVerified,
|
||||
Role: string(a.Role),
|
||||
RoleID: domainToNullableID(a.RoleID),
|
||||
VerificationCode: DomainToNullableString(a.VerificationCode),
|
||||
VerificationExpiration: a.VerificationExpiration,
|
||||
PasswordResetExpiration: a.PasswordResetExpiration,
|
||||
|
||||
Reference in new issue
Block a user