2017-07-26 10:50:26 +01:00
|
|
|
// 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 domain ...
|
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/documize/community/model/account"
|
2017-07-26 20:03:23 +01:00
|
|
|
"github.com/documize/community/model/attachment"
|
2017-07-26 10:50:26 +01:00
|
|
|
"github.com/documize/community/model/audit"
|
2017-07-26 20:03:23 +01:00
|
|
|
"github.com/documize/community/model/doc"
|
|
|
|
"github.com/documize/community/model/link"
|
2017-07-26 10:50:26 +01:00
|
|
|
"github.com/documize/community/model/org"
|
2017-07-26 20:03:23 +01:00
|
|
|
"github.com/documize/community/model/page"
|
2017-07-26 10:50:26 +01:00
|
|
|
"github.com/documize/community/model/pin"
|
|
|
|
"github.com/documize/community/model/space"
|
|
|
|
"github.com/documize/community/model/user"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Store provides access to data store (database)
|
|
|
|
type Store struct {
|
|
|
|
Space SpaceStorer
|
|
|
|
User UserStorer
|
|
|
|
Account AccountStorer
|
|
|
|
Organization OrganizationStorer
|
|
|
|
Pin PinStorer
|
|
|
|
Audit AuditStorer
|
|
|
|
Document DocumentStorer
|
2017-07-26 20:03:23 +01:00
|
|
|
Setting SettingStorer
|
|
|
|
Attachment AttachmentStorer
|
|
|
|
Link LinkStorer
|
|
|
|
Page PageStorer
|
2017-07-26 10:50:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// SpaceStorer defines required methods for space management
|
|
|
|
type SpaceStorer interface {
|
|
|
|
Add(ctx RequestContext, sp space.Space) (err error)
|
|
|
|
Get(ctx RequestContext, id string) (sp space.Space, err error)
|
|
|
|
PublicSpaces(ctx RequestContext, orgID string) (sp []space.Space, err error)
|
|
|
|
GetAll(ctx RequestContext) (sp []space.Space, err error)
|
|
|
|
Update(ctx RequestContext, sp space.Space) (err error)
|
|
|
|
ChangeOwner(ctx RequestContext, currentOwner, newOwner string) (err error)
|
|
|
|
Viewers(ctx RequestContext) (v []space.Viewer, err error)
|
|
|
|
Delete(ctx RequestContext, id string) (rows int64, err error)
|
|
|
|
AddRole(ctx RequestContext, r space.Role) (err error)
|
|
|
|
GetRoles(ctx RequestContext, labelID string) (r []space.Role, err error)
|
|
|
|
GetUserRoles(ctx RequestContext) (r []space.Role, err error)
|
|
|
|
DeleteRole(ctx RequestContext, roleID string) (rows int64, err error)
|
|
|
|
DeleteSpaceRoles(ctx RequestContext, spaceID string) (rows int64, err error)
|
|
|
|
DeleteUserSpaceRoles(ctx RequestContext, spaceID, userID string) (rows int64, err error)
|
|
|
|
MoveSpaceRoles(ctx RequestContext, previousLabel, newLabel string) (err error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserStorer defines required methods for user management
|
|
|
|
type UserStorer interface {
|
|
|
|
Add(ctx RequestContext, u user.User) (err error)
|
|
|
|
Get(ctx RequestContext, id string) (u user.User, err error)
|
|
|
|
GetByDomain(ctx RequestContext, domain, email string) (u user.User, err error)
|
|
|
|
GetByEmail(ctx RequestContext, email string) (u user.User, err error)
|
|
|
|
GetByToken(ctx RequestContext, token string) (u user.User, err error)
|
|
|
|
GetBySerial(ctx RequestContext, serial string) (u user.User, err error)
|
|
|
|
GetActiveUsersForOrganization(ctx RequestContext) (u []user.User, err error)
|
|
|
|
GetUsersForOrganization(ctx RequestContext) (u []user.User, err error)
|
|
|
|
GetSpaceUsers(ctx RequestContext, folderID string) (u []user.User, err error)
|
|
|
|
UpdateUser(ctx RequestContext, u user.User) (err error)
|
|
|
|
UpdateUserPassword(ctx RequestContext, userID, salt, password string) (err error)
|
|
|
|
DeactiveUser(ctx RequestContext, userID string) (err error)
|
|
|
|
ForgotUserPassword(ctx RequestContext, email, token string) (err error)
|
|
|
|
CountActiveUsers(ctx RequestContext) (c int)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AccountStorer defines required methods for account management
|
|
|
|
type AccountStorer interface {
|
|
|
|
Add(ctx RequestContext, account account.Account) (err error)
|
|
|
|
GetUserAccount(ctx RequestContext, userID string) (account account.Account, err error)
|
|
|
|
GetUserAccounts(ctx RequestContext, userID string) (t []account.Account, err error)
|
|
|
|
GetAccountsByOrg(ctx RequestContext) (t []account.Account, err error)
|
|
|
|
DeleteAccount(ctx RequestContext, ID string) (rows int64, err error)
|
|
|
|
UpdateAccount(ctx RequestContext, account account.Account) (err error)
|
|
|
|
HasOrgAccount(ctx RequestContext, orgID, userID string) bool
|
|
|
|
CountOrgAccounts(ctx RequestContext) int
|
|
|
|
}
|
|
|
|
|
|
|
|
// OrganizationStorer defines required methods for organization management
|
|
|
|
type OrganizationStorer interface {
|
|
|
|
AddOrganization(ctx RequestContext, org org.Organization) error
|
|
|
|
GetOrganization(ctx RequestContext, id string) (org org.Organization, err error)
|
|
|
|
GetOrganizationByDomain(ctx RequestContext, subdomain string) (org org.Organization, err error)
|
|
|
|
UpdateOrganization(ctx RequestContext, org org.Organization) (err error)
|
|
|
|
DeleteOrganization(ctx RequestContext, orgID string) (rows int64, err error)
|
|
|
|
RemoveOrganization(ctx RequestContext, orgID string) (err error)
|
|
|
|
UpdateAuthConfig(ctx RequestContext, org org.Organization) (err error)
|
|
|
|
CheckDomain(ctx RequestContext, domain string) string
|
|
|
|
}
|
|
|
|
|
|
|
|
// PinStorer defines required methods for pin management
|
|
|
|
type PinStorer interface {
|
|
|
|
Add(ctx RequestContext, pin pin.Pin) (err error)
|
|
|
|
GetPin(ctx RequestContext, id string) (pin pin.Pin, err error)
|
|
|
|
GetUserPins(ctx RequestContext, userID string) (pins []pin.Pin, err error)
|
|
|
|
UpdatePin(ctx RequestContext, pin pin.Pin) (err error)
|
|
|
|
UpdatePinSequence(ctx RequestContext, pinID string, sequence int) (err error)
|
|
|
|
DeletePin(ctx RequestContext, id string) (rows int64, err error)
|
|
|
|
DeletePinnedSpace(ctx RequestContext, spaceID string) (rows int64, err error)
|
|
|
|
DeletePinnedDocument(ctx RequestContext, documentID string) (rows int64, err error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AuditStorer defines required methods for audit trails
|
|
|
|
type AuditStorer interface {
|
|
|
|
Record(ctx RequestContext, t audit.EventType)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DocumentStorer defines required methods for document handling
|
|
|
|
type DocumentStorer interface {
|
2017-07-26 20:03:23 +01:00
|
|
|
Get(ctx RequestContext, id string) (document doc.Document, err error)
|
2017-07-26 10:50:26 +01:00
|
|
|
MoveDocumentSpace(ctx RequestContext, id, move string) (err error)
|
2017-07-26 20:03:23 +01:00
|
|
|
PublicDocuments(ctx RequestContext, orgID string) (documents []doc.SitemapDocument, err error)
|
2017-07-26 10:50:26 +01:00
|
|
|
}
|
|
|
|
|
2017-07-26 20:03:23 +01:00
|
|
|
// SettingStorer defines required methods for persisting global and user level settings
|
|
|
|
type SettingStorer interface {
|
|
|
|
Get(ctx RequestContext, area, path string) string
|
|
|
|
Set(ctx RequestContext, area, value string) error
|
|
|
|
GetUser(ctx RequestContext, orgID, userID, area, path string) string
|
|
|
|
SetUser(ctx RequestContext, orgID, userID, area, json string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// AttachmentStorer defines required methods for persisting document attachments
|
|
|
|
type AttachmentStorer interface {
|
|
|
|
Add(ctx RequestContext, a attachment.Attachment) (err error)
|
|
|
|
GetAttachment(ctx RequestContext, orgID, attachmentID string) (a attachment.Attachment, err error)
|
|
|
|
GetAttachments(ctx RequestContext, docID string) (a []attachment.Attachment, err error)
|
|
|
|
GetAttachmentsWithData(ctx RequestContext, docID string) (a []attachment.Attachment, err error)
|
|
|
|
Delete(ctx RequestContext, id string) (rows int64, err error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// LinkStorer defines required methods for persisting content links
|
|
|
|
type LinkStorer interface {
|
|
|
|
Add(ctx RequestContext, l link.Link) (err error)
|
|
|
|
SearchCandidates(ctx RequestContext, keywords string) (docs []link.Candidate, pages []link.Candidate, attachments []link.Candidate, err error)
|
|
|
|
GetDocumentOutboundLinks(ctx RequestContext, documentID string) (links []link.Link, err error)
|
|
|
|
GetPageLinks(ctx RequestContext, documentID, pageID string) (links []link.Link, err error)
|
|
|
|
MarkOrphanDocumentLink(ctx RequestContext, documentID string) (err error)
|
|
|
|
MarkOrphanPageLink(ctx RequestContext, pageID string) (err error)
|
|
|
|
MarkOrphanAttachmentLink(ctx RequestContext, attachmentID string) (err error)
|
|
|
|
DeleteSourcePageLinks(ctx RequestContext, pageID string) (rows int64, err error)
|
|
|
|
DeleteSourceDocumentLinks(ctx RequestContext, documentID string) (rows int64, err error)
|
|
|
|
DeleteLink(ctx RequestContext, id string) (rows int64, err error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PageStorer defines required methods for persisting document pages
|
|
|
|
type PageStorer interface {
|
|
|
|
GetPagesWithoutContent(ctx RequestContext, documentID string) (pages []page.Page, err error)
|
|
|
|
}
|