mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
fix: missing routes in get me api
https://github.com/crawlab-team/crawlab/issues/1550
This commit is contained in:
@@ -240,7 +240,7 @@ func DeleteUserList(c *gin.Context) {
|
||||
|
||||
func GetUserMe(c *gin.Context) {
|
||||
u := GetUserFromContext(c)
|
||||
getUserById(u.Id, c)
|
||||
getUserByIdWithRoutes(u.Id, c)
|
||||
}
|
||||
|
||||
func PutUserMe(c *gin.Context) {
|
||||
@@ -277,6 +277,34 @@ func getUserById(userId primitive.ObjectID, c *gin.Context) {
|
||||
HandleSuccessWithData(c, user)
|
||||
}
|
||||
|
||||
func getUserByIdWithRoutes(userId primitive.ObjectID, c *gin.Context) {
|
||||
if !utils.IsPro() {
|
||||
getUserById(userId, c)
|
||||
return
|
||||
}
|
||||
|
||||
// get user
|
||||
user, err := service.NewModelService[models.User]().GetById(userId)
|
||||
if err != nil {
|
||||
HandleErrorInternalServerError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// get role
|
||||
if !user.RoleId.IsZero() {
|
||||
role, err := service.NewModelService[models.Role]().GetById(user.RoleId)
|
||||
if err != nil {
|
||||
HandleErrorInternalServerError(c, err)
|
||||
return
|
||||
}
|
||||
user.Role = role.Name
|
||||
user.RootAdminRole = role.RootAdmin
|
||||
user.Routes = role.Routes
|
||||
}
|
||||
|
||||
HandleSuccessWithData(c, user)
|
||||
}
|
||||
|
||||
func putUser(userId primitive.ObjectID, c *gin.Context) {
|
||||
// get payload
|
||||
var user models.User
|
||||
|
||||
@@ -86,7 +86,6 @@ func GetModelInstances() []any {
|
||||
*new(NotificationSetting),
|
||||
*new(Permission),
|
||||
*new(Project),
|
||||
*new(RolePermission),
|
||||
*new(Role),
|
||||
*new(Schedule),
|
||||
*new(Setting),
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type RolePermission struct {
|
||||
any `collection:"role_permissions"`
|
||||
BaseModel[RolePermission] `bson:",inline"`
|
||||
RoleId primitive.ObjectID `json:"role_id" bson:"role_id"`
|
||||
PermissionId primitive.ObjectID `json:"permission_id" bson:"permission_id"`
|
||||
}
|
||||
Reference in New Issue
Block a user