mirror of
https://github.com/documize/community.git
synced 2025-08-05 05:25:27 +02:00
Per space label, icon, description
Labels introduce visual grouping and filtering of spaces.
This commit is contained in:
parent
fe8068965c
commit
a211ba051a
106 changed files with 3280 additions and 1008 deletions
|
@ -145,7 +145,7 @@ func (h *Handler) Download(w http.ResponseWriter, r *http.Request) {
|
|||
// can download as required.
|
||||
// Such secure document viewing links can have expiry dates.
|
||||
if len(authToken) == 0 && len(secureToken) > 0 {
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
// Send back error if caller unable view attachment
|
||||
|
|
|
@ -105,6 +105,14 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
err = h.Store.Space.IncrementCategoryCount(ctx, cat.SpaceID)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction.Commit()
|
||||
|
||||
cat, err = h.Store.Category.Get(ctx, cat.RefID)
|
||||
|
@ -295,6 +303,14 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
err = h.Store.Space.DecrementCategoryCount(ctx, cat.SpaceID)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction.Commit()
|
||||
|
||||
h.Store.Audit.Record(ctx, audit.EventTypeCategoryDelete)
|
||||
|
|
|
@ -262,6 +262,12 @@ func processDocument(ctx domain.RequestContext, r *env.Runtime, store *store.Sto
|
|||
|
||||
go indexer.IndexDocument(ctx, newDocument, da)
|
||||
|
||||
err = store.Space.IncrementContentCount(ctx, newDocument.SpaceID)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "cannot increment space content count")
|
||||
return
|
||||
}
|
||||
|
||||
store.Audit.Record(ctx, audit.EventTypeDocumentUpload)
|
||||
|
||||
return
|
||||
|
|
|
@ -396,6 +396,14 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
ActivityType: activity.TypeDeleted})
|
||||
}
|
||||
|
||||
err = h.Store.Space.DecrementContentCount(ctx, doc.SpaceID)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction.Commit()
|
||||
|
||||
h.Store.Audit.Record(ctx, audit.EventTypeDocumentDelete)
|
||||
|
|
|
@ -179,3 +179,19 @@ func (s Store) GetMembers(ctx domain.RequestContext) (r []group.Record, err erro
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
// RemoveUserGroups remove user from all group.
|
||||
func (s Store) RemoveUserGroups(ctx domain.RequestContext, userID string) (err error) {
|
||||
_, err = s.DeleteWhere(ctx.Transaction,
|
||||
fmt.Sprintf("DELETE FROM dmz_group_member WHERE c_orgid='%s' AND c_userid='%s'",
|
||||
ctx.OrgID, userID))
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "RemoveUserGroups")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
201
domain/label/endpoint.go
Normal file
201
domain/label/endpoint.go
Normal file
|
@ -0,0 +1,201 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package label
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/core/request"
|
||||
"github.com/documize/community/core/response"
|
||||
"github.com/documize/community/core/streamutil"
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/domain/store"
|
||||
"github.com/documize/community/model/audit"
|
||||
"github.com/documize/community/model/label"
|
||||
)
|
||||
|
||||
// Handler contains the runtime information such as logging and database.
|
||||
type Handler struct {
|
||||
Runtime *env.Runtime
|
||||
Store *store.Store
|
||||
}
|
||||
|
||||
// Add space label to the store.
|
||||
func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
||||
method := "label.Add"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.IsValid(ctx) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
||||
if !ctx.Administrator {
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
defer streamutil.Close(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := label.Label{}
|
||||
err = json.Unmarshal(body, &l)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
l.RefID = uniqueid.Generate()
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = h.Store.Label.Add(ctx, l)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction.Commit()
|
||||
|
||||
h.Store.Audit.Record(ctx, audit.EventTypeLabelAdd)
|
||||
|
||||
response.WriteJSON(w, l)
|
||||
}
|
||||
|
||||
// Get returns all space labels.
|
||||
func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
||||
method := "label.Get"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
l, err := h.Store.Label.Get(ctx)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
if len(l) == 0 {
|
||||
l = []label.Label{}
|
||||
}
|
||||
|
||||
response.WriteJSON(w, l)
|
||||
}
|
||||
|
||||
// Update persists label name/color changes.
|
||||
func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||
method := "label.Update"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !ctx.Administrator {
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
labelID := request.Param(r, "labelID")
|
||||
if len(labelID) == 0 {
|
||||
response.WriteMissingDataError(w, method, "labelID")
|
||||
return
|
||||
}
|
||||
|
||||
defer streamutil.Close(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "Bad payload")
|
||||
return
|
||||
}
|
||||
|
||||
l := label.Label{}
|
||||
err = json.Unmarshal(body, &l)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "Bad payload")
|
||||
return
|
||||
}
|
||||
|
||||
l.RefID = labelID
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = h.Store.Label.Update(ctx, l)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction.Commit()
|
||||
|
||||
h.Store.Audit.Record(ctx, audit.EventTypeLabelUpdate)
|
||||
|
||||
response.WriteEmpty(w)
|
||||
}
|
||||
|
||||
// Delete removes space label from store and
|
||||
// removes label association from spaces.
|
||||
func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
method := "label.Delete"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
labelID := request.Param(r, "labelID")
|
||||
if len(labelID) == 0 {
|
||||
response.WriteMissingDataError(w, method, "labelID")
|
||||
return
|
||||
}
|
||||
|
||||
var err error
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = h.Store.Label.Delete(ctx, labelID)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = h.Store.Label.RemoveReference(ctx, labelID)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction.Commit()
|
||||
|
||||
h.Store.Audit.Record(ctx, audit.EventTypeLabelDelete)
|
||||
|
||||
response.WriteEmpty(w)
|
||||
}
|
106
domain/label/store.go
Normal file
106
domain/label/store.go
Normal file
|
@ -0,0 +1,106 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package label
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/domain/store"
|
||||
"github.com/documize/community/model/label"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Store provides data access to section template information.
|
||||
type Store struct {
|
||||
store.Context
|
||||
store.LabelStorer
|
||||
}
|
||||
|
||||
// Add saves space label to store.
|
||||
func (s Store) Add(ctx domain.RequestContext, l label.Label) (err error) {
|
||||
l.OrgID = ctx.OrgID
|
||||
l.Created = time.Now().UTC()
|
||||
l.Revised = time.Now().UTC()
|
||||
|
||||
_, err = ctx.Transaction.Exec(s.Bind("INSERT INTO dmz_space_label (c_refid, c_orgid, c_name, c_color, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?)"),
|
||||
l.RefID, l.OrgID, l.Name, l.Color, l.Created, l.Revised)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute insert label")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Get returns all space labels from store.
|
||||
func (s Store) Get(ctx domain.RequestContext) (l []label.Label, err error) {
|
||||
err = s.Runtime.Db.Select(&l, s.Bind(`
|
||||
SELECT id, c_refid as refid,
|
||||
c_orgid as orgid,
|
||||
c_name AS name, c_color AS color,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_space_label
|
||||
WHERE c_orgid=?`),
|
||||
ctx.OrgID)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute select label")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Update persists space label changes to the store.
|
||||
func (s Store) Update(ctx domain.RequestContext, l label.Label) (err error) {
|
||||
l.Revised = time.Now().UTC()
|
||||
|
||||
_, err = ctx.Transaction.NamedExec(s.Bind(`UPDATE dmz_space_label SET
|
||||
c_name=:name, c_color=:color, c_revised=:revised
|
||||
WHERE c_orgid=:orgid AND c_refid=:refid`),
|
||||
l)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute update label")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Delete removes space label from the store.
|
||||
func (s Store) Delete(ctx domain.RequestContext, id string) (rows int64, err error) {
|
||||
return s.DeleteConstrained(ctx.Transaction, "dmz_space_label", ctx.OrgID, id)
|
||||
}
|
||||
|
||||
// RemoveReference clears space.labelID for given label.
|
||||
func (s Store) RemoveReference(ctx domain.RequestContext, spaceID string) (err error) {
|
||||
_, err = ctx.Transaction.Exec(s.Bind(`UPDATE dmz_space SET
|
||||
c_labelid='', c_revised=?
|
||||
WHERE c_orgid=? AND c_refid=?`),
|
||||
time.Now().UTC(), ctx.OrgID, spaceID)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute remove space label reference")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
|
@ -57,13 +57,13 @@ func (h *Handler) Meta(w http.ResponseWriter, r *http.Request) {
|
|||
data.AuthProvider = strings.TrimSpace(org.AuthProvider)
|
||||
data.AuthConfig = org.AuthConfig
|
||||
data.MaxTags = org.MaxTags
|
||||
data.Theme = org.Theme
|
||||
data.Version = h.Runtime.Product.Version
|
||||
data.Revision = h.Runtime.Product.Revision
|
||||
data.Edition = h.Runtime.Product.Edition
|
||||
data.ConversionEndpoint = org.ConversionEndpoint
|
||||
data.Storage = h.Runtime.StoreProvider.Type()
|
||||
data.Location = h.Runtime.Flags.Location // reserved
|
||||
data.Theme = org.Theme
|
||||
|
||||
// Strip secrets
|
||||
data.AuthConfig = auth.StripAuthSecrets(h.Runtime, org.AuthProvider, org.AuthConfig)
|
||||
|
@ -195,7 +195,7 @@ func (h *Handler) Reindex(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if !ctx.GlobalAdmin {
|
||||
response.WriteForbiddenError(w)
|
||||
h.Runtime.Log.Info(fmt.Sprintf("%s attempted search reindex"))
|
||||
h.Runtime.Log.Info(fmt.Sprintf("%s attempted search reindex", ctx.UserID))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ func (h *Handler) SearchStatus(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if !ctx.GlobalAdmin {
|
||||
response.WriteForbiddenError(w)
|
||||
h.Runtime.Log.Info(fmt.Sprintf("%s attempted get of search status"))
|
||||
h.Runtime.Log.Info(fmt.Sprintf("%s attempted get of search status", ctx.UserID))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -292,9 +292,12 @@ func (h *Handler) Themes(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
th := []theme{}
|
||||
th = append(th, theme{Name: "", Primary: "#280A42"})
|
||||
th = append(th, theme{Name: "Blue", Primary: "#176091"})
|
||||
th = append(th, theme{Name: "Deep Orange", Primary: "#BF360C"})
|
||||
th = append(th, theme{Name: "Teal", Primary: "#00695C"})
|
||||
th = append(th, theme{Name: "Brave", Primary: "#BF360C"})
|
||||
th = append(th, theme{Name: "Conference", Primary: "#176091"})
|
||||
th = append(th, theme{Name: "Forest", Primary: "#00695C"})
|
||||
th = append(th, theme{Name: "Harvest", Primary: "#A65F20"})
|
||||
th = append(th, theme{Name: "Silver", Primary: "#AEBECC"})
|
||||
th = append(th, theme{Name: "Sunflower", Primary: "#D7B92F"})
|
||||
|
||||
response.WriteJSON(w, th)
|
||||
}
|
||||
|
|
|
@ -50,9 +50,9 @@ func (s Store) GetOrganization(ctx domain.RequestContext, id string) (org org.Or
|
|||
c_title AS title, c_message AS message, c_domain AS domain,
|
||||
c_service AS conversionendpoint, c_email AS email, c_serial AS serial, c_active AS active,
|
||||
c_anonaccess AS allowanonymousaccess, c_authprovider AS authprovider,
|
||||
coalesce(c_authconfig,`+s.EmptyJSON()+`) AS authconfig,
|
||||
coalesce(c_authconfig,`+s.EmptyJSON()+`) AS authconfig,
|
||||
coalesce(c_sub,`+s.EmptyJSON()+`) AS subscription,
|
||||
c_maxtags AS maxtags, c_created AS created, c_revised AS revised
|
||||
c_maxtags AS maxtags, c_created AS created, c_revised AS revised, c_theme AS theme
|
||||
FROM dmz_org
|
||||
WHERE c_refid=?`),
|
||||
id)
|
||||
|
@ -82,9 +82,9 @@ func (s Store) GetOrganizationByDomain(subdomain string) (o org.Organization, er
|
|||
c_title AS title, c_message AS message, c_domain AS domain,
|
||||
c_service AS conversionendpoint, c_email AS email, c_serial AS serial, c_active AS active,
|
||||
c_anonaccess AS allowanonymousaccess, c_authprovider AS authprovider,
|
||||
coalesce(c_authconfig,`+s.EmptyJSON()+`) AS authconfig,
|
||||
coalesce(c_authconfig,`+s.EmptyJSON()+`) AS authconfig,
|
||||
coalesce(c_sub,`+s.EmptyJSON()+`) AS subscription,
|
||||
c_maxtags AS maxtags, c_created AS created, c_revised AS revised
|
||||
c_maxtags AS maxtags, c_created AS created, c_revised AS revised, c_theme AS theme
|
||||
FROM dmz_org
|
||||
WHERE c_domain=? AND c_active=true`),
|
||||
subdomain)
|
||||
|
@ -97,9 +97,9 @@ func (s Store) GetOrganizationByDomain(subdomain string) (o org.Organization, er
|
|||
c_title AS title, c_message AS message, c_domain AS domain,
|
||||
c_service AS conversionendpoint, c_email AS email, c_serial AS serial, c_active AS active,
|
||||
c_anonaccess AS allowanonymousaccess, c_authprovider AS authprovider,
|
||||
coalesce(c_authconfig,`+s.EmptyJSON()+`) AS authconfig,
|
||||
coalesce(c_authconfig,`+s.EmptyJSON()+`) AS authconfig,
|
||||
coalesce(c_sub,`+s.EmptyJSON()+`) AS subscription,
|
||||
c_maxtags AS maxtags, c_created AS created, c_revised AS revised
|
||||
c_maxtags AS maxtags, c_created AS created, c_revised AS revised, c_theme AS theme
|
||||
FROM dmz_org
|
||||
WHERE c_domain='' AND c_active=true`))
|
||||
|
||||
|
@ -116,7 +116,7 @@ func (s Store) UpdateOrganization(ctx domain.RequestContext, org org.Organizatio
|
|||
|
||||
_, err = ctx.Transaction.NamedExec(`UPDATE dmz_org SET
|
||||
c_title=:title, c_message=:message, c_service=:conversionendpoint, c_email=:email,
|
||||
c_anonaccess=:allowanonymousaccess, c_maxtags=:maxtags, c_revised=:revised
|
||||
c_anonaccess=:allowanonymousaccess, c_maxtags=:maxtags, c_theme=:theme, c_revised=:revised
|
||||
WHERE c_refid=:refid`,
|
||||
&org)
|
||||
|
||||
|
|
|
@ -30,8 +30,10 @@ type Store struct {
|
|||
|
||||
// Add adds new folder into the store.
|
||||
func (s Store) Add(ctx domain.RequestContext, sp space.Space) (err error) {
|
||||
_, err = ctx.Transaction.Exec(s.Bind("INSERT INTO dmz_space (c_refid, c_name, c_orgid, c_userid, c_type, c_lifecycle, c_likes, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"),
|
||||
sp.RefID, sp.Name, sp.OrgID, sp.UserID, sp.Type, sp.Lifecycle, sp.Likes, sp.Created, sp.Revised)
|
||||
_, err = ctx.Transaction.Exec(s.Bind("INSERT INTO dmz_space (c_refid, c_name, c_orgid, c_userid, c_type, c_lifecycle, c_likes, c_icon, c_desc, c_count_category, c_count_content, c_labelid, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"),
|
||||
sp.RefID, sp.Name, sp.OrgID, sp.UserID, sp.Type, sp.Lifecycle, sp.Likes,
|
||||
sp.Icon, sp.Description, sp.CountCategory, sp.CountContent, sp.LabelID,
|
||||
sp.Created, sp.Revised)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "unable to execute insert for space")
|
||||
|
@ -45,6 +47,8 @@ func (s Store) Get(ctx domain.RequestContext, id string) (sp space.Space, err er
|
|||
err = s.Runtime.Db.Get(&sp, s.Bind(`SELECT id, c_refid AS refid,
|
||||
c_name AS name, c_orgid AS orgid, c_userid AS userid,
|
||||
c_type AS type, c_lifecycle AS lifecycle, c_likes AS likes,
|
||||
c_icon AS icon, c_labelid AS labelid, c_desc AS description,
|
||||
c_count_category As countcategory, c_count_content AS countcontent,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_space
|
||||
WHERE c_orgid=? and c_refid=?`),
|
||||
|
@ -62,6 +66,8 @@ func (s Store) PublicSpaces(ctx domain.RequestContext, orgID string) (sp []space
|
|||
qry := s.Bind(`SELECT id, c_refid AS refid,
|
||||
c_name AS name, c_orgid AS orgid, c_userid AS userid,
|
||||
c_type AS type, c_lifecycle AS lifecycle, c_likes AS likes,
|
||||
c_icon AS icon, c_labelid AS labelid, c_desc AS desc,
|
||||
c_count_category as countcategory, c_count_content AS countcontent,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_space
|
||||
WHERE c_orgid=? AND c_type=1`)
|
||||
|
@ -85,6 +91,8 @@ func (s Store) GetViewable(ctx domain.RequestContext) (sp []space.Space, err err
|
|||
q := s.Bind(`SELECT id, c_refid AS refid,
|
||||
c_name AS name, c_orgid AS orgid, c_userid AS userid,
|
||||
c_type AS type, c_lifecycle AS lifecycle, c_likes AS likes,
|
||||
c_icon AS icon, c_labelid AS labelid, c_desc AS description,
|
||||
c_count_category AS countcategory, c_count_content AS countcontent,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_space
|
||||
WHERE c_orgid=? AND c_refid IN
|
||||
|
@ -122,14 +130,18 @@ func (s Store) AdminList(ctx domain.RequestContext) (sp []space.Space, err error
|
|||
SELECT id, c_refid AS refid,
|
||||
c_name AS name, c_orgid AS orgid, c_userid AS userid,
|
||||
c_type AS type, c_lifecycle AS lifecycle, c_likes AS likes,
|
||||
c_created AS created, c_revised AS revised
|
||||
c_created AS created, c_revised AS revised,
|
||||
c_icon AS icon, c_labelid AS labelid, c_desc AS description,
|
||||
c_count_category AS countcategory, c_count_content AS countcontent
|
||||
FROM dmz_space
|
||||
WHERE c_orgid=? AND (c_type=? OR c_type=?)
|
||||
UNION ALL
|
||||
SELECT id, c_refid AS refid,
|
||||
c_name AS name, c_orgid AS orgid, c_userid AS userid,
|
||||
c_type AS type, c_lifecycle AS lifecycle, c_likes AS likes,
|
||||
c_created AS created, c_revised AS revised
|
||||
c_created AS created, c_revised AS revised,
|
||||
c_icon AS icon, c_labelid AS labelid, c_desc AS description,
|
||||
c_count_category AS countcategory, c_count_content AS countcontent
|
||||
FROM dmz_space
|
||||
WHERE c_orgid=? AND (c_type=? OR c_type=?) AND c_refid NOT IN
|
||||
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_action='own')
|
||||
|
@ -154,7 +166,13 @@ func (s Store) AdminList(ctx domain.RequestContext) (sp []space.Space, err error
|
|||
func (s Store) Update(ctx domain.RequestContext, sp space.Space) (err error) {
|
||||
sp.Revised = time.Now().UTC()
|
||||
|
||||
_, err = ctx.Transaction.NamedExec("UPDATE dmz_space SET c_name=:name, c_type=:type, c_lifecycle=:lifecycle, c_userid=:userid, c_likes=:likes, c_revised=:revised WHERE c_orgid=:orgid AND c_refid=:refid", &sp)
|
||||
_, err = ctx.Transaction.NamedExec(`
|
||||
UPDATE dmz_space
|
||||
SET c_name=:name, c_type=:type, c_lifecycle=:lifecycle, c_userid=:userid,
|
||||
c_likes=:likes, c_desc=:description, c_labelid=:labelid, c_icon=:icon,
|
||||
c_count_category=:countcategory, c_count_content=:countcontent,
|
||||
c_revised=:revised
|
||||
WHERE c_orgid=:orgid AND c_refid=:refid`, &sp)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute update for space %s", sp.RefID))
|
||||
}
|
||||
|
@ -166,3 +184,55 @@ func (s Store) Update(ctx domain.RequestContext, sp space.Space) (err error) {
|
|||
func (s Store) Delete(ctx domain.RequestContext, id string) (rows int64, err error) {
|
||||
return s.DeleteConstrained(ctx.Transaction, "dmz_space", ctx.OrgID, id)
|
||||
}
|
||||
|
||||
// IncrementCategoryCount increments usage counter for space category.
|
||||
func (s Store) IncrementCategoryCount(ctx domain.RequestContext, spaceID string) (err error) {
|
||||
_, err = ctx.Transaction.Exec(s.Bind(`UPDATE dmz_space SET
|
||||
c_count_category=c_count_category+1, c_revised=? WHERE c_orgid=? AND c_refid=?`),
|
||||
time.Now().UTC(), ctx.OrgID, spaceID)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute increment category count")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DecrementCategoryCount decrements usage counter for space category.
|
||||
func (s Store) DecrementCategoryCount(ctx domain.RequestContext, spaceID string) (err error) {
|
||||
_, err = ctx.Transaction.Exec(s.Bind(`UPDATE dmz_space SET
|
||||
c_count_category=c_count_category-1, c_revised=? WHERE c_orgid=? AND c_refid=?`),
|
||||
time.Now().UTC(), ctx.OrgID, spaceID)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute decrement category count")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// IncrementContentCount increments usage counter for space category.
|
||||
func (s Store) IncrementContentCount(ctx domain.RequestContext, spaceID string) (err error) {
|
||||
_, err = ctx.Transaction.Exec(s.Bind(`UPDATE dmz_space SET
|
||||
c_count_content=c_count_content+1, c_revised=? WHERE c_orgid=? AND c_refid=?`),
|
||||
time.Now().UTC(), ctx.OrgID, spaceID)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute increment content count")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DecrementContentCount decrements usage counter for space category.
|
||||
func (s Store) DecrementContentCount(ctx domain.RequestContext, spaceID string) (err error) {
|
||||
_, err = ctx.Transaction.Exec(s.Bind(`UPDATE dmz_space SET
|
||||
c_count_content=c_count_content-1, c_revised=? WHERE c_orgid=? AND c_refid=?`),
|
||||
time.Now().UTC(), ctx.OrgID, spaceID)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute decrement category count")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"github.com/documize/community/model/category"
|
||||
"github.com/documize/community/model/doc"
|
||||
"github.com/documize/community/model/group"
|
||||
"github.com/documize/community/model/label"
|
||||
"github.com/documize/community/model/link"
|
||||
"github.com/documize/community/model/org"
|
||||
"github.com/documize/community/model/page"
|
||||
|
@ -42,6 +43,7 @@ type Store struct {
|
|||
Document DocumentStorer
|
||||
Group GroupStorer
|
||||
Link LinkStorer
|
||||
Label LabelStorer
|
||||
Meta MetaStorer
|
||||
Organization OrganizationStorer
|
||||
Page PageStorer
|
||||
|
@ -62,6 +64,10 @@ type SpaceStorer interface {
|
|||
Update(ctx domain.RequestContext, sp space.Space) (err error)
|
||||
Delete(ctx domain.RequestContext, id string) (rows int64, err error)
|
||||
AdminList(ctx domain.RequestContext) (sp []space.Space, err error)
|
||||
IncrementCategoryCount(ctx domain.RequestContext, spaceID string) (err error)
|
||||
DecrementCategoryCount(ctx domain.RequestContext, spaceID string) (err error)
|
||||
IncrementContentCount(ctx domain.RequestContext, spaceID string) (err error)
|
||||
DecrementContentCount(ctx domain.RequestContext, spaceID string) (err error)
|
||||
}
|
||||
|
||||
// CategoryStorer defines required methods for category and category membership management
|
||||
|
@ -285,6 +291,7 @@ type GroupStorer interface {
|
|||
GetMembers(ctx domain.RequestContext) (r []group.Record, err error)
|
||||
JoinGroup(ctx domain.RequestContext, groupID, userID string) (err error)
|
||||
LeaveGroup(ctx domain.RequestContext, groupID, userID string) (err error)
|
||||
RemoveUserGroups(ctx domain.RequestContext, userID string) (err error)
|
||||
}
|
||||
|
||||
// MetaStorer provide specialist methods for global administrators.
|
||||
|
@ -295,3 +302,12 @@ type MetaStorer interface {
|
|||
Attachments(ctx domain.RequestContext, docID string) (a []attachment.Attachment, err error)
|
||||
SearchIndexCount(ctx domain.RequestContext) (c int, err error)
|
||||
}
|
||||
|
||||
// LabelStorer defines required methods for space label management
|
||||
type LabelStorer interface {
|
||||
Add(ctx domain.RequestContext, l label.Label) (err error)
|
||||
Get(ctx domain.RequestContext) (l []label.Label, err error)
|
||||
Update(ctx domain.RequestContext, l label.Label) (err error)
|
||||
Delete(ctx domain.RequestContext, id string) (rows int64, err error)
|
||||
RemoveReference(ctx domain.RequestContext, spaceID string) (err error)
|
||||
}
|
||||
|
|
|
@ -245,6 +245,14 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
err = h.Store.Space.IncrementContentCount(ctx, doc.SpaceID)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Commit and return new document template
|
||||
ctx.Transaction.Commit()
|
||||
|
||||
|
@ -430,6 +438,14 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
err = h.Store.Space.IncrementContentCount(ctx, d.SpaceID)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction.Commit()
|
||||
|
||||
h.Store.Audit.Record(ctx, audit.EventTypeTemplateUse)
|
||||
|
|
|
@ -405,7 +405,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// remove all associated roles for this user
|
||||
// Remove user's permissions
|
||||
_, err = h.Store.Permission.DeleteUserPermissions(ctx, userID)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
|
@ -414,6 +414,15 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// Remove all user groups memberships
|
||||
err = h.Store.Group.RemoveUserGroups(ctx, userID)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction.Commit()
|
||||
|
||||
h.Store.Audit.Record(ctx, audit.EventTypeUserDelete)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue