mirror of
https://github.com/documize/community.git
synced 2025-07-20 21:59:42 +02:00
moved user.active to account.active
This commit is contained in:
parent
af80b39cd0
commit
5f2f9d5ae5
4 changed files with 21 additions and 17 deletions
|
@ -441,6 +441,7 @@ func UpdateUser(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
account.Editor = user.Editor
|
account.Editor = user.Editor
|
||||||
account.Admin = user.Admin
|
account.Admin = user.Admin
|
||||||
|
account.Active = user.Active
|
||||||
|
|
||||||
err = p.UpdateAccount(account)
|
err = p.UpdateAccount(account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -690,11 +691,13 @@ func attachUserAccounts(p request.Persister, orgID string, user *entity.User) {
|
||||||
user.Accounts = a
|
user.Accounts = a
|
||||||
user.Editor = false
|
user.Editor = false
|
||||||
user.Admin = false
|
user.Admin = false
|
||||||
|
user.Active = false
|
||||||
|
|
||||||
for _, account := range user.Accounts {
|
for _, account := range user.Accounts {
|
||||||
if account.OrgID == orgID {
|
if account.OrgID == orgID {
|
||||||
user.Admin = account.Admin
|
user.Admin = account.Admin
|
||||||
user.Editor = account.Editor
|
user.Editor = account.Editor
|
||||||
|
user.Active = account.Active
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,7 @@ type Account struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Domain string `json:"domain"`
|
Domain string `json:"domain"`
|
||||||
|
Active bool `json:"active"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Label defines a container for documents.
|
// Label defines a container for documents.
|
||||||
|
|
|
@ -26,7 +26,7 @@ func (p *Persister) AddAccount(account entity.Account) (err error) {
|
||||||
account.Created = time.Now().UTC()
|
account.Created = time.Now().UTC()
|
||||||
account.Revised = time.Now().UTC()
|
account.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := p.Context.Transaction.Preparex("INSERT INTO account (refid, orgid, userid, admin, editor, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?)")
|
stmt, err := p.Context.Transaction.Preparex("INSERT INTO account (refid, orgid, userid, admin, editor, active, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")
|
||||||
defer utility.Close(stmt)
|
defer utility.Close(stmt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -34,7 +34,7 @@ func (p *Persister) AddAccount(account entity.Account) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = stmt.Exec(account.RefID, account.OrgID, account.UserID, account.Admin, account.Editor, account.Created, account.Revised)
|
_, err = stmt.Exec(account.RefID, account.OrgID, account.UserID, account.Admin, account.Editor, account.Active, account.Created, account.Revised)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to execute insert for account", err)
|
log.Error("Unable to execute insert for account", err)
|
||||||
|
@ -44,9 +44,9 @@ func (p *Persister) AddAccount(account entity.Account) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserAccount returns the databse account record corresponding to the given userID, using the client's current organizaion.
|
// GetUserAccount returns the database account record corresponding to the given userID, using the client's current organizaion.
|
||||||
func (p *Persister) GetUserAccount(userID string) (account entity.Account, err error) {
|
func (p *Persister) GetUserAccount(userID string) (account entity.Account, err error) {
|
||||||
stmt, err := Db.Preparex("SELECT a.*, b.company, b.title, b.message, b.domain FROM account a, organization b WHERE b.refid=a.orgid and a.orgid=? and a.userid=? AND b.active=1")
|
stmt, err := Db.Preparex("SELECT a.*, b.company, b.title, b.message, b.domain FROM account a, organization b WHERE b.refid=a.orgid and a.orgid=? and a.userid=?")
|
||||||
defer utility.Close(stmt)
|
defer utility.Close(stmt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -66,7 +66,7 @@ func (p *Persister) GetUserAccount(userID string) (account entity.Account, err e
|
||||||
|
|
||||||
// GetUserAccounts returns a slice of database account records, for all organizations that the userID is a member of, in organization title order.
|
// GetUserAccounts returns a slice of database account records, for all organizations that the userID is a member of, in organization title order.
|
||||||
func (p *Persister) GetUserAccounts(userID string) (t []entity.Account, err error) {
|
func (p *Persister) GetUserAccounts(userID string) (t []entity.Account, err error) {
|
||||||
err = Db.Select(&t, "SELECT a.*, b.company, b.title, b.message, b.domain FROM account a, organization b WHERE a.userid=? AND a.orgid=b.refid AND b.active=1 ORDER BY b.title", userID)
|
err = Db.Select(&t, "SELECT a.*, 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)
|
||||||
|
|
||||||
if err != sql.ErrNoRows && err != nil {
|
if err != sql.ErrNoRows && err != nil {
|
||||||
log.Error(fmt.Sprintf("Unable to execute select account for user %s", userID), err)
|
log.Error(fmt.Sprintf("Unable to execute select account for user %s", userID), err)
|
||||||
|
@ -77,7 +77,7 @@ func (p *Persister) GetUserAccounts(userID string) (t []entity.Account, err erro
|
||||||
|
|
||||||
// GetAccountsByOrg returns a slice of database account records, for all users in the client's organization.
|
// GetAccountsByOrg returns a slice of database account records, for all users in the client's organization.
|
||||||
func (p *Persister) GetAccountsByOrg() (t []entity.Account, err error) {
|
func (p *Persister) GetAccountsByOrg() (t []entity.Account, err error) {
|
||||||
err = Db.Select(&t, "SELECT a.*, b.company, b.title, b.message, b.domain FROM account a, organization b WHERE a.orgid=b.refid AND a.orgid=? AND b.active=1", p.Context.OrgID)
|
err = Db.Select(&t, "SELECT a.*, 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", p.Context.OrgID)
|
||||||
|
|
||||||
if err != sql.ErrNoRows && err != nil {
|
if err != sql.ErrNoRows && err != nil {
|
||||||
log.Error(fmt.Sprintf("Unable to execute select account for org %s", p.Context.OrgID), err)
|
log.Error(fmt.Sprintf("Unable to execute select account for org %s", p.Context.OrgID), err)
|
||||||
|
@ -90,7 +90,7 @@ func (p *Persister) GetAccountsByOrg() (t []entity.Account, err error) {
|
||||||
func (p *Persister) UpdateAccount(account entity.Account) (err error) {
|
func (p *Persister) UpdateAccount(account entity.Account) (err error) {
|
||||||
account.Revised = time.Now().UTC()
|
account.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := p.Context.Transaction.PrepareNamed("UPDATE account SET userid=:userid, admin=:admin, editor=:editor, revised=:revised WHERE orgid=:orgid AND refid=:refid")
|
stmt, err := p.Context.Transaction.PrepareNamed("UPDATE account SET userid=:userid, admin=:admin, editor=:editor, active=:active, revised=:revised WHERE orgid=:orgid AND refid=:refid")
|
||||||
defer utility.Close(stmt)
|
defer utility.Close(stmt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -28,7 +28,7 @@ func (p *Persister) AddUser(user entity.User) (err error) {
|
||||||
user.Created = time.Now().UTC()
|
user.Created = time.Now().UTC()
|
||||||
user.Revised = time.Now().UTC()
|
user.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := p.Context.Transaction.Preparex("INSERT INTO user (refid, firstname, lastname, email, initials, password, salt, reset, active, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
stmt, err := p.Context.Transaction.Preparex("INSERT INTO user (refid, firstname, lastname, email, initials, password, salt, reset, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
||||||
defer utility.Close(stmt)
|
defer utility.Close(stmt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -36,7 +36,7 @@ func (p *Persister) AddUser(user entity.User) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := stmt.Exec(user.RefID, user.Firstname, user.Lastname, strings.ToLower(user.Email), user.Initials, user.Password, user.Salt, "", true, user.Created, user.Revised)
|
res, err := stmt.Exec(user.RefID, user.Firstname, user.Lastname, strings.ToLower(user.Email), user.Initials, user.Password, user.Salt, "", user.Created, user.Revised)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable insert for user", err)
|
log.Error("Unable insert for user", err)
|
||||||
return
|
return
|
||||||
|
@ -53,7 +53,7 @@ func (p *Persister) AddUser(user entity.User) (err error) {
|
||||||
|
|
||||||
// GetUser returns the user record for the given id.
|
// GetUser returns the user record for the given id.
|
||||||
func (p *Persister) GetUser(id string) (user entity.User, err error) {
|
func (p *Persister) GetUser(id string) (user entity.User, err error) {
|
||||||
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, active, created, revised FROM user WHERE refid=?")
|
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, created, revised FROM user WHERE refid=?")
|
||||||
defer utility.Close(stmt)
|
defer utility.Close(stmt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -75,7 +75,7 @@ func (p *Persister) GetUser(id string) (user entity.User, err error) {
|
||||||
func (p *Persister) GetUserByEmail(email string) (user entity.User, err error) {
|
func (p *Persister) GetUserByEmail(email string) (user entity.User, err error) {
|
||||||
email = strings.TrimSpace(strings.ToLower(email))
|
email = strings.TrimSpace(strings.ToLower(email))
|
||||||
|
|
||||||
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, active, created, revised FROM user WHERE TRIM(LOWER(email))=?")
|
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, created, revised FROM user WHERE TRIM(LOWER(email))=?")
|
||||||
defer utility.Close(stmt)
|
defer utility.Close(stmt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -97,7 +97,7 @@ func (p *Persister) GetUserByEmail(email string) (user entity.User, err error) {
|
||||||
func (p *Persister) GetUserByDomain(domain, email string) (user entity.User, err error) {
|
func (p *Persister) GetUserByDomain(domain, email string) (user entity.User, err error) {
|
||||||
email = strings.TrimSpace(strings.ToLower(email))
|
email = strings.TrimSpace(strings.ToLower(email))
|
||||||
|
|
||||||
stmt, err := Db.Preparex("SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.global, u.password, u.salt, u.reset, u.active, u.created, u.revised FROM user u, account a, organization o WHERE TRIM(LOWER(u.email))=? AND u.refid=a.userid AND a.orgid=o.refid AND TRIM(LOWER(o.domain))=?")
|
stmt, err := Db.Preparex("SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.global, u.password, u.salt, u.reset, u.created, u.revised FROM user u, account a, organization o WHERE TRIM(LOWER(u.email))=? AND u.refid=a.userid AND a.orgid=o.refid AND TRIM(LOWER(o.domain))=?")
|
||||||
defer utility.Close(stmt)
|
defer utility.Close(stmt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -117,7 +117,7 @@ func (p *Persister) GetUserByDomain(domain, email string) (user entity.User, err
|
||||||
|
|
||||||
// GetUserByToken returns a user record given a reset token value.
|
// GetUserByToken returns a user record given a reset token value.
|
||||||
func (p *Persister) GetUserByToken(token string) (user entity.User, err error) {
|
func (p *Persister) GetUserByToken(token string) (user entity.User, err error) {
|
||||||
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, active, created, revised FROM user WHERE reset=?")
|
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, created, revised FROM user WHERE reset=?")
|
||||||
defer utility.Close(stmt)
|
defer utility.Close(stmt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -139,7 +139,7 @@ func (p *Persister) GetUserByToken(token string) (user entity.User, err error) {
|
||||||
// This occurs when we you share a folder with a new user and they have to complete
|
// This occurs when we you share a folder with a new user and they have to complete
|
||||||
// the onboarding process.
|
// the onboarding process.
|
||||||
func (p *Persister) GetUserBySerial(serial string) (user entity.User, err error) {
|
func (p *Persister) GetUserBySerial(serial string) (user entity.User, err error) {
|
||||||
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, active, created, revised FROM user WHERE salt=?")
|
stmt, err := Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, created, revised FROM user WHERE salt=?")
|
||||||
defer utility.Close(stmt)
|
defer utility.Close(stmt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -159,7 +159,7 @@ func (p *Persister) GetUserBySerial(serial string) (user entity.User, err error)
|
||||||
// identified in the Persister.
|
// identified in the Persister.
|
||||||
func (p *Persister) GetUsersForOrganization() (users []entity.User, err error) {
|
func (p *Persister) GetUsersForOrganization() (users []entity.User, err error) {
|
||||||
err = Db.Select(&users,
|
err = Db.Select(&users,
|
||||||
"SELECT id, refid, firstname, lastname, email, initials, password, salt, reset, active, created, revised FROM user WHERE refid IN (SELECT userid FROM account where orgid = ?) ORDER BY firstname,lastname", p.Context.OrgID)
|
"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", p.Context.OrgID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(fmt.Sprintf("Unable to get all users for org %s", p.Context.OrgID), err)
|
log.Error(fmt.Sprintf("Unable to get all users for org %s", p.Context.OrgID), err)
|
||||||
|
@ -172,7 +172,7 @@ func (p *Persister) GetUsersForOrganization() (users []entity.User, err error) {
|
||||||
// GetFolderUsers returns a slice containing all user records for given folder.
|
// GetFolderUsers returns a slice containing all user records for given folder.
|
||||||
func (p *Persister) GetFolderUsers(folderID string) (users []entity.User, err error) {
|
func (p *Persister) GetFolderUsers(folderID string) (users []entity.User, err error) {
|
||||||
err = Db.Select(&users,
|
err = Db.Select(&users,
|
||||||
"SELECT id, refid, firstname, lastname, email, initials, password, salt, reset, active, created, revised FROM user WHERE refid IN (SELECT userid from labelrole WHERE orgid=? AND labelid=?) ORDER BY firstname,lastname", p.Context.OrgID, folderID)
|
"SELECT id, refid, firstname, lastname, email, initials, password, salt, reset, created, revised FROM user WHERE refid IN (SELECT userid from labelrole WHERE orgid=? AND labelid=?) ORDER BY firstname,lastname", p.Context.OrgID, folderID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(fmt.Sprintf("Unable to get all users for org %s", p.Context.OrgID), err)
|
log.Error(fmt.Sprintf("Unable to get all users for org %s", p.Context.OrgID), err)
|
||||||
|
@ -188,7 +188,7 @@ func (p *Persister) UpdateUser(user entity.User) (err error) {
|
||||||
user.Email = strings.ToLower(user.Email)
|
user.Email = strings.ToLower(user.Email)
|
||||||
|
|
||||||
stmt, err := p.Context.Transaction.PrepareNamed(
|
stmt, err := p.Context.Transaction.PrepareNamed(
|
||||||
"UPDATE user SET firstname=:firstname, lastname=:lastname, email=:email, revised=:revised, active=:active, initials=:initials WHERE refid=:refid")
|
"UPDATE user SET firstname=:firstname, lastname=:lastname, email=:email, revised=:revised, initials=:initials WHERE refid=:refid")
|
||||||
defer utility.Close(stmt)
|
defer utility.Close(stmt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue