@things-factory/auth-ui 10.1.3 → 10.1.6

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.
Files changed (38) hide show
  1. package/dist-client/components/change-password.d.ts +11 -0
  2. package/dist-client/components/change-password.js +103 -6
  3. package/dist-client/components/change-password.js.map +1 -1
  4. package/dist-client/components/role-detail.d.ts +144 -0
  5. package/dist-client/components/role-detail.js +698 -0
  6. package/dist-client/components/role-detail.js.map +1 -0
  7. package/dist-client/components/user-detail.d.ts +151 -0
  8. package/dist-client/components/user-detail.js +631 -0
  9. package/dist-client/components/user-detail.js.map +1 -0
  10. package/dist-client/components/user-invite.d.ts +80 -0
  11. package/dist-client/components/user-invite.js +422 -0
  12. package/dist-client/components/user-invite.js.map +1 -0
  13. package/dist-client/entries/auth/activate.d.ts +0 -1
  14. package/dist-client/entries/auth/activate.js +0 -8
  15. package/dist-client/entries/auth/activate.js.map +1 -1
  16. package/dist-client/pages/role/role-list-page.d.ts +112 -0
  17. package/dist-client/pages/role/role-list-page.js +514 -0
  18. package/dist-client/pages/role/role-list-page.js.map +1 -0
  19. package/dist-client/pages/role/role-privilege-page.d.ts +123 -0
  20. package/dist-client/pages/role/role-privilege-page.js +801 -0
  21. package/dist-client/pages/role/role-privilege-page.js.map +1 -0
  22. package/dist-client/pages/user/user-list-page.d.ts +88 -0
  23. package/dist-client/pages/user/user-list-page.js +474 -0
  24. package/dist-client/pages/user/user-list-page.js.map +1 -0
  25. package/dist-client/route.js +5 -2
  26. package/dist-client/route.js.map +1 -1
  27. package/dist-client/tsconfig.tsbuildinfo +1 -1
  28. package/dist-server/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +4 -4
  30. package/things-factory.config.js +3 -2
  31. package/translations/en.json +46 -3
  32. package/translations/ja.json +0 -2
  33. package/translations/ko.json +47 -4
  34. package/translations/ms.json +0 -2
  35. package/translations/zh.json +0 -2
  36. package/dist-client/components/contact-us.d.ts +0 -20
  37. package/dist-client/components/contact-us.js +0 -121
  38. package/dist-client/components/contact-us.js.map +0 -1
