mirror of
https://github.com/documize/community.git
synced 2025-07-21 14:19:43 +02:00
removed named sql statements
This commit is contained in:
parent
9ccd0fd19c
commit
8f80673cde
32 changed files with 218 additions and 937 deletions
|
@ -17,7 +17,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/streamutil"
|
|
||||||
"github.com/documize/community/domain"
|
"github.com/documize/community/domain"
|
||||||
"github.com/documize/community/domain/store/mysql"
|
"github.com/documize/community/domain/store/mysql"
|
||||||
"github.com/documize/community/model/account"
|
"github.com/documize/community/model/account"
|
||||||
|
@ -34,19 +33,11 @@ func (s Scope) Add(ctx domain.RequestContext, account account.Account) (err erro
|
||||||
account.Created = time.Now().UTC()
|
account.Created = time.Now().UTC()
|
||||||
account.Revised = time.Now().UTC()
|
account.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("INSERT INTO account (refid, orgid, userid, admin, editor, users, active, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
_, err = ctx.Transaction.Exec("INSERT INTO account (refid, orgid, userid, admin, editor, users, active, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
defer streamutil.Close(stmt)
|
account.RefID, account.OrgID, account.UserID, account.Admin, account.Editor, account.Users, account.Active, account.Created, account.Revised)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "unable to prepare insert for account")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(account.RefID, account.OrgID, account.UserID, account.Admin, account.Editor, account.Users, account.Active, account.Created, account.Revised)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "unable to execute insert for account")
|
err = errors.Wrap(err, "unable to execute insert for account")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -106,7 +97,6 @@ func (s Scope) CountOrgAccounts(ctx domain.RequestContext) (c int) {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "count org accounts")
|
err = errors.Wrap(err, "count org accounts")
|
||||||
return 0
|
return 0
|
||||||
|
@ -119,18 +109,10 @@ func (s Scope) CountOrgAccounts(ctx domain.RequestContext) (c int) {
|
||||||
func (s Scope) UpdateAccount(ctx domain.RequestContext, account account.Account) (err error) {
|
func (s Scope) UpdateAccount(ctx domain.RequestContext, account account.Account) (err error) {
|
||||||
account.Revised = time.Now().UTC()
|
account.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.PrepareNamed("UPDATE account SET userid=:userid, admin=:admin, editor=:editor, users=:users, active=:active, revised=:revised WHERE orgid=:orgid AND refid=:refid")
|
_, err = ctx.Transaction.NamedExec("UPDATE account SET userid=:userid, admin=:admin, editor=:editor, users=:users, active=:active, revised=:revised WHERE orgid=:orgid AND refid=:refid", &account)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("prepare update for account %s", account.RefID))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(&account)
|
|
||||||
if err != sql.ErrNoRows && err != nil {
|
if err != sql.ErrNoRows && err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute update for account %s", account.RefID))
|
err = errors.Wrap(err, fmt.Sprintf("execute update for account %s", account.RefID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -16,7 +16,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/streamutil"
|
|
||||||
"github.com/documize/community/domain"
|
"github.com/documize/community/domain"
|
||||||
"github.com/documize/community/model/activity"
|
"github.com/documize/community/model/activity"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -33,19 +32,11 @@ func (s Scope) RecordUserActivity(ctx domain.RequestContext, activity activity.U
|
||||||
activity.UserID = ctx.UserID
|
activity.UserID = ctx.UserID
|
||||||
activity.Created = time.Now().UTC()
|
activity.Created = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("INSERT INTO useractivity (orgid, userid, labelid, sourceid, sourcetype, activitytype, created) VALUES (?, ?, ?, ?, ?, ?, ?)")
|
_, err = ctx.Transaction.Exec("INSERT INTO useractivity (orgid, userid, labelid, sourceid, sourcetype, activitytype, created) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||||
defer streamutil.Close(stmt)
|
activity.OrgID, activity.UserID, activity.LabelID, activity.SourceID, activity.SourceType, activity.ActivityType, activity.Created)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare record user activity")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(activity.OrgID, activity.UserID, activity.LabelID, activity.SourceID, activity.SourceType, activity.ActivityType, activity.Created)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute record user activity")
|
err = errors.Wrap(err, "execute record user activity")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/streamutil"
|
|
||||||
"github.com/documize/community/model/attachment"
|
"github.com/documize/community/model/attachment"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -37,18 +36,11 @@ func (s Scope) Add(ctx domain.RequestContext, a attachment.Attachment) (err erro
|
||||||
bits := strings.Split(a.Filename, ".")
|
bits := strings.Split(a.Filename, ".")
|
||||||
a.Extension = bits[len(bits)-1]
|
a.Extension = bits[len(bits)-1]
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("INSERT INTO attachment (refid, orgid, documentid, job, fileid, filename, data, extension, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
_, err = ctx.Transaction.Exec("INSERT INTO attachment (refid, orgid, documentid, job, fileid, filename, data, extension, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
defer streamutil.Close(stmt)
|
a.RefID, a.OrgID, a.DocumentID, a.Job, a.FileID, a.Filename, a.Data, a.Extension, a.Created, a.Revised)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare insert attachment")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(a.RefID, a.OrgID, a.DocumentID, a.Job, a.FileID, a.Filename, a.Data, a.Extension, a.Created, a.Revised)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute insert attachment")
|
err = errors.Wrap(err, "execute insert attachment")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -56,18 +48,11 @@ func (s Scope) Add(ctx domain.RequestContext, a attachment.Attachment) (err erro
|
||||||
|
|
||||||
// GetAttachment returns the database attachment record specified by the parameters.
|
// GetAttachment returns the database attachment record specified by the parameters.
|
||||||
func (s Scope) GetAttachment(ctx domain.RequestContext, orgID, attachmentID string) (a attachment.Attachment, err error) {
|
func (s Scope) GetAttachment(ctx domain.RequestContext, orgID, attachmentID string) (a attachment.Attachment, err error) {
|
||||||
stmt, err := s.Runtime.Db.Preparex("SELECT id, refid, orgid, documentid, job, fileid, filename, data, extension, created, revised FROM attachment WHERE orgid=? and refid=?")
|
err = s.Runtime.Db.Get(&a, "SELECT id, refid, orgid, documentid, job, fileid, filename, data, extension, created, revised FROM attachment WHERE orgid=? and refid=?",
|
||||||
defer streamutil.Close(stmt)
|
orgID, attachmentID)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare select attachment")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&a, orgID, attachmentID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute select attachment")
|
err = errors.Wrap(err, "execute select attachment")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -79,7 +64,6 @@ func (s Scope) GetAttachments(ctx domain.RequestContext, docID string) (a []atta
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute select attachments")
|
err = errors.Wrap(err, "execute select attachments")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -91,7 +75,6 @@ func (s Scope) GetAttachmentsWithData(ctx domain.RequestContext, docID string) (
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute select attachments with data")
|
err = errors.Wrap(err, "execute select attachments with data")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -40,21 +40,15 @@ func (s Scope) Record(ctx domain.RequestContext, t audit.EventType) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt, err := tx.Preparex("INSERT INTO userevent (orgid, userid, eventtype, ip, created) VALUES (?, ?, ?, ?, ?)")
|
_, err = tx.Exec("INSERT INTO userevent (orgid, userid, eventtype, ip, created) VALUES (?, ?, ?, ?, ?)",
|
||||||
|
e.OrgID, e.UserID, e.Type, e.IP, e.Created)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
s.Runtime.Log.Error("prepare audit insert", err)
|
s.Runtime.Log.Error("prepare audit insert", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = stmt.Exec(e.OrgID, e.UserID, e.Type, e.IP, e.Created)
|
|
||||||
if err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
s.Runtime.Log.Error("execute audit insert", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
stmt.Close()
|
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -16,11 +16,9 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/streamutil"
|
|
||||||
"github.com/documize/community/domain"
|
"github.com/documize/community/domain"
|
||||||
"github.com/documize/community/domain/store/mysql"
|
"github.com/documize/community/domain/store/mysql"
|
||||||
"github.com/documize/community/model/block"
|
"github.com/documize/community/model/block"
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -36,18 +34,11 @@ func (s Scope) Add(ctx domain.RequestContext, b block.Block) (err error) {
|
||||||
b.Created = time.Now().UTC()
|
b.Created = time.Now().UTC()
|
||||||
b.Revised = time.Now().UTC()
|
b.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("INSERT INTO block (refid, orgid, labelid, userid, contenttype, pagetype, title, body, excerpt, rawbody, config, externalsource, used, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
_, err = ctx.Transaction.Exec("INSERT INTO block (refid, orgid, labelid, userid, contenttype, pagetype, title, body, excerpt, rawbody, config, externalsource, used, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
defer streamutil.Close(stmt)
|
b.RefID, b.OrgID, b.LabelID, b.UserID, b.ContentType, b.PageType, b.Title, b.Body, b.Excerpt, b.RawBody, b.Config, b.ExternalSource, b.Used, b.Created, b.Revised)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare insert block")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(b.RefID, b.OrgID, b.LabelID, b.UserID, b.ContentType, b.PageType, b.Title, b.Body, b.Excerpt, b.RawBody, b.Config, b.ExternalSource, b.Used, b.Created, b.Revised)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute insert block")
|
err = errors.Wrap(err, "execute insert block")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -55,18 +46,11 @@ func (s Scope) Add(ctx domain.RequestContext, b block.Block) (err error) {
|
||||||
|
|
||||||
// Get returns requested reusable content block.
|
// Get returns requested reusable content block.
|
||||||
func (s Scope) Get(ctx domain.RequestContext, id string) (b block.Block, err error) {
|
func (s Scope) Get(ctx domain.RequestContext, id string) (b block.Block, err error) {
|
||||||
stmt, err := s.Runtime.Db.Preparex("SELECT a.id, a.refid, a.orgid, a.labelid, a.userid, a.contenttype, a.pagetype, a.title, a.body, a.excerpt, a.rawbody, a.config, a.externalsource, a.used, a.created, a.revised, b.firstname, b.lastname FROM block a LEFT JOIN user b ON a.userid = b.refid WHERE a.orgid=? AND a.refid=?")
|
err = s.Runtime.Db.Get(&b, "SELECT a.id, a.refid, a.orgid, a.labelid, a.userid, a.contenttype, a.pagetype, a.title, a.body, a.excerpt, a.rawbody, a.config, a.externalsource, a.used, a.created, a.revised, b.firstname, b.lastname FROM block a LEFT JOIN user b ON a.userid = b.refid WHERE a.orgid=? AND a.refid=?",
|
||||||
defer streamutil.Close(stmt)
|
ctx.OrgID, id)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare select block")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&b, ctx.OrgID, id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute select block")
|
err = errors.Wrap(err, "execute select block")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -78,7 +62,6 @@ func (s Scope) GetBySpace(ctx domain.RequestContext, spaceID string) (b []block.
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "select space blocks")
|
err = errors.Wrap(err, "select space blocks")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -86,18 +69,10 @@ func (s Scope) GetBySpace(ctx domain.RequestContext, spaceID string) (b []block.
|
||||||
|
|
||||||
// IncrementUsage increments usage counter for content block.
|
// IncrementUsage increments usage counter for content block.
|
||||||
func (s Scope) IncrementUsage(ctx domain.RequestContext, id string) (err error) {
|
func (s Scope) IncrementUsage(ctx domain.RequestContext, id string) (err error) {
|
||||||
stmt, err := ctx.Transaction.Preparex("UPDATE block SET used=used+1, revised=? WHERE orgid=? AND refid=?")
|
_, err = ctx.Transaction.Exec("UPDATE block SET used=used+1, revised=? WHERE orgid=? AND refid=?", time.Now().UTC(), ctx.OrgID, id)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare increment block usage")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(time.Now().UTC(), ctx.OrgID, id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute increment block usage")
|
err = errors.Wrap(err, "execute increment block usage")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -105,18 +80,10 @@ func (s Scope) IncrementUsage(ctx domain.RequestContext, id string) (err error)
|
||||||
|
|
||||||
// DecrementUsage decrements usage counter for content block.
|
// DecrementUsage decrements usage counter for content block.
|
||||||
func (s Scope) DecrementUsage(ctx domain.RequestContext, id string) (err error) {
|
func (s Scope) DecrementUsage(ctx domain.RequestContext, id string) (err error) {
|
||||||
stmt, err := ctx.Transaction.Preparex("UPDATE block SET used=used-1, revised=? WHERE orgid=? AND refid=?")
|
_, err = ctx.Transaction.Exec("UPDATE block SET used=used-1, revised=? WHERE orgid=? AND refid=?", time.Now().UTC(), ctx.OrgID, id)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare decrement block usage")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(time.Now().UTC(), ctx.OrgID, id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute decrement block usage")
|
err = errors.Wrap(err, "execute decrement block usage")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -124,23 +91,13 @@ func (s Scope) DecrementUsage(ctx domain.RequestContext, id string) (err error)
|
||||||
|
|
||||||
// RemoveReference clears page.blockid for given blockID.
|
// RemoveReference clears page.blockid for given blockID.
|
||||||
func (s Scope) RemoveReference(ctx domain.RequestContext, id string) (err error) {
|
func (s Scope) RemoveReference(ctx domain.RequestContext, id string) (err error) {
|
||||||
stmt, err := ctx.Transaction.Preparex("UPDATE page SET blockid='', revised=? WHERE orgid=? AND blockid=?")
|
_, err = ctx.Transaction.Exec("UPDATE page SET blockid='', revised=? WHERE orgid=? AND blockid=?", time.Now().UTC(), ctx.OrgID, id)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare remove block ref")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(time.Now().UTC(), ctx.OrgID, id)
|
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute remove block ref")
|
err = errors.Wrap(err, "execute remove block ref")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -150,19 +107,10 @@ func (s Scope) RemoveReference(ctx domain.RequestContext, id string) (err error)
|
||||||
func (s Scope) Update(ctx domain.RequestContext, b block.Block) (err error) {
|
func (s Scope) Update(ctx domain.RequestContext, b block.Block) (err error) {
|
||||||
b.Revised = time.Now().UTC()
|
b.Revised = time.Now().UTC()
|
||||||
|
|
||||||
var stmt *sqlx.NamedStmt
|
_, err = ctx.Transaction.NamedExec("UPDATE block SET title=:title, body=:body, excerpt=:excerpt, rawbody=:rawbody, config=:config, revised=:revised WHERE orgid=:orgid AND refid=:refid", b)
|
||||||
stmt, err = ctx.Transaction.PrepareNamed("UPDATE block SET title=:title, body=:body, excerpt=:excerpt, rawbody=:rawbody, config=:config, revised=:revised WHERE orgid=:orgid AND refid=:refid")
|
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare update block")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(&b)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute update block")
|
err = errors.Wrap(err, "execute update block")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/streamutil"
|
|
||||||
"github.com/documize/community/domain"
|
"github.com/documize/community/domain"
|
||||||
"github.com/documize/community/domain/store/mysql"
|
"github.com/documize/community/domain/store/mysql"
|
||||||
"github.com/documize/community/model/category"
|
"github.com/documize/community/model/category"
|
||||||
|
@ -36,18 +35,11 @@ func (s Scope) Add(ctx domain.RequestContext, c category.Category) (err error) {
|
||||||
c.Created = time.Now().UTC()
|
c.Created = time.Now().UTC()
|
||||||
c.Revised = time.Now().UTC()
|
c.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("INSERT INTO category (refid, orgid, labelid, category, created, revised) VALUES (?, ?, ?, ?, ?, ?)")
|
_, err = ctx.Transaction.Exec("INSERT INTO category (refid, orgid, labelid, category, created, revised) VALUES (?, ?, ?, ?, ?, ?)",
|
||||||
defer streamutil.Close(stmt)
|
c.RefID, c.OrgID, c.LabelID, c.Category, c.Created, c.Revised)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "unable to prepare insert category")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(c.RefID, c.OrgID, c.LabelID, c.Category, c.Created, c.Revised)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "unable to execute insert category")
|
err = errors.Wrap(err, "unable to execute insert category")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -70,7 +62,6 @@ func (s Scope) GetBySpace(ctx domain.RequestContext, spaceID string) (c []catego
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute select categories for space %s", spaceID))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute select categories for space %s", spaceID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -93,7 +84,6 @@ func (s Scope) GetAllBySpace(ctx domain.RequestContext, spaceID string) (c []cat
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute select all categories for space %s", spaceID))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute select all categories for space %s", spaceID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -103,18 +93,10 @@ func (s Scope) GetAllBySpace(ctx domain.RequestContext, spaceID string) (c []cat
|
||||||
func (s Scope) Update(ctx domain.RequestContext, c category.Category) (err error) {
|
func (s Scope) Update(ctx domain.RequestContext, c category.Category) (err error) {
|
||||||
c.Revised = time.Now().UTC()
|
c.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.PrepareNamed("UPDATE category SET category=:category, revised=:revised WHERE orgid=:orgid AND refid=:refid")
|
_, err = ctx.Transaction.NamedExec("UPDATE category SET category=:category, revised=:revised WHERE orgid=:orgid AND refid=:refid", c)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to prepare update for category %s", c.RefID))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(&c)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute update for category %s", c.RefID))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute update for category %s", c.RefID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -122,19 +104,11 @@ func (s Scope) Update(ctx domain.RequestContext, c category.Category) (err error
|
||||||
|
|
||||||
// Get returns specified category
|
// Get returns specified category
|
||||||
func (s Scope) Get(ctx domain.RequestContext, id string) (c category.Category, err error) {
|
func (s Scope) Get(ctx domain.RequestContext, id string) (c category.Category, err error) {
|
||||||
stmt, err := s.Runtime.Db.Preparex("SELECT id, refid, orgid, labelid, category, created, revised FROM category WHERE orgid=? AND refid=?")
|
err = s.Runtime.Db.Get(&c, "SELECT id, refid, orgid, labelid, category, created, revised FROM category WHERE orgid=? AND refid=?",
|
||||||
defer streamutil.Close(stmt)
|
ctx.OrgID, id)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to prepare select for category %s", id))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&c, ctx.OrgID, id)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to get category %s", id))
|
err = errors.Wrap(err, fmt.Sprintf("unable to get category %s", id))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -151,18 +125,11 @@ func (s Scope) AssociateDocument(ctx domain.RequestContext, m category.Member) (
|
||||||
m.Created = time.Now().UTC()
|
m.Created = time.Now().UTC()
|
||||||
m.Revised = time.Now().UTC()
|
m.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("INSERT INTO categorymember (refid, orgid, categoryid, labelid, documentid, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?)")
|
_, err = ctx.Transaction.Exec("INSERT INTO categorymember (refid, orgid, categoryid, labelid, documentid, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||||
defer streamutil.Close(stmt)
|
m.RefID, m.OrgID, m.CategoryID, m.LabelID, m.DocumentID, m.Created, m.Revised)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "unable to prepare insert categorymember")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(m.RefID, m.OrgID, m.CategoryID, m.LabelID, m.DocumentID, m.Created, m.Revised)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "unable to execute insert categorymember")
|
err = errors.Wrap(err, "unable to execute insert categorymember")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -219,7 +186,6 @@ func (s Scope) GetSpaceCategorySummary(ctx domain.RequestContext, spaceID string
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute select category summary for space %s", spaceID))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute select category summary for space %s", spaceID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -236,7 +202,6 @@ func (s Scope) GetDocumentCategoryMembership(ctx domain.RequestContext, document
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute select categories for document %s", documentID))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute select categories for document %s", documentID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/streamutil"
|
|
||||||
"github.com/documize/community/domain"
|
"github.com/documize/community/domain"
|
||||||
"github.com/documize/community/domain/store/mysql"
|
"github.com/documize/community/domain/store/mysql"
|
||||||
"github.com/documize/community/model/doc"
|
"github.com/documize/community/model/doc"
|
||||||
|
@ -35,19 +34,11 @@ func (s Scope) Add(ctx domain.RequestContext, document doc.Document) (err error)
|
||||||
document.Created = time.Now().UTC()
|
document.Created = time.Now().UTC()
|
||||||
document.Revised = document.Created // put same time in both fields
|
document.Revised = document.Created // put same time in both fields
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("INSERT INTO document (refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
_, err = ctx.Transaction.Exec("INSERT INTO document (refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
defer streamutil.Close(stmt)
|
document.RefID, document.OrgID, document.LabelID, document.UserID, document.Job, document.Location, document.Title, document.Excerpt, document.Slug, document.Tags, document.Template, document.Created, document.Revised)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare insert document")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(document.RefID, document.OrgID, document.LabelID, document.UserID, document.Job, document.Location, document.Title, document.Excerpt, document.Slug, document.Tags, document.Template, document.Created, document.Revised)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execuet insert document")
|
err = errors.Wrap(err, "execuet insert document")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -55,18 +46,11 @@ func (s Scope) Add(ctx domain.RequestContext, document doc.Document) (err error)
|
||||||
|
|
||||||
// Get fetches the document record with the given id fromt the document table and audits that it has been got.
|
// Get fetches the document record with the given id fromt the document table and audits that it has been got.
|
||||||
func (s Scope) Get(ctx domain.RequestContext, id string) (document doc.Document, err error) {
|
func (s Scope) Get(ctx domain.RequestContext, id string) (document doc.Document, err error) {
|
||||||
stmt, err := s.Runtime.Db.Preparex("SELECT id, refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, layout, created, revised FROM document WHERE orgid=? and refid=?")
|
err = s.Runtime.Db.Get(&document, "SELECT id, refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, layout, created, revised FROM document WHERE orgid=? and refid=?",
|
||||||
defer streamutil.Close(stmt)
|
ctx.OrgID, id)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare select document")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&document, ctx.OrgID, id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute select document")
|
err = errors.Wrap(err, "execute select document")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -112,7 +96,6 @@ func (s Scope) GetAll() (ctx domain.RequestContext, documents []doc.Document, er
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "select documents")
|
err = errors.Wrap(err, "select documents")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -124,7 +107,6 @@ func (s Scope) GetBySpace(ctx domain.RequestContext, folderID string) (documents
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "select documents by space")
|
err = errors.Wrap(err, "select documents by space")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -150,7 +132,6 @@ func (s Scope) GetByTag(ctx domain.RequestContext, tag string) (documents []doc.
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "select documents by tag")
|
err = errors.Wrap(err, "select documents by tag")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -173,7 +154,6 @@ func (s Scope) Templates(ctx domain.RequestContext) (documents []doc.Document, e
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "select document templates")
|
err = errors.Wrap(err, "select document templates")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -201,7 +181,6 @@ func (s Scope) TemplatesBySpace(ctx domain.RequestContext, spaceID string) (docu
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "select space document templates")
|
err = errors.Wrap(err, "select space document templates")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -218,7 +197,6 @@ func (s Scope) PublicDocuments(ctx domain.RequestContext, orgID string) (documen
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute GetPublicDocuments for org %s%s", orgID))
|
err = errors.Wrap(err, fmt.Sprintf("execute GetPublicDocuments for org %s%s", orgID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -246,7 +224,6 @@ func (s Scope) DocumentList(ctx domain.RequestContext) (documents []doc.Document
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "select documents list")
|
err = errors.Wrap(err, "select documents list")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -256,19 +233,11 @@ func (s Scope) DocumentList(ctx domain.RequestContext) (documents []doc.Document
|
||||||
func (s Scope) Update(ctx domain.RequestContext, document doc.Document) (err error) {
|
func (s Scope) Update(ctx domain.RequestContext, document doc.Document) (err error) {
|
||||||
document.Revised = time.Now().UTC()
|
document.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.PrepareNamed("UPDATE document SET labelid=:labelid, userid=:userid, job=:job, location=:location, title=:title, excerpt=:excerpt, slug=:slug, tags=:tags, template=:template, layout=:layout, revised=:revised WHERE orgid=:orgid AND refid=:refid")
|
_, err = ctx.Transaction.NamedExec("UPDATE document SET labelid=:labelid, userid=:userid, job=:job, location=:location, title=:title, excerpt=:excerpt, slug=:slug, tags=:tags, template=:template, layout=:layout, revised=:revised WHERE orgid=:orgid AND refid=:refid",
|
||||||
defer streamutil.Close(stmt)
|
&document)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare update document")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(&document)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute update document")
|
err = errors.Wrap(err, "execute update document")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -278,19 +247,11 @@ func (s Scope) Update(ctx domain.RequestContext, document doc.Document) (err err
|
||||||
func (s Scope) ChangeDocumentSpace(ctx domain.RequestContext, document, space string) (err error) {
|
func (s Scope) ChangeDocumentSpace(ctx domain.RequestContext, document, space string) (err error) {
|
||||||
revised := time.Now().UTC()
|
revised := time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("UPDATE document SET labelid=?, revised=? WHERE orgid=? AND refid=?")
|
_, err = ctx.Transaction.Exec("UPDATE document SET labelid=?, revised=? WHERE orgid=? AND refid=?",
|
||||||
defer streamutil.Close(stmt)
|
space, revised, ctx.OrgID, document)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("prepare change document space %s", document))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(space, revised, ctx.OrgID, document)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute change document space %s", document))
|
err = errors.Wrap(err, fmt.Sprintf("execute change document space %s", document))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -298,18 +259,11 @@ func (s Scope) ChangeDocumentSpace(ctx domain.RequestContext, document, space st
|
||||||
|
|
||||||
// MoveDocumentSpace changes the space for client's organization's documents which have space "id", to "move".
|
// MoveDocumentSpace changes the space for client's organization's documents which have space "id", to "move".
|
||||||
func (s Scope) MoveDocumentSpace(ctx domain.RequestContext, id, move string) (err error) {
|
func (s Scope) MoveDocumentSpace(ctx domain.RequestContext, id, move string) (err error) {
|
||||||
stmt, err := ctx.Transaction.Preparex("UPDATE document SET labelid=? WHERE orgid=? AND labelid=?")
|
_, err = ctx.Transaction.Exec("UPDATE document SET labelid=? WHERE orgid=? AND labelid=?",
|
||||||
defer streamutil.Close(stmt)
|
move, ctx.OrgID, id)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("prepare document space move %s", id))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(move, ctx.OrgID, id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute document space move %s", id))
|
err = errors.Wrap(err, fmt.Sprintf("execute document space move %s", id))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -338,7 +292,7 @@ func (s Scope) Delete(ctx domain.RequestContext, documentID string) (rows int64,
|
||||||
return b.DeleteConstrained(ctx.Transaction, "document", ctx.OrgID, documentID)
|
return b.DeleteConstrained(ctx.Transaction, "document", ctx.OrgID, documentID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete removes all documents for given space.
|
// DeleteBySpace removes all documents for given space.
|
||||||
// Remove document pages, revisions, attachments, updates the search subsystem.
|
// Remove document pages, revisions, attachments, updates the search subsystem.
|
||||||
func (s Scope) DeleteBySpace(ctx domain.RequestContext, spaceID string) (rows int64, err error) {
|
func (s Scope) DeleteBySpace(ctx domain.RequestContext, spaceID string) (rows int64, err error) {
|
||||||
b := mysql.BaseQuery{}
|
b := mysql.BaseQuery{}
|
||||||
|
|
|
@ -12,12 +12,12 @@
|
||||||
package mysql
|
package mysql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/streamutil"
|
|
||||||
"github.com/documize/community/core/uniqueid"
|
"github.com/documize/community/core/uniqueid"
|
||||||
"github.com/documize/community/domain"
|
"github.com/documize/community/domain"
|
||||||
"github.com/documize/community/domain/store/mysql"
|
"github.com/documize/community/domain/store/mysql"
|
||||||
|
@ -36,18 +36,11 @@ func (s Scope) Add(ctx domain.RequestContext, l link.Link) (err error) {
|
||||||
l.Created = time.Now().UTC()
|
l.Created = time.Now().UTC()
|
||||||
l.Revised = time.Now().UTC()
|
l.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("INSERT INTO link (refid, orgid, folderid, userid, sourcedocumentid, sourcepageid, targetdocumentid, targetid, linktype, orphan, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
_, err = ctx.Transaction.Exec("INSERT INTO link (refid, orgid, folderid, userid, sourcedocumentid, sourcepageid, targetdocumentid, targetid, linktype, orphan, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
defer streamutil.Close(stmt)
|
l.RefID, l.OrgID, l.FolderID, l.UserID, l.SourceDocumentID, l.SourcePageID, l.TargetDocumentID, l.TargetID, l.LinkType, l.Orphan, l.Created, l.Revised)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare link insert")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(l.RefID, l.OrgID, l.FolderID, l.UserID, l.SourceDocumentID, l.SourcePageID, l.TargetDocumentID, l.TargetID, l.LinkType, l.Orphan, l.Created, l.Revised)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute link insert")
|
err = errors.Wrap(err, "execute link insert")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -62,7 +55,8 @@ func (s Scope) GetDocumentOutboundLinks(ctx domain.RequestContext, documentID st
|
||||||
ctx.OrgID,
|
ctx.OrgID,
|
||||||
documentID)
|
documentID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
|
err = errors.Wrap(err, "select document oubound links")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +77,8 @@ func (s Scope) GetPageLinks(ctx domain.RequestContext, documentID, pageID string
|
||||||
documentID,
|
documentID,
|
||||||
pageID)
|
pageID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
|
err = errors.Wrap(err, "get page links")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,15 +93,13 @@ func (s Scope) GetPageLinks(ctx domain.RequestContext, documentID, pageID string
|
||||||
func (s Scope) MarkOrphanDocumentLink(ctx domain.RequestContext, documentID string) (err error) {
|
func (s Scope) MarkOrphanDocumentLink(ctx domain.RequestContext, documentID string) (err error) {
|
||||||
revised := time.Now().UTC()
|
revised := time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("UPDATE link SET orphan=1, revised=? WHERE linktype='document' AND orgid=? AND targetdocumentid=?")
|
_, err = ctx.Transaction.Exec("UPDATE link SET orphan=1, revised=? WHERE linktype='document' AND orgid=? AND targetdocumentid=?",
|
||||||
defer streamutil.Close(stmt)
|
revised, ctx.OrgID, documentID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
err = errors.Wrap(err, "mark link as orphan")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = stmt.Exec(revised, ctx.OrgID, documentID)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,15 +107,12 @@ func (s Scope) MarkOrphanDocumentLink(ctx domain.RequestContext, documentID stri
|
||||||
func (s Scope) MarkOrphanPageLink(ctx domain.RequestContext, pageID string) (err error) {
|
func (s Scope) MarkOrphanPageLink(ctx domain.RequestContext, pageID string) (err error) {
|
||||||
revised := time.Now().UTC()
|
revised := time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("UPDATE link SET orphan=1, revised=? WHERE linktype='section' AND orgid=? AND targetid=?")
|
_, err = ctx.Transaction.Exec("UPDATE link SET orphan=1, revised=? WHERE linktype='section' AND orgid=? AND targetid=?", revised, ctx.OrgID, pageID)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
err = errors.Wrap(err, "mark orphan page link")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = stmt.Exec(revised, ctx.OrgID, pageID)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,15 +120,13 @@ func (s Scope) MarkOrphanPageLink(ctx domain.RequestContext, pageID string) (err
|
||||||
func (s Scope) MarkOrphanAttachmentLink(ctx domain.RequestContext, attachmentID string) (err error) {
|
func (s Scope) MarkOrphanAttachmentLink(ctx domain.RequestContext, attachmentID string) (err error) {
|
||||||
revised := time.Now().UTC()
|
revised := time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("UPDATE link SET orphan=1, revised=? WHERE linktype='file' AND orgid=? AND targetid=?")
|
_, err = ctx.Transaction.Exec("UPDATE link SET orphan=1, revised=? WHERE linktype='file' AND orgid=? AND targetid=?",
|
||||||
defer streamutil.Close(stmt)
|
revised, ctx.OrgID, attachmentID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
err = errors.Wrap(err, "mark orphan attachment link")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = stmt.Exec(revised, ctx.OrgID, attachmentID)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"github.com/documize/community/domain"
|
"github.com/documize/community/domain"
|
||||||
"github.com/documize/community/domain/store/mysql"
|
"github.com/documize/community/domain/store/mysql"
|
||||||
"github.com/documize/community/model/org"
|
"github.com/documize/community/model/org"
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,25 +31,17 @@ type Scope struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddOrganization inserts the passed organization record into the organization table.
|
// AddOrganization inserts the passed organization record into the organization table.
|
||||||
func (s Scope) AddOrganization(ctx domain.RequestContext, org org.Organization) error {
|
func (s Scope) AddOrganization(ctx domain.RequestContext, org org.Organization) (err error) {
|
||||||
org.Created = time.Now().UTC()
|
org.Created = time.Now().UTC()
|
||||||
org.Revised = time.Now().UTC()
|
org.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex(
|
_, err = ctx.Transaction.Exec(
|
||||||
"INSERT INTO organization (refid, company, title, message, url, domain, email, allowanonymousaccess, serial, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
"INSERT INTO organization (refid, company, title, message, url, domain, email, allowanonymousaccess, serial, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
defer streamutil.Close(stmt)
|
org.RefID, org.Company, org.Title, org.Message, strings.ToLower(org.URL), strings.ToLower(org.Domain),
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "unable to prepare insert for org")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(org.RefID, org.Company, org.Title, org.Message, strings.ToLower(org.URL), strings.ToLower(org.Domain),
|
|
||||||
strings.ToLower(org.Email), org.AllowAnonymousAccess, org.Serial, org.Created, org.Revised)
|
strings.ToLower(org.Email), org.AllowAnonymousAccess, org.Serial, org.Created, org.Revised)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "unable to execute insert for org")
|
err = errors.Wrap(err, "unable to execute insert for org")
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -88,33 +79,18 @@ func (s Scope) GetOrganizationByDomain(subdomain string) (o org.Organization, er
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var stmt *sqlx.Stmt
|
err = s.Runtime.Db.Get(&o, "SELECT id, refid, company, title, message, url, domain, service as conversionendpoint, email, serial, active, allowanonymousaccess, authprovider, coalesce(authconfig,JSON_UNQUOTE('{}')) as authconfig, created, revised FROM organization WHERE domain=? AND active=1",
|
||||||
stmt, err = s.Runtime.Db.Preparex("SELECT id, refid, company, title, message, url, domain, service as conversionendpoint, email, serial, active, allowanonymousaccess, authprovider, coalesce(authconfig,JSON_UNQUOTE('{}')) as authconfig, created, revised FROM organization WHERE domain=? AND active=1")
|
subdomain)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to prepare select for subdomain %s", subdomain))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&o, subdomain)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// we try to match on empty domain as last resort
|
// we try to match on empty domain as last resort
|
||||||
stmt, err = s.Runtime.Db.Preparex("SELECT id, refid, company, title, message, url, domain, service as conversionendpoint, email, serial, active, allowanonymousaccess, authprovider, coalesce(authconfig,JSON_UNQUOTE('{}')) as authconfig, created, revised FROM organization WHERE domain='' AND active=1")
|
err = s.Runtime.Db.Get(&o, "SELECT id, refid, company, title, message, url, domain, service as conversionendpoint, email, serial, active, allowanonymousaccess, authprovider, coalesce(authconfig,JSON_UNQUOTE('{}')) as authconfig, created, revised FROM organization WHERE domain='' AND active=1")
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "unable to prepare select for empty subdomain")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&o)
|
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
err = errors.Wrap(err, "unable to execute select for empty subdomain")
|
err = errors.Wrap(err, "unable to execute select for empty subdomain")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -124,18 +100,11 @@ func (s Scope) GetOrganizationByDomain(subdomain string) (o org.Organization, er
|
||||||
func (s Scope) UpdateOrganization(ctx domain.RequestContext, org org.Organization) (err error) {
|
func (s Scope) UpdateOrganization(ctx domain.RequestContext, org org.Organization) (err error) {
|
||||||
org.Revised = time.Now().UTC()
|
org.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.PrepareNamed("UPDATE organization SET title=:title, message=:message, service=:conversionendpoint, email=:email, allowanonymousaccess=:allowanonymousaccess, revised=:revised WHERE refid=:refid")
|
_, err = ctx.Transaction.NamedExec("UPDATE organization SET title=:title, message=:message, service=:conversionendpoint, email=:email, allowanonymousaccess=:allowanonymousaccess, revised=:revised WHERE refid=:refid",
|
||||||
defer streamutil.Close(stmt)
|
&org)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to prepare update for org %s", org.RefID))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(&org)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute update for org %s", org.RefID))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute update for org %s", org.RefID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -149,18 +118,10 @@ func (s Scope) DeleteOrganization(ctx domain.RequestContext, orgID string) (rows
|
||||||
|
|
||||||
// RemoveOrganization sets the orgID organization to be inactive, thus executing a "soft delete" operation.
|
// RemoveOrganization sets the orgID organization to be inactive, thus executing a "soft delete" operation.
|
||||||
func (s Scope) RemoveOrganization(ctx domain.RequestContext, orgID string) (err error) {
|
func (s Scope) RemoveOrganization(ctx domain.RequestContext, orgID string) (err error) {
|
||||||
stmt, err := ctx.Transaction.Preparex("UPDATE organization SET active=0 WHERE refid=?")
|
_, err = ctx.Transaction.Exec("UPDATE organization SET active=0 WHERE refid=?", orgID)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to prepare soft delete for org %s", orgID))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(orgID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute soft delete for org %s", orgID))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute soft delete for org %s", orgID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -170,18 +131,11 @@ func (s Scope) RemoveOrganization(ctx domain.RequestContext, orgID string) (err
|
||||||
func (s Scope) UpdateAuthConfig(ctx domain.RequestContext, org org.Organization) (err error) {
|
func (s Scope) UpdateAuthConfig(ctx domain.RequestContext, org org.Organization) (err error) {
|
||||||
org.Revised = time.Now().UTC()
|
org.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.PrepareNamed("UPDATE organization SET allowanonymousaccess=:allowanonymousaccess, authprovider=:authprovider, authconfig=:authconfig, revised=:revised WHERE refid=:refid")
|
_, err = ctx.Transaction.NamedExec("UPDATE organization SET allowanonymousaccess=:allowanonymousaccess, authprovider=:authprovider, authconfig=:authconfig, revised=:revised WHERE refid=:refid",
|
||||||
defer streamutil.Close(stmt)
|
&org)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to prepare UpdateAuthConfig %s", org.RefID))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(&org)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute UpdateAuthConfig %s", org.RefID))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute UpdateAuthConfig %s", org.RefID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -227,47 +227,6 @@ func (h *Handler) GetPages(w http.ResponseWriter, r *http.Request) {
|
||||||
response.WriteJSON(w, pages)
|
response.WriteJSON(w, pages)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPagesBatch gets specified pages for document.
|
|
||||||
func (h *Handler) GetPagesBatch(w http.ResponseWriter, r *http.Request) {
|
|
||||||
method := "page.batch"
|
|
||||||
ctx := domain.GetRequestContext(r)
|
|
||||||
|
|
||||||
documentID := request.Param(r, "documentID")
|
|
||||||
if len(documentID) == 0 {
|
|
||||||
response.WriteMissingDataError(w, method, "documentID")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !permission.CanViewDocument(ctx, *h.Store, documentID) {
|
|
||||||
response.WriteForbiddenError(w)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
defer streamutil.Close(r.Body)
|
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
|
||||||
if err != nil {
|
|
||||||
response.WriteBadRequestError(w, method, err.Error())
|
|
||||||
h.Runtime.Log.Error(method, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
requestedPages := string(body)
|
|
||||||
|
|
||||||
pages, err := h.Store.Page.GetPagesWhereIn(ctx, documentID, requestedPages)
|
|
||||||
if err == sql.ErrNoRows {
|
|
||||||
response.WriteNotFoundError(w, method, documentID)
|
|
||||||
h.Runtime.Log.Error(method, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
response.WriteServerError(w, method, err)
|
|
||||||
h.Runtime.Log.Error(method, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
response.WriteJSON(w, pages)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete deletes a page.
|
// Delete deletes a page.
|
||||||
func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||||
method := "page.delete"
|
method := "page.delete"
|
||||||
|
|
|
@ -12,16 +12,14 @@
|
||||||
package mysql
|
package mysql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/streamutil"
|
|
||||||
"github.com/documize/community/domain"
|
"github.com/documize/community/domain"
|
||||||
"github.com/documize/community/domain/store/mysql"
|
"github.com/documize/community/domain/store/mysql"
|
||||||
"github.com/documize/community/model/page"
|
"github.com/documize/community/model/page"
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -56,33 +54,14 @@ func (s Scope) Add(ctx domain.RequestContext, model page.NewPage) (err error) {
|
||||||
model.Page.Sequence = maxSeq * 2
|
model.Page.Sequence = maxSeq * 2
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("INSERT INTO page (refid, orgid, documentid, userid, contenttype, pagetype, level, title, body, revisions, sequence, blockid, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
_, err = ctx.Transaction.Exec("INSERT INTO page (refid, orgid, documentid, userid, contenttype, pagetype, level, title, body, revisions, sequence, blockid, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
defer streamutil.Close(stmt)
|
model.Page.RefID, model.Page.OrgID, model.Page.DocumentID, model.Page.UserID, model.Page.ContentType, model.Page.PageType, model.Page.Level, model.Page.Title, model.Page.Body, model.Page.Revisions, model.Page.Sequence, model.Page.BlockID, model.Page.Created, model.Page.Revised)
|
||||||
|
|
||||||
if err != nil {
|
_, err = ctx.Transaction.Exec("INSERT INTO pagemeta (pageid, orgid, userid, documentid, rawbody, config, externalsource, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
err = errors.Wrap(err, "prepare page insert")
|
model.Meta.PageID, model.Meta.OrgID, model.Meta.UserID, model.Meta.DocumentID, model.Meta.RawBody, model.Meta.Config, model.Meta.ExternalSource, model.Meta.Created, model.Meta.Revised)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(model.Page.RefID, model.Page.OrgID, model.Page.DocumentID, model.Page.UserID, model.Page.ContentType, model.Page.PageType, model.Page.Level, model.Page.Title, model.Page.Body, model.Page.Revisions, model.Page.Sequence, model.Page.BlockID, model.Page.Created, model.Page.Revised)
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "execute page insert")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
stmt2, err := ctx.Transaction.Preparex("INSERT INTO pagemeta (pageid, orgid, userid, documentid, rawbody, config, externalsource, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
|
||||||
defer streamutil.Close(stmt2)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare page meta insert")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt2.Exec(model.Meta.PageID, model.Meta.OrgID, model.Meta.UserID, model.Meta.DocumentID, model.Meta.RawBody, model.Meta.Config, model.Meta.ExternalSource, model.Meta.Created, model.Meta.Revised)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute page meta insert")
|
err = errors.Wrap(err, "execute page meta insert")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -90,18 +69,11 @@ func (s Scope) Add(ctx domain.RequestContext, model page.NewPage) (err error) {
|
||||||
|
|
||||||
// Get returns the pageID page record from the page table.
|
// Get returns the pageID page record from the page table.
|
||||||
func (s Scope) Get(ctx domain.RequestContext, pageID string) (p page.Page, err error) {
|
func (s Scope) Get(ctx domain.RequestContext, pageID string) (p page.Page, err error) {
|
||||||
stmt, err := s.Runtime.Db.Preparex("SELECT a.id, a.refid, a.orgid, a.documentid, a.userid, a.contenttype, a.pagetype, a.level, a.sequence, a.title, a.body, a.revisions, a.blockid, a.created, a.revised FROM page a WHERE a.orgid=? AND a.refid=?")
|
err = s.Runtime.Db.Get(&p, "SELECT a.id, a.refid, a.orgid, a.documentid, a.userid, a.contenttype, a.pagetype, a.level, a.sequence, a.title, a.body, a.revisions, a.blockid, a.created, a.revised FROM page a WHERE a.orgid=? AND a.refid=?",
|
||||||
defer streamutil.Close(stmt)
|
ctx.OrgID, pageID)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare get page")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&p, ctx.OrgID, pageID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute get page")
|
err = errors.Wrap(err, "execute get page")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -113,59 +85,6 @@ func (s Scope) GetPages(ctx domain.RequestContext, documentID string) (p []page.
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute get pages")
|
err = errors.Wrap(err, "execute get pages")
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPagesWhereIn returns a slice, in presentation sequence, containing those page records for a given documentID
|
|
||||||
// where their refid is in the comma-separated list passed as inPages.
|
|
||||||
func (s Scope) GetPagesWhereIn(ctx domain.RequestContext, documentID, inPages string) (p []page.Page, err error) {
|
|
||||||
args := []interface{}{ctx.OrgID, documentID}
|
|
||||||
tempValues := strings.Split(inPages, ",")
|
|
||||||
|
|
||||||
sql := "SELECT a.id, a.refid, a.orgid, a.documentid, a.userid, a.contenttype, a.pagetype, a.level, a.sequence, a.title, a.body, a.blockid, a.revisions, a.created, a.revised FROM page a WHERE a.orgid=? AND a.documentid=? AND a.refid IN (?" + strings.Repeat(",?", len(tempValues)-1) + ") ORDER BY sequence"
|
|
||||||
|
|
||||||
inValues := make([]interface{}, len(tempValues))
|
|
||||||
|
|
||||||
for i, v := range tempValues {
|
|
||||||
inValues[i] = interface{}(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
args = append(args, inValues...)
|
|
||||||
|
|
||||||
stmt, err := s.Runtime.Db.Preparex(sql)
|
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
rows, err := stmt.Queryx(args...)
|
|
||||||
defer streamutil.Close(rows)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for rows.Next() {
|
|
||||||
page := page.Page{}
|
|
||||||
|
|
||||||
err = rows.StructScan(&page)
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
p = append(p, page)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -178,7 +97,6 @@ func (s Scope) GetPagesWithoutContent(ctx domain.RequestContext, documentID stri
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("Unable to execute select pages for org %s and document %s", ctx.OrgID, documentID))
|
err = errors.Wrap(err, fmt.Sprintf("Unable to execute select pages for org %s and document %s", ctx.OrgID, documentID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -191,17 +109,9 @@ func (s Scope) Update(ctx domain.RequestContext, page page.Page, refID, userID s
|
||||||
|
|
||||||
// Store revision history
|
// Store revision history
|
||||||
if !skipRevision {
|
if !skipRevision {
|
||||||
var stmt *sqlx.Stmt
|
_, err = ctx.Transaction.Exec("INSERT INTO revision (refid, orgid, documentid, ownerid, pageid, userid, contenttype, pagetype, title, body, rawbody, config, created, revised) SELECT ? as refid, a.orgid, a.documentid, a.userid as ownerid, a.refid as pageid, ? as userid, a.contenttype, a.pagetype, a.title, a.body, b.rawbody, b.config, ? as created, ? as revised FROM page a, pagemeta b WHERE a.refid=? AND a.refid=b.pageid",
|
||||||
stmt, err = ctx.Transaction.Preparex("INSERT INTO revision (refid, orgid, documentid, ownerid, pageid, userid, contenttype, pagetype, title, body, rawbody, config, created, revised) SELECT ? as refid, a.orgid, a.documentid, a.userid as ownerid, a.refid as pageid, ? as userid, a.contenttype, a.pagetype, a.title, a.body, b.rawbody, b.config, ? as created, ? as revised FROM page a, pagemeta b WHERE a.refid=? AND a.refid=b.pageid")
|
refID, userID, time.Now().UTC(), time.Now().UTC(), page.RefID)
|
||||||
|
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare page revision insert")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(refID, userID, time.Now().UTC(), time.Now().UTC(), page.RefID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute page revision insert")
|
err = errors.Wrap(err, "execute page revision insert")
|
||||||
return err
|
return err
|
||||||
|
@ -209,16 +119,9 @@ func (s Scope) Update(ctx domain.RequestContext, page page.Page, refID, userID s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update page
|
// Update page
|
||||||
var stmt2 *sqlx.NamedStmt
|
_, err = ctx.Transaction.NamedExec("UPDATE page SET documentid=:documentid, level=:level, title=:title, body=:body, revisions=:revisions, sequence=:sequence, revised=:revised WHERE orgid=:orgid AND refid=:refid",
|
||||||
stmt2, err = ctx.Transaction.PrepareNamed("UPDATE page SET documentid=:documentid, level=:level, title=:title, body=:body, revisions=:revisions, sequence=:sequence, revised=:revised WHERE orgid=:orgid AND refid=:refid")
|
&page)
|
||||||
defer streamutil.Close(stmt2)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare page insert")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt2.Exec(&page)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute page insert")
|
err = errors.Wrap(err, "execute page insert")
|
||||||
return
|
return
|
||||||
|
@ -226,18 +129,10 @@ func (s Scope) Update(ctx domain.RequestContext, page page.Page, refID, userID s
|
||||||
|
|
||||||
// Update revisions counter
|
// Update revisions counter
|
||||||
if !skipRevision {
|
if !skipRevision {
|
||||||
stmt3, err := ctx.Transaction.Preparex("UPDATE page SET revisions=revisions+1 WHERE orgid=? AND refid=?")
|
_, err = ctx.Transaction.Exec("UPDATE page SET revisions=revisions+1 WHERE orgid=? AND refid=?", ctx.OrgID, page.RefID)
|
||||||
defer streamutil.Close(stmt3)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare page revision counter")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt3.Exec(ctx.OrgID, page.RefID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute page revision counter")
|
err = errors.Wrap(err, "execute page revision counter")
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,19 +147,11 @@ func (s Scope) UpdateMeta(ctx domain.RequestContext, meta page.Meta, updateUserI
|
||||||
meta.UserID = ctx.UserID
|
meta.UserID = ctx.UserID
|
||||||
}
|
}
|
||||||
|
|
||||||
var stmt *sqlx.NamedStmt
|
_, err = ctx.Transaction.NamedExec("UPDATE pagemeta SET userid=:userid, documentid=:documentid, rawbody=:rawbody, config=:config, externalsource=:externalsource, revised=:revised WHERE orgid=:orgid AND pageid=:pageid",
|
||||||
stmt, err = ctx.Transaction.PrepareNamed("UPDATE pagemeta SET userid=:userid, documentid=:documentid, rawbody=:rawbody, config=:config, externalsource=:externalsource, revised=:revised WHERE orgid=:orgid AND pageid=:pageid")
|
&meta)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare page meta update")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(&meta)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute page meta update")
|
err = errors.Wrap(err, "execute page meta update")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -273,18 +160,10 @@ func (s Scope) UpdateMeta(ctx domain.RequestContext, meta page.Meta, updateUserI
|
||||||
// UpdateSequence changes the presentation sequence of the pageID page in the document.
|
// UpdateSequence changes the presentation sequence of the pageID page in the document.
|
||||||
// It then propagates that change into the search table and audits that it has occurred.
|
// It then propagates that change into the search table and audits that it has occurred.
|
||||||
func (s Scope) UpdateSequence(ctx domain.RequestContext, documentID, pageID string, sequence float64) (err error) {
|
func (s Scope) UpdateSequence(ctx domain.RequestContext, documentID, pageID string, sequence float64) (err error) {
|
||||||
stmt, err := ctx.Transaction.Preparex("UPDATE page SET sequence=? WHERE orgid=? AND refid=?")
|
_, err = ctx.Transaction.Exec("UPDATE page SET sequence=? WHERE orgid=? AND refid=?", sequence, ctx.OrgID, pageID)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare page sequence update")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(sequence, ctx.OrgID, pageID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute page sequence update")
|
err = errors.Wrap(err, "execute page sequence update")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -293,18 +172,10 @@ func (s Scope) UpdateSequence(ctx domain.RequestContext, documentID, pageID stri
|
||||||
// UpdateLevel changes the heading level of the pageID page in the document.
|
// UpdateLevel changes the heading level of the pageID page in the document.
|
||||||
// It then propagates that change into the search table and audits that it has occurred.
|
// It then propagates that change into the search table and audits that it has occurred.
|
||||||
func (s Scope) UpdateLevel(ctx domain.RequestContext, documentID, pageID string, level int) (err error) {
|
func (s Scope) UpdateLevel(ctx domain.RequestContext, documentID, pageID string, level int) (err error) {
|
||||||
stmt, err := ctx.Transaction.Preparex("UPDATE page SET level=? WHERE orgid=? AND refid=?")
|
_, err = ctx.Transaction.Exec("UPDATE page SET level=? WHERE orgid=? AND refid=?", level, ctx.OrgID, pageID)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare page level update")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(level, ctx.OrgID, pageID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute page level update")
|
err = errors.Wrap(err, "execute page level update")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -325,18 +196,11 @@ func (s Scope) Delete(ctx domain.RequestContext, documentID, pageID string) (row
|
||||||
|
|
||||||
// GetPageMeta returns the meta information associated with the page.
|
// GetPageMeta returns the meta information associated with the page.
|
||||||
func (s Scope) GetPageMeta(ctx domain.RequestContext, pageID string) (meta page.Meta, err error) {
|
func (s Scope) GetPageMeta(ctx domain.RequestContext, pageID string) (meta page.Meta, err error) {
|
||||||
stmt, err := s.Runtime.Db.Preparex("SELECT id, pageid, orgid, userid, documentid, rawbody, coalesce(config,JSON_UNQUOTE('{}')) as config, externalsource, created, revised FROM pagemeta WHERE orgid=? AND pageid=?")
|
err = s.Runtime.Db.Get(&meta, "SELECT id, pageid, orgid, userid, documentid, rawbody, coalesce(config,JSON_UNQUOTE('{}')) as config, externalsource, created, revised FROM pagemeta WHERE orgid=? AND pageid=?",
|
||||||
defer streamutil.Close(stmt)
|
ctx.OrgID, pageID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
err = errors.Wrap(err, "prepare get page meta")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&meta, ctx.OrgID, pageID)
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "execute get page meta")
|
err = errors.Wrap(err, "execute get page meta")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -353,7 +217,6 @@ func (s Scope) GetDocumentPageMeta(ctx domain.RequestContext, documentID string,
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "get document page meta")
|
err = errors.Wrap(err, "get document page meta")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -365,18 +228,11 @@ func (s Scope) GetDocumentPageMeta(ctx domain.RequestContext, documentID string,
|
||||||
|
|
||||||
// GetPageRevision returns the revisionID page revision record.
|
// GetPageRevision returns the revisionID page revision record.
|
||||||
func (s Scope) GetPageRevision(ctx domain.RequestContext, revisionID string) (revision page.Revision, err error) {
|
func (s Scope) GetPageRevision(ctx domain.RequestContext, revisionID string) (revision page.Revision, err error) {
|
||||||
stmt, err := s.Runtime.Db.Preparex("SELECT id, refid, orgid, documentid, ownerid, pageid, userid, contenttype, pagetype, title, body, coalesce(rawbody, '') as rawbody, coalesce(config,JSON_UNQUOTE('{}')) as config, created, revised FROM revision WHERE orgid=? and refid=?")
|
err = s.Runtime.Db.Get(&revision, "SELECT id, refid, orgid, documentid, ownerid, pageid, userid, contenttype, pagetype, title, body, coalesce(rawbody, '') as rawbody, coalesce(config,JSON_UNQUOTE('{}')) as config, created, revised FROM revision WHERE orgid=? and refid=?",
|
||||||
defer streamutil.Close(stmt)
|
ctx.OrgID, revisionID)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare get page revisions")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&revision, ctx.OrgID, revisionID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute get page revisions")
|
err = errors.Wrap(err, "execute get page revisions")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -389,7 +245,6 @@ func (s Scope) GetPageRevisions(ctx domain.RequestContext, pageID string) (revis
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "get page revisions")
|
err = errors.Wrap(err, "get page revisions")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -400,22 +255,21 @@ func (s Scope) GetPageRevisions(ctx domain.RequestContext, pageID string) (revis
|
||||||
func (s Scope) GetDocumentRevisions(ctx domain.RequestContext, documentID string) (revisions []page.Revision, err error) {
|
func (s Scope) GetDocumentRevisions(ctx domain.RequestContext, documentID string) (revisions []page.Revision, err error) {
|
||||||
err = s.Runtime.Db.Select(&revisions, "SELECT a.id, a.refid, a.orgid, a.documentid, a.ownerid, a.pageid, a.userid, a.contenttype, a.pagetype, a.title, /*a.body, a.rawbody, a.config,*/ a.created, a.revised, coalesce(b.email,'') as email, coalesce(b.firstname,'') as firstname, coalesce(b.lastname,'') as lastname, coalesce(b.initials,'') as initials, coalesce(p.revisions, 0) as revisions FROM revision a LEFT JOIN user b ON a.userid=b.refid LEFT JOIN page p ON a.pageid=p.refid WHERE a.orgid=? AND a.documentid=? AND a.pagetype='section' ORDER BY a.id DESC", ctx.OrgID, documentID)
|
err = s.Runtime.Db.Select(&revisions, "SELECT a.id, a.refid, a.orgid, a.documentid, a.ownerid, a.pageid, a.userid, a.contenttype, a.pagetype, a.title, /*a.body, a.rawbody, a.config,*/ a.created, a.revised, coalesce(b.email,'') as email, coalesce(b.firstname,'') as firstname, coalesce(b.lastname,'') as lastname, coalesce(b.initials,'') as initials, coalesce(p.revisions, 0) as revisions FROM revision a LEFT JOIN user b ON a.userid=b.refid LEFT JOIN page p ON a.pageid=p.refid WHERE a.orgid=? AND a.documentid=? AND a.pagetype='section' ORDER BY a.id DESC", ctx.OrgID, documentID)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "get document revisions")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(revisions) == 0 {
|
if len(revisions) == 0 {
|
||||||
revisions = []page.Revision{}
|
revisions = []page.Revision{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil && err != sql.ErrNoRows {
|
||||||
|
err = errors.Wrap(err, "get document revisions")
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletePageRevisions deletes all of the page revision records for a given pageID.
|
// DeletePageRevisions deletes all of the page revision records for a given pageID.
|
||||||
func (s Scope) DeletePageRevisions(ctx domain.RequestContext, pageID string) (rows int64, err error) {
|
func (s Scope) DeletePageRevisions(ctx domain.RequestContext, pageID string) (rows int64, err error) {
|
||||||
b := mysql.BaseQuery{}
|
b := mysql.BaseQuery{}
|
||||||
rows, err =b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM revision WHERE orgid='%s' AND pageid='%s'", ctx.OrgID, pageID))
|
rows, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM revision WHERE orgid='%s' AND pageid='%s'", ctx.OrgID, pageID))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/streamutil"
|
|
||||||
"github.com/documize/community/domain"
|
"github.com/documize/community/domain"
|
||||||
"github.com/documize/community/domain/store/mysql"
|
"github.com/documize/community/domain/store/mysql"
|
||||||
"github.com/documize/community/model/permission"
|
"github.com/documize/community/model/permission"
|
||||||
|
@ -35,18 +34,11 @@ type Scope struct {
|
||||||
func (s Scope) AddPermission(ctx domain.RequestContext, r permission.Permission) (err error) {
|
func (s Scope) AddPermission(ctx domain.RequestContext, r permission.Permission) (err error) {
|
||||||
r.Created = time.Now().UTC()
|
r.Created = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("INSERT INTO permission (orgid, who, whoid, action, scope, location, refid, created) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")
|
_, err = ctx.Transaction.Exec("INSERT INTO permission (orgid, who, whoid, action, scope, location, refid, created) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
defer streamutil.Close(stmt)
|
r.OrgID, r.Who, r.WhoID, string(r.Action), r.Scope, r.Location, r.RefID, r.Created)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "unable to prepare insert permission")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(r.OrgID, r.Who, r.WhoID, string(r.Action), r.Scope, r.Location, r.RefID, r.Created)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "unable to execute insert permission")
|
err = errors.Wrap(err, "unable to execute insert permission")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -79,7 +71,6 @@ func (s Scope) GetUserSpacePermissions(ctx domain.RequestContext, spaceID string
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute select user permissions %s", ctx.UserID))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute select user permissions %s", ctx.UserID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -101,7 +92,6 @@ func (s Scope) GetSpacePermissions(ctx domain.RequestContext, spaceID string) (r
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute select space permissions %s", ctx.UserID))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute select space permissions %s", ctx.UserID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -173,7 +163,6 @@ func (s Scope) GetCategoryPermissions(ctx domain.RequestContext, catID string) (
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute select category permissions %s", catID))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute select category permissions %s", catID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -198,7 +187,6 @@ func (s Scope) GetCategoryUsers(ctx domain.RequestContext, catID string) (u []us
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute select users for category %s", catID))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute select users for category %s", catID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -16,11 +16,9 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/streamutil"
|
|
||||||
"github.com/documize/community/domain"
|
"github.com/documize/community/domain"
|
||||||
"github.com/documize/community/domain/store/mysql"
|
"github.com/documize/community/domain/store/mysql"
|
||||||
"github.com/documize/community/model/pin"
|
"github.com/documize/community/model/pin"
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -43,18 +41,11 @@ func (s Scope) Add(ctx domain.RequestContext, pin pin.Pin) (err error) {
|
||||||
pin.Revised = time.Now().UTC()
|
pin.Revised = time.Now().UTC()
|
||||||
pin.Sequence = maxSeq + 1
|
pin.Sequence = maxSeq + 1
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("INSERT INTO pin (refid, orgid, userid, labelid, documentid, pin, sequence, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
_, err = ctx.Transaction.Exec("INSERT INTO pin (refid, orgid, userid, labelid, documentid, pin, sequence, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
defer streamutil.Close(stmt)
|
pin.RefID, pin.OrgID, pin.UserID, pin.FolderID, pin.DocumentID, pin.Pin, pin.Sequence, pin.Created, pin.Revised)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare pin insert")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(pin.RefID, pin.OrgID, pin.UserID, pin.FolderID, pin.DocumentID, pin.Pin, pin.Sequence, pin.Created, pin.Revised)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute pin insert")
|
err = errors.Wrap(err, "execute pin insert")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -62,18 +53,11 @@ func (s Scope) Add(ctx domain.RequestContext, pin pin.Pin) (err error) {
|
||||||
|
|
||||||
// GetPin returns requested pinned item.
|
// GetPin returns requested pinned item.
|
||||||
func (s Scope) GetPin(ctx domain.RequestContext, id string) (pin pin.Pin, err error) {
|
func (s Scope) GetPin(ctx domain.RequestContext, id string) (pin pin.Pin, err error) {
|
||||||
stmt, err := s.Runtime.Db.Preparex("SELECT id, refid, orgid, userid, labelid as folderid, documentid, pin, sequence, created, revised FROM pin WHERE orgid=? AND refid=?")
|
err = s.Runtime.Db.Get(&pin, "SELECT id, refid, orgid, userid, labelid as folderid, documentid, pin, sequence, created, revised FROM pin WHERE orgid=? AND refid=?",
|
||||||
defer streamutil.Close(stmt)
|
ctx.OrgID, id)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("prepare select for pin %s", id))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&pin, ctx.OrgID, id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute select for pin %s", id))
|
err = errors.Wrap(err, fmt.Sprintf("execute select for pin %s", id))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -85,7 +69,6 @@ func (s Scope) GetUserPins(ctx domain.RequestContext, userID string) (pins []pin
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute select pins for org %s and user %s", ctx.OrgID, userID))
|
err = errors.Wrap(err, fmt.Sprintf("execute select pins for org %s and user %s", ctx.OrgID, userID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -95,19 +78,11 @@ func (s Scope) GetUserPins(ctx domain.RequestContext, userID string) (pins []pin
|
||||||
func (s Scope) UpdatePin(ctx domain.RequestContext, pin pin.Pin) (err error) {
|
func (s Scope) UpdatePin(ctx domain.RequestContext, pin pin.Pin) (err error) {
|
||||||
pin.Revised = time.Now().UTC()
|
pin.Revised = time.Now().UTC()
|
||||||
|
|
||||||
var stmt *sqlx.NamedStmt
|
_, err = ctx.Transaction.NamedExec("UPDATE pin SET labelid=:folderid, documentid=:documentid, pin=:pin, sequence=:sequence, revised=:revised WHERE orgid=:orgid AND refid=:refid",
|
||||||
stmt, err = ctx.Transaction.PrepareNamed("UPDATE pin SET labelid=:folderid, documentid=:documentid, pin=:pin, sequence=:sequence, revised=:revised WHERE orgid=:orgid AND refid=:refid")
|
&pin)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("prepare pin update %s", pin.RefID))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(&pin)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute pin update %s", pin.RefID))
|
err = errors.Wrap(err, fmt.Sprintf("execute pin update %s", pin.RefID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -115,18 +90,11 @@ func (s Scope) UpdatePin(ctx domain.RequestContext, pin pin.Pin) (err error) {
|
||||||
|
|
||||||
// UpdatePinSequence updates existing pinned item sequence number
|
// UpdatePinSequence updates existing pinned item sequence number
|
||||||
func (s Scope) UpdatePinSequence(ctx domain.RequestContext, pinID string, sequence int) (err error) {
|
func (s Scope) UpdatePinSequence(ctx domain.RequestContext, pinID string, sequence int) (err error) {
|
||||||
stmt, err := ctx.Transaction.Preparex("UPDATE pin SET sequence=?, revised=? WHERE orgid=? AND userid=? AND refid=?")
|
_, err = ctx.Transaction.Exec("UPDATE pin SET sequence=?, revised=? WHERE orgid=? AND userid=? AND refid=?",
|
||||||
defer streamutil.Close(stmt)
|
sequence, time.Now().UTC(), ctx.OrgID, ctx.UserID, pinID)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("prepare pin sequence update %s", pinID))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(sequence, time.Now().UTC(), ctx.OrgID, ctx.UserID, pinID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute pin sequence update %s", pinID))
|
err = errors.Wrap(err, fmt.Sprintf("execute pin sequence update %s", pinID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -37,33 +37,18 @@ type Scope struct {
|
||||||
// searchable items. Any existing document entries are removed.
|
// searchable items. Any existing document entries are removed.
|
||||||
func (s Scope) IndexDocument(ctx domain.RequestContext, doc doc.Document, a []attachment.Attachment) (err error) {
|
func (s Scope) IndexDocument(ctx domain.RequestContext, doc doc.Document, a []attachment.Attachment) (err error) {
|
||||||
// remove previous search entries
|
// remove previous search entries
|
||||||
var stmt1 *sqlx.Stmt
|
_, err = ctx.Transaction.Exec("DELETE FROM search WHERE orgid=? AND documentid=? AND (itemtype='doc' OR itemtype='file' OR itemtype='tag')",
|
||||||
stmt1, err = ctx.Transaction.Preparex("DELETE FROM search WHERE orgid=? AND documentid=? AND (itemtype='doc' OR itemtype='file' OR itemtype='tag')")
|
ctx.OrgID, doc.RefID)
|
||||||
defer streamutil.Close(stmt1)
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare delete document index entries")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt1.Exec(ctx.OrgID, doc.RefID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute delete document index entries")
|
err = errors.Wrap(err, "execute delete document index entries")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert doc title
|
// insert doc title
|
||||||
var stmt2 *sqlx.Stmt
|
_, err = ctx.Transaction.Exec("INSERT INTO search (orgid, documentid, itemid, itemtype, content) VALUES (?, ?, ?, ?, ?)",
|
||||||
stmt2, err = ctx.Transaction.Preparex("INSERT INTO search (orgid, documentid, itemid, itemtype, content) VALUES (?, ?, ?, ?, ?)")
|
ctx.OrgID, doc.RefID, "", "doc", doc.Title)
|
||||||
defer streamutil.Close(stmt2)
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare insert document title entry")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt2.Exec(ctx.OrgID, doc.RefID, "", "doc", doc.Title)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute insert document title entry")
|
err = errors.Wrap(err, "execute insert document title entry")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert doc tags
|
// insert doc tags
|
||||||
|
@ -73,15 +58,9 @@ func (s Scope) IndexDocument(ctx domain.RequestContext, doc doc.Document, a []at
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var stmt3 *sqlx.Stmt
|
_, err = ctx.Transaction.Exec("INSERT INTO search (orgid, documentid, itemid, itemtype, content) VALUES (?, ?, ?, ?, ?)",
|
||||||
stmt3, err = ctx.Transaction.Preparex("INSERT INTO search (orgid, documentid, itemid, itemtype, content) VALUES (?, ?, ?, ?, ?)")
|
ctx.OrgID, doc.RefID, "", "tag", t)
|
||||||
defer streamutil.Close(stmt3)
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare insert document tag entry")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt3.Exec(ctx.OrgID, doc.RefID, "", "tag", t)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute insert document tag entry")
|
err = errors.Wrap(err, "execute insert document tag entry")
|
||||||
return
|
return
|
||||||
|
@ -89,18 +68,11 @@ func (s Scope) IndexDocument(ctx domain.RequestContext, doc doc.Document, a []at
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range a {
|
for _, file := range a {
|
||||||
var stmt4 *sqlx.Stmt
|
_, err = ctx.Transaction.Exec("INSERT INTO search (orgid, documentid, itemid, itemtype, content) VALUES (?, ?, ?, ?, ?)",
|
||||||
stmt4, err = ctx.Transaction.Preparex("INSERT INTO search (orgid, documentid, itemid, itemtype, content) VALUES (?, ?, ?, ?, ?)")
|
ctx.OrgID, doc.RefID, file.RefID, "file", file.Filename)
|
||||||
defer streamutil.Close(stmt4)
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare insert document file entry")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt4.Exec(ctx.OrgID, doc.RefID, file.RefID, "file", file.Filename)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute insert document file entry")
|
err = errors.Wrap(err, "execute insert document file entry")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,19 +81,10 @@ func (s Scope) IndexDocument(ctx domain.RequestContext, doc doc.Document, a []at
|
||||||
|
|
||||||
// DeleteDocument removes all search entries for document.
|
// DeleteDocument removes all search entries for document.
|
||||||
func (s Scope) DeleteDocument(ctx domain.RequestContext, ID string) (err error) {
|
func (s Scope) DeleteDocument(ctx domain.RequestContext, ID string) (err error) {
|
||||||
// remove all search entries
|
_, err = ctx.Transaction.Exec("DELETE FROM search WHERE orgid=? AND documentid=?", ctx.OrgID, ID)
|
||||||
var stmt1 *sqlx.Stmt
|
|
||||||
stmt1, err = ctx.Transaction.Preparex("DELETE FROM search WHERE orgid=? AND documentid=?")
|
|
||||||
defer streamutil.Close(stmt1)
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare delete document entries")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt1.Exec(ctx.OrgID, ID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute delete document entries")
|
err = errors.Wrap(err, "execute delete document entries")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -131,27 +94,11 @@ func (s Scope) DeleteDocument(ctx domain.RequestContext, ID string) (err error)
|
||||||
// Any existing document entries are removed.
|
// Any existing document entries are removed.
|
||||||
func (s Scope) IndexContent(ctx domain.RequestContext, p page.Page) (err error) {
|
func (s Scope) IndexContent(ctx domain.RequestContext, p page.Page) (err error) {
|
||||||
// remove previous search entries
|
// remove previous search entries
|
||||||
var stmt1 *sqlx.Stmt
|
_, err = ctx.Transaction.Exec("DELETE FROM search WHERE orgid=? AND documentid=? AND itemid=? AND itemtype='page'",
|
||||||
stmt1, err = ctx.Transaction.Preparex("DELETE FROM search WHERE orgid=? AND documentid=? AND itemid=? AND itemtype='page'")
|
ctx.OrgID, p.DocumentID, p.RefID)
|
||||||
defer streamutil.Close(stmt1)
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare delete document content entry")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt1.Exec(ctx.OrgID, p.DocumentID, p.RefID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute delete document content entry")
|
err = errors.Wrap(err, "execute delete document content entry")
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// insert doc title
|
|
||||||
var stmt2 *sqlx.Stmt
|
|
||||||
stmt2, err = ctx.Transaction.Preparex("INSERT INTO search (orgid, documentid, itemid, itemtype, content) VALUES (?, ?, ?, ?, ?)")
|
|
||||||
defer streamutil.Close(stmt2)
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare insert document content entry")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare content
|
// prepare content
|
||||||
|
@ -162,10 +109,10 @@ func (s Scope) IndexContent(ctx domain.RequestContext, p page.Page) (err error)
|
||||||
}
|
}
|
||||||
content = strings.TrimSpace(content)
|
content = strings.TrimSpace(content)
|
||||||
|
|
||||||
_, err = stmt2.Exec(ctx.OrgID, p.DocumentID, p.RefID, "page", content)
|
_, err = ctx.Transaction.Exec("INSERT INTO search (orgid, documentid, itemid, itemtype, content) VALUES (?, ?, ?, ?, ?)",
|
||||||
|
ctx.OrgID, p.DocumentID, p.RefID, "page", content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute insert document content entry")
|
err = errors.Wrap(err, "execute insert document content entry")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -295,7 +242,6 @@ func (s Scope) matchFullText(ctx domain.RequestContext, keywords, itemType strin
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "search document "+itemType)
|
err = errors.Wrap(err, "search document "+itemType)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -353,7 +299,6 @@ func (s Scope) matchLike(ctx domain.RequestContext, keywords, itemType string) (
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "search document "+itemType)
|
err = errors.Wrap(err, "search document "+itemType)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -16,7 +16,6 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/streamutil"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,18 +29,13 @@ func (s Scope) Get(area, path string) (value string, err error) {
|
||||||
if path != "" {
|
if path != "" {
|
||||||
path = "." + path
|
path = "." + path
|
||||||
}
|
}
|
||||||
|
|
||||||
sql := "SELECT JSON_EXTRACT(`config`,'$" + path + "') FROM `config` WHERE `key` = '" + area + "';"
|
sql := "SELECT JSON_EXTRACT(`config`,'$" + path + "') FROM `config` WHERE `key` = '" + area + "';"
|
||||||
|
|
||||||
stmt, err := s.Runtime.Db.Preparex(sql)
|
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
var item = make([]uint8, 0)
|
var item = make([]uint8, 0)
|
||||||
|
|
||||||
err = stmt.Get(&item)
|
err = s.Runtime.Db.Get(&item, sql)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -55,7 +49,7 @@ func (s Scope) Get(area, path string) (value string, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set writes a configuration JSON element to the config table.
|
// Set writes a configuration JSON element to the config table.
|
||||||
func (s Scope) Set(area, json string) error {
|
func (s Scope) Set(area, json string) (err error) {
|
||||||
if area == "" {
|
if area == "" {
|
||||||
return errors.New("no area")
|
return errors.New("no area")
|
||||||
}
|
}
|
||||||
|
@ -64,15 +58,8 @@ func (s Scope) Set(area, json string) error {
|
||||||
"VALUES ('" + area + "','" + json +
|
"VALUES ('" + area + "','" + json +
|
||||||
"') ON DUPLICATE KEY UPDATE `config`='" + json + "';"
|
"') ON DUPLICATE KEY UPDATE `config`='" + json + "';"
|
||||||
|
|
||||||
stmt, err := s.Runtime.Db.Preparex(sql)
|
_, err = s.Runtime.Db.Exec(sql)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "failed to save global config value")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec()
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,16 +73,10 @@ func (s Scope) GetUser(orgID, userID, area, path string) (value string, err erro
|
||||||
qry := "SELECT JSON_EXTRACT(`config`,'$" + path + "') FROM `userconfig` WHERE `key` = '" + area +
|
qry := "SELECT JSON_EXTRACT(`config`,'$" + path + "') FROM `userconfig` WHERE `key` = '" + area +
|
||||||
"' AND `orgid` = '" + orgID + "' AND `userid` = '" + userID + "';"
|
"' AND `orgid` = '" + orgID + "' AND `userid` = '" + userID + "';"
|
||||||
|
|
||||||
stmt, err := s.Runtime.Db.Preparex(qry)
|
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
var item = make([]uint8, 0)
|
var item = make([]uint8, 0)
|
||||||
|
|
||||||
err = stmt.Get(&item)
|
err = s.Runtime.Db.Get(&item, qry)
|
||||||
|
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -109,7 +90,7 @@ func (s Scope) GetUser(orgID, userID, area, path string) (value string, err erro
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUser writes a configuration JSON element to the userconfig table for the current user.
|
// SetUser writes a configuration JSON element to the userconfig table for the current user.
|
||||||
func (s Scope) SetUser(orgID, userID, area, json string) error {
|
func (s Scope) SetUser(orgID, userID, area, json string) (err error) {
|
||||||
if area == "" {
|
if area == "" {
|
||||||
return errors.New("no area")
|
return errors.New("no area")
|
||||||
}
|
}
|
||||||
|
@ -118,14 +99,7 @@ func (s Scope) SetUser(orgID, userID, area, json string) error {
|
||||||
"VALUES ('" + orgID + "','" + userID + "','" + area + "','" + json +
|
"VALUES ('" + orgID + "','" + userID + "','" + area + "','" + json +
|
||||||
"') ON DUPLICATE KEY UPDATE `config`='" + json + "';"
|
"') ON DUPLICATE KEY UPDATE `config`='" + json + "';"
|
||||||
|
|
||||||
stmt, err := s.Runtime.Db.Preparex(sql)
|
_, err = s.Runtime.Db.Exec(sql)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec()
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/streamutil"
|
|
||||||
"github.com/documize/community/domain"
|
"github.com/documize/community/domain"
|
||||||
"github.com/documize/community/domain/store/mysql"
|
"github.com/documize/community/domain/store/mysql"
|
||||||
"github.com/documize/community/model/space"
|
"github.com/documize/community/model/space"
|
||||||
|
@ -35,18 +34,11 @@ func (s Scope) Add(ctx domain.RequestContext, sp space.Space) (err error) {
|
||||||
sp.Created = time.Now().UTC()
|
sp.Created = time.Now().UTC()
|
||||||
sp.Revised = time.Now().UTC()
|
sp.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("INSERT INTO label (refid, label, orgid, userid, type, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?)")
|
_, err = ctx.Transaction.Exec("INSERT INTO label (refid, label, orgid, userid, type, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||||
defer streamutil.Close(stmt)
|
sp.RefID, sp.Name, sp.OrgID, sp.UserID, sp.Type, sp.Created, sp.Revised)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "unable to prepare insert for label")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(sp.RefID, sp.Name, sp.OrgID, sp.UserID, sp.Type, sp.Created, sp.Revised)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "unable to execute insert for label")
|
err = errors.Wrap(err, "unable to execute insert for label")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -54,18 +46,11 @@ func (s Scope) Add(ctx domain.RequestContext, sp space.Space) (err error) {
|
||||||
|
|
||||||
// Get returns a space from the store.
|
// Get returns a space from the store.
|
||||||
func (s Scope) Get(ctx domain.RequestContext, id string) (sp space.Space, err error) {
|
func (s Scope) Get(ctx domain.RequestContext, id string) (sp space.Space, err error) {
|
||||||
stmt, err := s.Runtime.Db.Preparex("SELECT id,refid,label as name,orgid,userid,type,created,revised FROM label WHERE orgid=? and refid=?")
|
err = s.Runtime.Db.Get(&sp, "SELECT id,refid,label as name,orgid,userid,type,created,revised FROM label WHERE orgid=? and refid=?",
|
||||||
defer streamutil.Close(stmt)
|
ctx.OrgID, id)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to prepare select for label %s", id))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&sp, ctx.OrgID, id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute select for label %s", id))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute select for label %s", id))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -79,7 +64,6 @@ func (s Scope) PublicSpaces(ctx domain.RequestContext, orgID string) (sp []space
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("Unable to execute GetPublicFolders for org %s", orgID))
|
err = errors.Wrap(err, fmt.Sprintf("Unable to execute GetPublicFolders for org %s", orgID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -108,7 +92,6 @@ func (s Scope) GetAll(ctx domain.RequestContext) (sp []space.Space, err error) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("failed space.GetAll org %s", ctx.OrgID))
|
err = errors.Wrap(err, fmt.Sprintf("failed space.GetAll org %s", ctx.OrgID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -118,18 +101,10 @@ func (s Scope) GetAll(ctx domain.RequestContext) (sp []space.Space, err error) {
|
||||||
func (s Scope) Update(ctx domain.RequestContext, sp space.Space) (err error) {
|
func (s Scope) Update(ctx domain.RequestContext, sp space.Space) (err error) {
|
||||||
sp.Revised = time.Now().UTC()
|
sp.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.PrepareNamed("UPDATE label SET label=:name, type=:type, userid=:userid, revised=:revised WHERE orgid=:orgid AND refid=:refid")
|
_, err = ctx.Transaction.NamedExec("UPDATE label SET label=:name, type=:type, userid=:userid, revised=:revised WHERE orgid=:orgid AND refid=:refid", &sp)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to prepare update for label %s", sp.RefID))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(&sp)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute update for label %s", sp.RefID))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute update for label %s", sp.RefID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -14,7 +14,6 @@ package mysql
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/documize/community/core/streamutil"
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
@ -25,15 +24,8 @@ type BaseQuery struct {
|
||||||
|
|
||||||
// Delete record.
|
// Delete record.
|
||||||
func (m *BaseQuery) Delete(tx *sqlx.Tx, table string, id string) (rows int64, err error) {
|
func (m *BaseQuery) Delete(tx *sqlx.Tx, table string, id string) (rows int64, err error) {
|
||||||
stmt, err := tx.Preparex("DELETE FROM " + table + " WHERE refid=?")
|
result, err := tx.Exec("DELETE FROM "+table+" WHERE refid=?", id)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to prepare delete of row in table %s", table))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := stmt.Exec(id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to delete row in table %s", table))
|
err = errors.Wrap(err, fmt.Sprintf("unable to delete row in table %s", table))
|
||||||
return
|
return
|
||||||
|
@ -46,15 +38,8 @@ func (m *BaseQuery) Delete(tx *sqlx.Tx, table string, id string) (rows int64, er
|
||||||
|
|
||||||
// DeleteConstrained record constrained to Organization using refid.
|
// DeleteConstrained record constrained to Organization using refid.
|
||||||
func (m *BaseQuery) DeleteConstrained(tx *sqlx.Tx, table string, orgID, id string) (rows int64, err error) {
|
func (m *BaseQuery) DeleteConstrained(tx *sqlx.Tx, table string, orgID, id string) (rows int64, err error) {
|
||||||
stmt, err := tx.Preparex("DELETE FROM " + table + " WHERE orgid=? AND refid=?")
|
result, err := tx.Exec("DELETE FROM "+table+" WHERE orgid=? AND refid=?", orgID, id)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to prepare constrained delete of row in table %s", table))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := stmt.Exec(orgID, id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to delete row in table %s", table))
|
err = errors.Wrap(err, fmt.Sprintf("unable to delete row in table %s", table))
|
||||||
return
|
return
|
||||||
|
@ -67,15 +52,8 @@ func (m *BaseQuery) DeleteConstrained(tx *sqlx.Tx, table string, orgID, id strin
|
||||||
|
|
||||||
// DeleteConstrainedWithID record constrained to Organization using non refid.
|
// DeleteConstrainedWithID record constrained to Organization using non refid.
|
||||||
func (m *BaseQuery) DeleteConstrainedWithID(tx *sqlx.Tx, table string, orgID, id string) (rows int64, err error) {
|
func (m *BaseQuery) DeleteConstrainedWithID(tx *sqlx.Tx, table string, orgID, id string) (rows int64, err error) {
|
||||||
stmt, err := tx.Preparex("DELETE FROM " + table + " WHERE orgid=? AND id=?")
|
result, err := tx.Exec("DELETE FROM "+table+" WHERE orgid=? AND id=?", orgID, id)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to prepare ConstrainedWithID delete of row in table %s", table))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := stmt.Exec(orgID, id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to delete row in table %s", table))
|
err = errors.Wrap(err, fmt.Sprintf("unable to delete row in table %s", table))
|
||||||
return
|
return
|
||||||
|
@ -89,6 +67,7 @@ func (m *BaseQuery) DeleteConstrainedWithID(tx *sqlx.Tx, table string, orgID, id
|
||||||
// DeleteWhere free form query.
|
// DeleteWhere free form query.
|
||||||
func (m *BaseQuery) DeleteWhere(tx *sqlx.Tx, statement string) (rows int64, err error) {
|
func (m *BaseQuery) DeleteWhere(tx *sqlx.Tx, statement string) (rows int64, err error) {
|
||||||
result, err := tx.Exec(statement)
|
result, err := tx.Exec(statement)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to delete rows: %s", statement))
|
err = errors.Wrap(err, fmt.Sprintf("unable to delete rows: %s", statement))
|
||||||
return
|
return
|
||||||
|
|
|
@ -242,7 +242,6 @@ type PageStorer interface {
|
||||||
Add(ctx RequestContext, model page.NewPage) (err error)
|
Add(ctx RequestContext, model page.NewPage) (err error)
|
||||||
Get(ctx RequestContext, pageID string) (p page.Page, err error)
|
Get(ctx RequestContext, pageID string) (p page.Page, err error)
|
||||||
GetPages(ctx RequestContext, documentID string) (p []page.Page, err error)
|
GetPages(ctx RequestContext, documentID string) (p []page.Page, err error)
|
||||||
GetPagesWhereIn(ctx RequestContext, documentID, inPages string) (p []page.Page, err error)
|
|
||||||
GetPagesWithoutContent(ctx RequestContext, documentID string) (pages []page.Page, err error)
|
GetPagesWithoutContent(ctx RequestContext, documentID string) (pages []page.Page, err error)
|
||||||
Update(ctx RequestContext, page page.Page, refID, userID string, skipRevision bool) (err error)
|
Update(ctx RequestContext, page page.Page, refID, userID string, skipRevision bool) (err error)
|
||||||
UpdateMeta(ctx RequestContext, meta page.Meta, updateUserID bool) (err error)
|
UpdateMeta(ctx RequestContext, meta page.Meta, updateUserID bool) (err error)
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/streamutil"
|
|
||||||
"github.com/documize/community/domain"
|
"github.com/documize/community/domain"
|
||||||
"github.com/documize/community/model/user"
|
"github.com/documize/community/model/user"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -34,18 +33,11 @@ func (s Scope) Add(ctx domain.RequestContext, u user.User) (err error) {
|
||||||
u.Created = time.Now().UTC()
|
u.Created = time.Now().UTC()
|
||||||
u.Revised = time.Now().UTC()
|
u.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.Preparex("INSERT INTO user (refid, firstname, lastname, email, initials, password, salt, reset, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
_, err = ctx.Transaction.Exec("INSERT INTO user (refid, firstname, lastname, email, initials, password, salt, reset, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
defer streamutil.Close(stmt)
|
u.RefID, u.Firstname, u.Lastname, strings.ToLower(u.Email), u.Initials, u.Password, u.Salt, "", u.Created, u.Revised)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare user insert")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(u.RefID, u.Firstname, u.Lastname, strings.ToLower(u.Email), u.Initials, u.Password, u.Salt, "", u.Created, u.Revised)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute user insert")
|
err = errors.Wrap(err, "execute user insert")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -53,18 +45,10 @@ func (s Scope) Add(ctx domain.RequestContext, u user.User) (err error) {
|
||||||
|
|
||||||
// Get returns the user record for the given id.
|
// Get returns the user record for the given id.
|
||||||
func (s Scope) Get(ctx domain.RequestContext, id string) (u user.User, err error) {
|
func (s Scope) Get(ctx domain.RequestContext, id string) (u user.User, err error) {
|
||||||
stmt, err := s.Runtime.Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, created, revised FROM user WHERE refid=?")
|
err = s.Runtime.Db.Get(&u, "SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, created, revised FROM user WHERE refid=?", id)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to prepare select for user %s", id))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&u, id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute select for user %s", id))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute select for user %s", id))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -74,18 +58,11 @@ func (s Scope) Get(ctx domain.RequestContext, id string) (u user.User, err error
|
||||||
func (s Scope) GetByDomain(ctx domain.RequestContext, domain, email string) (u user.User, err error) {
|
func (s Scope) GetByDomain(ctx domain.RequestContext, domain, email string) (u user.User, err error) {
|
||||||
email = strings.TrimSpace(strings.ToLower(email))
|
email = strings.TrimSpace(strings.ToLower(email))
|
||||||
|
|
||||||
stmt, err := s.Runtime.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))=?")
|
err = s.Runtime.Db.Get(&u, "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 streamutil.Close(stmt)
|
email, domain)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("Unable to prepare GetUserByDomain %s %s", domain, email))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&u, email, domain)
|
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("Unable to execute GetUserByDomain %s %s", domain, email))
|
err = errors.Wrap(err, fmt.Sprintf("Unable to execute GetUserByDomain %s %s", domain, email))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -95,18 +72,10 @@ func (s Scope) GetByDomain(ctx domain.RequestContext, domain, email string) (u u
|
||||||
func (s Scope) GetByEmail(ctx domain.RequestContext, email string) (u user.User, err error) {
|
func (s Scope) GetByEmail(ctx domain.RequestContext, email string) (u user.User, err error) {
|
||||||
email = strings.TrimSpace(strings.ToLower(email))
|
email = strings.TrimSpace(strings.ToLower(email))
|
||||||
|
|
||||||
stmt, err := s.Runtime.Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, created, revised FROM user WHERE TRIM(LOWER(email))=?")
|
err = s.Runtime.Db.Get(&u, "SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, created, revised FROM user WHERE TRIM(LOWER(email))=?", email)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("prepare select user by email %s", email))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&u, email)
|
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute select user by email %s", email))
|
err = errors.Wrap(err, fmt.Sprintf("execute select user by email %s", email))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -114,18 +83,10 @@ func (s Scope) GetByEmail(ctx domain.RequestContext, email string) (u user.User,
|
||||||
|
|
||||||
// GetByToken returns a user record given a reset token value.
|
// GetByToken returns a user record given a reset token value.
|
||||||
func (s Scope) GetByToken(ctx domain.RequestContext, token string) (u user.User, err error) {
|
func (s Scope) GetByToken(ctx domain.RequestContext, token string) (u user.User, err error) {
|
||||||
stmt, err := s.Runtime.Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, created, revised FROM user WHERE reset=?")
|
err = s.Runtime.Db.Get(&u, "SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, created, revised FROM user WHERE reset=?", token)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("prepare user select by token %s", token))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&u, token)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute user select by token %s", token))
|
err = errors.Wrap(err, fmt.Sprintf("execute user select by token %s", token))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -135,18 +96,10 @@ func (s Scope) GetByToken(ctx domain.RequestContext, token string) (u user.User,
|
||||||
// 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 (s Scope) GetBySerial(ctx domain.RequestContext, serial string) (u user.User, err error) {
|
func (s Scope) GetBySerial(ctx domain.RequestContext, serial string) (u user.User, err error) {
|
||||||
stmt, err := s.Runtime.Db.Preparex("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, created, revised FROM user WHERE salt=?")
|
err = s.Runtime.Db.Get("SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, created, revised FROM user WHERE salt=?", serial)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("prepare user select by serial %s", serial))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = stmt.Get(&u, serial)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute user select by serial %s", serial))
|
err = errors.Wrap(err, fmt.Sprintf("execute user select by serial %s", serial))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -163,7 +116,6 @@ func (s Scope) GetActiveUsersForOrganization(ctx domain.RequestContext) (u []use
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("get active users by org %s", ctx.OrgID))
|
err = errors.Wrap(err, fmt.Sprintf("get active users by org %s", ctx.OrgID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -179,7 +131,6 @@ func (s Scope) GetUsersForOrganization(ctx domain.RequestContext) (u []user.User
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf(" get users for org %s", ctx.OrgID))
|
err = errors.Wrap(err, fmt.Sprintf(" get users for org %s", ctx.OrgID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -200,7 +151,6 @@ func (s Scope) GetSpaceUsers(ctx domain.RequestContext, spaceID string) (u []use
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("get space users for org %s", ctx.OrgID))
|
err = errors.Wrap(err, fmt.Sprintf("get space users for org %s", ctx.OrgID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -239,7 +189,6 @@ func (s Scope) GetVisibleUsers(ctx domain.RequestContext) (u []user.User, err er
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("get visible users for org %s user %s", ctx.OrgID, ctx.UserID))
|
err = errors.Wrap(err, fmt.Sprintf("get visible users for org %s user %s", ctx.OrgID, ctx.UserID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -250,19 +199,11 @@ func (s Scope) UpdateUser(ctx domain.RequestContext, u user.User) (err error) {
|
||||||
u.Revised = time.Now().UTC()
|
u.Revised = time.Now().UTC()
|
||||||
u.Email = strings.ToLower(u.Email)
|
u.Email = strings.ToLower(u.Email)
|
||||||
|
|
||||||
stmt, err := ctx.Transaction.PrepareNamed(
|
_, err = ctx.Transaction.NamedExec(
|
||||||
"UPDATE user SET firstname=:firstname, lastname=:lastname, email=:email, revised=:revised, initials=:initials WHERE refid=:refid")
|
"UPDATE user SET firstname=:firstname, lastname=:lastname, email=:email, revised=:revised, initials=:initials WHERE refid=:refid", &u)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("prepare user update %s", u.RefID))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(&u)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute user update %s", u.RefID))
|
err = errors.Wrap(err, fmt.Sprintf("execute user update %s", u.RefID))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -270,18 +211,11 @@ func (s Scope) UpdateUser(ctx domain.RequestContext, u user.User) (err error) {
|
||||||
|
|
||||||
// UpdateUserPassword updates a user record with new password and salt values.
|
// UpdateUserPassword updates a user record with new password and salt values.
|
||||||
func (s Scope) UpdateUserPassword(ctx domain.RequestContext, userID, salt, password string) (err error) {
|
func (s Scope) UpdateUserPassword(ctx domain.RequestContext, userID, salt, password string) (err error) {
|
||||||
stmt, err := ctx.Transaction.Preparex("UPDATE user SET salt=?, password=?, reset='' WHERE refid=?")
|
_, err = ctx.Transaction.Exec("UPDATE user SET salt=?, password=?, reset='' WHERE refid=?",
|
||||||
defer streamutil.Close(stmt)
|
salt, password, userID)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare user update")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(salt, password, userID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute user update")
|
err = errors.Wrap(err, "execute user update")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -289,19 +223,10 @@ func (s Scope) UpdateUserPassword(ctx domain.RequestContext, userID, salt, passw
|
||||||
|
|
||||||
// DeactiveUser deletes the account record for the given userID and persister.Context.OrgID.
|
// DeactiveUser deletes the account record for the given userID and persister.Context.OrgID.
|
||||||
func (s Scope) DeactiveUser(ctx domain.RequestContext, userID string) (err error) {
|
func (s Scope) DeactiveUser(ctx domain.RequestContext, userID string) (err error) {
|
||||||
stmt, err := ctx.Transaction.Preparex("DELETE FROM account WHERE userid=? and orgid=?")
|
_, err = ctx.Transaction.Exec("DELETE FROM account WHERE userid=? and orgid=?", userID, ctx.OrgID)
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare user deactivation")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(userID, ctx.OrgID)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute user deactivation")
|
err = errors.Wrap(err, "execute user deactivation")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -309,18 +234,10 @@ func (s Scope) DeactiveUser(ctx domain.RequestContext, userID string) (err error
|
||||||
|
|
||||||
// ForgotUserPassword sets the password to '' and the reset field to token, for a user identified by email.
|
// ForgotUserPassword sets the password to '' and the reset field to token, for a user identified by email.
|
||||||
func (s Scope) ForgotUserPassword(ctx domain.RequestContext, email, token string) (err error) {
|
func (s Scope) ForgotUserPassword(ctx domain.RequestContext, email, token string) (err error) {
|
||||||
stmt, err := ctx.Transaction.Preparex("UPDATE user SET reset=?, password='' WHERE LOWER(email)=?")
|
_, err = ctx.Transaction.Exec("UPDATE user SET reset=?, password='' WHERE LOWER(email)=?", token, strings.ToLower(email))
|
||||||
defer streamutil.Close(stmt)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "prepare password reset")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stmt.Exec(token, strings.ToLower(email))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute password reset")
|
err = errors.Wrap(err, "execute password reset")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -37,6 +37,8 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, {
|
||||||
deleteSpaceName: '',
|
deleteSpaceName: '',
|
||||||
|
|
||||||
didReceiveAttrs() {
|
didReceiveAttrs() {
|
||||||
|
this._super(...arguments);
|
||||||
|
|
||||||
let targets = _.reject(this.get('folders'), {
|
let targets = _.reject(this.get('folders'), {
|
||||||
id: this.get('folder').get('id')
|
id: this.get('folder').get('id')
|
||||||
});
|
});
|
||||||
|
@ -50,6 +52,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, {
|
||||||
},
|
},
|
||||||
|
|
||||||
didRender() {
|
didRender() {
|
||||||
|
this._super(...arguments);
|
||||||
this.renderTooltips();
|
this.renderTooltips();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -82,6 +85,8 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, {
|
||||||
},
|
},
|
||||||
|
|
||||||
willDestroyElement() {
|
willDestroyElement() {
|
||||||
|
this._super(...arguments);
|
||||||
|
|
||||||
if (this.get('isDestroyed') || this.get('isDestroying')) {
|
if (this.get('isDestroyed') || this.get('isDestroying')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
{{#layout/zone-content}}
|
{{#layout/zone-content}}
|
||||||
<div class="back-to-space">
|
<div class="back-to-space">
|
||||||
{{#link-to 'folder' model.folder.id model.folder.slug}}
|
{{#link-to 'folder' model.folder.id model.folder.slug}}
|
||||||
<div class="regular-button button-gray">
|
<div class="regular-button button-nav">
|
||||||
<i class="material-icons">arrow_back</i>
|
<i class="material-icons">arrow_back</i>
|
||||||
<div class="name">{{model.folder.name}}</div>
|
<div class="name">{{model.folder.name}}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -79,21 +79,6 @@ export default Ember.Service.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getBatchedPages: function (documentId, payload) {
|
|
||||||
let url = `documents/${documentId}/pages/batch`;
|
|
||||||
|
|
||||||
return this.get('ajax').request(url, {
|
|
||||||
method: 'POST',
|
|
||||||
data: payload
|
|
||||||
}).then((pages) => {
|
|
||||||
if (is.not.array(pages)) {
|
|
||||||
pages = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return pages;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
changePageSequence: function (documentId, payload) {
|
changePageSequence: function (documentId, payload) {
|
||||||
let url = `documents/${documentId}/pages/sequence`;
|
let url = `documents/${documentId}/pages/sequence`;
|
||||||
|
|
||||||
|
|
|
@ -9,41 +9,46 @@
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
|
// Theme-neutral colors
|
||||||
$color-off-white: #f5f5f5;
|
$color-off-white: #f5f5f5;
|
||||||
$color-off-black: #393939;
|
$color-off-black: #393939;
|
||||||
$color-black: #000000;
|
$color-black: #000000;
|
||||||
$color-white: #ffffff;
|
$color-white: #ffffff;
|
||||||
$color-primary: #2667af;
|
|
||||||
$color-red: #d04134;
|
$color-red: #d04134;
|
||||||
$color-green: #4caf50;
|
$color-green: #4caf50;
|
||||||
$color-blue: #2667af;
|
$color-blue: #2667af;
|
||||||
$color-gray: #8b9096;
|
$color-gray: #8b9096;
|
||||||
$color-goldy: #cc9933;
|
$color-goldy: #cc9933;
|
||||||
|
|
||||||
$color-sidebar: #f3f5f8;
|
|
||||||
$color-link: #0092d3;
|
|
||||||
$color-border: #f3f5f8;
|
|
||||||
|
|
||||||
$color-input: #5a5a5a;
|
|
||||||
$color-stroke: #e1e1e1;
|
|
||||||
|
|
||||||
$color-tooltip: #a1a1a1;
|
|
||||||
$color-toast: #4c4c4c;
|
|
||||||
$color-checkbox: #2667af;
|
|
||||||
$color-card-active: #f7fcff;
|
|
||||||
|
|
||||||
$color-chip: #dff0f9;
|
|
||||||
$color-chip-border: #daeaf3;
|
|
||||||
$color-chip-text: #1b88e3;
|
|
||||||
|
|
||||||
$color-symbol-box: #dce5e8;
|
|
||||||
$color-symbol-icon: #a4b8be;
|
|
||||||
|
|
||||||
$color-table-border: #e1e1e1;
|
$color-table-border: #e1e1e1;
|
||||||
$color-table-header: #f5f5f5;
|
$color-table-header: #f5f5f5;
|
||||||
$color-toolbar: #eeeeee;
|
$color-toolbar: #eeeeee;
|
||||||
$color-wysiwyg: #3c3c3c;
|
$color-wysiwyg: #3c3c3c;
|
||||||
|
|
||||||
|
$color-input: #5a5a5a;
|
||||||
|
$color-stroke: #e1e1e1;
|
||||||
|
$color-tooltip: #a1a1a1;
|
||||||
|
$color-toast: #4c4c4c;
|
||||||
|
|
||||||
|
// Theme colors
|
||||||
|
$color-primary: #2667af;
|
||||||
|
$color-link: #0092d3;
|
||||||
|
$color-border: #f3f5f8;
|
||||||
|
|
||||||
|
$color-checkbox: #0092d3;
|
||||||
|
$color-card-active: #f7fcff;
|
||||||
|
|
||||||
|
$color-nav-button: #f2faff;
|
||||||
|
$color-nav-button-text: #2667af;
|
||||||
|
$color-nav-button-border: #dff0f9;
|
||||||
|
|
||||||
|
$color-sidebar: #f2faff;
|
||||||
|
$color-sidebar-border: #dff0f9;
|
||||||
|
$color-sidebar-text: $color-off-black;
|
||||||
|
$color-sidebar-link: $color-link;
|
||||||
|
|
||||||
|
// Color utility classes for direct usage in HTML
|
||||||
.color-white {
|
.color-white {
|
||||||
color: $color-white !important;
|
color: $color-white !important;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
.zone-document-content {
|
.zone-document-content {
|
||||||
> .document-header-zone {
|
> .document-header-zone {
|
||||||
padding: 20px 30px;
|
// padding: 20px 30px;
|
||||||
border: 1px solid $color-stroke;
|
// @include border-radius(3px);
|
||||||
@include border-radius(3px);
|
// border: 1px solid $color-stroke;
|
||||||
background-color: $color-off-white;
|
// background-color: $color-off-white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.doc-title {
|
.doc-title {
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
margin: 50px 0 10px;
|
margin: 50px 0 10px;
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
|
// color: $color-primary;
|
||||||
}
|
}
|
||||||
|
|
||||||
.doc-excerpt {
|
.doc-excerpt {
|
||||||
font-size: 1rem;
|
font-size: 1.2rem;
|
||||||
color: $color-gray;
|
color: $color-gray;
|
||||||
margin: 0 0 45px;
|
margin: 0 0 45px;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +32,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.edit-doc-excerpt {
|
.edit-doc-excerpt {
|
||||||
font-size: 1rem;
|
font-size: 1.2rem;
|
||||||
margin: 0 0 10px;
|
margin: 0 0 10px;
|
||||||
color: $color-gray;
|
color: $color-gray;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ $sidebar-width: 400px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#sidebar-wrapper {
|
#sidebar-wrapper {
|
||||||
background-color: $color-off-white;
|
|
||||||
z-index: 888;
|
z-index: 888;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
|
@ -19,12 +18,13 @@ $sidebar-width: 400px;
|
||||||
width: 0;
|
width: 0;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
margin-left: -$sidebar-width;
|
margin-left: -$sidebar-width;
|
||||||
border-right: 1px solid $color-stroke;
|
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
-webkit-transition: all 0.5s ease;
|
-webkit-transition: all 0.5s ease;
|
||||||
-moz-transition: all 0.5s ease;
|
-moz-transition: all 0.5s ease;
|
||||||
-o-transition: all 0.5s ease;
|
-o-transition: all 0.5s ease;
|
||||||
transition: all 0.5s ease;
|
transition: all 0.5s ease;
|
||||||
|
background-color: $color-sidebar;
|
||||||
|
border-right: 1px solid $color-sidebar-border;
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-container {
|
.page-container {
|
||||||
|
@ -68,22 +68,30 @@ $sidebar-width: 400px;
|
||||||
|
|
||||||
.zone-sidebar-page-title {
|
.zone-sidebar-page-title {
|
||||||
color: $color-primary;
|
color: $color-primary;
|
||||||
font-size: 1.3rem;
|
font-size: 1.5rem;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.zone-sidebar-page-info {
|
.zone-sidebar-page-info {
|
||||||
color: $color-gray;
|
color: $color-black;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
line-height: 1.5rem;
|
line-height: 1.5rem;
|
||||||
margin-bottom: 30px;
|
margin-bottom: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
color: $color-sidebar-text !important;
|
||||||
|
|
||||||
|
a, a:visited {
|
||||||
|
&:hover {
|
||||||
|
color: $color-sidebar-link !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-wrapper {
|
.sidebar-wrapper {
|
||||||
padding: 40px 20px 40px 20px;
|
padding: 40px 20px 40px 20px;
|
||||||
margin-left: 20px;
|
margin: 0 20px;
|
||||||
|
|
||||||
.sidebar-panel {
|
.sidebar-panel {
|
||||||
width: 300px;
|
width: 300px;
|
||||||
|
@ -100,7 +108,15 @@ $sidebar-width: 400px;
|
||||||
@include border-radius(3px);
|
@include border-radius(3px);
|
||||||
background-color: $color-white;
|
background-color: $color-white;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
color: $color-sidebar-text !important;
|
||||||
|
|
||||||
|
a, a:visited {
|
||||||
|
&:hover {
|
||||||
|
color: $color-sidebar-link !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.navigation {
|
.navigation {
|
||||||
|
|
|
@ -242,11 +242,10 @@
|
||||||
border: 1px solid $color-gray;
|
border: 1px solid $color-gray;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button-chip {
|
.button-nav {
|
||||||
background-color: $color-chip;
|
background-color: $color-nav-button;
|
||||||
color: $color-chip-text;
|
color: $color-nav-button-text;
|
||||||
border: 1px solid $color-chip-border;
|
border: 1px solid $color-nav-button;
|
||||||
@include button-hover-state($color-chip);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.flat-button {
|
.flat-button {
|
||||||
|
|
|
@ -5,45 +5,17 @@
|
||||||
height: 25px;
|
height: 25px;
|
||||||
line-height: 0;
|
line-height: 0;
|
||||||
margin: 0 5px 10px 0;
|
margin: 0 5px 10px 0;
|
||||||
border: 1px solid $color-chip-border;
|
border: 1px solid $color-gray;
|
||||||
background-color: $color-chip;
|
background-color: $color-gray;
|
||||||
color: $color-chip-text;
|
color: $color-white;
|
||||||
|
|
||||||
&:hover {
|
|
||||||
> i.material-icons {
|
|
||||||
visibility: visible;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
> .chip-text {
|
> .chip-text {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
color: $color-chip-text;
|
color: $color-white;
|
||||||
padding: 11px 10px 0 10px;
|
padding: 11px 10px 0 10px;
|
||||||
letter-spacing: 0.7px;
|
letter-spacing: 0.7px;
|
||||||
line-height: 0;
|
line-height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
> i.material-icons {
|
|
||||||
visibility: hidden;
|
|
||||||
color: $color-chip-text;
|
|
||||||
font-size: 13px;
|
|
||||||
margin: 13px 8px 0 0;
|
|
||||||
padding: 0;
|
|
||||||
line-height: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.chip-action {
|
|
||||||
@extend .chip;
|
|
||||||
background-color: $color-white;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
> .chip-text {
|
|
||||||
color: $color-chip-text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
.symbol {
|
|
||||||
display: inline-block;
|
|
||||||
border-radius: 2px;
|
|
||||||
height: 40px;
|
|
||||||
width: 40px;
|
|
||||||
padding: 0;
|
|
||||||
line-height: 0;
|
|
||||||
margin: 0;
|
|
||||||
text-align: center;
|
|
||||||
background-color: $color-symbol-box;
|
|
||||||
|
|
||||||
> .material-icons {
|
|
||||||
font-size: 22px;
|
|
||||||
margin-top: 20px;
|
|
||||||
color: $color-symbol-icon;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -73,7 +73,6 @@
|
||||||
@import "widget-radio";
|
@import "widget-radio";
|
||||||
@import "widget-selection";
|
@import "widget-selection";
|
||||||
@import "widget-sidebar-menu";
|
@import "widget-sidebar-menu";
|
||||||
@import "widget-symbol";
|
|
||||||
@import "widget-tab";
|
@import "widget-tab";
|
||||||
@import "widget-table";
|
@import "widget-table";
|
||||||
@import "widget-tooltip";
|
@import "widget-tooltip";
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<div class="back-to-space document-space">
|
<div class="back-to-space document-space">
|
||||||
<div class="caption">Space</div>
|
<div class="caption">Space</div>
|
||||||
{{#link-to 'folder' folder.id folder.slug}}
|
{{#link-to 'folder' folder.id folder.slug}}
|
||||||
<div class="regular-button button-gray">
|
<div class="regular-button button-nav">
|
||||||
<i class="material-icons">arrow_back</i>
|
<i class="material-icons">arrow_back</i>
|
||||||
<div class="name">{{folder.name}}</div>
|
<div class="name">{{folder.name}}</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
<div class="caption">Category</div>
|
<div class="caption">Category</div>
|
||||||
|
|
||||||
{{#each selectedCategories as |cat|}}
|
{{#each selectedCategories as |cat|}}
|
||||||
<div class="regular-button button-blue">{{cat.category}}</div>
|
<div class="regular-button button-nav">{{cat.category}}</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
{{#if canAddCategory}}
|
{{#if canAddCategory}}
|
||||||
{{#link-to 'folder.settings.category' folder.id folder.slug}}Manage{{/link-to}}
|
{{#link-to 'folder.settings.category' folder.id folder.slug}}Manage{{/link-to}}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<div class="document-tags">
|
<div class="document-tags">
|
||||||
<div class="caption">Tag</div>
|
<div class="caption">Tag</div>
|
||||||
{{#each tagz as |t index|}}
|
{{#each tagz as |t index|}}
|
||||||
<div class="regular-button button-chip" id="{{concat 'delete-tag-' index}}">{{concat '#' t}}</div>
|
<div class="regular-button button-gray" id="{{concat 'delete-tag-' index}}">{{concat '#' t}}</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{#if canAdd}}
|
{{#if canAdd}}
|
||||||
<div class="regular-button button-white" id="document-tag-button">
|
<div class="regular-button button-white" id="document-tag-button">
|
||||||
|
|
|
@ -94,7 +94,6 @@ func RegisterEndpoints(rt *env.Runtime, s *domain.Store) {
|
||||||
|
|
||||||
Add(rt, RoutePrefixPrivate, "documents/{documentID}/pages/level", []string{"POST", "OPTIONS"}, nil, page.ChangePageLevel)
|
Add(rt, RoutePrefixPrivate, "documents/{documentID}/pages/level", []string{"POST", "OPTIONS"}, nil, page.ChangePageLevel)
|
||||||
Add(rt, RoutePrefixPrivate, "documents/{documentID}/pages/sequence", []string{"POST", "OPTIONS"}, nil, page.ChangePageSequence)
|
Add(rt, RoutePrefixPrivate, "documents/{documentID}/pages/sequence", []string{"POST", "OPTIONS"}, nil, page.ChangePageSequence)
|
||||||
Add(rt, RoutePrefixPrivate, "documents/{documentID}/pages/batch", []string{"POST", "OPTIONS"}, nil, page.GetPagesBatch)
|
|
||||||
Add(rt, RoutePrefixPrivate, "documents/{documentID}/pages/{pageID}/revisions", []string{"GET", "OPTIONS"}, nil, page.GetRevisions)
|
Add(rt, RoutePrefixPrivate, "documents/{documentID}/pages/{pageID}/revisions", []string{"GET", "OPTIONS"}, nil, page.GetRevisions)
|
||||||
Add(rt, RoutePrefixPrivate, "documents/{documentID}/pages/{pageID}/revisions/{revisionID}", []string{"GET", "OPTIONS"}, nil, page.GetDiff)
|
Add(rt, RoutePrefixPrivate, "documents/{documentID}/pages/{pageID}/revisions/{revisionID}", []string{"GET", "OPTIONS"}, nil, page.GetDiff)
|
||||||
Add(rt, RoutePrefixPrivate, "documents/{documentID}/pages/{pageID}/revisions/{revisionID}", []string{"POST", "OPTIONS"}, nil, page.Rollback)
|
Add(rt, RoutePrefixPrivate, "documents/{documentID}/pages/{pageID}/revisions/{revisionID}", []string{"POST", "OPTIONS"}, nil, page.Rollback)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue