@paramira/access 0.1.0 → 0.2.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/README.md CHANGED
@@ -24,6 +24,7 @@ keeps); signed out is `null`. Every signed-in account is **community**.
24
24
  | contributor | enter the admin; write, edit, translate, send for review; review translations; comment; add media; the glossary; assess ideas (feasible or not); the dictionary: edit, review proposals, import, the grammar profile, recordings |
25
25
  | editor | the contributor's writing; review, publish, return, archive, hide and show, restore; decide on suggestions; remove media; moderate discussions; review new ideas; the dictionary: the contributor's, and hide and show, archive, publish documented terms (ADR-0056) |
26
26
  | customer | help agreed (ADR-0041): create their community's team (ADR-0042) |
27
+ | speaker | known to speak the language, given by an admin (readfine ADR-0061): the dictionary's community permissions, answer and correct checks (`lexicon.check`), record learner trials (`lexicon.trial`, contributors too) |
27
28
  | admin | enter the admin; settings, the tools catalog, people and roles (never admin itself), all requests and moving them along, every team and its limits, the log; assess and plan ideas |
28
29
 
29
30
  `assert` throws an `AccessError` with `statusCode` 401 (signed out) or 403.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paramira/access",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Who may do what on a site: roles from identity-provider groups, permissions that add up, deny by default",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // Every server handler asks `can()` (or `assert()`) before acting.
5
5
 
6
6
  export const GROUP_PREFIX = 'paramira-web-'
7
- export const ROLES = ['community', 'contributor', 'editor', 'customer', 'admin']
7
+ export const ROLES = ['community', 'contributor', 'editor', 'customer', 'speaker', 'admin', 'treasurer']
8
8
 
9
9
  /** What each role may do. Signed-out visitors may only read. */
10
10
  export const PERMISSIONS = {
@@ -43,7 +43,11 @@ export const PERMISSIONS = {
43
43
  'lexicon.review',
44
44
  'lexicon.import',
45
45
  'lexicon.profile',
46
- 'lexicon.record'
46
+ 'lexicon.record',
47
+ // Record a learner trial an observer watched (readfine ADR-0064).
48
+ 'lexicon.trial',
49
+ // The home carousel (design 0016, ADR-0072): cards point to published items.
50
+ 'carousel.edit'
47
51
  ],
48
52
  editor: [
49
53
  'admin.enter',
@@ -76,12 +80,25 @@ export const PERMISSIONS = {
76
80
  // Hide and restore, archive, and publish documented terms (ADR-0056).
77
81
  'lexicon.hide',
78
82
  'lexicon.archive',
79
- 'lexicon.document'
83
+ 'lexicon.document',
84
+ 'carousel.edit'
80
85
  ],
81
86
  // Help agreed (ADR-0041): they may make their community's team (ADR-0042).
82
87
  customer: [
83
88
  'team.create'
84
89
  ],
90
+ // Someone known to speak the language (readfine design 0014, ADR-0061):
91
+ // an admin gives it by hand. Speakers answer and correct the dictionary's
92
+ // checks and record learner trials; they also get the community role's
93
+ // dictionary permissions, so the role works on its own. Contributors and
94
+ // editors don't check with their own role: someone can hold both.
95
+ speaker: [
96
+ 'lexicon.propose',
97
+ 'lexicon.confirm',
98
+ 'lexicon.report',
99
+ 'lexicon.check',
100
+ 'lexicon.trial'
101
+ ],
85
102
  admin: [
86
103
  'admin.enter',
87
104
  'settings.edit',
@@ -102,12 +119,23 @@ export const PERMISSIONS = {
102
119
  'invite.create',
103
120
  'invite.cancel',
104
121
  'idea.assess',
105
- 'idea.plan'
122
+ 'idea.plan',
123
+ 'carousel.edit'
124
+ ],
125
+ // The association's treasurer and at most one deputy (ADR-0069): given
126
+ // only in Authentik, like admin. Reads paid requests and confirms their
127
+ // payments; writes no quote and no invoice.
128
+ treasurer: [
129
+ 'admin.enter',
130
+ 'request.read',
131
+ 'payment.read',
132
+ 'payment.confirm',
133
+ 'paidSupport.report'
106
134
  ]
107
135
  }
108
136
 
109
- /** Roles an admin may give or take from the site; admin only in the identity provider. */
110
- export const ASSIGNABLE = ['community', 'contributor', 'editor', 'customer']
137
+ /** Roles an admin may give or take from the site; admin and treasurer only in the identity provider. */
138
+ export const ASSIGNABLE = ['community', 'contributor', 'editor', 'customer', 'speaker']
111
139
 
112
140
  export class AccessError extends Error {
113
141
  constructor (status, message) {
@@ -142,14 +170,15 @@ export function permissionsOf (session) {
142
170
  * May the session do `action` (on `resource`)?
143
171
  *
144
172
  * - `request.read`: anyone signed in reads their own requests
145
- * (`resource.owner` is their account); an admin reads all.
173
+ * (`resource.owner` is their account); an admin or a treasurer reads all
174
+ * (the site shows a treasurer only the paid ones).
146
175
  * - `people.assign`: only the assignable roles (`resource.role`), never admin.
147
176
  */
148
177
  export function can (session, action, resource = {}) {
149
178
  const granted = permissionsOf(session)
150
179
  if (!granted.has(action)) return false
151
180
  const roles = rolesOf(session)
152
- if (action === 'request.read' && !roles.includes('admin')) {
181
+ if (action === 'request.read' && !roles.includes('admin') && !roles.includes('treasurer')) {
153
182
  return resource.owner !== undefined && resource.owner !== null && String(resource.owner) === String(session.user.pk)
154
183
  }
155
184
  if (action === 'people.assign') return ASSIGNABLE.includes(resource.role)