mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-03 02:14:24 +08:00
fix: add user group struct to get user response (#3336)
* fix: add user group struct to user response * fix: set auto-created network groups as default
This commit is contained in:
parent
7bc7b2569f
commit
f46030e40f
5 changed files with 18 additions and 4 deletions
|
@ -258,6 +258,15 @@ func getUserV1(w http.ResponseWriter, r *http.Request) {
|
|||
resp := models.ReturnUserWithRolesAndGroups{
|
||||
ReturnUser: user,
|
||||
PlatformRole: userRoleTemplate,
|
||||
UserGroups: map[models.UserGroupID]models.UserGroup{},
|
||||
}
|
||||
for gId := range user.UserGroups {
|
||||
grp, err := logic.GetUserGroup(gId)
|
||||
if err != nil {
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
resp.UserGroups[gId] = grp
|
||||
}
|
||||
logger.Log(2, r.Header.Get("user"), "fetched user", usernameFetched)
|
||||
logic.ReturnSuccessResponseWithJson(w, r, resp, "fetched user with role info")
|
||||
|
|
|
@ -60,6 +60,7 @@ var DeleteNetworkRoles = func(netID string) {}
|
|||
var CreateDefaultNetworkRolesAndGroups = func(netID models.NetworkID) {}
|
||||
var CreateDefaultUserPolicies = func(netID models.NetworkID) {}
|
||||
var GetUserGroupsInNetwork = func(netID models.NetworkID) (networkGrps map[models.UserGroupID]models.UserGroup) { return }
|
||||
var GetUserGroup = func(groupId models.UserGroupID) (userGrps models.UserGroup, err error) { return }
|
||||
var AddGlobalNetRolesToAdmins = func(u models.User) {}
|
||||
|
||||
// GetRole - fetches role template by id
|
||||
|
|
|
@ -159,6 +159,7 @@ type User struct {
|
|||
type ReturnUserWithRolesAndGroups struct {
|
||||
ReturnUser
|
||||
PlatformRole UserRolePermissionTemplate `json:"platform_role"`
|
||||
UserGroups map[UserGroupID]UserGroup `json:"user_group_ids"`
|
||||
}
|
||||
|
||||
// ReturnUser - return user struct
|
||||
|
|
|
@ -133,6 +133,7 @@ func InitPro() {
|
|||
logic.IntialiseGroups = proLogic.UserGroupsInit
|
||||
logic.AddGlobalNetRolesToAdmins = proLogic.AddGlobalNetRolesToAdmins
|
||||
logic.GetUserGroupsInNetwork = proLogic.GetUserGroupsInNetwork
|
||||
logic.GetUserGroup = proLogic.GetUserGroup
|
||||
logic.GetNodeStatus = proLogic.GetNodeStatus
|
||||
}
|
||||
|
||||
|
|
|
@ -216,8 +216,9 @@ func CreateDefaultNetworkRolesAndGroups(netID models.NetworkID) {
|
|||
|
||||
// create default network groups
|
||||
var NetworkAdminGroup = models.UserGroup{
|
||||
ID: models.UserGroupID(fmt.Sprintf("%s-%s-grp", netID, models.NetworkAdmin)),
|
||||
Name: fmt.Sprintf("%s Admin Group", netID),
|
||||
ID: models.UserGroupID(fmt.Sprintf("%s-%s-grp", netID, models.NetworkAdmin)),
|
||||
Name: fmt.Sprintf("%s Admin Group", netID),
|
||||
Default: true,
|
||||
NetworkRoles: map[models.NetworkID]map[models.UserRoleID]struct{}{
|
||||
netID: {
|
||||
models.UserRoleID(fmt.Sprintf("%s-%s", netID, models.NetworkAdmin)): {},
|
||||
|
@ -226,8 +227,9 @@ func CreateDefaultNetworkRolesAndGroups(netID models.NetworkID) {
|
|||
MetaData: fmt.Sprintf("can manage your network `%s` configuration including adding and removing devices.", netID),
|
||||
}
|
||||
var NetworkUserGroup = models.UserGroup{
|
||||
ID: models.UserGroupID(fmt.Sprintf("%s-%s-grp", netID, models.NetworkUser)),
|
||||
Name: fmt.Sprintf("%s User Group", netID),
|
||||
ID: models.UserGroupID(fmt.Sprintf("%s-%s-grp", netID, models.NetworkUser)),
|
||||
Name: fmt.Sprintf("%s User Group", netID),
|
||||
Default: true,
|
||||
NetworkRoles: map[models.NetworkID]map[models.UserRoleID]struct{}{
|
||||
netID: {
|
||||
models.UserRoleID(fmt.Sprintf("%s-%s", netID, models.NetworkUser)): {},
|
||||
|
|
Loading…
Add table
Reference in a new issue