feat: add licensing and access controls

This commit is contained in:
ShukeBta
2026-05-29 12:47:54 +08:00
parent 2f7ec3ab17
commit 27df93fa3d
61 changed files with 2032 additions and 237 deletions
+10 -2
View File
@@ -59,8 +59,16 @@ func (p *ProfileService) AdminUpdateRole(ctx context.Context, userID, role strin
if role != "admin" && role != "user" {
return nil, errors.New("role must be admin or user")
}
if err := p.repo.DB.Model(&model.User{}).Where("id = ?", userID).
Update("role", role).Error; err != nil {
if firstAdmin, err := p.repo.User.FirstAdmin(ctx); err != nil {
return nil, err
} else if firstAdmin != nil && firstAdmin.ID == userID && role != "admin" {
return nil, errors.New("default admin must keep admin role")
}
updates := map[string]any{"role": role}
if role == "admin" {
updates["tier"] = "plus"
}
if err := p.repo.User.UpdateFields(ctx, userID, updates); err != nil {
return nil, err
}
return p.repo.User.FindByID(ctx, userID)