@things-factory/auth-ui 10.1.4 → 10.1.7
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/dist-client/components/change-password.d.ts +11 -0
- package/dist-client/components/change-password.js +103 -6
- package/dist-client/components/change-password.js.map +1 -1
- package/dist-client/components/role-privilege-picker.d.ts +37 -0
- package/dist-client/components/role-privilege-picker.js +58 -0
- package/dist-client/components/role-privilege-picker.js.map +1 -0
- package/dist-client/components/role-template-picker.d.ts +83 -0
- package/dist-client/components/role-template-picker.js +487 -0
- package/dist-client/components/role-template-picker.js.map +1 -0
- package/dist-client/components/user-detail.d.ts +151 -0
- package/dist-client/components/user-detail.js +631 -0
- package/dist-client/components/user-detail.js.map +1 -0
- package/dist-client/components/user-invite.d.ts +80 -0
- package/dist-client/components/user-invite.js +422 -0
- package/dist-client/components/user-invite.js.map +1 -0
- package/dist-client/entries/auth/activate.d.ts +0 -1
- package/dist-client/entries/auth/activate.js +0 -8
- package/dist-client/entries/auth/activate.js.map +1 -1
- package/dist-client/pages/role/role-list-page.d.ts +203 -0
- package/dist-client/pages/role/role-list-page.js +838 -0
- package/dist-client/pages/role/role-list-page.js.map +1 -0
- package/dist-client/pages/role/role-privilege-page.d.ts +181 -0
- package/dist-client/pages/role/role-privilege-page.js +980 -0
- package/dist-client/pages/role/role-privilege-page.js.map +1 -0
- package/dist-client/pages/user/user-list-page.d.ts +88 -0
- package/dist-client/pages/user/user-list-page.js +474 -0
- package/dist-client/pages/user/user-list-page.js.map +1 -0
- package/dist-client/route.js +5 -2
- package/dist-client/route.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/things-factory.config.js +3 -2
- package/translations/en.json +72 -3
- package/translations/ja.json +14 -3
- package/translations/ko.json +73 -4
- package/translations/ms.json +15 -4
- package/translations/zh.json +14 -3
- package/dist-client/components/contact-us.d.ts +0 -20
- package/dist-client/components/contact-us.js +0 -121
- package/dist-client/components/contact-us.js.map +0 -1
- package/dist-client/components/create-role.d.ts +0 -1
- package/dist-client/components/create-role.js +0 -117
- package/dist-client/components/create-role.js.map +0 -1
- package/dist-client/components/credential-manager.d.ts +0 -11
- package/dist-client/components/credential-manager.js +0 -64
- package/dist-client/components/credential-manager.js.map +0 -1
- package/dist-client/components/role-edit-form.d.ts +0 -1
- package/dist-client/components/role-edit-form.js +0 -95
- package/dist-client/components/role-edit-form.js.map +0 -1
- package/dist-client/components/role-privilege-editor.d.ts +0 -1
- package/dist-client/components/role-privilege-editor.js +0 -368
- package/dist-client/components/role-privilege-editor.js.map +0 -1
- package/dist-client/pages/role/role-management.d.ts +0 -4
- package/dist-client/pages/role/role-management.js +0 -137
- package/dist-client/pages/role/role-management.js.map +0 -1
- package/dist-client/pages/user/user-management.d.ts +0 -35
- package/dist-client/pages/user/user-management.js +0 -223
- package/dist-client/pages/user/user-management.js.map +0 -1
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import '@material/web/icon/icon.js';
|
|
3
|
+
import '@material/web/button/elevated-button.js';
|
|
4
|
+
import '@material/web/button/outlined-button.js';
|
|
5
|
+
import '@material/web/checkbox/checkbox.js';
|
|
6
|
+
import './ownership-transfer-popup.js';
|
|
7
|
+
import gql from 'graphql-tag';
|
|
8
|
+
import { css, html, LitElement, nothing } from 'lit';
|
|
9
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
|
10
|
+
import { client, gqlContext } from '@operato/graphql';
|
|
11
|
+
import { i18next, localize } from '@operato/i18n';
|
|
12
|
+
import { openPopup } from '@operato/layout';
|
|
13
|
+
import { OxPrompt } from '@operato/popup/ox-prompt.js';
|
|
14
|
+
import { InheritedValueType, store } from '@operato/shell';
|
|
15
|
+
import { ButtonContainerStyles } from '@operato/styles';
|
|
16
|
+
import { hasPrivilege } from '@things-factory/auth-base/dist-client';
|
|
17
|
+
/**
|
|
18
|
+
* 한 사람의 역할을 고치는 자리.
|
|
19
|
+
*
|
|
20
|
+
* ── 담는 그릇을 모른다 ──────────────────────────────────────────────────────
|
|
21
|
+
* 팝업이든 서랍이든 그 안에 들어간다. 그래서 여기서는 **아무것도 열거나 닫지 않고** 두 가지만
|
|
22
|
+
* 알린다 — 저장이 끝났다(`user-updated`), 닫아 달라(`close`). 그릇이 어느 것이 될지는 아직
|
|
23
|
+
* 정해지지 않았고, 그 결정이 이 파일을 바꾸지 않게 한다.
|
|
24
|
+
*
|
|
25
|
+
* ── 옛 화면이 하던 것 (`components/user-role-editor.ts`) ────────────────────
|
|
26
|
+
* 저장할 때 `querySelectorAll('role-selector')` 로 **화면을 훑어** 「가능한 역할 전부」와
|
|
27
|
+
* 「고른 역할」을 만들어 보냈다.
|
|
28
|
+
*
|
|
29
|
+
* `updateUserRoles` 의 계약은 이렇다 — `availableRoles` 는 **부르는 쪽이 책임지는 범위**이고,
|
|
30
|
+
* 그 범위 안의 역할을 일단 다 뗀 다음 `selectedRoles` 를 다시 붙인다. 범위 밖의 역할은
|
|
31
|
+
* 건드리지 않는다(`user-mutation.ts` 의 `updateUserRoles`).
|
|
32
|
+
*
|
|
33
|
+
* 계약 자체는 옳다 — 화면이 일부만 편집할 수 있게 해 준다. 잘못된 것은 **그 범위를 DOM 에서
|
|
34
|
+
* 만든 것**이다. 목록이 늦게 오거나 잘려 있으면 화면은 그것을 모른 채 좁은 범위를 보내고,
|
|
35
|
+
* 안 보낸 역할이 어떻게 되는지가 그날의 렌더링에 달린다.
|
|
36
|
+
*
|
|
37
|
+
* 여기서는 범위를 **상태에서** 만든다. 읽어 온 목록이 곧 범위이고, 아직 못 읽었으면 저장하지
|
|
38
|
+
* 않는다.
|
|
39
|
+
*/
|
|
40
|
+
let UserDetail = class UserDetail extends localize(i18next)(LitElement) {
|
|
41
|
+
constructor() {
|
|
42
|
+
super(...arguments);
|
|
43
|
+
this.availableRoles = [];
|
|
44
|
+
this.selected = new Set();
|
|
45
|
+
this.loading = true;
|
|
46
|
+
this.saving = false;
|
|
47
|
+
/*
|
|
48
|
+
* **내가 이 도메인에서 무엇을 할 수 있나 — 서버 선언을 그대로 되묻는다.**
|
|
49
|
+
*
|
|
50
|
+
* `/auth/profile` 이 `privileges`·`owner`·`super` 를 전부 담아 주고, `hasPrivilege`
|
|
51
|
+
* (`auth-base/client/profiled.ts`)가 서버의 `checkPermission` 과 같은 규칙으로 그것을 판정한다
|
|
52
|
+
* — 안전하지 않은 IP 에서 소유권 우회를 빼는 것까지 같다. 그래서 **서버 지시자에 적힌 인자를
|
|
53
|
+
* 그대로 넘기는 것**이 화면과 문을 어긋나지 않게 하는 방법이다.
|
|
54
|
+
*
|
|
55
|
+
* 옛 화면은 이것을 두고 `me.email === domainOwner.email` 로 판정했다 — 목록에서 뽑은 대표
|
|
56
|
+
* 소유자 한 명과 견주는 것이라 **공동 소유자가 자기 권한을 잃었고**, `user:mutation` 을 역할로
|
|
57
|
+
* 받은 사람은 아예 단추를 못 봤다.
|
|
58
|
+
*
|
|
59
|
+
* 둘이 다른 선언을 쓴다.
|
|
60
|
+
*
|
|
61
|
+
* 활성/비활성·초기화·제외 user:mutation + domainOwnerGranted
|
|
62
|
+
* 소유권 이전 domainOwnerGranted + superUserGranted (권한 쌍이 없다)
|
|
63
|
+
*
|
|
64
|
+
* ⚠ 수퍼유저가 자동으로 다 통과하지 않는다 — `checkPermission` 은 지시자가
|
|
65
|
+
* `superUserGranted` 를 선언한 곳에서만 그것을 본다. 그래서 위 둘을 뭉치면 안 된다.
|
|
66
|
+
*/
|
|
67
|
+
this.canManage = false;
|
|
68
|
+
this.canOwn = false;
|
|
69
|
+
this.myEmail = '';
|
|
70
|
+
/** 기본 비밀번호가 설정돼 있지 않으면 초기화는 서버에서 던진다 — 단추를 내주지 않는다. */
|
|
71
|
+
this.defaultPasswordConfigured = false;
|
|
72
|
+
/**
|
|
73
|
+
* 이 도메인(과 부모)의 역할 id.
|
|
74
|
+
*
|
|
75
|
+
* 소유권 이전은 **받는 사람이 이 도메인에 역할을 하나라도 가질 때만** 된다
|
|
76
|
+
* (`transferOwner` 가 상속 역할까지 자격으로 인정하고, 그 밖은 던진다). 파트너십으로 넘어온
|
|
77
|
+
* 역할은 자격이 아니므로 `availableRoles`(합친 것)로는 판정할 수 없다.
|
|
78
|
+
*/
|
|
79
|
+
this.domainRoleIds = new Set();
|
|
80
|
+
}
|
|
81
|
+
static { this.styles = [
|
|
82
|
+
ButtonContainerStyles,
|
|
83
|
+
css `
|
|
84
|
+
:host {
|
|
85
|
+
display: flex;
|
|
86
|
+
flex-direction: column;
|
|
87
|
+
gap: var(--spacing-medium, 8px);
|
|
88
|
+
padding: var(--spacing-large, 12px);
|
|
89
|
+
background-color: var(--md-sys-color-surface);
|
|
90
|
+
color: var(--md-sys-color-on-surface);
|
|
91
|
+
overflow: auto;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
[headline] {
|
|
95
|
+
font: var(--headline-font, inherit);
|
|
96
|
+
font-size: 1.05rem;
|
|
97
|
+
font-weight: 600;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
[sub] {
|
|
101
|
+
color: var(--md-sys-color-on-surface-variant);
|
|
102
|
+
font-size: 0.85rem;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
[section] {
|
|
106
|
+
margin-top: var(--spacing-medium, 8px);
|
|
107
|
+
color: var(--md-sys-color-on-surface-variant);
|
|
108
|
+
font-size: 0.8rem;
|
|
109
|
+
text-transform: capitalize;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
ul[roles] {
|
|
113
|
+
list-style: none;
|
|
114
|
+
margin: 0;
|
|
115
|
+
padding: 0;
|
|
116
|
+
display: flex;
|
|
117
|
+
flex-direction: column;
|
|
118
|
+
gap: 2px;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
ul[roles] li {
|
|
122
|
+
display: flex;
|
|
123
|
+
align-items: center;
|
|
124
|
+
gap: 8px;
|
|
125
|
+
padding: 5px 2px;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
ul[roles] li [desc] {
|
|
129
|
+
color: var(--md-sys-color-on-surface-variant);
|
|
130
|
+
font-size: 0.8rem;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/*
|
|
134
|
+
색은 짝으로 쓰고, 「무엇이 나를 기다리나」에만 쓴다.
|
|
135
|
+
소유자 안내는 조치가 필요한 것이 아니라 사실이므로 조용한 면을 쓴다.
|
|
136
|
+
*/
|
|
137
|
+
[note] {
|
|
138
|
+
padding: 8px 10px;
|
|
139
|
+
border-radius: var(--md-sys-shape-corner-small, 6px);
|
|
140
|
+
font-size: 0.82rem;
|
|
141
|
+
background-color: var(--md-sys-color-surface-variant);
|
|
142
|
+
color: var(--md-sys-color-on-surface-variant);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
[note][attention] {
|
|
146
|
+
background-color: var(--md-sys-color-error-container);
|
|
147
|
+
color: var(--md-sys-color-on-error-container);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/*
|
|
151
|
+
되돌릴 수 없는 조치 — 선으로 갈라 두고, 색은 글자에만 쓴다.
|
|
152
|
+
면을 error 로 칠하면 「지금 문제가 있다」로 읽힌다.
|
|
153
|
+
*/
|
|
154
|
+
[danger-zone] {
|
|
155
|
+
margin-top: var(--spacing-large, 12px);
|
|
156
|
+
border-top: 1px solid var(--md-sys-color-outline-variant);
|
|
157
|
+
padding-top: var(--spacing-small, 4px);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
[danger-zone] md-outlined-button {
|
|
161
|
+
--md-outlined-button-label-text-color: var(--md-sys-color-error);
|
|
162
|
+
--md-outlined-button-outline-color: var(--md-sys-color-outline-variant);
|
|
163
|
+
--md-outlined-button-hover-label-text-color: var(--md-sys-color-error);
|
|
164
|
+
--md-outlined-button-hover-state-layer-color: var(--md-sys-color-error);
|
|
165
|
+
--md-outlined-button-pressed-label-text-color: var(--md-sys-color-error);
|
|
166
|
+
}
|
|
167
|
+
`
|
|
168
|
+
]; }
|
|
169
|
+
/*
|
|
170
|
+
* **저장할 수 있나 — 단추와 처리기가 같은 답을 본다.**
|
|
171
|
+
*
|
|
172
|
+
* 셋을 갈라야 한다. 화면에서 갈라 놓고 저장에서 뭉치면, 「아직 못 읽었다」와 「읽었는데
|
|
173
|
+
* 역할이 없다」가 똑같이 **눌러도 아무 일이 없는 단추**가 된다. 그것이 조용히 되돌아가는
|
|
174
|
+
* 자리이고, 사람은 저장이 됐는지 안 됐는지 알 수 없다.
|
|
175
|
+
*
|
|
176
|
+
* 못 읽었다 아직 범위를 모른다 — 눌리면 안 된다
|
|
177
|
+
* 역할이 0개 보낼 것이 없다 — 눌리면 안 되고, 무엇을 해야 하는지는 목록 자리가 말한다
|
|
178
|
+
* 읽었고 있다 저장한다
|
|
179
|
+
*/
|
|
180
|
+
get savable() {
|
|
181
|
+
return !this.loading && !this.saving && this.availableRoles.length > 0;
|
|
182
|
+
}
|
|
183
|
+
render() {
|
|
184
|
+
const user = this.user || {};
|
|
185
|
+
return html `
|
|
186
|
+
<div headline>${user.name || user.username || user.email}</div>
|
|
187
|
+
<div sub>${user.email}</div>
|
|
188
|
+
|
|
189
|
+
${user.owner
|
|
190
|
+
? html `<div note>
|
|
191
|
+
<md-icon style="--md-icon-size: 16px; vertical-align: -3px;">supervisor_account</md-icon>
|
|
192
|
+
${i18next.t('text.owner opens everything without a role')}
|
|
193
|
+
</div>`
|
|
194
|
+
: nothing}
|
|
195
|
+
${this.renderAccountState(user)}
|
|
196
|
+
|
|
197
|
+
<div section>${i18next.t('field.roles')}</div>
|
|
198
|
+
${this.renderRoles()}
|
|
199
|
+
|
|
200
|
+
<div class="button-container">
|
|
201
|
+
<md-elevated-button ?disabled=${!this.savable} @click=${() => this.onSave()}>
|
|
202
|
+
${i18next.t('button.save')}
|
|
203
|
+
</md-elevated-button>
|
|
204
|
+
<md-elevated-button @click=${() => this.dispatchEvent(new CustomEvent('close'))}>
|
|
205
|
+
${i18next.t('button.cancel')}
|
|
206
|
+
</md-elevated-button>
|
|
207
|
+
</div>
|
|
208
|
+
|
|
209
|
+
${this.renderDangerZone(user)}
|
|
210
|
+
`;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* 되돌릴 수 없는 조치.
|
|
214
|
+
*
|
|
215
|
+
* ── 왜 아래에 따로 두나 ─────────────────────────────────────────────────────
|
|
216
|
+
* 옛 화면은 저장·소유권 이전·초기화·제외·비활성화를 **한 줄에 나란히** 뒀다. 매일 누르는
|
|
217
|
+
* 「저장」 옆에 한 번 누르면 끝인 「제외」가 같은 크기로 있었다.
|
|
218
|
+
*
|
|
219
|
+
* 그래서 선을 하나 긋고, 위는 채운 단추(주 동작), 아래는 테두리 단추로 둔다. 색은
|
|
220
|
+
* error 짝으로 글자에만 쓴다 — 면을 다 칠하면 「지금 문제가 있다」로 읽힌다.
|
|
221
|
+
*
|
|
222
|
+
* ── 무엇을 언제 내주나 ──────────────────────────────────────────────────────
|
|
223
|
+
* 조건은 전부 **서버가 실제로 던지는 것**을 그대로 옮긴 것이다. 눌리는 단추를 보여 주고
|
|
224
|
+
* 서버가 거절하면 그것은 안내가 아니라 오류다.
|
|
225
|
+
*
|
|
226
|
+
* 비밀번호 초기화 기본 비밀번호가 설정돼 있고, 내가 아니다
|
|
227
|
+
* 소유권 이전 활성 상태고, 소유자가 아니고, 이 도메인에 역할이 하나라도 있다
|
|
228
|
+
* 도메인에서 제외 소유자가 아니고, 내가 아니다
|
|
229
|
+
*
|
|
230
|
+
* ── 이름 ────────────────────────────────────────────────────────────────────
|
|
231
|
+
* `deleteDomainUser` 는 계정을 지우지 않는다 — **이 도메인에서만 뗀다**(서버 설명도 그렇게
|
|
232
|
+
* 적혀 있다). 옛 화면의 「사용자 삭제」는 하지 않는 일을 말하고 있었다.
|
|
233
|
+
*/
|
|
234
|
+
renderDangerZone(user) {
|
|
235
|
+
const me = this.myEmail && user.email === this.myEmail;
|
|
236
|
+
const resettable = this.canManage && this.defaultPasswordConfigured && !me;
|
|
237
|
+
const transferable = this.canOwn &&
|
|
238
|
+
!user.owner &&
|
|
239
|
+
user.status === 'activated' &&
|
|
240
|
+
(user.roles || []).some((role) => this.domainRoleIds.has(role.id));
|
|
241
|
+
const removable = this.canManage && !user.owner && !me;
|
|
242
|
+
if (!resettable && !transferable && !removable) {
|
|
243
|
+
return nothing;
|
|
244
|
+
}
|
|
245
|
+
return html `
|
|
246
|
+
<div danger-zone>
|
|
247
|
+
<div section>${i18next.t('text.cannot be undone')}</div>
|
|
248
|
+
<div class="button-container">
|
|
249
|
+
${resettable
|
|
250
|
+
? html `<md-outlined-button @click=${() => this.onResetPassword()}>
|
|
251
|
+
${i18next.t('title.reset password')}
|
|
252
|
+
</md-outlined-button>`
|
|
253
|
+
: nothing}
|
|
254
|
+
${transferable
|
|
255
|
+
? html `<md-outlined-button @click=${() => this.onTransfer()}>
|
|
256
|
+
${i18next.t('button.transfer owner')}
|
|
257
|
+
</md-outlined-button>`
|
|
258
|
+
: nothing}
|
|
259
|
+
${removable
|
|
260
|
+
? html `<md-outlined-button @click=${() => this.onRemoveFromDomain()}>
|
|
261
|
+
${i18next.t('button.remove from domain')}
|
|
262
|
+
</md-outlined-button>`
|
|
263
|
+
: nothing}
|
|
264
|
+
</div>
|
|
265
|
+
</div>
|
|
266
|
+
`;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* 계정 상태와, 그것을 되돌리는 단추.
|
|
270
|
+
*
|
|
271
|
+
* **잠금 해제와 활성화는 서버에서 같은 것이다** — `activateUser` 가 `failCount` 를 0 으로
|
|
272
|
+
* 두고 `ACTIVATED` 로 되돌린다. 그래서 부르는 것은 하나이고, **글자만 상황에 맞춰 바꾼다.**
|
|
273
|
+
* 잠긴 사람에게 「활성화」라고 하면 무슨 일이 일어나는지 알 수 없다.
|
|
274
|
+
*
|
|
275
|
+
* 비활성화는 소유자와 나 자신에게는 내주지 않는다. 서버도 같은 것을 막지만
|
|
276
|
+
* (`inactivateUser` 가 소유자·admin 을 거절한다), **화면이 눌리는 단추를 보여 주고 서버가
|
|
277
|
+
* 거절하면 그것은 안내가 아니라 오류다.**
|
|
278
|
+
*/
|
|
279
|
+
renderAccountState(user) {
|
|
280
|
+
const status = user.status;
|
|
281
|
+
if (!this.canManage) {
|
|
282
|
+
return nothing;
|
|
283
|
+
}
|
|
284
|
+
if (status === 'locked') {
|
|
285
|
+
return html `<div class="button-container">
|
|
286
|
+
<md-elevated-button @click=${() => this.onActivate()}> ${i18next.t('button.unlock')} </md-elevated-button>
|
|
287
|
+
</div>`;
|
|
288
|
+
}
|
|
289
|
+
if (status !== 'activated') {
|
|
290
|
+
return html `<div class="button-container">
|
|
291
|
+
<md-elevated-button @click=${() => this.onActivate()}> ${i18next.t('button.activate')} </md-elevated-button>
|
|
292
|
+
</div>`;
|
|
293
|
+
}
|
|
294
|
+
/* 활성 상태 — 되돌릴 수 있는 사람에게만, 그리고 자기 자신과 소유자에게는 안 준다. */
|
|
295
|
+
if (user.owner || (this.myEmail && user.email === this.myEmail)) {
|
|
296
|
+
return nothing;
|
|
297
|
+
}
|
|
298
|
+
return html `<div class="button-container">
|
|
299
|
+
<md-elevated-button danger @click=${() => this.onInactivate()}>
|
|
300
|
+
${i18next.t('button.deactivate')}
|
|
301
|
+
</md-elevated-button>
|
|
302
|
+
</div>`;
|
|
303
|
+
}
|
|
304
|
+
renderRoles() {
|
|
305
|
+
if (this.loading) {
|
|
306
|
+
return html `<div sub>${i18next.t('text.loading')}</div>`;
|
|
307
|
+
}
|
|
308
|
+
if (!this.availableRoles.length) {
|
|
309
|
+
/*
|
|
310
|
+
* 「역할이 없다」와 「못 읽었다」는 다른 말이다. 여기까지 왔다는 것은 읽었다는 뜻이므로
|
|
311
|
+
* 없는 것이 맞고, 그때는 무엇을 해야 하는지를 말한다.
|
|
312
|
+
*/
|
|
313
|
+
return html `<div note attention>${i18next.t('text.no role defined in this domain')}</div>`;
|
|
314
|
+
}
|
|
315
|
+
return html `
|
|
316
|
+
<ul roles>
|
|
317
|
+
${this.availableRoles.map(role => html `
|
|
318
|
+
<li>
|
|
319
|
+
<md-checkbox
|
|
320
|
+
id="role-${role.id}"
|
|
321
|
+
.checked=${this.selected.has(role.id)}
|
|
322
|
+
@change=${(e) => this.onToggle(role.id, e.target.checked)}
|
|
323
|
+
></md-checkbox>
|
|
324
|
+
<label for="role-${role.id}">${role.name}</label>
|
|
325
|
+
${role.description ? html `<span desc>${role.description}</span>` : nothing}
|
|
326
|
+
</li>
|
|
327
|
+
`)}
|
|
328
|
+
</ul>
|
|
329
|
+
`;
|
|
330
|
+
}
|
|
331
|
+
connectedCallback() {
|
|
332
|
+
super.connectedCallback();
|
|
333
|
+
this.applyMe();
|
|
334
|
+
this.unsubscribe = store.subscribe(() => this.applyMe());
|
|
335
|
+
this.checkGates();
|
|
336
|
+
}
|
|
337
|
+
disconnectedCallback() {
|
|
338
|
+
super.disconnectedCallback();
|
|
339
|
+
this.unsubscribe?.();
|
|
340
|
+
}
|
|
341
|
+
applyMe() {
|
|
342
|
+
const me = store.getState().auth?.user || {};
|
|
343
|
+
this.myEmail = me.email || '';
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* 서버 지시자에 적힌 인자를 그대로 되묻는다.
|
|
347
|
+
*
|
|
348
|
+
* 기본 비밀번호 여부도 여기서 함께 읽는다. 서버에 같은 답을 주는 질의가 둘 있는데
|
|
349
|
+
* (`checkDefaultPassword` 와 `checkResettablePasswordToDefault` — 둘 다
|
|
350
|
+
* `Boolean(defaultPassword)`), 하나만 쓴다.
|
|
351
|
+
*/
|
|
352
|
+
async checkGates() {
|
|
353
|
+
this.canManage = Boolean(await hasPrivilege({ category: 'user', privilege: 'mutation', domainOwnerGranted: true }));
|
|
354
|
+
this.canOwn = Boolean(await hasPrivilege({ domainOwnerGranted: true, superUserGranted: true }));
|
|
355
|
+
const response = await client.query({
|
|
356
|
+
query: gql `
|
|
357
|
+
query {
|
|
358
|
+
checkDefaultPassword
|
|
359
|
+
}
|
|
360
|
+
`,
|
|
361
|
+
context: gqlContext()
|
|
362
|
+
});
|
|
363
|
+
this.defaultPasswordConfigured = Boolean(response.data?.checkDefaultPassword);
|
|
364
|
+
}
|
|
365
|
+
updated(changes) {
|
|
366
|
+
if (changes.has('user')) {
|
|
367
|
+
this.fetch();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* 부여할 수 있는 역할을 읽는다.
|
|
372
|
+
*
|
|
373
|
+
* **이 사람이 지금 가진 역할은 다시 묻지 않는다** — 목록이 이미 실어 왔다(`user.roles`).
|
|
374
|
+
* 옛 화면은 email 로 사용자를 다시 찾았는데, 역할 이름과 달리 email 은 유일하긴 해도
|
|
375
|
+
* 손에 든 `id` 를 두고 다른 열쇠로 같은 사람을 찾는 것이었다. 안 물으면 그 문제가 없다.
|
|
376
|
+
*
|
|
377
|
+
* **이 도메인의 역할과 파트너십으로 넘어온 역할을 한 목록으로 합친다.** 옛 화면은 그 둘을
|
|
378
|
+
* 따로 그리고 저장할 때 화면에서 다시 모았는데, 합치는 자리가 화면이면 화면이 못 그린 것은
|
|
379
|
+
* 저장에서도 빠진다.
|
|
380
|
+
*/
|
|
381
|
+
async fetch() {
|
|
382
|
+
const user = this.user;
|
|
383
|
+
if (!user?.id) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
this.loading = true;
|
|
387
|
+
const response = await client.query({
|
|
388
|
+
query: gql `
|
|
389
|
+
query ($inherited: InheritedValueType) {
|
|
390
|
+
roles(inherited: $inherited) {
|
|
391
|
+
items {
|
|
392
|
+
id
|
|
393
|
+
name
|
|
394
|
+
description
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
grantedRoles {
|
|
398
|
+
role {
|
|
399
|
+
id
|
|
400
|
+
name
|
|
401
|
+
description
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
`,
|
|
406
|
+
variables: { inherited: InheritedValueType.Include },
|
|
407
|
+
context: gqlContext()
|
|
408
|
+
});
|
|
409
|
+
const roles = response.data?.roles?.items || [];
|
|
410
|
+
const granted = (response.data?.grantedRoles || []).map((g) => g.role).filter(Boolean);
|
|
411
|
+
/* 같은 역할이 두 경로로 올 수 있다 — id 로 한 번만 담는다. */
|
|
412
|
+
const byId = new Map();
|
|
413
|
+
for (const role of [...roles, ...granted]) {
|
|
414
|
+
byId.set(role.id, role);
|
|
415
|
+
}
|
|
416
|
+
this.availableRoles = [...byId.values()];
|
|
417
|
+
/* 소유권 이전 자격은 **이 도메인(과 부모)의 역할**만 인정한다 — 합친 목록으로는 못 본다. */
|
|
418
|
+
this.domainRoleIds = new Set(roles.map((role) => role.id));
|
|
419
|
+
this.selected = new Set((user.roles || []).map((r) => r.id));
|
|
420
|
+
this.loading = false;
|
|
421
|
+
}
|
|
422
|
+
/** 잠금 해제와 활성화가 같은 부름이다 — 서버가 `failCount` 도 0 으로 되돌린다. */
|
|
423
|
+
async onActivate() {
|
|
424
|
+
await this.runUserMutation(gql `
|
|
425
|
+
mutation ($username: String!) {
|
|
426
|
+
activateUser(username: $username)
|
|
427
|
+
}
|
|
428
|
+
`);
|
|
429
|
+
}
|
|
430
|
+
async onInactivate() {
|
|
431
|
+
await this.runUserMutation(gql `
|
|
432
|
+
mutation ($username: String!) {
|
|
433
|
+
inactivateUser(username: $username)
|
|
434
|
+
}
|
|
435
|
+
`);
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* 비밀번호를 기본값으로 되돌린다.
|
|
439
|
+
*
|
|
440
|
+
* **무엇이 되는지 사람이 알 수 있게 말한다.** 「초기화하시겠습니까」는 그 뒤에 무엇을 알려
|
|
441
|
+
* 줘야 하는지를 안 말한다 — 초기화된 비밀번호는 관리자가 상대에게 따로 전해야 한다(서버가
|
|
442
|
+
* 메일을 보내지 않는다).
|
|
443
|
+
*/
|
|
444
|
+
async onResetPassword() {
|
|
445
|
+
const confirmed = await OxPrompt.open({
|
|
446
|
+
type: 'warning',
|
|
447
|
+
title: i18next.t('title.reset password'),
|
|
448
|
+
text: i18next.t('text.password becomes the default and must be told to them'),
|
|
449
|
+
confirmButton: { text: i18next.t('button.confirm') },
|
|
450
|
+
cancelButton: { text: i18next.t('button.cancel') }
|
|
451
|
+
});
|
|
452
|
+
if (!confirmed) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const done = await this.runUserMutation(gql `
|
|
456
|
+
mutation ($username: String!) {
|
|
457
|
+
resetPasswordToDefault(username: $username)
|
|
458
|
+
}
|
|
459
|
+
`, { notify: false });
|
|
460
|
+
if (done) {
|
|
461
|
+
await OxPrompt.open({
|
|
462
|
+
type: 'success',
|
|
463
|
+
title: i18next.t('text.completed'),
|
|
464
|
+
text: i18next.t('text.password reset succeed'),
|
|
465
|
+
confirmButton: { text: i18next.t('button.confirm') }
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* 이 도메인에서만 뗀다 — 계정은 남는다.
|
|
471
|
+
*
|
|
472
|
+
* 그래서 확인 문구도 「지웁니다」가 아니다. 이 사람은 다른 도메인에서 계속 일할 수 있고,
|
|
473
|
+
* 다시 부르면 된다.
|
|
474
|
+
*/
|
|
475
|
+
async onRemoveFromDomain() {
|
|
476
|
+
const user = this.user || {};
|
|
477
|
+
const confirmed = await OxPrompt.open({
|
|
478
|
+
type: 'warning',
|
|
479
|
+
title: i18next.t('button.remove from domain'),
|
|
480
|
+
text: i18next.t('text.they lose access to this domain but keep the account'),
|
|
481
|
+
confirmButton: { text: i18next.t('button.confirm') },
|
|
482
|
+
cancelButton: { text: i18next.t('button.cancel') }
|
|
483
|
+
});
|
|
484
|
+
if (!confirmed) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
const done = await this.runUserMutation(gql `
|
|
488
|
+
mutation ($username: String!) {
|
|
489
|
+
deleteDomainUser(username: $username)
|
|
490
|
+
}
|
|
491
|
+
`);
|
|
492
|
+
if (done) {
|
|
493
|
+
/* 이 사람은 이제 목록에 없다 — 상세를 열어 둘 이유가 없다. */
|
|
494
|
+
this.dispatchEvent(new CustomEvent('close'));
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* 소유권을 넘긴다.
|
|
499
|
+
*
|
|
500
|
+
* 이미 있는 `ownership-transfer-popup` 을 그대로 쓴다 — 그 안에 **이메일을 다시 적게 하는**
|
|
501
|
+
* 확인이 들어 있다. 되돌릴 수 없는 것 중에서 유일하게 두 단계인 것이고, 그 판단이 맞다.
|
|
502
|
+
*/
|
|
503
|
+
onTransfer() {
|
|
504
|
+
const popup = openPopup(html `<ownership-transfer-popup
|
|
505
|
+
.user=${this.user}
|
|
506
|
+
@ownershipTransferred=${() => {
|
|
507
|
+
popup.close();
|
|
508
|
+
this.dispatchEvent(new CustomEvent('user-updated', { detail: this.user, bubbles: true, composed: true }));
|
|
509
|
+
}}
|
|
510
|
+
></ownership-transfer-popup>`, {
|
|
511
|
+
backdrop: true,
|
|
512
|
+
size: 'large',
|
|
513
|
+
title: i18next.t('title.owner_transfer')
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
async runUserMutation(mutation, { notify = true } = {}) {
|
|
517
|
+
const username = this.user?.username || this.user?.email;
|
|
518
|
+
if (!username || this.saving) {
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
this.saving = true;
|
|
522
|
+
try {
|
|
523
|
+
const response = await client.mutate({ mutation, variables: { username }, context: gqlContext() });
|
|
524
|
+
if (response.errors) {
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
/*
|
|
528
|
+
* 비밀번호 초기화만 목록을 바꾸지 않는다 — 상태도 역할도 그대로다. 그때 목록을 다시
|
|
529
|
+
* 읽으면 아무것도 안 달라진 화면이 깜빡이고, 사람은 뭐가 됐는지 더 모르게 된다.
|
|
530
|
+
*/
|
|
531
|
+
if (notify) {
|
|
532
|
+
this.dispatchEvent(new CustomEvent('user-updated', { detail: this.user, bubbles: true, composed: true }));
|
|
533
|
+
}
|
|
534
|
+
return true;
|
|
535
|
+
}
|
|
536
|
+
finally {
|
|
537
|
+
this.saving = false;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
onToggle(id, checked) {
|
|
541
|
+
const next = new Set(this.selected);
|
|
542
|
+
checked ? next.add(id) : next.delete(id);
|
|
543
|
+
this.selected = next;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* **범위를 상태에서 만든다.** 읽어 온 목록이 곧 `availableRoles` 다.
|
|
547
|
+
*
|
|
548
|
+
* 빈 범위를 보내면 서버는 「뗄 것이 없다」로 읽어 아무것도 안 한다 — 우연히 무해한 것이지
|
|
549
|
+
* 뜻한 바가 아니므로, 그 경우는 여기까지 오지 않는다(`savable`).
|
|
550
|
+
*/
|
|
551
|
+
async onSave() {
|
|
552
|
+
/* 단추가 이미 막고 있다 — 여기 걸리면 단추와 이 자리가 어긋난 것이다. */
|
|
553
|
+
if (!this.savable) {
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
const user = this.user;
|
|
557
|
+
const username = user?.username || user?.email;
|
|
558
|
+
if (!username) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
this.saving = true;
|
|
562
|
+
try {
|
|
563
|
+
const response = await client.mutate({
|
|
564
|
+
mutation: gql `
|
|
565
|
+
mutation ($username: String!, $availableRoles: [ObjectRef!]!, $selectedRoles: [ObjectRef!]!) {
|
|
566
|
+
updateUserRoles(username: $username, availableRoles: $availableRoles, selectedRoles: $selectedRoles) {
|
|
567
|
+
id
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
`,
|
|
571
|
+
variables: {
|
|
572
|
+
username,
|
|
573
|
+
availableRoles: this.availableRoles.map(role => ({ id: role.id })),
|
|
574
|
+
selectedRoles: this.availableRoles.filter(role => this.selected.has(role.id)).map(role => ({ id: role.id }))
|
|
575
|
+
},
|
|
576
|
+
context: gqlContext()
|
|
577
|
+
});
|
|
578
|
+
if (!response.errors) {
|
|
579
|
+
this.dispatchEvent(new CustomEvent('user-updated', { detail: user, bubbles: true, composed: true }));
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
finally {
|
|
583
|
+
this.saving = false;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
__decorate([
|
|
588
|
+
property({ type: Object }),
|
|
589
|
+
__metadata("design:type", Object)
|
|
590
|
+
], UserDetail.prototype, "user", void 0);
|
|
591
|
+
__decorate([
|
|
592
|
+
state(),
|
|
593
|
+
__metadata("design:type", Array)
|
|
594
|
+
], UserDetail.prototype, "availableRoles", void 0);
|
|
595
|
+
__decorate([
|
|
596
|
+
state(),
|
|
597
|
+
__metadata("design:type", Set)
|
|
598
|
+
], UserDetail.prototype, "selected", void 0);
|
|
599
|
+
__decorate([
|
|
600
|
+
state(),
|
|
601
|
+
__metadata("design:type", Boolean)
|
|
602
|
+
], UserDetail.prototype, "loading", void 0);
|
|
603
|
+
__decorate([
|
|
604
|
+
state(),
|
|
605
|
+
__metadata("design:type", Boolean)
|
|
606
|
+
], UserDetail.prototype, "saving", void 0);
|
|
607
|
+
__decorate([
|
|
608
|
+
state(),
|
|
609
|
+
__metadata("design:type", Boolean)
|
|
610
|
+
], UserDetail.prototype, "canManage", void 0);
|
|
611
|
+
__decorate([
|
|
612
|
+
state(),
|
|
613
|
+
__metadata("design:type", Boolean)
|
|
614
|
+
], UserDetail.prototype, "canOwn", void 0);
|
|
615
|
+
__decorate([
|
|
616
|
+
state(),
|
|
617
|
+
__metadata("design:type", String)
|
|
618
|
+
], UserDetail.prototype, "myEmail", void 0);
|
|
619
|
+
__decorate([
|
|
620
|
+
state(),
|
|
621
|
+
__metadata("design:type", Boolean)
|
|
622
|
+
], UserDetail.prototype, "defaultPasswordConfigured", void 0);
|
|
623
|
+
__decorate([
|
|
624
|
+
state(),
|
|
625
|
+
__metadata("design:type", Set)
|
|
626
|
+
], UserDetail.prototype, "domainRoleIds", void 0);
|
|
627
|
+
UserDetail = __decorate([
|
|
628
|
+
customElement('user-detail')
|
|
629
|
+
], UserDetail);
|
|
630
|
+
export { UserDetail };
|
|
631
|
+
//# sourceMappingURL=user-detail.js.map
|