2017-07-24 16:24:21 +01:00
|
|
|
// 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"
|
2018-09-27 15:14:48 +01:00
|
|
|
"github.com/documize/community/domain/store"
|
2017-07-26 10:50:26 +01:00
|
|
|
"github.com/documize/community/model/user"
|
2017-07-24 16:24:21 +01:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetSecuredUser contain associated accounts but credentials are wiped.
|
2018-09-27 15:14:48 +01:00
|
|
|
func GetSecuredUser(ctx domain.RequestContext, s store.Store, orgID, id string) (u user.User, err error) {
|
2018-06-11 14:40:21 +01:00
|
|
|
u, err = s.User.Get(ctx, id)
|
2017-07-26 10:50:26 +01:00
|
|
|
AttachUserAccounts(ctx, s, orgID, &u)
|
2017-07-24 16:24:21 +01:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// AttachUserAccounts attachs user accounts to user object.
|
2018-09-27 15:14:48 +01:00
|
|
|
func AttachUserAccounts(ctx domain.RequestContext, s store.Store, orgID string, u *user.User) {
|
2017-07-24 16:24:21 +01:00
|
|
|
u.ProtectSecrets()
|
|
|
|
|
2017-07-26 10:50:26 +01:00
|
|
|
a, err := s.Account.GetUserAccounts(ctx, u.RefID)
|
2017-07-24 16:24:21 +01:00
|
|
|
if err != nil {
|
|
|
|
err = errors.Wrap(err, "fetch user accounts")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
u.Accounts = a
|
|
|
|
u.Editor = false
|
|
|
|
u.Admin = false
|
|
|
|
u.Active = false
|
2017-09-12 09:59:43 +01:00
|
|
|
u.ViewUsers = false
|
2018-04-05 19:59:57 +01:00
|
|
|
u.Analytics = false
|
2017-07-24 16:24:21 +01:00
|
|
|
|
|
|
|
for _, account := range u.Accounts {
|
|
|
|
if account.OrgID == orgID {
|
|
|
|
u.Admin = account.Admin
|
|
|
|
u.Editor = account.Editor
|
|
|
|
u.Active = account.Active
|
2017-09-12 09:59:43 +01:00
|
|
|
u.ViewUsers = account.Users
|
2018-04-05 19:59:57 +01:00
|
|
|
u.Analytics = account.Analytics
|
2017-07-24 16:24:21 +01:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|