mirror of
https://github.com/documize/community.git
synced 2025-07-19 21:29:42 +02:00
Exclude draft versions from non-lifecycle users
Only show draft documents to those with lifecycle permissions. Closes #242
This commit is contained in:
parent
2fffb7869e
commit
e10d04d22e
5 changed files with 753 additions and 734 deletions
4
build.sh
4
build.sh
|
@ -49,10 +49,10 @@ for arch in amd64 ; do
|
||||||
for os in darwin linux windows ; do
|
for os in darwin linux windows ; do
|
||||||
if [ "$os" == "windows" ] ; then
|
if [ "$os" == "windows" ] ; then
|
||||||
echo "Compiling documize-community-$os-$arch.exe"
|
echo "Compiling documize-community-$os-$arch.exe"
|
||||||
env GOOS=$os GOARCH=$arch GODEBUG=tls13=1 go build -ldflags="-s -w" -gcflags="all=-trimpath=$GOPATH" -o bin/documize-community-$os-$arch.exe ./edition/community.go
|
env GOOS=$os GOARCH=$arch GODEBUG=tls13=1 go build -gcflags="all=-trimpath=$GOPATH" -o bin/documize-community-$os-$arch.exe ./edition/community.go
|
||||||
else
|
else
|
||||||
echo "Compiling documize-community-$os-$arch"
|
echo "Compiling documize-community-$os-$arch"
|
||||||
env GOOS=$os GOARCH=$arch GODEBUG=tls13=1 go build -ldflags="-s -w" -gcflags="all=-trimpath=$GOPATH" -o bin/documize-community-$os-$arch ./edition/community.go
|
env GOOS=$os GOARCH=$arch GODEBUG=tls13=1 go build -gcflags="all=-trimpath=$GOPATH" -o bin/documize-community-$os-$arch ./edition/community.go
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
|
@ -586,6 +586,12 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if draft document can been seen by user.
|
||||||
|
if document.Lifecycle == workflow.LifecycleDraft && !permission.CanViewDrafts(ctx, *h.Store, document.SpaceID) {
|
||||||
|
response.WriteForbiddenError(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// permissions
|
// permissions
|
||||||
perms, err := h.Store.Permission.GetUserSpacePermissions(ctx, document.SpaceID)
|
perms, err := h.Store.Permission.GetUserSpacePermissions(ctx, document.SpaceID)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
|
@ -633,14 +639,26 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Get version information for this document.
|
// Get version information for this document.
|
||||||
v := []doc.Version{}
|
v := []doc.Version{}
|
||||||
|
|
||||||
if len(document.GroupID) > 0 {
|
if len(document.GroupID) > 0 {
|
||||||
v, err = h.Store.Document.GetVersions(ctx, document.GroupID)
|
// Get versions.
|
||||||
if err != nil && err != sql.ErrNoRows {
|
vt, err := h.Store.Document.GetVersions(ctx, document.GroupID)
|
||||||
|
if err != nil {
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
h.Runtime.Log.Error(method, err)
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// What about draft document versions?
|
||||||
|
if record.DocumentLifecycle {
|
||||||
|
// We can see and manage document lifecycle so take all versions.
|
||||||
|
v = vt
|
||||||
|
} else {
|
||||||
|
// Only send back LIVE content because user cannot drafts.
|
||||||
|
for i := range vt {
|
||||||
|
if vt[i].Lifecycle == workflow.LifecycleLive {
|
||||||
|
v = append(v, vt[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare response.
|
// Prepare response.
|
||||||
|
|
|
@ -316,7 +316,7 @@ func (s Store) GetVersions(ctx domain.RequestContext, groupID string) (v []doc.V
|
||||||
v = []doc.Version{}
|
v = []doc.Version{}
|
||||||
|
|
||||||
err = s.Runtime.Db.Select(&v, s.Bind(`
|
err = s.Runtime.Db.Select(&v, s.Bind(`
|
||||||
SELECT c_versionid AS versionid, c_refid As documentid
|
SELECT c_versionid AS versionid, c_refid As documentid, c_lifecycle AS lifecycle
|
||||||
FROM dmz_doc
|
FROM dmz_doc
|
||||||
WHERE c_orgid=? AND c_groupid=?
|
WHERE c_orgid=? AND c_groupid=?
|
||||||
ORDER BY c_versionorder`),
|
ORDER BY c_versionorder`),
|
||||||
|
|
1452
embed/bindata.go
1452
embed/bindata.go
File diff suppressed because one or more lines are too long
|
@ -107,6 +107,7 @@ type SitemapDocument struct {
|
||||||
|
|
||||||
// Version points to a version of a document.
|
// Version points to a version of a document.
|
||||||
type Version struct {
|
type Version struct {
|
||||||
VersionID string `json:"versionId"`
|
VersionID string `json:"versionId"`
|
||||||
DocumentID string `json:"documentId"`
|
DocumentID string `json:"documentId"`
|
||||||
|
Lifecycle workflow.Lifecycle `json:"lifecycle"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue