-
Notifications
You must be signed in to change notification settings - Fork 208
/
objects.go
567 lines (499 loc) · 18.1 KB
/
objects.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
// 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 entity provides types that mirror database tables.
package entity
import (
"fmt"
"strings"
"time"
)
// BaseEntity contains the database fields used in every table.
type BaseEntity struct {
ID uint64 `json:"-"`
RefID string `json:"id"`
Created time.Time `json:"created"`
Revised time.Time `json:"revised"`
}
// BaseEntityObfuscated is a mirror of BaseEntity,
// but with the fields invisible to JSON.
type BaseEntityObfuscated struct {
ID uint64 `json:"-"`
RefID string `json:"-"`
Created time.Time `json:"-"`
Revised time.Time `json:"-"`
}
// User defines a login.
type User struct {
BaseEntity
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Email string `json:"email"`
Initials string `json:"initials"`
Active bool `json:"active"`
Editor bool `json:"editor"`
Admin bool `json:"admin"`
Global bool `json:"global"`
Password string `json:"-"`
Salt string `json:"-"`
Reset string `json:"-"`
Accounts []Account `json:"accounts"`
}
// ProtectSecrets blanks sensitive data.
func (user *User) ProtectSecrets() {
user.Password = ""
user.Salt = ""
user.Reset = ""
}
// Fullname returns Firstname + Lastname.
func (user *User) Fullname() string {
return fmt.Sprintf("%s %s", user.Firstname, user.Lastname)
}
// GetAccount returns matching org account using orgID
func (user *User) GetAccount(orgID string) (a Account, found bool) {
for _, a := range user.Accounts {
if a.OrgID == orgID {
return a, true
}
}
return a, false
}
// Organization defines a company that uses this app.
type Organization struct {
BaseEntity
Company string `json:"-"`
Title string `json:"title"`
Message string `json:"message"`
URL string `json:"url"`
Domain string `json:"domain"`
Email string `json:"email"`
AllowAnonymousAccess bool `json:"allowAnonymousAccess"`
AuthProvider string `json:"authProvider"`
AuthConfig string `json:"authConfig"`
ConversionEndpoint string `json:"conversionEndpoint"`
Serial string `json:"-"`
Active bool `json:"-"`
}
// Account links a User to an Organization.
type Account struct {
BaseEntity
Admin bool `json:"admin"`
Editor bool `json:"editor"`
UserID string `json:"userId"`
OrgID string `json:"orgId"`
Company string `json:"company"`
Title string `json:"title"`
Message string `json:"message"`
Domain string `json:"domain"`
Active bool `json:"active"`
}
// Label defines a container for documents.
type Label struct {
BaseEntity
Name string `json:"name"`
OrgID string `json:"orgId"`
UserID string `json:"userId"`
Type FolderType `json:"folderType"`
}
// FolderType determines folder visibility.
type FolderType int
const (
// FolderTypePublic can be seen by anyone
FolderTypePublic FolderType = 1
// FolderTypePrivate can only be seen by the person who owns it
FolderTypePrivate FolderType = 2
// FolderTypeRestricted can be seen by selected users
FolderTypeRestricted FolderType = 3
)
// IsPublic means the folder can be seen by anyone.
func (l *Label) IsPublic() bool {
return l.Type == FolderTypePublic
}
// IsPrivate means the folder can only be seen by the person who owns it.
func (l *Label) IsPrivate() bool {
return l.Type == FolderTypePrivate
}
// IsRestricted means the folder can be seen by selected users.
func (l *Label) IsRestricted() bool {
return l.Type == FolderTypeRestricted
}
// LabelRole determines user permissions for a folder.
type LabelRole struct {
BaseEntityObfuscated
OrgID string `json:"-"`
LabelID string `json:"folderId"`
UserID string `json:"userId"`
CanView bool `json:"canView"`
CanEdit bool `json:"canEdit"`
}
// Document represents a document.
type Document struct {
BaseEntity
OrgID string `json:"orgId"`
LabelID string `json:"folderId"`
UserID string `json:"userId"`
Job string `json:"job"`
Location string `json:"location"`
Title string `json:"name"`
Excerpt string `json:"excerpt"`
Slug string `json:"-"`
Tags string `json:"tags"`
Template bool `json:"template"`
Layout string `json:"layout"`
}
// SetDefaults ensures on blanks and cleans.
func (d *Document) SetDefaults() {
d.Title = strings.TrimSpace(d.Title)
if len(d.Title) == 0 {
d.Title = "Document"
}
}
// Attachment represents an attachment to a document.
type Attachment struct {
BaseEntity
OrgID string `json:"orgId"`
DocumentID string `json:"documentId"`
Job string `json:"job"`
FileID string `json:"fileId"`
Filename string `json:"filename"`
Data []byte `json:"-"`
Extension string `json:"extension"`
}
// Page represents a section within a document.
type Page struct {
BaseEntity
OrgID string `json:"orgId"`
DocumentID string `json:"documentId"`
UserID string `json:"userId"`
ContentType string `json:"contentType"`
PageType string `json:"pageType"`
BlockID string `json:"blockId"`
Level uint64 `json:"level"`
Sequence float64 `json:"sequence"`
Title string `json:"title"`
Body string `json:"body"`
Revisions uint64 `json:"revisions"`
}
// SetDefaults ensures no blank values.
func (p *Page) SetDefaults() {
if len(p.ContentType) == 0 {
p.ContentType = "wysiwyg"
}
p.Title = strings.TrimSpace(p.Title)
}
// IsSectionType tells us that page is "words"
func (p *Page) IsSectionType() bool {
return p.PageType == "section"
}
// IsTabType tells us that page is "SaaS data embed"
func (p *Page) IsTabType() bool {
return p.PageType == "tab"
}
// PageMeta holds raw page data that is used to
// render the actual page data.
type PageMeta struct {
ID uint64 `json:"id"`
Created time.Time `json:"created"`
Revised time.Time `json:"revised"`
OrgID string `json:"orgId"`
UserID string `json:"userId"`
DocumentID string `json:"documentId"`
PageID string `json:"pageId"`
RawBody string `json:"rawBody"` // a blob of data
Config string `json:"config"` // JSON based custom config for this type
ExternalSource bool `json:"externalSource"` // true indicates data sourced externally
}
// SetDefaults ensures no blank values.
func (p *PageMeta) SetDefaults() {
if len(p.Config) == 0 {
p.Config = "{}"
}
}
// Revision holds the previous version of a Page.
type Revision struct {
BaseEntity
OrgID string `json:"orgId"`
DocumentID string `json:"documentId"`
PageID string `json:"pageId"`
OwnerID string `json:"ownerId"`
UserID string `json:"userId"`
ContentType string `json:"contentType"`
PageType string `json:"pageType"`
Title string `json:"title"`
Body string `json:"body"`
RawBody string `json:"rawBody"`
Config string `json:"config"`
Email string `json:"email"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Initials string `json:"initials"`
Revisions int `json:"revisions"`
}
// Block represents a section that has been published as a reusable content block.
type Block struct {
BaseEntity
OrgID string `json:"orgId"`
LabelID string `json:"folderId"`
UserID string `json:"userId"`
ContentType string `json:"contentType"`
PageType string `json:"pageType"`
Title string `json:"title"`
Body string `json:"body"`
Excerpt string `json:"excerpt"`
RawBody string `json:"rawBody"` // a blob of data
Config string `json:"config"` // JSON based custom config for this type
ExternalSource bool `json:"externalSource"` // true indicates data sourced externally
Used uint64 `json:"used"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
}
// DocumentMeta details who viewed the document.
type DocumentMeta struct {
Viewers []DocumentMetaViewer `json:"viewers"`
Editors []DocumentMetaEditor `json:"editors"`
}
// DocumentMetaViewer contains the "view" metatdata content.
type DocumentMetaViewer struct {
UserID string `json:"userId"`
Created time.Time `json:"created"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
}
// DocumentMetaEditor contains the "edit" metatdata content.
type DocumentMetaEditor struct {
PageID string `json:"pageId"`
UserID string `json:"userId"`
Action string `json:"action"`
Created time.Time `json:"created"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
}
// Search holds raw search results.
type Search struct {
ID string `json:"id"`
Created time.Time `json:"created"`
Revised time.Time `json:"revised"`
OrgID string
DocumentID string
Level uint64
Sequence float64
DocumentTitle string
Slug string
PageTitle string
Body string
}
// DocumentSearch represents 'presentable' search results.
type DocumentSearch struct {
ID string `json:"id"`
DocumentID string `json:"documentId"`
DocumentTitle string `json:"documentTitle"`
DocumentSlug string `json:"documentSlug"`
DocumentExcerpt string `json:"documentExcerpt"`
Tags string `json:"documentTags"`
PageTitle string `json:"pageTitle"`
LabelID string `json:"folderId"`
LabelName string `json:"folderName"`
FolderSlug string `json:"folderSlug"`
}
// SiteMeta holds information associated with an Organization.
type SiteMeta struct {
OrgID string `json:"orgId"`
Title string `json:"title"`
Message string `json:"message"`
URL string `json:"url"`
AllowAnonymousAccess bool `json:"allowAnonymousAccess"`
AuthProvider string `json:"authProvider"`
AuthConfig string `json:"authConfig"`
Version string `json:"version"`
Edition string `json:"edition"`
Valid bool `json:"valid"`
ConversionEndpoint string `json:"conversionEndpoint"`
}
// Template is used to create a new document.
// Template can consist of content, attachments and
// have associated meta data indentifying author, version
// contact details and more.
type Template struct {
ID string `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Author string `json:"author"`
Type TemplateType `json:"type"`
Dated time.Time `json:"dated"`
}
// TemplateType determines who can see a template.
type TemplateType int
const (
// TemplateTypePublic means anyone can see the template.
TemplateTypePublic TemplateType = 1
// TemplateTypePrivate means only the owner can see the template.
TemplateTypePrivate TemplateType = 2
// TemplateTypeRestricted means selected users can see the template.
TemplateTypeRestricted TemplateType = 3
)
// IsPublic means anyone can see the template.
func (t *Template) IsPublic() bool {
return t.Type == TemplateTypePublic
}
// IsPrivate means only the owner can see the template.
func (t *Template) IsPrivate() bool {
return t.Type == TemplateTypePrivate
}
// IsRestricted means selected users can see the template.
func (t *Template) IsRestricted() bool {
return t.Type == TemplateTypeRestricted
}
// FolderVisibility details who can see a particular folder
type FolderVisibility struct {
Name string `json:"name"`
LabelID string `json:"folderId"`
Type int `json:"folderType"`
UserID string `json:"userId"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Email string `json:"email"`
}
// SitemapDocument details a document that can be exposed via Sitemap.
type SitemapDocument struct {
DocumentID string
Document string
FolderID string
Folder string
Revised time.Time
}
// Link defines a reference between a section and another document/section/attachment.
type Link struct {
BaseEntity
OrgID string `json:"orgId"`
FolderID string `json:"folderId"`
UserID string `json:"userId"`
LinkType string `json:"linkType"`
SourceDocumentID string `json:"sourceDocumentId"`
SourcePageID string `json:"sourcePageId"`
TargetDocumentID string `json:"targetDocumentId"`
TargetID string `json:"targetId"`
Orphan bool `json:"orphan"`
}
// LinkCandidate defines a potential link to a document/section/attachment.
type LinkCandidate struct {
RefID string `json:"id"`
LinkType string `json:"linkType"`
FolderID string `json:"folderId"`
DocumentID string `json:"documentId"`
TargetID string `json:"targetId"`
Title string `json:"title"` // what we label the link
Context string `json:"context"` // additional context (e.g. excerpt, parent, file extension)
}
// Pin defines a saved link to a document or space
type Pin struct {
BaseEntity
OrgID string `json:"orgId"`
UserID string `json:"userId"`
FolderID string `json:"folderId"`
DocumentID string `json:"documentId"`
Pin string `json:"pin"`
Sequence int `json:"sequence"`
}
// UserActivity represents an activity undertaken by a user.
type UserActivity struct {
ID uint64 `json:"-"`
OrgID string `json:"orgId"`
UserID string `json:"userId"`
LabelID string `json:"folderId"`
SourceID string `json:"sourceId"`
SourceName string `json:"sourceName"` // e.g. Document or Space name
SourceType ActivitySourceType `json:"sourceType"`
ActivityType ActivityType `json:"activityType"`
Created time.Time `json:"created"`
}
// ActivitySourceType details where the activity occured.
type ActivitySourceType int
// ActivityType determines type of user activity
type ActivityType int
const (
// ActivitySourceTypeSpace indicates activity against a space.
ActivitySourceTypeSpace ActivitySourceType = 1
// ActivitySourceTypeDocument indicates activity against a document.
ActivitySourceTypeDocument ActivitySourceType = 2
)
const (
// ActivityTypeCreated records user document creation
ActivityTypeCreated ActivityType = 1
// ActivityTypeRead states user has read document
ActivityTypeRead ActivityType = 2
// ActivityTypeEdited states user has editing document
ActivityTypeEdited ActivityType = 3
// ActivityTypeDeleted records user deleting space/document
ActivityTypeDeleted ActivityType = 4
// ActivityTypeArchived records user archiving space/document
ActivityTypeArchived ActivityType = 5
// ActivityTypeApproved records user approval of document
ActivityTypeApproved ActivityType = 6
// ActivityTypeReverted records user content roll-back to previous version
ActivityTypeReverted ActivityType = 7
// ActivityTypePublishedTemplate records user creating new document template
ActivityTypePublishedTemplate ActivityType = 8
// ActivityTypePublishedBlock records user creating reusable content block
ActivityTypePublishedBlock ActivityType = 9
// ActivityTypeFeedback records user providing document feedback
ActivityTypeFeedback ActivityType = 10
)
// AppEvent represents an event initiated by a user.
type AppEvent struct {
ID uint64 `json:"-"`
OrgID string `json:"orgId"`
UserID string `json:"userId"`
Type string `json:"eventType"`
IP string `json:"ip"`
Created time.Time `json:"created"`
}
// EventType defines valid event entry types
type EventType string
const (
EventTypeDocumentAdd EventType = "added-document"
EventTypeDocumentUpload EventType = "uploaded-document"
EventTypeDocumentView EventType = "viewed-document"
EventTypeDocumentUpdate EventType = "updated-document"
EventTypeDocumentDelete EventType = "removed-document"
EventTypeDocumentRevisions EventType = "viewed-document-revisions"
EventTypeSpaceAdd EventType = "added-space"
EventTypeSpaceUpdate EventType = "updated-space"
EventTypeSpaceDelete EventType = "removed-space"
EventTypeSpacePermission EventType = "changed-space-permissions"
EventTypeSpaceJoin EventType = "joined-space"
EventTypeSpaceInvite EventType = "invited-space"
EventTypeSectionAdd EventType = "added-document-section"
EventTypeSectionUpdate EventType = "updated-document-section"
EventTypeSectionDelete EventType = "removed-document-section"
EventTypeSectionRollback EventType = "rolled-back-document-section"
EventTypeSectionResequence EventType = "resequenced-document-section"
EventTypeSectionCopy EventType = "copied-document-section"
EventTypeAttachmentAdd EventType = "added-attachment"
EventTypeAttachmentDownload EventType = "downloaded-attachment"
EventTypeAttachmentDelete EventType = "removed-attachment"
EventTypePinAdd EventType = "added-pin"
EventTypePinDelete EventType = "removed-pin"
EventTypePinResequence EventType = "resequenced-pin"
EventTypeBlockAdd EventType = "added-reusable-block"
EventTypeBlockUpdate EventType = "updated-reusable-block"
EventTypeBlockDelete EventType = "removed-reusable-block"
EventTypeTemplateAdd EventType = "added-document-template"
EventTypeTemplateUse EventType = "used-document-template"
EventTypeUserAdd EventType = "added-user"
EventTypeUserUpdate EventType = "updated-user"
EventTypeUserDelete EventType = "removed-user"
EventTypeUserPasswordReset EventType = "reset-user-password"
EventTypeAccountAdd EventType = "added-account"
EventTypeSystemLicense EventType = "changed-system-license"
EventTypeSystemAuth EventType = "changed-system-auth"
EventTypeSystemSMTP EventType = "changed-system-smtp"
EventTypeSessionStart EventType = "started-session"
EventTypeSearch EventType = "searched"
)