mirror of
https://github.com/documize/community.git
synced 2025-08-02 20:15:26 +02:00
More SQL changes in line with new schema
This commit is contained in:
parent
944fd98421
commit
8ee63de6c7
14 changed files with 45 additions and 37 deletions
|
@ -82,6 +82,7 @@ func (h *Handler) Login(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error("unable to fetch user", err)
|
||||
return
|
||||
}
|
||||
if len(u.Reset) > 0 || len(u.Password) == 0 {
|
||||
|
|
|
@ -134,7 +134,7 @@ func (s Scope) RemoveReference(ctx domain.RequestContext, id string) (err error)
|
|||
func (s Scope) Update(ctx domain.RequestContext, b block.Block) (err error) {
|
||||
b.Revised = time.Now().UTC()
|
||||
_, err = ctx.Transaction.NamedExec(`UPDATE dmz_section_template SET
|
||||
c_name=:title, c_body=:body, c_desc=:excerpt, c_rawbody=:rawbody,
|
||||
c_name=:name, c_body=:body, c_desc=:excerpt, c_rawbody=:rawbody,
|
||||
c_config=:config, c_revised=:revised
|
||||
WHERE c_orgid=:orgid AND c_refid=:refid`,
|
||||
b)
|
||||
|
|
|
@ -164,6 +164,7 @@ func (h *Handler) GetAll(w http.ResponseWriter, r *http.Request) {
|
|||
cat, err := h.Store.Category.GetAllBySpace(ctx, spaceID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -249,6 +250,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
cat, err := h.Store.Category.Get(ctx, catID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -318,8 +320,8 @@ func (h *Handler) GetSummary(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
s, err := h.Store.Category.GetSpaceCategorySummary(ctx, spaceID)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("get space category summary failed", err)
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -77,14 +77,14 @@ func (s Scope) GetAllBySpace(ctx domain.RequestContext, spaceID string) (c []cat
|
|||
err = s.Runtime.Db.Select(&c, `
|
||||
SELECT id, c_refid AS refid, c_orgid AS orgid, c_spaceid AS spaceid, c_name AS name, c_created AS created, c_revised AS revised
|
||||
FROM dmz_category
|
||||
WHERE c_orgid=? AND c_spaceid=? AND spaceid IN
|
||||
WHERE c_orgid=? AND c_spaceid=? AND c_spaceid IN
|
||||
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_location='space' AND c_refid IN
|
||||
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0') AND c_location='space' AND c_action='view'
|
||||
UNION ALL
|
||||
SELECT p.c_refid FROM dmz_permission p LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid
|
||||
WHERE p.c_orgid=? AND p.c_who='role' AND p.c_location='space' AND p.c_action='view' AND (r.c_userid=? OR r.c_userid='0')
|
||||
))
|
||||
ORDER BY dmz_category`, ctx.OrgID, spaceID, ctx.OrgID, ctx.OrgID, ctx.UserID, ctx.OrgID, ctx.UserID)
|
||||
ORDER BY c_name`, ctx.OrgID, spaceID, ctx.OrgID, ctx.OrgID, ctx.UserID, ctx.OrgID, ctx.UserID)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
|
@ -108,7 +108,7 @@ func (s Scope) GetByOrg(ctx domain.RequestContext, userID string) (c []category.
|
|||
SELECT p.c_refid FROM dmz_permission p LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid
|
||||
WHERE p.c_orgid=? AND p.c_who='role' AND p.c_location='category' AND (r.c_userid=? OR r.c_userid='0')
|
||||
))
|
||||
ORDER BY dmz_category`, ctx.OrgID, ctx.OrgID, ctx.OrgID, userID, ctx.OrgID, userID)
|
||||
ORDER BY c_name`, ctx.OrgID, ctx.OrgID, ctx.OrgID, userID, ctx.OrgID, userID)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
|
|
|
@ -305,7 +305,7 @@ func (s Scope) Delete(ctx domain.RequestContext, documentID string) (rows int64,
|
|||
return
|
||||
}
|
||||
|
||||
return b.DeleteConstrained(ctx.Transaction, "document", ctx.OrgID, documentID)
|
||||
return b.DeleteConstrained(ctx.Transaction, "dmz_doc", ctx.OrgID, documentID)
|
||||
}
|
||||
|
||||
// DeleteBySpace removes all documents for given space.
|
||||
|
|
|
@ -192,6 +192,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
g, err := h.Store.Group.Get(ctx, groupID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ func (s Scope) Add(ctx domain.RequestContext, g group.Group) (err error) {
|
|||
// Get returns requested group.
|
||||
func (s Scope) Get(ctx domain.RequestContext, refID string) (g group.Group, err error) {
|
||||
err = s.Runtime.Db.Get(&g, `
|
||||
SELECT id, c_refid AS refid, c_orgid AS orgid, c_name AS name, c_desc AS purpose, c_created, c_revised
|
||||
SELECT id, c_refid AS refid, c_orgid AS orgid, c_name AS name, c_desc AS purpose, c_created AS created, c_revised AS revised
|
||||
FROM dmz_group
|
||||
WHERE c_orgid=? AND c_refid=?`,
|
||||
ctx.OrgID, refID)
|
||||
|
@ -63,8 +63,8 @@ func (s Scope) GetAll(ctx domain.RequestContext) (groups []group.Group, err erro
|
|||
groups = []group.Group{}
|
||||
|
||||
err = s.Runtime.Db.Select(&groups, `
|
||||
SELECT id, c_refid AS refid, c_orgid AS orgid, c_name AS name, c_desc AS purpose, c_created, c_revised
|
||||
COUNT(b.groupid) AS members
|
||||
SELECT a.id, a.c_refid AS refid, a.c_orgid AS orgid, a.c_name AS name, a.c_desc AS purpose, a.c_created AS created, a.c_revised AS revised,
|
||||
COUNT(b.c_groupid) AS members
|
||||
FROM dmz_group a
|
||||
LEFT JOIN dmz_group_member b ON a.c_refid=b.c_groupid
|
||||
WHERE a.c_orgid=?
|
||||
|
@ -101,7 +101,10 @@ func (s Scope) Update(ctx domain.RequestContext, g group.Group) (err error) {
|
|||
// Delete removes group from store.
|
||||
func (s Scope) Delete(ctx domain.RequestContext, refID string) (rows int64, err error) {
|
||||
b := mysql.BaseQuery{}
|
||||
b.DeleteConstrained(ctx.Transaction, "role", ctx.OrgID, refID)
|
||||
_, err = b.DeleteConstrained(ctx.Transaction, "dmz_group", ctx.OrgID, refID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_group_member WHERE c_orgid=\"%s\" AND c_groupid=\"%s\"", ctx.OrgID, refID))
|
||||
}
|
||||
|
||||
|
@ -130,7 +133,7 @@ func (s Scope) GetGroupMembers(ctx domain.RequestContext, groupID string) (membe
|
|||
|
||||
// JoinGroup adds user to group.
|
||||
func (s Scope) JoinGroup(ctx domain.RequestContext, groupID, userID string) (err error) {
|
||||
_, err = ctx.Transaction.Exec("INSERT INTO dmz_group_member (orgid, groupid, userid) VALUES (?, ?, ?)", ctx.OrgID, groupID, userID)
|
||||
_, err = ctx.Transaction.Exec("INSERT INTO dmz_group_member (c_orgid, c_groupid, c_userid) VALUES (?, ?, ?)", ctx.OrgID, groupID, userID)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "insert group member")
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ func (s Scope) GetDocumentPages(ctx domain.RequestContext, documentID string) (p
|
|||
SELECT id, c_refid AS refid, c_orgid AS orgid, c_docid AS documentid,
|
||||
c_userid AS userid, c_contenttype AS contenttype,
|
||||
c_type AS type, c_level AS level, c_sequence AS sequence, c_name AS name,
|
||||
c_body AS body, c_revisions AS revisions, c_blockid AS templateid,
|
||||
c_body AS body, c_revisions AS revisions, c_templateid AS templateid,
|
||||
c_status AS status, c_relativeid AS relativeid, c_created AS created, c_revised AS revised
|
||||
FROM dmz_section
|
||||
WHERE c_docid=? AND (c_status=0 OR ((c_status=4 OR c_status=2) AND c_relativeid=''))`,
|
||||
|
|
|
@ -141,7 +141,7 @@ func (s Scope) GetCategoryPermissions(ctx domain.RequestContext, catID string) (
|
|||
FROM dmz_permission
|
||||
WHERE c_orgid=? AND c_location='category' AND c_who='user' AND (c_refid=? OR c_refid='0')
|
||||
UNION ALL
|
||||
SELECT id, p.c_orgid AS orgid, p.c_who AS who, p.c_whoid AS whoid, p.c_action AS action, p.c_scope AS scope, p.c_location AS location, p.c_refid AS refid
|
||||
SELECT p.id, p.c_orgid AS orgid, p.c_who AS who, p.c_whoid AS whoid, p.c_action AS action, p.c_scope AS scope, p.c_location AS location, p.c_refid AS refid
|
||||
FROM dmz_permission p
|
||||
LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid
|
||||
WHERE p.c_orgid=? AND p.c_location='category' AND p.c_who='role' AND (p.c_refid=? OR p.c_refid='0')`,
|
||||
|
@ -163,7 +163,8 @@ func (s Scope) GetCategoryUsers(ctx domain.RequestContext, catID string) (u []us
|
|||
|
||||
err = s.Runtime.Db.Select(&u, `
|
||||
SELECT u.id, IFNULL(u.c_refid, '') AS refid, IFNULL(u.c_firstname, '') AS firstname, IFNULL(u.c_lastname, '') as lastname, u.email AS email, u.initials AS initials, u.password AS password, u.salt AS salt, u.c_reset AS reset, u.c_created AS created, u.c_revised AS revised
|
||||
FROM dmz_user u LEFT JOIN dmz_user_account a ON u.c_refid = a.c_userid
|
||||
FROM dmz_user u
|
||||
LEFT JOIN dmz_user_account a ON u.c_refid = a.c_userid
|
||||
WHERE a.c_orgid=? AND a.c_active=1 AND u.c_refid IN (
|
||||
SELECT c_whoid from dmz_permission
|
||||
WHERE c_orgid=? AND c_who='user' AND c_location='category' AND c_refid=?
|
||||
|
|
|
@ -70,8 +70,8 @@ func (s Scope) GetByDomain(ctx domain.RequestContext, domain, email string) (u u
|
|||
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||
u.c_created, u.c_revised
|
||||
FROM dmz_user u, dmz_account a, dmz_org o
|
||||
u.c_created AS created, u.c_revised AS revised
|
||||
FROM dmz_user u, dmz_user_account a, dmz_org o
|
||||
WHERE TRIM(LOWER(u.c_email))=? AND u.c_refid=a.c_userid AND a.c_orgid=o.c_refid AND TRIM(LOWER(o.c_domain))=?`,
|
||||
email, domain)
|
||||
|
||||
|
@ -90,9 +90,9 @@ func (s Scope) GetByEmail(ctx domain.RequestContext, email string) (u user.User,
|
|||
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||
u.c_created, u.c_revised
|
||||
FROM dmz_user
|
||||
WHERE TRIM(LOWER(c_email))=?`,
|
||||
u.c_created AS created, u.c_revised AS revised
|
||||
FROM dmz_user u
|
||||
WHERE TRIM(LOWER(u.c_email))=?`,
|
||||
email)
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
|
@ -108,9 +108,9 @@ func (s Scope) GetByToken(ctx domain.RequestContext, token string) (u user.User,
|
|||
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||
u.c_created, u.c_revised
|
||||
FROM dmz_user
|
||||
WHERE c_reset=?`,
|
||||
u.c_created AS created, u.c_revised AS revised
|
||||
FROM dmz_user u
|
||||
WHERE u.c_reset=?`,
|
||||
token)
|
||||
|
||||
if err != nil {
|
||||
|
@ -128,9 +128,9 @@ func (s Scope) GetBySerial(ctx domain.RequestContext, serial string) (u user.Use
|
|||
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||
u.c_created, u.c_revised
|
||||
FROM dmz_user
|
||||
WHERE c_salt=?`,
|
||||
u.c_created AS created, u.c_revised AS revised
|
||||
FROM dmz_user u
|
||||
WHERE u.c_salt=?`,
|
||||
serial)
|
||||
|
||||
if err != nil {
|
||||
|
@ -149,7 +149,7 @@ func (s Scope) GetActiveUsersForOrganization(ctx domain.RequestContext) (u []use
|
|||
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||
u.c_created, u.c_revised,
|
||||
u.c_created AS created, u.c_revised AS revised,
|
||||
a.c_active AS active, a.c_editor AS editor, a.c_admin AS admin, a.c_users AS viewusers, a.c_analytics AS analytics
|
||||
FROM dmz_user u, dmz_user_account a
|
||||
WHERE u.c_refid=a.c_userid AND a.c_orgid=? AND a.c_active=1
|
||||
|
@ -181,7 +181,7 @@ func (s Scope) GetUsersForOrganization(ctx domain.RequestContext, filter string,
|
|||
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||
u.c_created, u.c_revised,
|
||||
u.c_created AS created, u.c_revised AS revised,
|
||||
a.c_active AS active, a.c_editor AS editor, a.c_admin AS admin, a.c_users AS viewusers, a.c_analytics AS analytics
|
||||
FROM dmz_user u, dmz_user_account a
|
||||
WHERE u.c_refid=a.c_userid AND a.c_orgid=? `+likeQuery+
|
||||
|
@ -206,7 +206,7 @@ func (s Scope) GetSpaceUsers(ctx domain.RequestContext, spaceID string) (u []use
|
|||
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||
u.c_created, u.c_revised,
|
||||
u.c_created AS created, u.c_revised AS revised,
|
||||
a.c_active AS active, a.c_editor AS editor, a.c_admin AS admin, a.c_users AS viewusers, a.c_analytics AS analytics
|
||||
FROM dmz_user u, dmz_user_account a
|
||||
WHERE a.c_orgid=? AND u.c_refid = a.c_userid AND a.c_active=1 AND u.c_refid IN (
|
||||
|
@ -240,7 +240,7 @@ func (s Scope) GetUsersForSpaces(ctx domain.RequestContext, spaces []string) (u
|
|||
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||
u.c_created, u.c_revised,
|
||||
u.c_created AS created, u.c_revised AS revised,
|
||||
a.c_active AS active, a.c_editor AS editor, a.c_admin AS admin, a.c_users AS viewusers, a.c_analytics AS analytics
|
||||
FROM dmz_user u, dmz_user_account a
|
||||
WHERE a.c_orgid=? AND u.c_refid = a.c_userid AND a.c_active=1 AND u.c_refid IN (
|
||||
|
@ -339,7 +339,7 @@ func (s Scope) MatchUsers(ctx domain.RequestContext, text string, maxMatches int
|
|||
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||
u.c_created, u.c_revised,
|
||||
u.c_created AS created, u.c_revised AS revised,
|
||||
a.c_active AS active, a.c_editor AS editor, a.c_admin AS admin, a.c_users AS viewusers, a.c_analytics AS analytics
|
||||
FROM dmz_user u, dmz_user_account a
|
||||
WHERE a.c_orgid=? AND u.c_refid=a.c_userid AND a.c_active=1 `+likeQuery+` ORDER BY u.c_firstname, u.c_lastname LIMIT `+strconv.Itoa(maxMatches),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue