mirror of
https://github.com/documize/community.git
synced 2025-08-01 19:45:24 +02:00
user/account store loading
This commit is contained in:
parent
620fe28b27
commit
f5f30d2322
27 changed files with 238 additions and 221 deletions
|
@ -46,7 +46,7 @@ func (s Scope) Add(ctx domain.RequestContext, account account.Account) (err erro
|
|||
// GetUserAccount returns the database account record corresponding to the given userID, using the client's current organizaion.
|
||||
func (s Scope) GetUserAccount(ctx domain.RequestContext, userID string) (account account.Account, err error) {
|
||||
err = s.Runtime.Db.Get(&account, `
|
||||
SELECT a.id, a.refid, a.orgid, a.userid, a.editor, a.admin, a.active, a.created, a.revised,
|
||||
SELECT a.id, a.refid, a.orgid, a.userid, a.editor, a.admin, a.users, a.active, a.created, a.revised,
|
||||
b.company, b.title, b.message, b.domain
|
||||
FROM account a, organization b
|
||||
WHERE b.refid=a.orgid AND a.orgid=? AND a.userid=?`, ctx.OrgID, userID)
|
||||
|
@ -61,7 +61,7 @@ func (s Scope) GetUserAccount(ctx domain.RequestContext, userID string) (account
|
|||
// GetUserAccounts returns a slice of database account records, for all organizations that the userID is a member of, in organization title order.
|
||||
func (s Scope) GetUserAccounts(ctx domain.RequestContext, userID string) (t []account.Account, err error) {
|
||||
err = s.Runtime.Db.Select(&t, `
|
||||
SELECT a.id, a.refid, a.orgid, a.userid, a.editor, a.admin, a.active, a.created, a.revised,
|
||||
SELECT a.id, a.refid, a.orgid, a.userid, a.editor, a.admin, a.users, a.active, a.created, a.revised,
|
||||
b.company, b.title, b.message, b.domain
|
||||
FROM account a, organization b
|
||||
WHERE a.userid=? AND a.orgid=b.refid AND a.active=1 ORDER BY b.title`, userID)
|
||||
|
@ -76,7 +76,7 @@ func (s Scope) GetUserAccounts(ctx domain.RequestContext, userID string) (t []ac
|
|||
// GetAccountsByOrg returns a slice of database account records, for all users in the client's organization.
|
||||
func (s Scope) GetAccountsByOrg(ctx domain.RequestContext) (t []account.Account, err error) {
|
||||
err = s.Runtime.Db.Select(&t,
|
||||
`SELECT a.id, a.refid, a.orgid, a.userid, a.editor, a.admin, a.active, a.created, a.revised,
|
||||
`SELECT a.id, a.refid, a.orgid, a.userid, a.editor, a.admin, a.users, a.active, a.created, a.revised,
|
||||
b.company, b.title, b.message, b.domain
|
||||
FROM account a, organization b
|
||||
WHERE a.orgid=b.refid AND a.orgid=? AND a.active=1`, ctx.OrgID)
|
||||
|
|
|
@ -136,7 +136,7 @@ func (h *Handler) SetSpacePermissions(w http.ResponseWriter, r *http.Request) {
|
|||
// Only persist if there is a role!
|
||||
if permission.HasAnyPermission(perm) {
|
||||
// identify publically shared spaces
|
||||
if len(perm.UserID) == 0 {
|
||||
if perm.UserID == "0" {
|
||||
hasEveryoneRole = true
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ func (h *Handler) SetSpacePermissions(w http.ResponseWriter, r *http.Request) {
|
|||
if _, isExisting := previousRoleUsers[perm.UserID]; !isExisting {
|
||||
|
||||
// we skip 'everyone' (user id != empty string)
|
||||
if len(perm.UserID) > 0 {
|
||||
if perm.UserID != "0" {
|
||||
existingUser, err := h.Store.User.Get(ctx, perm.UserID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
|
|
|
@ -59,11 +59,11 @@ func (s Scope) AddPermissions(ctx domain.RequestContext, r permission.Permission
|
|||
func (s Scope) GetUserSpacePermissions(ctx domain.RequestContext, spaceID string) (r []permission.Permission, err error) {
|
||||
err = s.Runtime.Db.Select(&r, `
|
||||
SELECT id, orgid, who, whoid, action, scope, location, refid
|
||||
FROM permission WHERE orgid=? AND location='space' AND refid=? AND who='user' AND (whoid=? OR whoid='')
|
||||
FROM permission WHERE orgid=? AND location='space' AND refid=? AND who='user' AND (whoid=? OR whoid='0')
|
||||
UNION ALL
|
||||
SELECT p.id, p.orgid, p.who, p.whoid, p.action, p.scope, p.location, p.refid
|
||||
FROM permission p LEFT JOIN rolemember r ON p.whoid=r.roleid WHERE p.orgid=? AND p.location='space' AND refid=?
|
||||
AND p.who='role' AND (r.userid=? OR r.userid='')`,
|
||||
AND p.who='role' AND (r.userid=? OR r.userid='0')`,
|
||||
ctx.OrgID, spaceID, ctx.UserID, ctx.OrgID, spaceID, ctx.OrgID)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
|
|
|
@ -278,7 +278,6 @@ func (h *Handler) GetSpaceUsers(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// Get user account as we need to know if user can see all users.
|
||||
// account.users == false means we restrict viewing to just space users
|
||||
account, err := h.Store.Account.GetUserAccount(ctx, ctx.UserID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteJSON(w, u)
|
||||
|
@ -286,6 +285,7 @@ func (h *Handler) GetSpaceUsers(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// account.users == false means we restrict viewing to just space users
|
||||
if account.Users {
|
||||
// can see all users
|
||||
u, err = h.Store.User.GetActiveUsersForOrganization(ctx)
|
||||
|
|
|
@ -109,9 +109,11 @@ func (s Scope) GetBySerial(ctx domain.RequestContext, serial string) (u user.Use
|
|||
// identified in the Persister.
|
||||
func (s Scope) GetActiveUsersForOrganization(ctx domain.RequestContext) (u []user.User, err error) {
|
||||
err = s.Runtime.Db.Select(&u,
|
||||
`SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.created, u.revised
|
||||
FROM user u
|
||||
WHERE u.refid IN (SELECT userid FROM account WHERE orgid = ? AND active=1) ORDER BY u.firstname,u.lastname`,
|
||||
`SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.created, u.revised,
|
||||
u.global, a.active, a.editor, a.admin, a.users as viewusers
|
||||
FROM user u, account a
|
||||
WHERE u.refid=a.userid AND a.orgid=? AND a.active=1
|
||||
ORDER BY u.firstname,u.lastname`,
|
||||
ctx.OrgID)
|
||||
|
||||
if err != nil {
|
||||
|
@ -125,9 +127,11 @@ func (s Scope) GetActiveUsersForOrganization(ctx domain.RequestContext) (u []use
|
|||
// identified in the Persister.
|
||||
func (s Scope) GetUsersForOrganization(ctx domain.RequestContext) (u []user.User, err error) {
|
||||
err = s.Runtime.Db.Select(&u,
|
||||
`SELECT id, refid, firstname, lastname, email, initials, password, salt, reset, created, revised
|
||||
FROM user WHERE refid IN (SELECT userid FROM account where orgid = ?)
|
||||
ORDER BY firstname,lastname`, ctx.OrgID)
|
||||
`SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.created, u.revised,
|
||||
u.global, a.active, a.editor, a.admin, a.users as viewusers
|
||||
FROM user u, account a
|
||||
WHERE u.refid=a.userid AND a.orgid=?
|
||||
ORDER BY u.firstname, u.lastname`, ctx.OrgID)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf(" get users for org %s", ctx.OrgID))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue