-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.go
124 lines (112 loc) · 5.13 KB
/
service.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
package forge
import (
"context"
"fmt"
)
type Service interface {
FindEntryTypes(ctx context.Context) ([]string, error)
FindBaseEntryTypes(ctx context.Context) ([]string, error)
FindOverrideEntryTypes(ctx context.Context) ([]string, error)
AddEntryType(ctx context.Context, name string) error
RenameEntryType(ctx context.Context, name, newName string) error
DeleteEntryType(ctx context.Context, name string) error
FindDefaults(ctx context.Context, find DefaultFinder) ([]*Default, error)
AddDefault(ctx context.Context, d *Default) error
UpdateDefault(ctx context.Context, upd DefaultUpdater) error
DeleteDefault(ctx context.Context, entType, ctg, name string) error
FindGlobals(ctx context.Context, find GlobalFinder) ([]*Global, error)
GetGlobal(ctx context.Context, entType, name string) (*Global, error)
AddGlobal(ctx context.Context, d *Global) error
UpdateGlobal(ctx context.Context, upd GlobalUpdater) error
DeleteGlobal(ctx context.Context, entType, name string) error
FindEntries(ctx context.Context, find EntryFinder) ([]*Entry, error)
SearchEntries(ctx context.Context, search EntrySearcher) ([]*Entry, error)
CountAllSubEntries(ctx context.Context, path string) (int, error)
GetEntry(ctx context.Context, path string) (*Entry, error)
AddEntry(ctx context.Context, ent *Entry) error
RenameEntry(ctx context.Context, path string, newName string) error
ArchiveEntry(ctx context.Context, path string) error
UnarchiveEntry(ctx context.Context, path string) error
DeleteEntry(ctx context.Context, path string) error
DeleteEntryRecursive(ctx context.Context, path string) error
AddThumbnail(ctx context.Context, thumb *Thumbnail) error
UpdateThumbnail(ctx context.Context, upd ThumbnailUpdater) error
GetThumbnail(ctx context.Context, path string) (*Thumbnail, error)
DeleteThumbnail(ctx context.Context, path string) error
EntryProperties(ctx context.Context, path string) ([]*Property, error)
GetProperty(ctx context.Context, path, name string) (*Property, error)
UpdateProperty(ctx context.Context, upd PropertyUpdater) error
UpdateProperties(ctx context.Context, upds []PropertyUpdater) error
EntryEnvirons(ctx context.Context, path string) ([]*Property, error)
GetEnvirons(ctx context.Context, path string) ([]*Property, error)
GetEnviron(ctx context.Context, path, name string) (*Property, error)
AddEnviron(ctx context.Context, p *Property) error
UpdateEnviron(ctx context.Context, upd PropertyUpdater) error
DeleteEnviron(ctx context.Context, path string, name string) error
EntryAccessList(ctx context.Context, path string) ([]*Access, error)
GetAccessList(ctx context.Context, path string) ([]*Access, error)
GetAccess(ctx context.Context, path, name string) (*Access, error)
AddAccess(ctx context.Context, ac *Access) error
UpdateAccess(ctx context.Context, upd AccessUpdater) error
DeleteAccess(ctx context.Context, path string, name string) error
IsAdmin(ctx context.Context, user string) (bool, error)
FindLogs(ctx context.Context, find LogFinder) ([]*Log, error)
GetLogs(ctx context.Context, path, ctg, name string) ([]*Log, error)
FindUsers(ctx context.Context, find UserFinder) ([]*User, error)
AddUser(ctx context.Context, u *User) error
UpdateUser(ctx context.Context, upd UserUpdater) error
GetUser(ctx context.Context, user string) (*User, error)
GetUserSetting(ctx context.Context, user string) (*UserSetting, error)
UpdateUserSetting(ctx context.Context, upd UserSettingUpdater) error
FindUserData(ctx context.Context, find UserDataFinder) ([]*UserDataSection, error)
AddUserDataSection(ctx context.Context, user, section string) error
GetUserDataSection(ctx context.Context, user, section string) (*UserDataSection, error)
DeleteUserDataSection(ctx context.Context, user, section string) error
GetUserData(ctx context.Context, user, section, key string) (string, error)
SetUserData(ctx context.Context, user, section, key, value string) error
DeleteUserData(ctx context.Context, user, section, key string) error
FindGroups(ctx context.Context, find GroupFinder) ([]*Group, error)
AddGroup(ctx context.Context, g *Group) error
UpdateGroup(ctx context.Context, upd GroupUpdater) error
FindGroupMembers(ctx context.Context, find MemberFinder) ([]*Member, error)
AddGroupMember(ctx context.Context, m *Member) error
DeleteGroupMember(ctx context.Context, group, member string) error
}
type NotFoundError struct {
err error
}
func (e *NotFoundError) Error() string {
if e.err == nil {
return ""
}
return e.err.Error()
}
func NotFound(s string, is ...any) *NotFoundError {
return &NotFoundError{fmt.Errorf(s, is...)}
}
type UnauthorizedError struct {
err error
}
func (e *UnauthorizedError) Error() string {
if e.err == nil {
return ""
}
return e.err.Error()
}
func Unauthorized(s string, is ...any) *UnauthorizedError {
return &UnauthorizedError{fmt.Errorf(s, is...)}
}
type contextKey int
const (
userNameContextKey = contextKey(iota + 1)
)
func ContextWithUserName(ctx context.Context, email string) context.Context {
return context.WithValue(ctx, userNameContextKey, email)
}
func UserNameFromContext(ctx context.Context) string {
email := ctx.Value(userNameContextKey)
if email == nil {
return ""
}
return email.(string)
}