mirror of
https://github.com/documize/community.git
synced 2025-07-24 15:49:44 +02:00
Persist space permissions for groups and users
This commit is contained in:
parent
0d39f7251e
commit
7ccb3b4658
16 changed files with 320 additions and 157 deletions
|
@ -41,3 +41,27 @@ type Record struct {
|
|||
Name string `json:"name"`
|
||||
Purpose string `json:"purpose"`
|
||||
}
|
||||
|
||||
// UserHasGroupMembership returns true if user belongs to specified group.
|
||||
func UserHasGroupMembership(r []Record, groupID, userID string) bool {
|
||||
for i := range r {
|
||||
if r[i].RoleID == groupID && r[i].UserID == userID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// FilterGroupRecords returns only those records matching group ID.
|
||||
func FilterGroupRecords(r []Record, groupID string) (m []Record) {
|
||||
m = []Record{}
|
||||
|
||||
for i := range r {
|
||||
if r[i].RoleID == groupID {
|
||||
m = append(m, r[i])
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -15,11 +15,12 @@ package permission
|
|||
// This data structure is made from database permission records for the document,
|
||||
// and it is designed to be sent to HTTP clients (web, mobile).
|
||||
type DocumentRecord struct {
|
||||
OrgID string `json:"orgId"`
|
||||
DocumentID string `json:"documentId"`
|
||||
UserID string `json:"userId"`
|
||||
DocumentRoleEdit bool `json:"documentRoleEdit"`
|
||||
DocumentRoleApprove bool `json:"documentRoleApprove"`
|
||||
OrgID string `json:"orgId"`
|
||||
DocumentID string `json:"documentId"`
|
||||
WhoID string `json:"whoId"`
|
||||
Who WhoType `json:"who"`
|
||||
DocumentRoleEdit bool `json:"documentRoleEdit"`
|
||||
DocumentRoleApprove bool `json:"documentRoleApprove"`
|
||||
}
|
||||
|
||||
// DecodeUserDocumentPermissions returns a flat, usable permission summary record
|
||||
|
@ -29,7 +30,8 @@ func DecodeUserDocumentPermissions(perm []Permission) (r DocumentRecord) {
|
|||
|
||||
if len(perm) > 0 {
|
||||
r.OrgID = perm[0].OrgID
|
||||
r.UserID = perm[0].WhoID
|
||||
r.WhoID = perm[0].WhoID
|
||||
r.Who = perm[0].Who
|
||||
r.DocumentID = perm[0].RefID
|
||||
}
|
||||
|
||||
|
@ -67,8 +69,8 @@ func HasAnyDocumentPermission(p DocumentRecord) bool {
|
|||
func EncodeDocumentRecord(r DocumentRecord, a Action) (p Permission) {
|
||||
p = Permission{}
|
||||
p.OrgID = r.OrgID
|
||||
p.Who = UserPermission
|
||||
p.WhoID = r.UserID
|
||||
p.WhoID = r.WhoID
|
||||
p.Who = r.Who
|
||||
p.Location = LocationDocument
|
||||
p.RefID = r.DocumentID
|
||||
p.Action = a
|
||||
|
|
|
@ -15,19 +15,21 @@ package permission
|
|||
// This data structure is made from database permission records for the space,
|
||||
// and it is designed to be sent to HTTP clients (web, mobile).
|
||||
type Record struct {
|
||||
OrgID string `json:"orgId"`
|
||||
SpaceID string `json:"folderId"`
|
||||
UserID string `json:"userId"`
|
||||
SpaceView bool `json:"spaceView"`
|
||||
SpaceManage bool `json:"spaceManage"`
|
||||
SpaceOwner bool `json:"spaceOwner"`
|
||||
DocumentAdd bool `json:"documentAdd"`
|
||||
DocumentEdit bool `json:"documentEdit"`
|
||||
DocumentDelete bool `json:"documentDelete"`
|
||||
DocumentMove bool `json:"documentMove"`
|
||||
DocumentCopy bool `json:"documentCopy"`
|
||||
DocumentTemplate bool `json:"documentTemplate"`
|
||||
DocumentApprove bool `json:"documentApprove"`
|
||||
OrgID string `json:"orgId"`
|
||||
SpaceID string `json:"folderId"`
|
||||
WhoID string `json:"whoId"`
|
||||
Who WhoType `json:"who"`
|
||||
SpaceView bool `json:"spaceView"`
|
||||
SpaceManage bool `json:"spaceManage"`
|
||||
SpaceOwner bool `json:"spaceOwner"`
|
||||
DocumentAdd bool `json:"documentAdd"`
|
||||
DocumentEdit bool `json:"documentEdit"`
|
||||
DocumentDelete bool `json:"documentDelete"`
|
||||
DocumentMove bool `json:"documentMove"`
|
||||
DocumentCopy bool `json:"documentCopy"`
|
||||
DocumentTemplate bool `json:"documentTemplate"`
|
||||
DocumentApprove bool `json:"documentApprove"`
|
||||
Name string `json:"name"` // read-only, user or group name
|
||||
}
|
||||
|
||||
// DecodeUserPermissions returns a flat, usable permission summary record
|
||||
|
@ -37,7 +39,8 @@ func DecodeUserPermissions(perm []Permission) (r Record) {
|
|||
|
||||
if len(perm) > 0 {
|
||||
r.OrgID = perm[0].OrgID
|
||||
r.UserID = perm[0].WhoID
|
||||
r.WhoID = perm[0].WhoID
|
||||
r.Who = perm[0].Who
|
||||
r.SpaceID = perm[0].RefID
|
||||
}
|
||||
|
||||
|
@ -118,8 +121,8 @@ func HasAnyPermission(p Record) bool {
|
|||
func EncodeRecord(r Record, a Action) (p Permission) {
|
||||
p = Permission{}
|
||||
p.OrgID = r.OrgID
|
||||
p.Who = UserPermission
|
||||
p.WhoID = r.UserID
|
||||
p.Who = r.Who
|
||||
p.WhoID = r.WhoID
|
||||
p.Location = LocationSpace
|
||||
p.RefID = r.SpaceID
|
||||
p.Action = a
|
||||
|
|
|
@ -71,3 +71,8 @@ func Exists(users []User, userID string) bool {
|
|||
|
||||
return false
|
||||
}
|
||||
|
||||
const (
|
||||
// EveryoneUserID provides a shortcut to state "all authenticated users".
|
||||
EveryoneUserID string = "0"
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue