@meith/authorization 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +165 -0
- package/package.json +24 -0
- package/src/authorizer.ts +569 -0
- package/src/combine.ts +43 -0
- package/src/fixture.ts +226 -0
- package/src/index.ts +38 -0
- package/src/matrix-editor.ts +145 -0
- package/src/matrix.fixture.ts +131 -0
- package/src/memory-source.ts +68 -0
- package/src/resolve.ts +45 -0
- package/src/types.ts +158 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { ContentVisibility, ForumPermissions, PermissionSet } from '@meith/core'
|
|
2
|
+
|
|
3
|
+
export type ActorState = 'guest' | 'active' | 'banned' | 'awaiting_activation'
|
|
4
|
+
|
|
5
|
+
export interface Actor {
|
|
6
|
+
readonly userId: number | null
|
|
7
|
+
readonly groupIds: readonly number[]
|
|
8
|
+
readonly primaryGroupId: number | null
|
|
9
|
+
readonly state: ActorState
|
|
10
|
+
readonly global: PermissionSet
|
|
11
|
+
readonly permissionVersion: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type Action =
|
|
15
|
+
| 'forum.view'
|
|
16
|
+
| 'thread.view'
|
|
17
|
+
| 'thread.viewOthers'
|
|
18
|
+
| 'thread.post'
|
|
19
|
+
| 'reply.post'
|
|
20
|
+
| 'poll.post'
|
|
21
|
+
| 'poll.vote'
|
|
22
|
+
| 'thread.rate'
|
|
23
|
+
| 'post.editOwn'
|
|
24
|
+
| 'post.editOthers'
|
|
25
|
+
| 'post.deleteOwn'
|
|
26
|
+
| 'post.softDelete'
|
|
27
|
+
| 'post.restore'
|
|
28
|
+
| 'content.viewUnapproved'
|
|
29
|
+
| 'content.viewDeleted'
|
|
30
|
+
| 'content.approve'
|
|
31
|
+
| 'thread.lock'
|
|
32
|
+
| 'thread.stick'
|
|
33
|
+
| 'thread.move'
|
|
34
|
+
| 'thread.delete'
|
|
35
|
+
| 'thread.restore'
|
|
36
|
+
| 'thread.merge'
|
|
37
|
+
| 'thread.split'
|
|
38
|
+
| 'attachment.upload'
|
|
39
|
+
| 'attachment.download'
|
|
40
|
+
| 'forum.search'
|
|
41
|
+
| 'forum.subscribe'
|
|
42
|
+
| 'profile.view'
|
|
43
|
+
| 'memberlist.view'
|
|
44
|
+
| 'pm.use'
|
|
45
|
+
| 'avatar.upload'
|
|
46
|
+
| 'content.report'
|
|
47
|
+
| 'modcp.access'
|
|
48
|
+
| 'admincp.access'
|
|
49
|
+
| 'board.viewOffline'
|
|
50
|
+
| 'user.warn'
|
|
51
|
+
| 'flood.bypass'
|
|
52
|
+
| 'reputation.give'
|
|
53
|
+
| 'signature.use'
|
|
54
|
+
|
|
55
|
+
export type NumericGlobalPermission = {
|
|
56
|
+
[K in keyof PermissionSet]: PermissionSet[K] extends number ? K : never
|
|
57
|
+
}[keyof PermissionSet]
|
|
58
|
+
|
|
59
|
+
export type { ContentVisibility }
|
|
60
|
+
|
|
61
|
+
export interface Target {
|
|
62
|
+
readonly forumId?: number
|
|
63
|
+
readonly forum?: ForumPermissions
|
|
64
|
+
readonly ownerId?: number | null
|
|
65
|
+
readonly threadAuthorId?: number | null
|
|
66
|
+
readonly visibility?: ContentVisibility
|
|
67
|
+
readonly isForumModerator?: boolean
|
|
68
|
+
readonly moderatorRights?: ModeratorRights
|
|
69
|
+
readonly passwordRequired?: boolean
|
|
70
|
+
readonly passwordSatisfied?: boolean
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface ModeratedTarget extends Target {
|
|
74
|
+
readonly forumId: number
|
|
75
|
+
readonly forum: ForumPermissions
|
|
76
|
+
readonly moderatorRights: ModeratorRights
|
|
77
|
+
readonly isForumModerator: boolean
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface GroupDefaults {
|
|
81
|
+
readonly groupId: number
|
|
82
|
+
readonly permissions: PermissionSet
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface ForumOverride {
|
|
86
|
+
readonly forumId: number
|
|
87
|
+
readonly groupId: number
|
|
88
|
+
readonly overrides: Partial<ForumPermissions>
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface AuthorizationSource {
|
|
92
|
+
groupDefaults(groupIds: readonly number[]): Promise<readonly GroupDefaults[]>
|
|
93
|
+
ancestorChain(forumId: number): Promise<readonly number[]>
|
|
94
|
+
forumOverrides(
|
|
95
|
+
forumIds: readonly number[],
|
|
96
|
+
groupIds: readonly number[],
|
|
97
|
+
): Promise<readonly ForumOverride[]>
|
|
98
|
+
allForumIds(): Promise<readonly number[]>
|
|
99
|
+
|
|
100
|
+
allAncestorChains(): Promise<ReadonlyMap<number, readonly number[]>>
|
|
101
|
+
|
|
102
|
+
moderatorAppointments(
|
|
103
|
+
userId: number | null,
|
|
104
|
+
groupIds: readonly number[],
|
|
105
|
+
): Promise<readonly ModeratorAppointment[]>
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface ModeratorRights {
|
|
109
|
+
readonly canApproveContent: boolean
|
|
110
|
+
readonly canEditPosts: boolean
|
|
111
|
+
readonly canSoftDeletePosts: boolean
|
|
112
|
+
readonly canRestorePosts: boolean
|
|
113
|
+
readonly canOpenCloseThreads: boolean
|
|
114
|
+
readonly canStickThreads: boolean
|
|
115
|
+
readonly canMoveThreads: boolean
|
|
116
|
+
readonly canMergeThreads: boolean
|
|
117
|
+
readonly canSplitThreads: boolean
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface ModeratorAppointment extends ModeratorRights {
|
|
121
|
+
readonly forumId: number
|
|
122
|
+
readonly cascadeToSubforums: boolean
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function hasAnyModeratorRight(rights: ModeratorRights): boolean {
|
|
126
|
+
return (
|
|
127
|
+
rights.canApproveContent ||
|
|
128
|
+
rights.canEditPosts ||
|
|
129
|
+
rights.canSoftDeletePosts ||
|
|
130
|
+
rights.canRestorePosts ||
|
|
131
|
+
rights.canOpenCloseThreads ||
|
|
132
|
+
rights.canStickThreads ||
|
|
133
|
+
rights.canMoveThreads ||
|
|
134
|
+
rights.canMergeThreads ||
|
|
135
|
+
rights.canSplitThreads
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export const NO_MODERATOR_RIGHTS: ModeratorRights = {
|
|
140
|
+
canApproveContent: false,
|
|
141
|
+
canEditPosts: false,
|
|
142
|
+
canSoftDeletePosts: false,
|
|
143
|
+
canRestorePosts: false,
|
|
144
|
+
canOpenCloseThreads: false,
|
|
145
|
+
canStickThreads: false,
|
|
146
|
+
canMoveThreads: false,
|
|
147
|
+
canMergeThreads: false,
|
|
148
|
+
canSplitThreads: false,
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface ActorSource {
|
|
152
|
+
buildGuest(): Promise<Actor>
|
|
153
|
+
buildForUser(userId: number): Promise<Actor | null>
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface Visible {
|
|
157
|
+
readonly forumId: number
|
|
158
|
+
}
|