Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5e989df
[management] user info with role permissions
pnmcosta Apr 15, 2025
f6d6cd6
Merge branch 'feature/additional-roles' into feature/user-info-with-r…
pnmcosta Apr 15, 2025
467b0f9
better naming of exposed user permissions
pnmcosta Apr 16, 2025
96b22d5
Merge branch 'feature/additional-roles' into feature/user-info-with-r…
pnmcosta Apr 16, 2025
ca356f1
fix rest test
pnmcosta Apr 16, 2025
974f297
Merge branch 'feature/additional-roles' into feature/user-info-with-r…
pnmcosta Apr 16, 2025
ab391ed
[management] restrict dashboard only to restrictable roles
pnmcosta Apr 16, 2025
e42d4c0
fix rest test
pnmcosta Apr 16, 2025
82ab78d
make user permissions optional
pnmcosta Apr 17, 2025
a01a817
Merge branch 'feature/additional-roles' into feature/user-info-with-r…
pnmcosta Apr 17, 2025
d9ad20f
get role permissions for all modules
pnmcosta Apr 17, 2025
808b770
better method name
pnmcosta Apr 17, 2025
e32e74e
Merge branch 'feature/additional-roles' into feature/user-info-with-r…
pnmcosta Apr 22, 2025
b3572ab
Merge branch 'feature/additional-roles' into feature/user-info-with-r…
pnmcosta Apr 23, 2025
546e2cc
Merge branch 'feature/additional-roles' into feature/user-info-with-r…
pnmcosta Apr 23, 2025
67f7d7e
Merge branch 'main' into feature/user-info-with-role-permissions
pnmcosta Apr 24, 2025
73176e7
Merge branch 'main' into feature/user-info-with-role-permissions
pnmcosta Apr 24, 2025
32463ac
Merge branch 'main' into feature/user-info-with-role-permissions
pnmcosta Apr 24, 2025
e877d36
Merge branch 'main' into feature/user-info-with-role-permissions
pnmcosta Apr 25, 2025
c08901a
Merge branch 'main' into feature/user-info-with-role-permissions
pnmcosta Apr 25, 2025
60dcab0
Merge branch 'main' into feature/user-info-with-role-permissions
pnmcosta Apr 28, 2025
e82597d
Merge branch 'main' into feature/user-info-with-role-permissions
pnmcosta Apr 29, 2025
a5a8aa7
[management] auditor allow view all peers
pnmcosta Apr 29, 2025
bf709eb
Merge branch 'fix/auditor-view-all-peers' into feature/user-info-with…
pnmcosta Apr 29, 2025
a531869
shift all peers logic to filter by user only if it does not have read…
pnmcosta Apr 29, 2025
8246ddd
Merge branch 'fix/auditor-view-all-peers' into feature/user-info-with…
pnmcosta Apr 29, 2025
a404bb1
only restrictable roles get restricted peers views
pnmcosta Apr 29, 2025
4988032
prevent child account user from being restricted
pnmcosta Apr 29, 2025
b12f6d0
Merge branch 'main' into fix/auditor-view-all-peers
pnmcosta Apr 29, 2025
f049433
Merge branch 'fix/auditor-view-all-peers' into feature/user-info-with…
pnmcosta Apr 29, 2025
d48ebc4
Merge branch 'main' into fix/auditor-view-all-peers
pnmcosta Apr 30, 2025
1c3d948
Merge branch 'fix/auditor-view-all-peers' into feature/user-info-with…
pnmcosta Apr 30, 2025
0741acf
Merge branch 'main' into feature/user-info-with-role-permissions
pnmcosta Apr 30, 2025
76d35b1
update openapi permissions example to crud
pnmcosta Apr 30, 2025
43dd250
openapi remove enums for a description instead
pnmcosta Apr 30, 2025
6e0d234
Merge branch 'main' into feature/user-info-with-role-permissions
pnmcosta May 1, 2025
eaf6433
network admin with peers read permission for all account peers
pnmcosta May 1, 2025
47e6bd3
note about create pats for service users
pnmcosta May 1, 2025
67270c0
network admin with full groups permissions
pnmcosta May 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions management/client/rest/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ var (
Issued: ptr("api"),
LastLogin: &time.Time{},
Name: "M. Essam",
Permissions: &api.UserPermissions{
DashboardView: ptr(api.UserPermissionsDashboardViewFull),
},
Role: "user",
Status: api.UserStatusActive,
Role: "user",
Status: api.UserStatusActive,
}
)

