mirror of
https://github.com/documize/community.git
synced 2025-08-05 05:25:27 +02:00
document list: show by selected space/category
This commit is contained in:
parent
2cee83d570
commit
5481de4e1c
21 changed files with 342 additions and 157 deletions
|
@ -415,6 +415,32 @@ func (h *Handler) GetDocumentCategoryMembership(w http.ResponseWriter, r *http.R
|
|||
response.WriteJSON(w, cat)
|
||||
}
|
||||
|
||||
/*
|
||||
- filter space documents by category -- URL param? nested route?
|
||||
*/
|
||||
// GetSpaceCategoryMembers returns category/document associations within space.
|
||||
func (h *Handler) GetSpaceCategoryMembers(w http.ResponseWriter, r *http.Request) {
|
||||
method := "category.GetSpaceCategoryMembers"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
spaceID := request.Param(r, "spaceID")
|
||||
if len(spaceID) == 0 {
|
||||
response.WriteMissingDataError(w, method, "spaceID")
|
||||
return
|
||||
}
|
||||
|
||||
if !permission.HasPermission(ctx, *h.Store, spaceID, pm.SpaceView) {
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
cat, err := h.Store.Category.GetSpaceCategoryMembership(ctx, spaceID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
h.Runtime.Log.Error("get document category membership for space", err)
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(cat) == 0 {
|
||||
cat = []category.Member{}
|
||||
}
|
||||
|
||||
response.WriteJSON(w, cat)
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ func (s Scope) Add(ctx domain.RequestContext, c category.Category) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// GetBySpace returns space categories for a user.
|
||||
// GetBySpace returns space categories accessible by user.
|
||||
// Context is used to for user ID.
|
||||
func (s Scope) GetBySpace(ctx domain.RequestContext, spaceID string) (c []category.Category, err error) {
|
||||
err = s.Runtime.Db.Select(&c, `
|
||||
|
@ -185,7 +185,7 @@ func (s Scope) GetSpaceCategorySummary(ctx domain.RequestContext, spaceID string
|
|||
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("select category summary for space %s", spaceID))
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -206,3 +206,25 @@ func (s Scope) GetDocumentCategoryMembership(ctx domain.RequestContext, document
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
// GetSpaceCategoryMembership returns category/document associations within space.
|
||||
func (s Scope) GetSpaceCategoryMembership(ctx domain.RequestContext, spaceID string) (c []category.Member, err error) {
|
||||
err = s.Runtime.Db.Select(&c, `
|
||||
SELECT id, refid, orgid, labelid, categoryid, documentid, created, revised FROM categorymember
|
||||
WHERE orgid=? AND labelid=?
|
||||
AND labelid IN (SELECT refid FROM permission WHERE orgid=? AND location='space' AND refid IN (
|
||||
SELECT refid from permission WHERE orgid=? AND who='user' AND whoid=? AND location='space' UNION ALL
|
||||
SELECT p.refid from permission p LEFT JOIN rolemember r ON p.whoid=r.roleid WHERE p.orgid=? AND p.who='role' AND p.location='space'
|
||||
AND p.action='view' AND r.userid=?
|
||||
))
|
||||
ORDER BY documentid`, ctx.OrgID, spaceID, ctx.OrgID, ctx.OrgID, ctx.UserID, ctx.OrgID, ctx.UserID)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("select all category/document membership for space %s", spaceID))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue