1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00
documize/domain/user/user.go

52 lines
1.3 KiB
Go
Raw Normal View History

// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
package user
import (
"github.com/documize/community/domain"
2017-07-26 10:50:26 +01:00
"github.com/documize/community/model/user"
"github.com/pkg/errors"
)
// GetSecuredUser contain associated accounts but credentials are wiped.
2017-07-26 10:50:26 +01:00
func GetSecuredUser(ctx domain.RequestContext, s domain.Store, orgID, q string) (u user.User, err error) {
u, err = s.User.Get(ctx, q)
AttachUserAccounts(ctx, s, orgID, &u)
return
}
// AttachUserAccounts attachs user accounts to user object.
2017-07-26 10:50:26 +01:00
func AttachUserAccounts(ctx domain.RequestContext, s domain.Store, orgID string, u *user.User) {
u.ProtectSecrets()
2017-07-26 10:50:26 +01:00
a, err := s.Account.GetUserAccounts(ctx, u.RefID)
if err != nil {
err = errors.Wrap(err, "fetch user accounts")
return
}
u.Accounts = a
u.Editor = false
u.Admin = false
u.Active = false
for _, account := range u.Accounts {
if account.OrgID == orgID {
u.Admin = account.Admin
u.Editor = account.Editor
u.Active = account.Active
break
}
}
}