Expand Down
3 changes: 2 additions & 1 deletion management/server/account/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/netbirdio/netbird/management/server/posture"
"github.com/netbirdio/netbird/management/server/store"
"github.com/netbirdio/netbird/management/server/types"
"github.com/netbirdio/netbird/management/server/users"
"github.com/netbirdio/netbird/route"
)

Expand Down Expand Up @@ -115,5 +116,5 @@ type Manager interface {
CreateAccountByPrivateDomain(ctx context.Context, initiatorId, domain string) (*types.Account, error)
UpdateToPrimaryAccount(ctx context.Context, accountId string) (*types.Account, error)
GetOwnerInfo(ctx context.Context, accountId string) (*types.UserInfo, error)
GetCurrentUserInfo(ctx context.Context, accountID, userID string) (*types.UserInfo, error)
GetCurrentUserInfo(ctx context.Context, userAuth nbcontext.UserAuth) (*users.UserInfoWithPermissions, error)
}
24 changes: 19 additions & 5 deletions management/server/http/api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,25 @@ components:
UserPermissions:
type: object
properties:
dashboard_view:
description: User's permission to view the dashboard
type: string
enum: [ "limited", "blocked", "full" ]
example: limited
is_restricted:
type: boolean
description: Indicates whether this User's Peers view is restricted
modules:
type: object
additionalProperties:
type: object
additionalProperties:
type: boolean
propertyNames:
type: string
description: The operation type
propertyNames:
type: string
description: The module name
example: {"networks": { "read": true, "create": false, "update": false, "delete": false}, "peers": { "read": false, "create": false, "update": false, "delete": false} }
required:
- modules
- is_restricted
UserRequest:
type: object
properties:
Expand Down
15 changes: 3 additions & 12 deletions management/server/http/api/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 23 additions & 7 deletions management/server/http/handlers/users/users_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/netbirdio/netbird/management/server/http/util"
"github.com/netbirdio/netbird/management/server/status"
"github.com/netbirdio/netbird/management/server/types"
"github.com/netbirdio/netbird/management/server/users"

nbcontext "github.com/netbirdio/netbird/management/server/context"
)
Expand Down Expand Up @@ -272,15 +273,33 @@ func (h *handler) getCurrentUser(w http.ResponseWriter, r *http.Request) {
return
}

accountID, userID := userAuth.AccountId, userAuth.UserId

user, err := h.accountManager.GetCurrentUserInfo(ctx, accountID, userID)
user, err := h.accountManager.GetCurrentUserInfo(ctx, userAuth)
if err != nil {
util.WriteError(r.Context(), err, w)
return
}

util.WriteJSONObject(r.Context(), w, toUserResponse(user, userID))
util.WriteJSONObject(r.Context(), w, toUserWithPermissionsResponse(user, userAuth.UserId))
}

func toUserWithPermissionsResponse(user *users.UserInfoWithPermissions, userID string) *api.User {
response := toUserResponse(user.UserInfo, userID)

// stringify modules and operations keys
modules := make(map[string]map[string]bool)
for module, operations := range user.Permissions {
modules[string(module)] = make(map[string]bool)
for op, val := range operations {
modules[string(module)][string(op)] = val
}
}

response.Permissions = &api.UserPermissions{
IsRestricted: user.Restricted,
Modules: modules,
}

return response
}

func toUserResponse(user *types.UserInfo, currenUserID string) *api.User {
Expand Down Expand Up @@ -316,8 +335,5 @@ func toUserResponse(user *types.UserInfo, currenUserID string) *api.User {
IsBlocked: user.IsBlocked,
LastLogin: &user.LastLogin,
Issued: &user.Issued,
Permissions: &api.UserPermissions{
DashboardView: (*api.UserPermissionsDashboardView)(&user.Permissions.DashboardView),
},
}
}
Loading
Loading