@@ -0,0 +1,801 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import '@material/web/icon/icon.js';
3
+ import '@material/web/textfield/filled-text-field.js';
4
+ import '@material/web/checkbox/checkbox.js';
5
+ import '@operato/oops/ox-oops-note.js';
6
+ import gql from 'graphql-tag';
7
+ import { css, html, nothing } from 'lit';
8
+ import { customElement, property, state } from 'lit/decorators.js';
9
+ import { client, gqlContext } from '@operato/graphql';
10
+ import { i18next, localize } from '@operato/i18n';
11
+ import { PageView } from '@operato/shell';
12
+ import { CommonHeaderStyles, ScrollbarStyles } from '@operato/styles';
13
+ import { getDomain } from '@things-factory/auth-base/dist-client';
14
+ /** 아는 축은 사람 말로 쓰고, 그 순서로 세운다. 모르는 축은 자기 이름으로 뒤에 붙는다. */
15
+ const KNOWN_AXES = ['query', 'mutation', 'execute'];
16
+ const AXIS_LABEL = {
17
+ query: 'label.read',
18
+ mutation: 'label.write',
19
+ execute: 'label.execute'
20
+ };
21
+ /**
22
+ * 한 역할이 무엇을 열 수 있나 — **왼쪽에 모듈, 오른쪽에 그 모듈에서 되는 일.**
23
+ *
24
+ * ── 왜 페이지인가 (UX 레인, 2026-09-10) ─────────────────────────────────────
25
+ * 처음에는 이것을 팝업에 넣었고 사용자에게 「팝업이 너무 작다」를 들었다. 그때 `size` 를 키우는
26
+ * 것으로 답했는데 그것이 증상 처리였다 — **모듈이 46개고 각 줄에 설명 문장이 붙으면 팝업에
27
+ * 안 들어간다.** 자리 자체가 틀렸다.
28
+ *
29
+ * 그리고 이 저장소의 관례가 그렇다: `editable` 컬럼 139 파일 대 `openPopup` 96 파일 —
30
+ * **격자에서 고치고, 팝업은 격자가 못 담는 것에 쓴다.** 역할의 이름과 설명은 목록 격자에서
31
+ * 고치고(`updateMultipleRole`), 권한은 격자가 못 담으므로 이 페이지가 받는다.
32
+ *
33
+ * ── 「배울 것이 없다」를 고치는 자리 ────────────────────────────────────────
34
+ * 사용자 평가가 이랬다 — **「화면으로부터 배울 수 있는 것이 없고, 혼란스럽고, 어렵고, 불편하다」.**
35
+ * 옛 격자는 `board` 라고만 쓰고 「쓰기를 켜면 이 사람이 무엇을 할 수 있게 되나」를 어디에도 안
36
+ * 적었다. 설명을 체크박스 `title` 에 숨겨 놨는데 마우스를 올려야 나오고, 그건 배우는 길이 아니다.
37
+ *
38
+ * 그래서 **설명은 본문이다.** 체크박스 옆에 문장이 함께 선다.
39
+ *
40
+ * ⚠ **그런데 그 문장이 아직 시스템에 없다.** `Privilege.description` 은 칸도 있고
41
+ * `createPrivilege` 가 받지만, 부팅 동기화는 `{ category, name }` 둘만 저장하고
42
+ * (`auth-base/server/index.ts:34-36`) 그 mutation 을 부르는 화면이 없다 — 713개 선언이 전부
43
+ * 빈 설명이다. 그래서 이 화면은 **없으면 없다고 말한다.** 코드 낱말(`board mutation`)을 다시
44
+ * 보여 주지 않고, 지어내지도 않는다. 글은 UX 레인이 `privilege.category.*` 키로 채우는 중이다.
45
+ *
46
+ * ── 저장 범위는 서버가 준 목록이다 ──────────────────────────────────────────
47
+ * 옛 편집기는 `querySelectorAll('input:checked')` 로 보냈다. 왼쪽에서 다른 모듈을 고르면
48
+ * 앞 모듈의 체크박스는 **DOM 에 없다** — 그 방식이면 모듈을 옮겨 다니는 것만으로 권한이
49
+ * 조용히 떨어진다. 여기서는 `rolePrivileges` 가 준 전체가 범위이고, 켠 것은 `assigned` 에만
50
+ * 있다. 화면이 무엇을 그렸는지와 무관하다.
51
+ */
52
+ let RolePrivilegePage = class RolePrivilegePage extends localize(i18next)(PageView) {
53
+ constructor() {
54
+ super(...arguments);
55
+ /*
56
+ * 이름을 `role` 로 두면 안 된다 — `HTMLElement` 가 ARIA 반영으로 `role` 을 이미 갖고 있어서
57
+ * private 필드로 가리면 `CustomElementClass` 에 안 맞는다(TS1238·TS2415).
58
+ */
59
+ this.subject = {};
60
+ this.modules = [];
61
+ this.assigned = new Set();
62
+ this.holders = [];
63
+ this.selected = '';
64
+ this.keyword = '';
65
+ this.mySubdomain = '';
66
+ this.fetchState = 'loading';
67
+ this.saving = false;
68
+ }
69
+ static { this.styles = [
70
+ ScrollbarStyles,
71
+ CommonHeaderStyles,
72
+ css `
73
+ :host {
74
+ display: flex;
75
+ flex-direction: column;
76
+ width: 100%;
77
+ min-height: 0;
78
+ background-color: var(--md-sys-color-surface);
79
+ color: var(--md-sys-color-on-surface);
80
+ }
81
+
82
+ [body] {
83
+ flex: 1;
84
+ min-height: 0;
85
+ display: grid;
86
+ /* 왼쪽은 이름만 담으므로 고정, 오른쪽이 문장을 받으므로 남는 폭을 준다. */
87
+ grid-template-columns: minmax(200px, 280px) 1fr;
88
+ gap: var(--spacing-large, 12px);
89
+ padding: var(--spacing-large, 12px);
90
+ }
91
+
92
+ @media screen and (max-width: 780px) {
93
+ [body] {
94
+ /* 좁으면 위아래로. 고른 모듈이 아래에 오는 것이 읽는 순서와 같다. */
95
+ grid-template-columns: 1fr;
96
+ grid-template-rows: auto 1fr;
97
+ }
98
+ }
99
+
100
+ [panel] {
101
+ display: flex;
102
+ flex-direction: column;
103
+ min-height: 0;
104
+ border: 1px solid var(--md-sys-color-outline-variant);
105
+ border-radius: var(--md-sys-shape-corner-medium, 10px);
106
+ background-color: var(--md-sys-color-surface-container-lowest, var(--md-sys-color-surface));
107
+ overflow: hidden;
108
+ }
109
+
110
+ [panel] > header {
111
+ display: flex;
112
+ align-items: baseline;
113
+ gap: 8px;
114
+ padding: 10px 12px;
115
+ border-bottom: 1px solid var(--md-sys-color-outline-variant);
116
+ color: var(--md-sys-color-on-surface-variant);
117
+ font-size: 0.8rem;
118
+ }
119
+
120
+ [panel] > header [count] {
121
+ color: var(--md-sys-color-outline);
122
+ }
123
+
124
+ [scroll] {
125
+ flex: 1;
126
+ min-height: 0;
127
+ overflow: auto;
128
+ }
129
+
130
+ /*
131
+ 입력 상자는 md-filled-text-field 다 — 생 input 이 아니다.
132
+ 같은 일을 하는 create-role.ts·create-user.ts 가 이것을 쓰고, 이 꾸러미에서 10개
133
+ 파일이 그렇다(UX 레인이 재서 바로잡아 준 것). 생 input 은 비밀번호·프로필 셋뿐이다.
134
+ */
135
+ md-filled-text-field {
136
+ margin: 8px 12px;
137
+ width: calc(100% - 24px);
138
+ }
139
+
140
+ /* ── 왼쪽: 모듈 ──────────────────────────────────────────────────────── */
141
+ ul[modules] {
142
+ list-style: none;
143
+ margin: 0;
144
+ padding: 0;
145
+ }
146
+
147
+ ul[modules] li {
148
+ display: flex;
149
+ align-items: baseline;
150
+ justify-content: space-between;
151
+ gap: 8px;
152
+ padding: 8px 12px;
153
+ cursor: pointer;
154
+ border-left: 3px solid transparent;
155
+ }
156
+
157
+ ul[modules] li:hover {
158
+ background-color: var(--md-sys-color-surface-variant);
159
+ }
160
+
161
+ /* 고른 것은 면과 왼쪽 선으로 말한다 — 글자색만 바꾸면 야간에 안 보인다. */
162
+ ul[modules] li[selected] {
163
+ border-left-color: var(--md-sys-color-primary);
164
+ background-color: var(--md-sys-color-secondary-container);
165
+ color: var(--md-sys-color-on-secondary-container);
166
+ }
167
+
168
+ ul[modules] li [on] {
169
+ font-size: 0.78rem;
170
+ color: var(--md-sys-color-primary);
171
+ }
172
+
173
+ ul[modules] li[selected] [on] {
174
+ color: var(--md-sys-color-on-secondary-container);
175
+ }
176
+
177
+ ul[modules] li [none] {
178
+ font-size: 0.78rem;
179
+ color: var(--md-sys-color-outline);
180
+ }
181
+
182
+ /* ── 오른쪽: 그 모듈에서 되는 일 ────────────────────────────────────── */
183
+ ul[axes] {
184
+ list-style: none;
185
+ margin: 0;
186
+ padding: 0;
187
+ }
188
+
189
+ ul[axes] li {
190
+ display: grid;
191
+ grid-template-columns: auto 1fr;
192
+ gap: 4px 10px;
193
+ padding: 12px 14px;
194
+ border-bottom: 1px solid var(--md-sys-color-surface-variant);
195
+ }
196
+
197
+ ul[axes] li:last-child {
198
+ border-bottom: none;
199
+ }
200
+
201
+ ul[axes] label {
202
+ font-size: 0.95rem;
203
+ font-weight: 600;
204
+ cursor: pointer;
205
+ }
206
+
207
+ ul[axes] li[ghost] label {
208
+ cursor: default;
209
+ }
210
+
211
+ /* 설명은 **본문**이다 — tooltip 이 아니다. 체크박스 아래 칸을 비워 두고 거기 놓는다. */
212
+ ul[axes] [says] {
213
+ grid-column: 2;
214
+ color: var(--md-sys-color-on-surface-variant);
215
+ font-size: 0.85rem;
216
+ line-height: 1.55;
217
+ }
218
+
219
+ ul[axes] [says][missing] {
220
+ color: var(--md-sys-color-outline);
221
+ font-style: italic;
222
+ }
223
+
224
+ ul[axes] li[ghost] label {
225
+ text-decoration: line-through;
226
+ color: var(--md-sys-color-outline);
227
+ }
228
+
229
+ /*
230
+ Which role is this? The header alone was not enough - it is one line of chrome above a
231
+ page full of module names, and a role carries a description that says what the job is.
232
+ Name and description sit in the body, where the reader is already looking.
233
+ */
234
+ [subject] {
235
+ margin: var(--spacing-large, 12px) var(--spacing-large, 12px) 0;
236
+ }
237
+
238
+ [subject] [name] {
239
+ font-size: 1.15rem;
240
+ font-weight: 640;
241
+ }
242
+
243
+ [subject] [says] {
244
+ margin-top: 2px;
245
+ font-size: 0.88rem;
246
+ line-height: 1.55;
247
+ color: var(--md-sys-color-on-surface-variant);
248
+ }
249
+
250
+ [subject] [says][missing] {
251
+ color: var(--md-sys-color-outline);
252
+ font-style: italic;
253
+ }
254
+
255
+ /*
256
+ What is on, all together. The two panels answer "what can this role do in one module";
257
+ they cannot answer "what does this role do", because that reading needs 46 clicks.
258
+ */
259
+ [granted] {
260
+ margin: var(--spacing-medium, 8px) var(--spacing-large, 12px) 0;
261
+ border: 1px solid var(--md-sys-color-outline-variant);
262
+ border-radius: var(--md-sys-shape-corner-medium, 10px);
263
+ background-color: var(--md-sys-color-surface-container-lowest, var(--md-sys-color-surface));
264
+ }
265
+
266
+ [granted] > header {
267
+ display: flex;
268
+ align-items: baseline;
269
+ gap: 8px;
270
+ padding: 8px 12px;
271
+ color: var(--md-sys-color-on-surface-variant);
272
+ font-size: 0.8rem;
273
+ }
274
+
275
+ [granted] > header [count] {
276
+ color: var(--md-sys-color-outline);
277
+ }
278
+
279
+ [granted] ul {
280
+ display: flex;
281
+ flex-wrap: wrap;
282
+ gap: 4px 6px;
283
+ list-style: none;
284
+ margin: 0;
285
+ padding: 0 12px 10px;
286
+ /* Long-running roles reach every module; cap the block so the panels stay on screen. */
287
+ max-height: 22vh;
288
+ overflow: auto;
289
+ }
290
+
291
+ [granted] li {
292
+ display: inline-flex;
293
+ align-items: baseline;
294
+ gap: 5px;
295
+ padding: 3px 9px;
296
+ border-radius: var(--md-sys-shape-corner-small, 6px);
297
+ background-color: var(--md-sys-color-surface-variant);
298
+ color: var(--md-sys-color-on-surface-variant);
299
+ font-size: 0.82rem;
300
+ cursor: pointer;
301
+ }
302
+
303
+ [granted] li:hover {
304
+ background-color: var(--md-sys-color-secondary-container);
305
+ color: var(--md-sys-color-on-secondary-container);
306
+ }
307
+
308
+ [granted] li [axes] {
309
+ color: var(--md-sys-color-primary);
310
+ }
311
+
312
+ [granted] li:hover [axes] {
313
+ color: var(--md-sys-color-on-secondary-container);
314
+ }
315
+
316
+ [granted] [empty] {
317
+ padding: 0 12px 10px;
318
+ }
319
+
320
+ [note] {
321
+ margin: var(--spacing-large, 12px);
322
+ padding: 10px 12px;
323
+ border-radius: var(--md-sys-shape-corner-small, 6px);
324
+ font-size: 0.85rem;
325
+ line-height: 1.55;
326
+ background-color: var(--md-sys-color-surface-variant);
327
+ color: var(--md-sys-color-on-surface-variant);
328
+ }
329
+
330
+ [note][attention] {
331
+ background-color: var(--md-sys-color-error-container);
332
+ color: var(--md-sys-color-on-error-container);
333
+ }
334
+
335
+ [empty] {
336
+ padding: var(--spacing-large, 12px);
337
+ color: var(--md-sys-color-on-surface-variant);
338
+ font-size: 0.85rem;
339
+ }
340
+ `
341
+ ]; }
342
+ /**
343
+ * 부모 도메인의 역할은 여기서 못 고친다 — `updateRole` 의 범위가 `domain.id` 하나다.
344
+ * 목록이 상속으로 보여 주므로 관리자가 여기까지 온다. 읽기 전용으로 두고 어디로 가야 하는지
345
+ * 말한다. (프로필의 `domain` 에 `id` 가 없어서 `subdomain` 으로 견준다.)
346
+ */
347
+ get inherited() {
348
+ const subdomain = this.subject?.domain?.subdomain;
349
+ return Boolean(subdomain && this.mySubdomain && subdomain !== this.mySubdomain);
350
+ }
351
+ get savable() {
352
+ return this.fetchState === 'loaded' && !this.saving && !this.inherited;
353
+ }
354
+ get visibleModules() {
355
+ const keyword = this.keyword.trim().toLowerCase();
356
+ return keyword ? this.modules.filter(m => m.category.toLowerCase().includes(keyword)) : this.modules;
357
+ }
358
+ get context() {
359
+ return {
360
+ title: this.subject?.name || i18next.t('field.privileges'),
361
+ help: 'auth/roles',
362
+ actions: this.inherited
363
+ ? []
364
+ : [
365
+ {
366
+ title: i18next.t('button.save'),
367
+ action: this.onSave.bind(this)
368
+ }
369
+ ]
370
+ };
371
+ }
372
+ render() {
373
+ if (this.fetchState === 'failed') {
374
+ return html `<ox-oops-note
375
+ icon="error_outline"
376
+ title=${i18next.t('text.failed to fetch')}
377
+ description=${i18next.t('text.please try again')}
378
+ ></ox-oops-note>`;
379
+ }
380
+ return html `
381
+ ${this.inherited
382
+ ? html `<div note attention>
383
+ ${i18next.t('text.role belongs to x domain and is edited there', {
384
+ x: this.subject?.domain?.name || this.subject?.domain?.subdomain
385
+ })}
386
+ </div>`
387
+ : nothing}
388
+ ${this.renderSubject()} ${this.renderGranted()} ${this.renderHolders()}
389
+
390
+ <div body>
391
+ <div panel>
392
+ <header>
393
+ ${i18next.t('field.module')}
394
+ <span count>${this.modules.length}</span>
395
+ </header>
396
+ <md-filled-text-field
397
+ type="text"
398
+ label=${i18next.t('text.filter by module name')}
399
+ .value=${this.keyword}
400
+ @input=${(e) => (this.keyword = e.target.value)}
401
+ ></md-filled-text-field>
402
+ <div scroll>${this.renderModules()}</div>
403
+ </div>
404
+
405
+ <div panel>
406
+ <header>
407
+ ${this.selected ? moduleLabel(this.selected) : i18next.t('field.privileges')}
408
+ <span count>${i18next.t('text.x of y on', { x: this.assigned.size, y: this.cellCount() })}</span>
409
+ </header>
410
+ <div scroll>${this.renderAxes()}</div>
411
+ </div>
412
+ </div>
413
+ `;
414
+ }
415
+ /**
416
+ * Which role am I editing, and what is it for.
417
+ *
418
+ * The page header carried the name and nothing else, and the description - the one line that
419
+ * says what the job is - was only visible back on the list. A reader who arrives by link had
420
+ * no way to tell "Administrator" from "PLANT-MANAGER" beyond the word itself.
421
+ *
422
+ * A role with no description says so. The next thing to do is write one, in the list grid.
423
+ */
424
+ renderSubject() {
425
+ if (this.fetchState !== 'loaded') {
426
+ return nothing;
427
+ }
428
+ return html `
429
+ <div subject>
430
+ <div name>${this.subject?.name || i18next.t('label.role')}</div>
431
+ ${this.subject?.description
432
+ ? html `<div says>${this.subject.description}</div>`
433
+ : html `<div says missing>${i18next.t('text.no description for this role')}</div>`}
434
+ </div>
435
+ `;
436
+ }
437
+ /**
438
+ * Everything this role has, in one block.
439
+ *
440
+ * The two panels answer "what can this role do in this module". They cannot answer "what does
441
+ * this role do at all" - that reading costs one click per module, 46 of them, and the person
442
+ * granting a role needs the whole answer before they grant it.
443
+ *
444
+ * Only what is on. The full matrix is what the panels are for, and repeating it here would
445
+ * put the same 46 modules on screen twice.
446
+ *
447
+ * Each entry moves the panels to that module, so this block doubles as the way in.
448
+ */
449
+ renderGranted() {
450
+ if (this.fetchState !== 'loaded' || !this.modules.length) {
451
+ return nothing;
452
+ }
453
+ const on = this.modules
454
+ .map(module => ({
455
+ category: module.category,
456
+ axes: module.cells.filter(cell => this.assigned.has(cell.id))
457
+ }))
458
+ .filter(entry => entry.axes.length);
459
+ return html `
460
+ <div granted>
461
+ <header>
462
+ ${i18next.t('field.granted privileges')}
463
+ <span count>${i18next.t('text.x of y on', { x: this.assigned.size, y: this.cellCount() })}</span>
464
+ </header>
465
+ ${on.length
466
+ ? html `<ul>
467
+ ${on.map(entry => html `<li
468
+ title=${i18next.t('text.pick a module on the left')}
469
+ @click=${() => (this.selected = entry.category)}
470
+ >
471
+ ${moduleLabel(entry.category)}
472
+ <span axes>${entry.axes.map(cell => axisLabel(cell.axis)).join(' · ')}</span>
473
+ </li>`)}
474
+ </ul>`
475
+ : html `<div empty>${i18next.t('text.nothing is on for this role yet')}</div>`}
476
+ </div>
477
+ `;
478
+ }
479
+ /**
480
+ * 이 역할을 가진 사람.
481
+ *
482
+ * 권한을 켜기 **전에** 누가 영향을 받는지 보이는 자리다. 아무도 안 가진 역할을 고치는 것과
483
+ * 40명이 가진 역할을 고치는 것은 다른 일인데, 옛 화면은 그 둘이 똑같이 보였다.
484
+ */
485
+ renderHolders() {
486
+ if (this.fetchState !== 'loaded') {
487
+ return nothing;
488
+ }
489
+ return this.holders.length
490
+ ? html `<div note>
491
+ ${i18next.t('text.x people hold this role', { x: this.holders.length })}
492
+ — ${this.holders.map(h => h.name || h.email).join(', ')}
493
+ </div>`
494
+ : html `<div note>${i18next.t('text.no one holds this role yet')}</div>`;
495
+ }
496
+ renderModules() {
497
+ if (this.fetchState === 'loading') {
498
+ return html `<div empty>${i18next.t('text.loading')}</div>`;
499
+ }
500
+ if (!this.modules.length) {
501
+ return html `<div empty>${i18next.t('text.no privilege declared in this deployment')}</div>`;
502
+ }
503
+ if (!this.visibleModules.length) {
504
+ return html `<div empty>${i18next.t('text.nothing matches x', { x: this.keyword })}</div>`;
505
+ }
506
+ return html `
507
+ <ul modules>
508
+ ${this.visibleModules.map(module => {
509
+ const on = module.cells.filter(cell => this.assigned.has(cell.id)).length;
510
+ return html `
511
+ <li ?selected=${module.category === this.selected} @click=${() => (this.selected = module.category)}>
512
+ <span>${moduleLabel(module.category)}</span>
513
+ ${on
514
+ ? html `<span on>${i18next.t('text.x on', { x: on })}</span>`
515
+ : html `<span none>${i18next.t('text.none on')}</span>`}
516
+ </li>
517
+ `;
518
+ })}
519
+ </ul>
520
+ `;
521
+ }
522
+ renderAxes() {
523
+ if (this.fetchState === 'loading') {
524
+ return html `<div empty>${i18next.t('text.loading')}</div>`;
525
+ }
526
+ const module = this.modules.find(m => m.category === this.selected);
527
+ if (!module) {
528
+ /* 아무것도 안 고른 상태 — 무엇을 해야 하는지 말한다. */
529
+ return html `<div empty>${i18next.t('text.pick a module on the left')}</div>`;
530
+ }
531
+ return html `
532
+ <ul axes>
533
+ ${module.cells.map(cell => {
534
+ const on = this.assigned.has(cell.id);
535
+ return html `
536
+ <li ?ghost=${cell.deprecated}>
537
+ <md-checkbox
538
+ id="cell-${cell.id}"
539
+ touch-target="wrapper"
540
+ .checked=${on}
541
+ ?disabled=${this.inherited || (cell.deprecated && !on)}
542
+ @change=${(e) => this.onToggle(cell.id, e.target.checked)}
543
+ ></md-checkbox>
544
+ <!--
545
+ md-checkbox 는 native input 이 아니라서 label for 로는 안 눌린다.
546
+ 글자를 눌러도 켜지는 것이 사람이 기대하는 것이므로 같은 처리기를 붙인다.
547
+ -->
548
+ <label
549
+ for="cell-${cell.id}"
550
+ @click=${() => {
551
+ if (!this.inherited && !(cell.deprecated && !on)) {
552
+ this.onToggle(cell.id, !on);
553
+ }
554
+ }}
555
+ >${axisLabel(cell.axis)}</label
556
+ >
557
+
558
+ ${cell.deprecated
559
+ ? html `<div says>${i18next.t('text.privilege no longer declared')}</div>`
560
+ : axisSays(module.category, cell) ||
561
+ html `<div says missing>${i18next.t('text.no description for this privilege')}</div>`}
562
+ </li>
563
+ `;
564
+ })}
565
+ </ul>
566
+ `;
567
+ }
568
+ cellCount() {
569
+ return this.modules.reduce((sum, module) => sum + module.cells.length, 0);
570
+ }
571
+ async pageUpdated(changes, lifecycle) {
572
+ if (this.active) {
573
+ this.lifecycle = lifecycle;
574
+ await this.fetch();
575
+ }
576
+ }
577
+ /**
578
+ * 한 번의 질의로 **전체 권한과 이 역할이 가진 것**을 함께 읽는다(`rolePrivileges(roleId:)`).
579
+ *
580
+ * 역할 이름과 가진 사람은 `roles(filters: id)` 로 같은 문서에서 받는다 — 옛 편집기는 역할을
581
+ * **이름**으로 다시 찾았고, 부모 도메인에 같은 이름이 있으면 남의 역할을 그렸다.
582
+ */
583
+ async fetch() {
584
+ const roleId = this.lifecycle?.resourceId;
585
+ if (!roleId) {
586
+ this.fetchState = 'failed';
587
+ return;
588
+ }
589
+ this.fetchState = 'loading';
590
+ this.mySubdomain = (await getDomain())?.subdomain || '';
591
+ const response = await client.query({
592
+ query: gql `
593
+ query ($roleId: String!, $filters: [Filter!]) {
594
+ rolePrivileges(roleId: $roleId) {
595
+ id
596
+ name
597
+ category
598
+ description
599
+ assigned
600
+ deprecated
601
+ }
602
+ roles(filters: $filters) {
603
+ items {
604
+ id
605
+ name
606
+ description
607
+ domain {
608
+ id
609
+ name
610
+ subdomain
611
+ }
612
+ users {
613
+ id
614
+ name
615
+ email
616
+ }
617
+ }
618
+ }
619
+ }
620
+ `,
621
+ variables: { roleId, filters: [{ name: 'id', operator: 'eq', value: roleId }] },
622
+ context: gqlContext()
623
+ });
624
+ if (response.errors?.length) {
625
+ /* 실패를 「권한이 하나도 없다」로 그리지 않는다 — 저장하면 실제로 그렇게 된다. */
626
+ this.fetchState = 'failed';
627
+ return;
628
+ }
629
+ this.subject = response.data?.roles?.items?.[0] || {};
630
+ this.holders = this.subject.users || [];
631
+ this.build(response.data?.rolePrivileges || []);
632
+ this.fetchState = 'loaded';
633
+ /*
634
+ * The shell reads `context` once, when the page becomes active - before this fetch
635
+ * resolves. Without this call the header keeps the fallback, so the screen showed
636
+ * "권한" and never said which role was being edited.
637
+ */
638
+ this.updateContext();
639
+ }
640
+ /** 평평한 목록을 모듈로 접는다. 축 순서는 아는 것 먼저, 나머지는 이름 순. */
641
+ build(privileges) {
642
+ const byCategory = new Map();
643
+ const assigned = new Set();
644
+ for (const privilege of privileges) {
645
+ const { id, name, category, description, deprecated } = privilege;
646
+ if (!id || !name || !category) {
647
+ continue;
648
+ }
649
+ if (privilege.assigned) {
650
+ assigned.add(id);
651
+ }
652
+ const module = byCategory.get(category) || { category, cells: [] };
653
+ module.cells.push({ id, axis: name, deprecated: Boolean(deprecated), description });
654
+ byCategory.set(category, module);
655
+ }
656
+ for (const module of byCategory.values()) {
657
+ module.cells.sort((a, b) => axisOrder(a.axis) - axisOrder(b.axis) || a.axis.localeCompare(b.axis));
658
+ }
659
+ this.modules = [...byCategory.values()].sort((a, b) => moduleLabel(a.category).localeCompare(moduleLabel(b.category)));
660
+ this.assigned = assigned;
661
+ /* 고른 것이 없으면 첫 모듈을 연다 — 빈 오른쪽 판을 처음 화면으로 두지 않는다. */
662
+ if (!this.modules.find(m => m.category === this.selected)) {
663
+ this.selected = this.modules[0]?.category || '';
664
+ }
665
+ }
666
+ onToggle(id, checked) {
667
+ const next = new Set(this.assigned);
668
+ checked ? next.add(id) : next.delete(id);
669
+ this.assigned = next;
670
+ }
671
+ /**
672
+ * 저장.
673
+ *
674
+ * **범위는 `modules` 전체다.** 왼쪽에서 다른 모듈을 고르면 앞 모듈의 체크박스는 DOM 에
675
+ * 없는데, 그것을 훑어 보내던 것이 옛 편집기가 권한을 조용히 떼던 자리다.
676
+ *
677
+ * `privileges` 만 보낸다 — 이름과 설명은 목록 격자가 소유한다.
678
+ */
679
+ async onSave() {
680
+ if (!this.savable) {
681
+ return;
682
+ }
683
+ this.saving = true;
684
+ try {
685
+ const response = await client.mutate({
686
+ mutation: gql `
687
+ mutation ($id: String!, $patch: RolePatch!) {
688
+ updateRole(id: $id, patch: $patch) {
689
+ id
690
+ }
691
+ }
692
+ `,
693
+ variables: {
694
+ id: this.subject.id,
695
+ patch: { privileges: [...this.assigned].map(id => ({ id })) }
696
+ },
697
+ context: gqlContext()
698
+ });
699
+ if (response.errors?.length) {
700
+ document.dispatchEvent(new CustomEvent('notify', { detail: { level: 'error', message: response.errors[0]?.message } }));
701
+ return;
702
+ }
703
+ document.dispatchEvent(new CustomEvent('notify', { detail: { message: i18next.t('text.data_updated_successfully') } }));
704
+ /* 유령을 뗐으면 목록에서 사라져야 하고, 켠 것이 요약에 반영돼야 한다. */
705
+ await this.fetch();
706
+ }
707
+ finally {
708
+ this.saving = false;
709
+ }
710
+ }
711
+ };
712
+ __decorate([
713
+ property({ type: Object }),
714
+ __metadata("design:type", Object)
715
+ ], RolePrivilegePage.prototype, "lifecycle", void 0);
716
+ __decorate([
717
+ state(),
718
+ __metadata("design:type", Object)
719
+ ], RolePrivilegePage.prototype, "subject", void 0);
720
+ __decorate([
721
+ state(),
722
+ __metadata("design:type", Array)
723
+ ], RolePrivilegePage.prototype, "modules", void 0);
724
+ __decorate([
725
+ state(),
726
+ __metadata("design:type", Set)
727
+ ], RolePrivilegePage.prototype, "assigned", void 0);
728
+ __decorate([
729
+ state(),
730
+ __metadata("design:type", Array)
731
+ ], RolePrivilegePage.prototype, "holders", void 0);
732
+ __decorate([
733
+ state(),
734
+ __metadata("design:type", String)
735
+ ], RolePrivilegePage.prototype, "selected", void 0);
736
+ __decorate([
737
+ state(),
738
+ __metadata("design:type", String)
739
+ ], RolePrivilegePage.prototype, "keyword", void 0);
740
+ __decorate([
741
+ state(),
742
+ __metadata("design:type", String)
743
+ ], RolePrivilegePage.prototype, "mySubdomain", void 0);
744
+ __decorate([
745
+ state(),
746
+ __metadata("design:type", String)
747
+ ], RolePrivilegePage.prototype, "fetchState", void 0);
748
+ __decorate([
749
+ state(),
750
+ __metadata("design:type", Boolean)
751
+ ], RolePrivilegePage.prototype, "saving", void 0);
752
+ RolePrivilegePage = __decorate([
753
+ customElement('role-privilege-page')
754
+ ], RolePrivilegePage);
755
+ export { RolePrivilegePage };
756
+ /**
757
+ * 모듈 이름을 사람 말로.
758
+ *
759
+ * `privilege.category.<category>` 키가 있으면 그것을 쓰고, 없으면 **코드 낱말을 그대로** 낸다 —
760
+ * 지어내지 않는다. 지금 46개 중 하나(`system`)만 채워져 있고, UX 레인이 나머지를 쓰고 있다.
761
+ */
762
+ function moduleLabel(category) {
763
+ const key = `privilege.category.${category}`;
764
+ return i18next.t(key, { defaultValue: category });
765
+ }
766
+ function axisLabel(axis) {
767
+ return AXIS_LABEL[axis] ? i18next.t(AXIS_LABEL[axis]) : axis;
768
+ }
769
+ /**
770
+ * 「켜면 무엇을 할 수 있게 되나」 — **이 화면의 이유다.**
771
+ *
772
+ * 사용자 평가가 「화면으로부터 배울 수 있는 것이 없다」였고, 그 원인은 화면이 감춘 것이 아니라
773
+ * 시스템에 그 문장이 없던 것이었다. 부팅 동기화가 `{ category, name }` 둘만 저장해서
774
+ * (`auth-base/server/index.ts:34-36`) 713개 선언이 전부 빈 설명이었다.
775
+ *
776
+ * 그 글을 UX 레인이 `privilege.allows.<category>.<axis>` 로 썼다(57 모듈 · 104 문장, ko·en).
777
+ * 번역은 디스크에서 서비스되므로 **배포를 기다리지 않고 붙는다.**
778
+ *
779
+ * ── 보는 순서 ───────────────────────────────────────────────────────────────
780
+ * ```
781
+ * 1 서버 칸 채워지면 그것이 이긴다 — 배포마다 다를 수 있는 사실은 서버가 안다
782
+ * 2 우리가 쓴 글 privilege.allows.<category>.<axis>
783
+ * 3 없다고 말한다 둘 다 없으면. 지어내지 않는다
784
+ * ```
785
+ *
786
+ * ⚠ **`defaultValue: ''` 가 없으면 3번으로 못 떨어진다** — i18next 는 키가 없을 때 **키 이름을
787
+ * 그대로** 돌려주므로 화면에 `privilege.allows.board.query` 가 찍힌다. 빈 문자열을 기본값으로
788
+ * 줘서 「없음」이 거짓으로 판정되게 한다.
789
+ */
790
+ function axisSays(category, cell) {
791
+ if (cell.description) {
792
+ return html `<div says>${cell.description}</div>`;
793
+ }
794
+ const written = i18next.t(`privilege.allows.${category}.${cell.axis}`, { defaultValue: '' });
795
+ return written ? html `<div says>${written}</div>` : null;
796
+ }
797
+ function axisOrder(axis) {
798
+ const index = KNOWN_AXES.indexOf(axis);
799
+ return index < 0 ? KNOWN_AXES.length : index;
800
+ }
801
+ //# sourceMappingURL=role-privilege-page.js.map