|
|
|
|
package role
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/veypi/vbase/cfg"
|
|
|
|
|
"github.com/veypi/vbase/models"
|
|
|
|
|
"github.com/veypi/vigo"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type PatchReq struct {
|
|
|
|
|
ID string `src:"path@id" desc:"Role ID"`
|
|
|
|
|
Name *string `json:"name" src:"json" desc:"Role Name"`
|
refactor: Remove multi-tenant org system and simplify auth
- Delete org API endpoints (add_member, create, del, get, list, member, patch, tree)
- Delete models/org.go and remove Org/OrgMember models
- Delete org-related test files (org_crud, org_load_middleware, org_permission, multi_tenant)
- Delete org test scripts (03_org_permission.sh, 04_org_load_middleware.sh)
- Simplify auth/auth.go by removing org context and role loading logic
- Remove org claims from JWT tokens and login/register responses
- Redesign Permission model with hierarchical level-based access control
- Add auth/design.md with new permission system specification
- Update user and role APIs to work without org context
5 days ago
|
|
|
Code *string `json:"code" src:"json" desc:"Role Code"`
|
|
|
|
|
Scope *string `json:"scope" src:"json" desc:"Scope"`
|
|
|
|
|
Description *string `json:"description" src:"json" desc:"Role Description"`
|
|
|
|
|
Status *int `json:"status" src:"json" desc:"Status"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func patch(x *vigo.X, req *PatchReq) (*models.Role, error) {
|
|
|
|
|
var role models.Role
|
|
|
|
|
if err := cfg.DB().First(&role, "id = ?", req.ID).Error; err != nil {
|
|
|
|
|
return nil, vigo.ErrNotFound
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if role.IsSystem {
|
|
|
|
|
return nil, vigo.NewError("cannot modify system role").WithCode(40300)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updates := map[string]interface{}{}
|
refactor: Remove multi-tenant org system and simplify auth
- Delete org API endpoints (add_member, create, del, get, list, member, patch, tree)
- Delete models/org.go and remove Org/OrgMember models
- Delete org-related test files (org_crud, org_load_middleware, org_permission, multi_tenant)
- Delete org test scripts (03_org_permission.sh, 04_org_load_middleware.sh)
- Simplify auth/auth.go by removing org context and role loading logic
- Remove org claims from JWT tokens and login/register responses
- Redesign Permission model with hierarchical level-based access control
- Add auth/design.md with new permission system specification
- Update user and role APIs to work without org context
5 days ago
|
|
|
|
|
|
|
|
// Check if code or scope is being updated
|
|
|
|
|
if req.Code != nil || req.Scope != nil {
|
|
|
|
|
newCode := role.Code
|
|
|
|
|
if req.Code != nil {
|
|
|
|
|
newCode = *req.Code
|
|
|
|
|
}
|
|
|
|
|
newScope := role.Scope
|
|
|
|
|
if req.Scope != nil {
|
|
|
|
|
newScope = *req.Scope
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for uniqueness if changed
|
|
|
|
|
if newCode != role.Code || newScope != role.Scope {
|
|
|
|
|
var count int64
|
|
|
|
|
if err := cfg.DB().Model(&models.Role{}).Where("code = ? AND scope = ? AND id != ?", newCode, newScope, role.ID).Count(&count).Error; err != nil {
|
|
|
|
|
return nil, vigo.ErrInternalServer.WithError(err)
|
|
|
|
|
}
|
|
|
|
|
if count > 0 {
|
|
|
|
|
return nil, vigo.ErrAlreadyExists.WithArgs("Role Code in Scope")
|
|
|
|
|
}
|
|
|
|
|
updates["code"] = newCode
|
|
|
|
|
updates["scope"] = newScope
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if req.Name != nil {
|
|
|
|
|
updates["name"] = *req.Name
|
|
|
|
|
}
|
|
|
|
|
if req.Description != nil {
|
|
|
|
|
updates["description"] = *req.Description
|
|
|
|
|
}
|
|
|
|
|
if req.Status != nil {
|
|
|
|
|
updates["status"] = *req.Status
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(updates) > 0 {
|
|
|
|
|
if err := cfg.DB().Model(&role).Updates(updates).Error; err != nil {
|
|
|
|
|
return nil, vigo.ErrDatabase.WithError(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &role, nil
|
|
|
|
|
}
|