2021-12-27 13:17:15 +01:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2022-05-25 18:26:50 +02:00
|
|
|
"fmt"
|
2023-03-01 20:12:04 +01:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
2023-01-02 15:11:32 +01:00
|
|
|
"github.com/netbirdio/netbird/management/server/activity"
|
2022-09-22 09:06:32 +02:00
|
|
|
"github.com/netbirdio/netbird/management/server/idp"
|
2023-01-02 15:11:32 +01:00
|
|
|
"github.com/netbirdio/netbird/management/server/jwtclaims"
|
2022-11-11 20:36:45 +01:00
|
|
|
"github.com/netbirdio/netbird/management/server/status"
|
2021-12-27 13:17:15 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-09-23 14:18:42 +02:00
|
|
|
UserRoleAdmin UserRole = "admin"
|
|
|
|
UserRoleUser UserRole = "user"
|
|
|
|
UserRoleUnknown UserRole = "unknown"
|
2022-10-13 18:26:31 +02:00
|
|
|
|
|
|
|
UserStatusActive UserStatus = "active"
|
|
|
|
UserStatusDisabled UserStatus = "disabled"
|
|
|
|
UserStatusInvited UserStatus = "invited"
|
2021-12-27 13:17:15 +01:00
|
|
|
)
|
|
|
|
|
2022-09-23 14:18:42 +02:00
|
|
|
// StrRoleToUserRole returns UserRole for a given strRole or UserRoleUnknown if the specified role is unknown
|
|
|
|
func StrRoleToUserRole(strRole string) UserRole {
|
|
|
|
switch strings.ToLower(strRole) {
|
|
|
|
case "admin":
|
|
|
|
return UserRoleAdmin
|
|
|
|
case "user":
|
|
|
|
return UserRoleUser
|
|
|
|
default:
|
|
|
|
return UserRoleUnknown
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-13 18:26:31 +02:00
|
|
|
// UserStatus is the status of a User
|
|
|
|
type UserStatus string
|
|
|
|
|
|
|
|
// UserRole is the role of a User
|
2021-12-27 13:17:15 +01:00
|
|
|
type UserRole string
|
|
|
|
|
|
|
|
// User represents a user of the system
|
|
|
|
type User struct {
|
|
|
|
Id string
|
|
|
|
Role UserRole
|
2022-09-22 09:06:32 +02:00
|
|
|
// AutoGroups is a list of Group IDs to auto-assign to peers registered by this user
|
|
|
|
AutoGroups []string
|
2023-03-20 16:14:55 +01:00
|
|
|
PATs map[string]*PersonalAccessToken
|
2021-12-27 13:17:15 +01:00
|
|
|
}
|
|
|
|
|
2022-11-05 10:24:50 +01:00
|
|
|
// IsAdmin returns true if user is an admin, false otherwise
|
|
|
|
func (u *User) IsAdmin() bool {
|
|
|
|
return u.Role == UserRoleAdmin
|
|
|
|
}
|
|
|
|
|
2022-09-22 09:06:32 +02:00
|
|
|
// toUserInfo converts a User object to a UserInfo object.
|
|
|
|
func (u *User) toUserInfo(userData *idp.UserData) (*UserInfo, error) {
|
|
|
|
autoGroups := u.AutoGroups
|
|
|
|
if autoGroups == nil {
|
|
|
|
autoGroups = []string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
if userData == nil {
|
|
|
|
return &UserInfo{
|
|
|
|
ID: u.Id,
|
|
|
|
Email: "",
|
|
|
|
Name: "",
|
|
|
|
Role: string(u.Role),
|
|
|
|
AutoGroups: u.AutoGroups,
|
2022-10-13 18:26:31 +02:00
|
|
|
Status: string(UserStatusActive),
|
2022-09-22 09:06:32 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
if userData.ID != u.Id {
|
|
|
|
return nil, fmt.Errorf("wrong UserData provided for user %s", u.Id)
|
|
|
|
}
|
|
|
|
|
2022-10-13 18:26:31 +02:00
|
|
|
userStatus := UserStatusActive
|
2022-10-19 17:51:41 +02:00
|
|
|
if userData.AppMetadata.WTPendingInvite != nil && *userData.AppMetadata.WTPendingInvite {
|
2022-10-13 18:26:31 +02:00
|
|
|
userStatus = UserStatusInvited
|
|
|
|
}
|
|
|
|
|
2022-09-22 09:06:32 +02:00
|
|
|
return &UserInfo{
|
|
|
|
ID: u.Id,
|
|
|
|
Email: userData.Email,
|
|
|
|
Name: userData.Name,
|
|
|
|
Role: string(u.Role),
|
|
|
|
AutoGroups: autoGroups,
|
2022-10-13 18:26:31 +02:00
|
|
|
Status: string(userStatus),
|
2022-09-22 09:06:32 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the user
|
2021-12-27 13:17:15 +01:00
|
|
|
func (u *User) Copy() *User {
|
2023-03-16 11:32:55 +01:00
|
|
|
autoGroups := make([]string, len(u.AutoGroups))
|
|
|
|
copy(autoGroups, u.AutoGroups)
|
2023-03-20 16:14:55 +01:00
|
|
|
pats := make(map[string]*PersonalAccessToken, len(u.PATs))
|
|
|
|
for k, v := range u.PATs {
|
|
|
|
patCopy := new(PersonalAccessToken)
|
|
|
|
*patCopy = *v
|
|
|
|
pats[k] = patCopy
|
|
|
|
}
|
2021-12-27 13:17:15 +01:00
|
|
|
return &User{
|
2022-09-22 09:06:32 +02:00
|
|
|
Id: u.Id,
|
|
|
|
Role: u.Role,
|
|
|
|
AutoGroups: autoGroups,
|
2023-03-08 11:54:10 +01:00
|
|
|
PATs: pats,
|
2021-12-27 13:17:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewUser creates a new user
|
|
|
|
func NewUser(id string, role UserRole) *User {
|
|
|
|
return &User{
|
2022-09-22 09:06:32 +02:00
|
|
|
Id: id,
|
|
|
|
Role: role,
|
|
|
|
AutoGroups: []string{},
|
2021-12-27 13:17:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-01 15:22:18 +01:00
|
|
|
// NewRegularUser creates a new user with role UserRoleAdmin
|
|
|
|
func NewRegularUser(id string) *User {
|
|
|
|
return NewUser(id, UserRoleUser)
|
|
|
|
}
|
|
|
|
|
2021-12-27 13:17:15 +01:00
|
|
|
// NewAdminUser creates a new user with role UserRoleAdmin
|
|
|
|
func NewAdminUser(id string) *User {
|
|
|
|
return NewUser(id, UserRoleAdmin)
|
|
|
|
}
|
|
|
|
|
2022-10-13 18:26:31 +02:00
|
|
|
// CreateUser creates a new user under the given account. Effectively this is a user invite.
|
2023-01-02 15:11:32 +01:00
|
|
|
func (am *DefaultAccountManager) CreateUser(accountID, userID string, invite *UserInfo) (*UserInfo, error) {
|
2022-11-07 17:52:23 +01:00
|
|
|
unlock := am.Store.AcquireAccountLock(accountID)
|
|
|
|
defer unlock()
|
2022-10-13 18:26:31 +02:00
|
|
|
|
|
|
|
if am.idpManager == nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
return nil, status.Errorf(status.PreconditionFailed, "IdP manager must be enabled to send user invites")
|
2022-10-13 18:26:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if invite == nil {
|
|
|
|
return nil, fmt.Errorf("provided user update is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
account, err := am.Store.GetAccount(accountID)
|
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
return nil, status.Errorf(status.NotFound, "account %s doesn't exist", accountID)
|
2022-10-13 18:26:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// check if the user is already registered with this email => reject
|
|
|
|
user, err := am.lookupUserInCacheByEmail(invite.Email, accountID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if user != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
return nil, status.Errorf(status.UserAlreadyExists, "user has an existing account")
|
2022-10-13 18:26:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
users, err := am.idpManager.GetUserByEmail(invite.Email)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(users) > 0 {
|
2022-11-11 20:36:45 +01:00
|
|
|
return nil, status.Errorf(status.UserAlreadyExists, "user has an existing account")
|
2022-10-13 18:26:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
idpUser, err := am.idpManager.CreateUser(invite.Email, invite.Name, accountID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
role := StrRoleToUserRole(invite.Role)
|
|
|
|
newUser := &User{
|
|
|
|
Id: idpUser.ID,
|
|
|
|
Role: role,
|
|
|
|
AutoGroups: invite.AutoGroups,
|
|
|
|
}
|
|
|
|
account.Users[idpUser.ID] = newUser
|
|
|
|
|
|
|
|
err = am.Store.SaveAccount(account)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = am.refreshCache(account.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-01-24 10:17:24 +01:00
|
|
|
am.storeEvent(userID, newUser.Id, accountID, activity.UserInvited, nil)
|
2023-01-02 15:11:32 +01:00
|
|
|
|
2022-10-13 18:26:31 +02:00
|
|
|
return newUser.toUserInfo(idpUser)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-03-16 15:57:44 +01:00
|
|
|
// AddPATToUser takes the userID and the accountID the user belongs to and assigns a provided PersonalAccessToken to that user
|
2023-03-20 16:14:55 +01:00
|
|
|
func (am *DefaultAccountManager) AddPATToUser(accountID string, userID string, pat *PersonalAccessToken) error {
|
2023-03-16 15:57:44 +01:00
|
|
|
unlock := am.Store.AcquireAccountLock(accountID)
|
|
|
|
defer unlock()
|
|
|
|
|
|
|
|
account, err := am.Store.GetAccount(accountID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
user := account.Users[userID]
|
|
|
|
if user == nil {
|
|
|
|
return status.Errorf(status.NotFound, "user not found")
|
|
|
|
}
|
|
|
|
|
2023-03-20 16:14:55 +01:00
|
|
|
user.PATs[pat.ID] = pat
|
|
|
|
|
|
|
|
err = am.Store.SaveAccount(account)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-03-20 16:38:17 +01:00
|
|
|
// DeletePAT deletes a specific PAT from a user
|
2023-03-20 16:14:55 +01:00
|
|
|
func (am *DefaultAccountManager) DeletePAT(accountID string, userID string, tokenID string) error {
|
|
|
|
unlock := am.Store.AcquireAccountLock(accountID)
|
|
|
|
defer unlock()
|
|
|
|
|
|
|
|
account, err := am.Store.GetAccount(accountID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
user := account.Users[userID]
|
|
|
|
if user == nil {
|
|
|
|
return status.Errorf(status.NotFound, "user not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
pat := user.PATs["tokenID"]
|
|
|
|
if pat == nil {
|
|
|
|
return status.Errorf(status.NotFound, "PAT not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
err = am.Store.DeleteTokenID2UserIDIndex(pat.ID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = am.Store.DeleteHashedPAT2TokenIDIndex(pat.HashedToken)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
delete(user.PATs, tokenID)
|
2023-03-16 15:57:44 +01:00
|
|
|
|
2023-03-20 11:44:12 +01:00
|
|
|
err = am.Store.SaveAccount(account)
|
|
|
|
return err
|
2023-03-16 15:57:44 +01:00
|
|
|
}
|
|
|
|
|
2022-09-22 09:06:32 +02:00
|
|
|
// SaveUser saves updates a given user. If the user doesn't exit it will throw status.NotFound error.
|
|
|
|
// Only User.AutoGroups field is allowed to be updated for now.
|
2023-01-02 15:11:32 +01:00
|
|
|
func (am *DefaultAccountManager) SaveUser(accountID, userID string, update *User) (*UserInfo, error) {
|
2022-11-07 17:52:23 +01:00
|
|
|
unlock := am.Store.AcquireAccountLock(accountID)
|
|
|
|
defer unlock()
|
2022-09-22 09:06:32 +02:00
|
|
|
|
|
|
|
if update == nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
return nil, status.Errorf(status.InvalidArgument, "provided user update is nil")
|
2022-09-22 09:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
account, err := am.Store.GetAccount(accountID)
|
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
return nil, err
|
2022-09-22 09:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, newGroupID := range update.AutoGroups {
|
|
|
|
if _, ok := account.Groups[newGroupID]; !ok {
|
2022-11-11 20:36:45 +01:00
|
|
|
return nil, status.Errorf(status.InvalidArgument, "provided group ID %s in the user %s update doesn't exist",
|
|
|
|
newGroupID, update.Id)
|
2022-09-22 09:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
oldUser := account.Users[update.Id]
|
|
|
|
if oldUser == nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
return nil, status.Errorf(status.NotFound, "update not found")
|
2022-09-22 09:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// only auto groups, revoked status, and name can be updated for now
|
|
|
|
newUser := oldUser.Copy()
|
|
|
|
newUser.AutoGroups = update.AutoGroups
|
2022-09-23 14:18:42 +02:00
|
|
|
newUser.Role = update.Role
|
2022-09-22 09:06:32 +02:00
|
|
|
|
|
|
|
account.Users[newUser.Id] = newUser
|
|
|
|
|
|
|
|
if err = am.Store.SaveAccount(account); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-01-02 15:11:32 +01:00
|
|
|
defer func() {
|
|
|
|
if oldUser.Role != newUser.Role {
|
2023-01-24 10:17:24 +01:00
|
|
|
am.storeEvent(userID, oldUser.Id, accountID, activity.UserRoleUpdated, map[string]any{"role": newUser.Role})
|
2023-01-02 15:11:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
removedGroups := difference(oldUser.AutoGroups, update.AutoGroups)
|
|
|
|
addedGroups := difference(newUser.AutoGroups, oldUser.AutoGroups)
|
|
|
|
for _, g := range removedGroups {
|
|
|
|
group := account.GetGroup(g)
|
|
|
|
if group != nil {
|
2023-01-24 10:17:24 +01:00
|
|
|
am.storeEvent(userID, oldUser.Id, accountID, activity.GroupRemovedFromUser,
|
|
|
|
map[string]any{"group": group.Name, "group_id": group.ID})
|
2023-01-02 15:11:32 +01:00
|
|
|
} else {
|
|
|
|
log.Errorf("group %s not found while saving user activity event of account %s", g, account.Id)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, g := range addedGroups {
|
|
|
|
group := account.GetGroup(g)
|
|
|
|
if group != nil {
|
2023-01-24 10:17:24 +01:00
|
|
|
am.storeEvent(userID, oldUser.Id, accountID, activity.GroupAddedToUser,
|
|
|
|
map[string]any{"group": group.Name, "group_id": group.ID})
|
2023-01-02 15:11:32 +01:00
|
|
|
} else {
|
|
|
|
log.Errorf("group %s not found while saving user activity event of account %s", g, account.Id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2022-09-22 09:06:32 +02:00
|
|
|
if !isNil(am.idpManager) {
|
2022-10-13 18:26:31 +02:00
|
|
|
userData, err := am.lookupUserInCache(newUser.Id, account)
|
2022-09-22 09:06:32 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-10-13 18:26:31 +02:00
|
|
|
if userData == nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
return nil, status.Errorf(status.NotFound, "user %s not found in the IdP", newUser.Id)
|
2022-10-13 18:26:31 +02:00
|
|
|
}
|
2022-09-22 09:06:32 +02:00
|
|
|
return newUser.toUserInfo(userData)
|
|
|
|
}
|
|
|
|
return newUser.toUserInfo(nil)
|
|
|
|
}
|
|
|
|
|
2021-12-27 13:17:15 +01:00
|
|
|
// GetOrCreateAccountByUser returns an existing account for a given user id or creates a new one if doesn't exist
|
2022-11-07 17:52:23 +01:00
|
|
|
func (am *DefaultAccountManager) GetOrCreateAccountByUser(userID, domain string) (*Account, error) {
|
|
|
|
unlock := am.Store.AcquireGlobalLock()
|
|
|
|
defer unlock()
|
2021-12-27 13:17:15 +01:00
|
|
|
|
2022-03-01 15:22:18 +01:00
|
|
|
lowerDomain := strings.ToLower(domain)
|
|
|
|
|
2022-11-07 17:52:23 +01:00
|
|
|
account, err := am.Store.GetAccountByUser(userID)
|
2021-12-27 13:17:15 +01:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
if s, ok := status.FromError(err); ok && s.Type() == status.NotFound {
|
2022-11-07 17:52:23 +01:00
|
|
|
account, err = am.newAccount(userID, lowerDomain)
|
2022-06-20 18:20:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-12-27 13:17:15 +01:00
|
|
|
err = am.Store.SaveAccount(account)
|
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
return nil, err
|
2021-12-27 13:17:15 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// other error
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-07 17:52:23 +01:00
|
|
|
userObj := account.Users[userID]
|
2022-06-20 18:20:43 +02:00
|
|
|
|
|
|
|
if account.Domain != lowerDomain && userObj.Role == UserRoleAdmin {
|
2022-03-01 15:22:18 +01:00
|
|
|
account.Domain = lowerDomain
|
2022-02-11 17:18:18 +01:00
|
|
|
err = am.Store.SaveAccount(account)
|
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
return nil, status.Errorf(status.Internal, "failed updating account with domain")
|
2022-02-11 17:18:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-27 13:17:15 +01:00
|
|
|
return account, nil
|
|
|
|
}
|
|
|
|
|
2022-05-25 18:26:50 +02:00
|
|
|
// IsUserAdmin flag for current user authenticated by JWT token
|
|
|
|
func (am *DefaultAccountManager) IsUserAdmin(claims jwtclaims.AuthorizationClaims) (bool, error) {
|
2022-11-11 20:36:45 +01:00
|
|
|
account, _, err := am.GetAccountFromToken(claims)
|
2022-05-25 18:26:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("get account: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
user, ok := account.Users[claims.UserId]
|
|
|
|
if !ok {
|
2022-11-11 20:36:45 +01:00
|
|
|
return false, status.Errorf(status.NotFound, "user not found")
|
2022-05-25 18:26:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return user.Role == UserRoleAdmin, nil
|
|
|
|
}
|
2022-09-22 09:06:32 +02:00
|
|
|
|
2022-11-05 10:24:50 +01:00
|
|
|
// GetUsersFromAccount performs a batched request for users from IDP by account ID apply filter on what data to return
|
|
|
|
// based on provided user role.
|
|
|
|
func (am *DefaultAccountManager) GetUsersFromAccount(accountID, userID string) ([]*UserInfo, error) {
|
2022-11-07 17:52:23 +01:00
|
|
|
account, err := am.Store.GetAccount(accountID)
|
2022-09-22 09:06:32 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-11-05 10:24:50 +01:00
|
|
|
user, err := account.FindUser(userID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-09-22 09:06:32 +02:00
|
|
|
queriedUsers := make([]*idp.UserData, 0)
|
|
|
|
if !isNil(am.idpManager) {
|
2022-10-13 18:26:31 +02:00
|
|
|
users := make(map[string]struct{}, len(account.Users))
|
|
|
|
for _, user := range account.Users {
|
|
|
|
users[user.Id] = struct{}{}
|
|
|
|
}
|
|
|
|
queriedUsers, err = am.lookupCache(users, accountID)
|
2022-09-22 09:06:32 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
userInfos := make([]*UserInfo, 0)
|
|
|
|
|
|
|
|
// in case of self-hosted, or IDP doesn't return anything, we will return the locally stored userInfo
|
|
|
|
if len(queriedUsers) == 0 {
|
2022-11-05 10:24:50 +01:00
|
|
|
for _, accountUser := range account.Users {
|
|
|
|
if !user.IsAdmin() && user.Id != accountUser.Id {
|
|
|
|
// if user is not an admin then show only current user and do not show other users
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
info, err := accountUser.toUserInfo(nil)
|
2022-09-22 09:06:32 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
userInfos = append(userInfos, info)
|
|
|
|
}
|
|
|
|
return userInfos, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, queriedUser := range queriedUsers {
|
2022-11-05 10:24:50 +01:00
|
|
|
if !user.IsAdmin() && user.Id != queriedUser.ID {
|
|
|
|
// if user is not an admin then show only current user and do not show other users
|
|
|
|
continue
|
|
|
|
}
|
2022-09-22 09:06:32 +02:00
|
|
|
if localUser, contains := account.Users[queriedUser.ID]; contains {
|
|
|
|
|
|
|
|
info, err := localUser.toUserInfo(queriedUser)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
userInfos = append(userInfos, info)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return userInfos, nil
|
|
|
|
}
|