@crombolo/core 0.35.2 → 0.36.2
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/package.json +1 -1
- package/src/media-access.ts +25 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.2",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Domain model, entity keys and shared contracts for crombolo. No I/O.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
package/src/media-access.ts
CHANGED
|
@@ -6,21 +6,28 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
/** An item's own setting: `inherit` follows the nearest rule. */
|
|
9
|
-
export type MediaPolicy = 'inherit' | 'public' | 'groups' | 'creator' | 'none'
|
|
9
|
+
export type MediaPolicy = 'inherit' | 'public' | 'members' | 'groups' | 'creator' | 'none'
|
|
10
10
|
|
|
11
11
|
/** Who may see a file created in a folder later. */
|
|
12
|
-
export type NewMediaRead = 'public' | 'groups' | 'creator'
|
|
12
|
+
export type NewMediaRead = 'public' | 'members' | 'groups' | 'creator' | 'none'
|
|
13
13
|
/** Who may change a file created in a folder later. */
|
|
14
14
|
export type NewMediaWrite = 'groups' | 'creator' | 'none'
|
|
15
15
|
|
|
16
16
|
export const MEDIA_POLICIES: readonly MediaPolicy[] = [
|
|
17
17
|
'inherit',
|
|
18
18
|
'public',
|
|
19
|
+
'members',
|
|
19
20
|
'groups',
|
|
20
21
|
'creator',
|
|
21
22
|
'none',
|
|
22
23
|
]
|
|
23
|
-
export const NEW_MEDIA_READ: readonly NewMediaRead[] = [
|
|
24
|
+
export const NEW_MEDIA_READ: readonly NewMediaRead[] = [
|
|
25
|
+
'public',
|
|
26
|
+
'none',
|
|
27
|
+
'members',
|
|
28
|
+
'groups',
|
|
29
|
+
'creator',
|
|
30
|
+
]
|
|
24
31
|
export const NEW_MEDIA_WRITE: readonly NewMediaWrite[] = ['groups', 'creator', 'none']
|
|
25
32
|
|
|
26
33
|
/** A rule set on a media folder or item, governing it and everything below that sets none. */
|
|
@@ -31,6 +38,8 @@ export interface MediaRule {
|
|
|
31
38
|
publicRead: boolean
|
|
32
39
|
readGroups: readonly string[]
|
|
33
40
|
writeGroups: readonly string[]
|
|
41
|
+
readMembers?: readonly string[]
|
|
42
|
+
writeMembers?: readonly string[]
|
|
34
43
|
/** What files created below get; null leaves them following the rule. */
|
|
35
44
|
newRead: NewMediaRead | null
|
|
36
45
|
newWrite: NewMediaWrite | null
|
|
@@ -96,11 +105,17 @@ export function memberMay(
|
|
|
96
105
|
): boolean {
|
|
97
106
|
const policy = action === 'read' ? item.readPolicy : item.writePolicy
|
|
98
107
|
const groups = action === 'read' ? (rule?.readGroups ?? []) : (rule?.writeGroups ?? [])
|
|
108
|
+
const selected = action === 'read' ? rule?.readMembers : rule?.writeMembers
|
|
109
|
+
const allowed =
|
|
110
|
+
inGroups(groups, member) ||
|
|
111
|
+
Boolean(member && selected?.some((key) => key.toLowerCase() === member.key.toLowerCase()))
|
|
99
112
|
switch (policy) {
|
|
100
113
|
case 'public':
|
|
101
114
|
return action === 'read'
|
|
115
|
+
case 'members':
|
|
116
|
+
return action === 'read' && member !== undefined
|
|
102
117
|
case 'groups':
|
|
103
|
-
return
|
|
118
|
+
return allowed
|
|
104
119
|
case 'creator':
|
|
105
120
|
return (
|
|
106
121
|
member !== undefined &&
|
|
@@ -110,8 +125,8 @@ export function memberMay(
|
|
|
110
125
|
case 'none':
|
|
111
126
|
return false
|
|
112
127
|
case 'inherit':
|
|
113
|
-
if (action === 'read') return !rule || rule.publicRead ||
|
|
114
|
-
return
|
|
128
|
+
if (action === 'read') return !rule || rule.publicRead || allowed
|
|
129
|
+
return allowed
|
|
115
130
|
}
|
|
116
131
|
}
|
|
117
132
|
|
|
@@ -119,7 +134,10 @@ export function memberMay(
|
|
|
119
134
|
export const isProtectedMedia = (item: MediaItemAccess, rule: MediaRule | undefined): boolean =>
|
|
120
135
|
!memberMay('read', item, rule, undefined)
|
|
121
136
|
|
|
122
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* The policies a new file gets from the rule above it: `inherit`, following
|
|
139
|
+
* the folder live, unless the rule sets an explicit default for new files. Pure.
|
|
140
|
+
*/
|
|
123
141
|
export function stampedPolicies(rule: MediaRule | undefined): {
|
|
124
142
|
readPolicy: MediaPolicy
|
|
125
143
|
writePolicy: MediaPolicy
|