mirror of https://github.com/veypi/OneAuth.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
763 B
Go
37 lines
763 B
Go
|
1 week ago
|
// Copyright (C) 2024 veypi <i@veypi.com>
|
||
|
|
// 2025-03-04 16:08:06
|
||
|
|
// Distributed under terms of the MIT license.
|
||
|
|
|
||
|
|
package role
|
||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/veypi/vbase/cfg"
|
||
|
|
"github.com/veypi/vbase/models"
|
||
|
|
"github.com/veypi/vigo"
|
||
|
|
)
|
||
|
|
|
||
|
|
type GetRequest struct {
|
||
|
|
RoleID string `src:"path@role_id" desc:"角色ID"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type RoleDetail struct {
|
||
|
|
models.Role
|
||
|
|
Policies []models.Policy `json:"policies"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func get(x *vigo.X, req *GetRequest) (*RoleDetail, error) {
|
||
|
|
var role models.Role
|
||
|
|
if err := cfg.DB().First(&role, "id = ?", req.RoleID).Error; err != nil {
|
||
|
|
return nil, vigo.ErrNotFound
|
||
|
|
}
|
||
|
|
|
||
|
|
// 解析策略ID列表
|
||
|
|
policies := []models.Policy{}
|
||
|
|
// TODO: 根据 role.PolicyIDs 查询策略列表
|
||
|
|
|
||
|
|
return &RoleDetail{
|
||
|
|
Role: role,
|
||
|
|
Policies: policies,
|
||
|
|
}, nil
|
||
|
|
}
|