@things-factory/auth-ui 7.0.1-rc.0 → 7.0.1-rc.10
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/client/auth-style-sign.ts +2 -1
- package/client/components/abstract-sign.ts +30 -72
- package/client/components/contact-us.ts +0 -4
- package/client/components/delete-user-popup.ts +1 -0
- package/client/components/partner-role-editor.ts +0 -4
- package/client/components/profile-component.ts +27 -91
- package/client/components/role-privilege-editor.ts +0 -3
- package/client/components/user-role-editor.ts +0 -4
- package/client/entries/auth/activate.ts +4 -5
- package/client/entries/auth/checkin.ts +5 -2
- package/client/entries/auth/result.ts +5 -3
- package/client/entries/oauth2/oauth2-decision-page.ts +0 -4
- package/client/pages/app-binding/app-binding.ts +38 -22
- package/client/pages/app-binding/app-bindings.ts +20 -1
- package/client/pages/appliance/appliance.ts +75 -18
- package/client/pages/appliance/home.ts +23 -1
- package/client/pages/application/application.ts +93 -40
- package/client/pages/application/applications.ts +19 -1
- package/dist-client/auth-style-sign.js +2 -1
- package/dist-client/auth-style-sign.js.map +1 -1
- package/dist-client/components/abstract-sign.d.ts +1 -1
- package/dist-client/components/abstract-sign.js +26 -60
- package/dist-client/components/abstract-sign.js.map +1 -1
- package/dist-client/components/contact-us.js +0 -4
- package/dist-client/components/contact-us.js.map +1 -1
- package/dist-client/components/delete-user-popup.js +1 -0
- package/dist-client/components/delete-user-popup.js.map +1 -1
- package/dist-client/components/partner-role-editor.js +0 -4
- package/dist-client/components/partner-role-editor.js.map +1 -1
- package/dist-client/components/profile-component.d.ts +1 -1
- package/dist-client/components/profile-component.js +25 -80
- package/dist-client/components/profile-component.js.map +1 -1
- package/dist-client/components/role-privilege-editor.js +0 -3
- package/dist-client/components/role-privilege-editor.js.map +1 -1
- package/dist-client/components/user-role-editor.js +0 -4
- package/dist-client/components/user-role-editor.js.map +1 -1
- package/dist-client/entries/auth/activate.js +4 -5
- package/dist-client/entries/auth/activate.js.map +1 -1
- package/dist-client/entries/auth/checkin.js +5 -2
- package/dist-client/entries/auth/checkin.js.map +1 -1
- package/dist-client/entries/auth/result.js +5 -3
- package/dist-client/entries/auth/result.js.map +1 -1
- package/dist-client/entries/oauth2/oauth2-decision-page.js +0 -4
- package/dist-client/entries/oauth2/oauth2-decision-page.js.map +1 -1
- package/dist-client/pages/app-binding/app-binding.js +38 -22
- package/dist-client/pages/app-binding/app-binding.js.map +1 -1
- package/dist-client/pages/app-binding/app-bindings.d.ts +2 -1
- package/dist-client/pages/app-binding/app-bindings.js +19 -1
- package/dist-client/pages/app-binding/app-bindings.js.map +1 -1
- package/dist-client/pages/appliance/appliance.js +75 -18
- package/dist-client/pages/appliance/appliance.js.map +1 -1
- package/dist-client/pages/appliance/home.d.ts +2 -1
- package/dist-client/pages/appliance/home.js +22 -1
- package/dist-client/pages/appliance/home.js.map +1 -1
- package/dist-client/pages/application/application.js +93 -40
- package/dist-client/pages/application/application.js.map +1 -1
- package/dist-client/pages/application/applications.d.ts +2 -1
- package/dist-client/pages/application/applications.js +18 -1
- package/dist-client/pages/application/applications.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { html, nothing } from 'lit';
|
|
2
|
-
import base64url from 'base64url';
|
|
3
1
|
import '@operato/i18n/ox-i18n.js';
|
|
2
|
+
import { html, nothing } from 'lit';
|
|
3
|
+
import { startAuthentication } from '@simplewebauthn/browser';
|
|
4
4
|
import { i18next } from '@operato/i18n';
|
|
5
5
|
import { notify } from '@operato/layout';
|
|
6
6
|
import { AbstractAuthPage } from './abstract-auth-page.js';
|
|
@@ -66,75 +66,41 @@ export class AbstractSign extends AbstractAuthPage {
|
|
|
66
66
|
<ox-i18n msgid="field.${this.pageName}"> </ox-i18n>
|
|
67
67
|
</md-elevated-button>
|
|
68
68
|
${isAvailableWebauthn
|
|
69
|
-
? html ` <md-icon class="fingerprint" raised @click=${e => this.
|
|
69
|
+
? html ` <md-icon class="fingerprint" raised @click=${e => this.authenticateUser()}> fingerprint </md-icon>`
|
|
70
70
|
: nothing}
|
|
71
71
|
</div>
|
|
72
72
|
`;
|
|
73
73
|
}
|
|
74
|
-
async
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const options = await response.json();
|
|
91
|
-
const credential = (await navigator.credentials.get({
|
|
92
|
-
publicKey: {
|
|
93
|
-
challenge: Buffer.from(options.challenge, 'base64')
|
|
74
|
+
async authenticateUser() {
|
|
75
|
+
try {
|
|
76
|
+
const options = await fetch('/auth/signin-webauthn/challenge').then(res => res.json());
|
|
77
|
+
const assertionResp = await startAuthentication(options);
|
|
78
|
+
const verification = await fetch('/auth/signin-webauthn', {
|
|
79
|
+
method: 'POST',
|
|
80
|
+
headers: {
|
|
81
|
+
'Content-Type': 'application/json'
|
|
82
|
+
},
|
|
83
|
+
body: JSON.stringify(assertionResp)
|
|
84
|
+
}).then(res => res.json());
|
|
85
|
+
if (verification.verified) {
|
|
86
|
+
const { redirectURL } = verification;
|
|
87
|
+
if (redirectURL) {
|
|
88
|
+
window.location.href = redirectURL;
|
|
89
|
+
}
|
|
94
90
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const assertionResponse = {
|
|
104
|
-
id: credential.id,
|
|
105
|
-
response: {
|
|
106
|
-
clientDataJSON: base64url.encode(Buffer.from(credential.response.clientDataJSON)),
|
|
107
|
-
authenticatorData: base64url.encode(credential.response.authenticatorData),
|
|
108
|
-
signature: base64url.encode(credential.response.signature),
|
|
109
|
-
userHandle: credential.response.userHandle
|
|
110
|
-
? base64url.encode(credential.response.userHandle)
|
|
111
|
-
: null
|
|
91
|
+
else {
|
|
92
|
+
notify({
|
|
93
|
+
level: 'error',
|
|
94
|
+
message: verification.message
|
|
95
|
+
});
|
|
112
96
|
}
|
|
113
|
-
};
|
|
114
|
-
if (credential.authenticatorAttachment) {
|
|
115
|
-
assertionResponse.authenticatorAttachment = credential.authenticatorAttachment;
|
|
116
97
|
}
|
|
117
|
-
|
|
118
|
-
method: 'POST',
|
|
119
|
-
headers: {
|
|
120
|
-
'Content-Type': 'application/json',
|
|
121
|
-
Accept: 'application/json'
|
|
122
|
-
},
|
|
123
|
-
body: JSON.stringify(assertionResponse),
|
|
124
|
-
credentials: 'include'
|
|
125
|
-
});
|
|
126
|
-
if (!signinResponse.ok) {
|
|
98
|
+
catch (error) {
|
|
127
99
|
notify({
|
|
128
100
|
level: 'error',
|
|
129
|
-
message:
|
|
101
|
+
message: i18next.t('error.authn verification failed')
|
|
130
102
|
});
|
|
131
103
|
}
|
|
132
|
-
else {
|
|
133
|
-
const { redirectURL } = await signinResponse.json();
|
|
134
|
-
if (redirectURL) {
|
|
135
|
-
window.location.href = redirectURL;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
104
|
}
|
|
139
105
|
}
|
|
140
106
|
//# sourceMappingURL=abstract-sign.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-sign.js","sourceRoot":"","sources":["../../client/components/abstract-sign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AACnC,OAAO,
|
|
1
|
+
{"version":3,"file":"abstract-sign.js","sourceRoot":"","sources":["../../client/components/abstract-sign.ts"],"names":[],"mappings":"AAAA,OAAO,0BAA0B,CAAA;AAEjC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAE7D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,CAAC;QAEH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC;gBACL,KAAK,EAAE,OAAO;gBACd,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,iCAAiC,CAAC;aACtD,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF","sourcesContent":["import '@operato/i18n/ox-i18n.js'\n\nimport { html, nothing } from 'lit'\nimport { startAuthentication } from '@simplewebauthn/browser'\n\nimport { i18next } from '@operato/i18n'\nimport { notify } from '@operato/layout'\n\nimport { AbstractAuthPage } from './abstract-auth-page.js'\n\nconst isAvailableWebauthn = 'PublicKeyCredential' in window\n\ninterface AssertionResponse {\n id: string\n rawId?: number[]\n response: {\n authenticatorData: string\n clientDataJSON: string\n signature: string\n userHandle: string | null\n }\n type: PublicKeyCredentialType\n authenticatorAttachment?: AuthenticatorAttachment\n}\n\nexport abstract class AbstractSign extends AbstractAuthPage {\n async submit() {\n this.formEl.submit()\n }\n\n updated(changed) {\n super.updated(changed)\n\n if (changed.has('message')) {\n if (!this.message) {\n this.hideSnackbar()\n } else {\n this.showSnackbar({\n level: 'error',\n timer: -1\n })\n }\n }\n }\n\n get formfields() {\n const email = this.data?.email || ''\n\n return html`\n <input id=\"redirectTo\" type=\"hidden\" name=\"redirectTo\" .value=${this.redirectTo || '/'} />\n\n <div class=\"field\">\n <md-filled-text-field\n name=\"email\"\n type=\"email\"\n label=${String(i18next.t('field.email'))}\n required\n .value=${email}\n autocomplete=\"username\"\n autocapitalize=\"off\"\n @input=${(e: Event) => {\n const target = e.target as HTMLInputElement\n if (target.validity.typeMismatch) {\n target.setCustomValidity(i18next.t('text.invalid-email'))\n } else {\n target.setCustomValidity('')\n }\n }}\n ><md-icon slot=\"leading-icon\">mail</md-icon></md-filled-text-field\n >\n </div>\n <div class=\"field\">\n <md-filled-text-field\n name=\"password\"\n type=\"password\"\n label=${String(i18next.t('field.password'))}\n autocomplete=\"current-password\"\n required\n ><md-icon slot=\"leading-icon\">vpn_key</md-icon></md-filled-text-field\n >\n </div>\n\n <div class=\"submit-buttons-container\">\n <md-elevated-button class=\"submit-button\" type=\"submit\" raised @click=${e => this._onSubmit(e)}>\n <ox-i18n msgid=\"field.${this.pageName}\"> </ox-i18n>\n </md-elevated-button>\n ${isAvailableWebauthn\n ? html` <md-icon class=\"fingerprint\" raised @click=${e => this.authenticateUser()}> fingerprint </md-icon>`\n : nothing}\n </div>\n `\n }\n\n async authenticateUser() {\n try {\n const options = await fetch('/auth/signin-webauthn/challenge').then(res => res.json())\n const assertionResp = await startAuthentication(options)\n const verification = await fetch('/auth/signin-webauthn', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify(assertionResp)\n }).then(res => res.json())\n\n if (verification.verified) {\n const { redirectURL } = verification\n \n if (redirectURL) {\n window.location.href = redirectURL\n }\n } else {\n notify({\n level: 'error',\n message: verification.message\n })\n }\n \n } catch (error) {\n notify({\n level: 'error',\n message: i18next.t('error.authn verification failed')\n })\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contact-us.js","sourceRoot":"","sources":["../../client/components/contact-us.ts"],"names":[],"mappings":";AAAA,OAAO,qCAAqC,CAAA;AAC5C,OAAO,yCAAyC,CAAA;AAChD,OAAO,8CAA8C,CAAA;AACrD,OAAO,gCAAgC,CAAA;AAEvC,OAAO,eAAe,CAAA;AAEtB,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAExD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,+CAA+C,CAAA;AAG7D,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;IAC1D,MAAM,KAAK,MAAM;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AC7B;IAAxB,KAAK,CAAC,gBAAgB,CAAC;8BAAgB,gBAAgB;+CAAA;AAxB7C,SAAS;IADrB,aAAa,CAAC,YAAY,CAAC;GACf,SAAS,CAkGrB","sourcesContent":["import '@material/web/button/text-button.js'\nimport '@material/web/button/elevated-button.js'\nimport '@material/web/textfield/filled-text-field.js'\nimport '@material/web/dialog/dialog.js'\n\nimport '@operato/i18n'\n\nimport { css, html, LitElement } from 'lit'\nimport { customElement, query } from 'lit/decorators.js'\n\nimport { i18next, localize } from '@operato/i18n'\nimport { auth } from '@things-factory/auth-base/dist-client/auth.js'\n\n@customElement('contact-us')\nexport class ContactUs extends localize(i18next)(LitElement) {\n static get styles() {\n return [\n css`\n * {\n box-sizing: border-box;\n }\n\n *:focus {\n outline: none;\n }\n\n #input-form {\n display: grid;\n grid-template-rows: 1fr 1fr 3fr;\n grid-gap: 10px 0;\n }\n `\n ]\n }\n\n @query('#dialog') dialog!: HTMLElement & { open: boolean }\n @query('#subject-input') subjectInput!: HTMLInputElement\n @query('#sender-input') senderInput!: HTMLInputElement\n @query('#content-input') contentInput!: HTMLInputElement\n\n render() {\n return html`\n <md-elevated-button @click=${e => (this.dialog.open = true)}>${i18next.t('button.need help')}</md-elevated-button>\n\n <md-dialog id=\"dialog\" heading=${i18next.t('title.need help')}>\n <form action=\"\" method=\"POST\">\n <input id=\"subject-input\" name=\"subject\" type=\"hidden\" />\n <input id=\"sender-input\" name=\"sender\" type=\"hidden\" />\n <input id=\"content-input\" name=\"content\" type=\"hidden\" />\n </form>\n <div id=\"input-form\">\n <md-filled-text-field\n type=\"text\"\n label=${i18next.t('label.subject')}\n dialogInitialFocus\n required\n @input=${e => {\n const val = e.target.value\n this.subjectInput.value = val\n }}\n ></md-filled-text-field>\n <md-filled-text-field\n type=\"text\"\n name=\"sender\"\n label=${i18next.t('label.email')}\n required\n @input=${e => {\n const val = e.target.value\n this.senderInput.value = val\n }}\n ></md-filled-text-field>\n <md-filled-text-field\n name=\"content\"\n type=\"textarea\"\n label=${i18next.t('label.content')}\n required\n @keydown=${e => e.stopPropagation()}\n @input=${e => {\n const val = e.target.value\n this.contentInput.value = val\n }}\n ></md-filled-text-field>\n </div>\n <md-elevated-button slot=\"primaryAction\" type=\"submit\" @click=${e => this._submit(e)}\n >${i18next.t('button.submit')}</md-elevated-button\n >\n <md-text-button slot=\"secondaryAction\" dialogAction=\"cancel\">${i18next.t('button.cancel')}</md-text-button>\n </md-dialog>\n `\n }\n\n _checkValidity(): boolean {\n return false\n }\n\n _submit(e: MouseEvent) {\n if (!this._checkValidity()) return\n\n const form = e.target as HTMLFormElement\n\n const formData = new FormData(form)\n let json = {}\n\n //convert form into json\n for (const [key, value] of formData.entries()) {\n json[key] = value\n }\n\n auth.changePassword(json)\n\n form.reset()\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-user-popup.js","sourceRoot":"","sources":["../../client/components/delete-user-popup.ts"],"names":[],"mappings":";AAAA,OAAO,0BAA0B,CAAA;AAEjC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,+CAA+C,CAAA;AAG7D,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"delete-user-popup.js","sourceRoot":"","sources":["../../client/components/delete-user-popup.ts"],"names":[],"mappings":";AAAA,OAAO,0BAA0B,CAAA;AAEjC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAyDF;CACF,AA3DY,CA2DZ;AA5DU,eAAe;IAD3B,aAAa,CAAC,mBAAmB,CAAC;GACtB,eAAe,CA0G3B","sourcesContent":["import '@operato/i18n/ox-i18n.js'\n\nimport { css, html, LitElement } from 'lit'\nimport { customElement } from 'lit/decorators.js'\n\nimport { i18next, localize } from '@operato/i18n'\nimport { notify } from '@operato/layout'\nimport { auth } from '@things-factory/auth-base/dist-client/auth.js'\n\n@customElement('delete-user-popup')\nexport class DeleteUserPopup extends localize(i18next)(LitElement) {\n static styles = [\n css`\n :host {\n display: flex;\n flex-direction: column;\n color: var(--popup-content-color);\n background-color: var(--popup-content-background-color);\n padding: var(--popup-content-padding);\n }\n\n * {\n box-sizing: border-box;\n }\n *:focus {\n outline: none;\n }\n\n label {\n font: bold 14px var(--theme-font);\n color: var(--md-sys-color-primary);\n }\n\n input {\n border: var(--change-password-field-border);\n border-radius: var(--change-password-field-border-radius);\n padding: var(--change-password-field-padding);\n\n font: var(--change-password-field-font);\n width: var(--change-password-field-width);\n }\n input:focus {\n border: 1px solid var(--focus-background-color);\n }\n\n div.field {\n padding-bottom: 10px;\n }\n\n ::placeholder {\n font-size: 0.8rem;\n text-transform: capitalize;\n }\n\n button {\n background-color: var(--status-danger-color, #d14946);\n margin: 2px 2px 10px 2px;\n height: var(--button-height, 28px);\n color: var(--button-color, #fff);\n font: var(--button-font);\n border-radius: var(--button-radius, 5px);\n border: var(--button-border, 1px solid transparent);\n line-height: 1.5;\n }\n button:hover,\n button:active {\n background-color: var(--button-active-background-color, #22a6a7);\n border: var(--button-active-border);\n }\n `\n ]\n\n render() {\n return html`\n <h1><ox-i18n msgid=\"label.delete account\"></ox-i18n></h1>\n <span><ox-i18n msgid=\"text.delete account warning message\"></ox-i18n></span>\n <form @submit=${e => this.submit(e)}>\n <div class=\"field\">\n <label for=\"email\"><ox-i18n msgid=\"label.email\"></ox-i18n></label>\n <input id=\"email\" type=\"email\" name=\"email\" autocapitalize=\"off\" required />\n <label for=\"password\"><ox-i18n msgid=\"label.password\"></ox-i18n></label>\n <input id=\"password\" type=\"password\" name=\"password\" required />\n </div>\n\n <button class=\"ui button\" type=\"submit\"><ox-i18n msgid=\"label.delete account\"></ox-i18n></button>\n </form>\n `\n }\n\n async submit(e: Event) {\n e.preventDefault()\n\n const form = e.target as HTMLFormElement\n\n var params = {}\n new FormData(form).forEach((value, key) => {\n params[key] = value\n })\n\n try {\n const message = await auth.deleteUser(params)\n notify({\n level: 'info',\n message\n })\n\n auth.signout()\n } catch (e: any) {\n form.reset()\n\n notify({\n level: 'error',\n message: 'message' in e ? e.message : e\n })\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"partner-role-editor.js","sourceRoot":"","sources":["../../client/components/partner-role-editor.ts"],"names":[],"mappings":";AAAA,OAAO,yCAAyC,CAAA;AAChD,OAAO,oBAAoB,CAAA;AAE3B,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAElE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAG9C,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;IAA7D;;
|
|
1
|
+
{"version":3,"file":"partner-role-editor.js","sourceRoot":"","s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AvIM,wBAAM,GAAG;IACd,qBAAqB;IACrB,GAAG,CAAA;;;;;;;;;;;;;;KAcF;CACF,AAjBY,CAiBZ;AAE2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;mDAAc;AACd;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;gDAAkB;AACjB;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;wDAA0B;AAE5B;IAAvB,KAAK,CAAC,eAAe,CAAC;8BAAgB,YAAY;uDAAA;AAxB/C,iBAAiB;IADtB,aAAa,CAAC,qBAAqB,CAAC;GAC/B,iBAAiB,CAyItB","sourcesContent":["import '@material/web/button/elevated-button.js'\nimport './role-selector.js'\n\nimport gql from 'graphql-tag'\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\n\nimport { client, gqlContext } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { OxPrompt } from '@operato/popup/ox-prompt.js'\nimport { ButtonContainerStyles } from '@operato/styles'\n\nimport { RoleSelector } from './role-selector'\n\n@customElement('partner-role-editor')\nclass PartnerRoleEditor extends localize(i18next)(LitElement) {\n static styles = [\n ButtonContainerStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n\n border: 1px solid var(--md-sys-color-primary);\n padding: var(--padding-default);\n font: normal 15px var(--theme-font);\n color: var(--md-sys-color-secondary);\n }\n\n md-elevated-button {\n margin-right: var(--padding-narrow);\n }\n `\n ]\n\n @property({ type: Object }) customer: any\n @property({ type: Array }) roles: any[] = []\n @property({ type: Array }) grantingRoles: any[] = []\n\n @query('role-selector') roleSelector!: RoleSelector\n\n render() {\n const roles = this.roles || []\n const grantingRoles = this.grantingRoles || []\n\n return html`\n <role-selector .roles=\"${roles}\" .userRoles=\"${grantingRoles}\"></role-selector>\n\n <div class=\"button-container\">\n <md-elevated-button @click=${this.onSave}>${i18next.t('button.save')}</md-elevated-button>\n <md-elevated-button @click=${this.onTerminateContract} danger\n >${i18next.t('button.terminate contract')}</md-elevated-button\n >\n </div>\n `\n }\n\n updated(changes) {\n if (changes.has('customer')) {\n this.refreshRoles()\n }\n }\n\n async refreshRoles() {\n const response = await client.query({\n query: gql`\n query roles($customerId: String!) {\n roles {\n items {\n id\n name\n description\n }\n total\n }\n grantingRoles(customerId: $customerId) {\n id\n role {\n id\n name\n description\n }\n }\n }\n `,\n variables: { customerId: this.customer.id },\n context: gqlContext()\n })\n\n if (!response.errors?.length) {\n this.roles = response.data.roles.items\n this.grantingRoles = response.data.grantingRoles.map(grantingRole => grantingRole.role)\n } else {\n this.roles = []\n this.grantingRoles = []\n }\n }\n\n async onSave() {\n const roles = this.roleSelector.selectedRoles()\n\n const response = await client.mutate({\n mutation: gql`\n mutation grantRoles($customerId: String!, $roles: [RolePatch!]!) {\n grantRoles(customerId: $customerId, roles: $roles)\n }\n `,\n variables: { customerId: this.customer.id, roles },\n context: gqlContext()\n })\n\n if (!response.errors?.length) {\n this.showToast(i18next.t('text.data_updated_successfully'))\n }\n }\n\n async onTerminateContract() {\n if (\n await OxPrompt.open({\n title: i18next.t('text.are_you_sure'),\n text: i18next.t('text.are_you_sure_to_terminate_contract'),\n confirmButton: { text: i18next.t('button.terminate contract') },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n ) {\n const response = await client.mutate({\n mutation: gql`\n mutation terminateContract($partnerName: String!) {\n terminateContract(partnerName: $partnerName)\n }\n `,\n variables: { partnerName: this.customer.name },\n context: gqlContext()\n })\n\n if (!response.errors?.length) {\n const answer = this.dispatchEvent(new CustomEvent('contractTerminated'))\n\n if (answer) {\n await OxPrompt.open({\n type: 'success',\n title: i18next.t('text.completed'),\n confirmButton: { text: i18next.t('button.confirm') }\n })\n }\n }\n }\n }\n\n showToast(message) {\n document.dispatchEvent(new CustomEvent('notify', { detail: { message, option: { timer: 1000 } } }))\n }\n}\n"]}
|
|
@@ -23,7 +23,7 @@ export declare class ProfileComponent extends ProfileComponent_base {
|
|
|
23
23
|
onLocaleChanged(value: any): Promise<void>;
|
|
24
24
|
openLoginHistory(): void;
|
|
25
25
|
deleteUser(): void;
|
|
26
|
-
|
|
26
|
+
registerUser(): Promise<void>;
|
|
27
27
|
get applicationMeta(): {
|
|
28
28
|
icon: string;
|
|
29
29
|
title: string;
|
|
@@ -4,9 +4,9 @@ import '@operato/i18n/ox-i18n-selector.js';
|
|
|
4
4
|
import './change-password';
|
|
5
5
|
import './delete-user-popup';
|
|
6
6
|
import './my-login-history';
|
|
7
|
-
import base64url from 'base64url';
|
|
8
7
|
import { css, html, LitElement, nothing } from 'lit';
|
|
9
8
|
import { customElement, property, query, state } from 'lit/decorators.js';
|
|
9
|
+
import { startRegistration } from '@simplewebauthn/browser';
|
|
10
10
|
import { i18next, localize } from '@operato/i18n';
|
|
11
11
|
import { notify, openPopup } from '@operato/layout';
|
|
12
12
|
import { auth, getLanguages } from '@things-factory/auth-base/dist-client';
|
|
@@ -63,7 +63,7 @@ let ProfileComponent = class ProfileComponent extends localize(i18next)(LitEleme
|
|
|
63
63
|
|
|
64
64
|
${isAvailableWebauthn
|
|
65
65
|
? html `
|
|
66
|
-
<md-text-button @click=${() => this.
|
|
66
|
+
<md-text-button @click=${() => this.registerUser()}
|
|
67
67
|
>${i18next.t('button.security-key registration')}</md-text-button
|
|
68
68
|
>
|
|
69
69
|
`
|
|
@@ -133,86 +133,35 @@ let ProfileComponent = class ProfileComponent extends localize(i18next)(LitEleme
|
|
|
133
133
|
title: i18next.t('label.delete account')
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
|
-
async
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
credentials: 'include'
|
|
145
|
-
});
|
|
146
|
-
if (!challenge.ok) {
|
|
147
|
-
notify({
|
|
148
|
-
level: 'error',
|
|
149
|
-
message: await challenge.text()
|
|
150
|
-
});
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
const options = await challenge.json();
|
|
154
|
-
const credential = (await navigator.credentials.create({
|
|
155
|
-
publicKey: {
|
|
156
|
-
rp: {
|
|
157
|
-
name: this.applicationMeta.title
|
|
158
|
-
},
|
|
159
|
-
user: {
|
|
160
|
-
id: Uint8Array.from(base64url.toBuffer(options.user.id)).buffer,
|
|
161
|
-
name: options.user.name,
|
|
162
|
-
displayName: options.user.displayName
|
|
136
|
+
async registerUser() {
|
|
137
|
+
try {
|
|
138
|
+
const options = await fetch('/auth/register-webauthn/challenge').then(res => res.json());
|
|
139
|
+
const attResp = await startRegistration(options);
|
|
140
|
+
const verification = await fetch('/auth/verify-registration', {
|
|
141
|
+
method: 'POST',
|
|
142
|
+
headers: {
|
|
143
|
+
'Content-Type': 'application/json'
|
|
163
144
|
},
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
type: 'public-key',
|
|
172
|
-
alg: -257 // RS256
|
|
173
|
-
}
|
|
174
|
-
],
|
|
175
|
-
authenticatorSelection: {
|
|
176
|
-
userVerification: 'preferred'
|
|
177
|
-
}
|
|
145
|
+
body: JSON.stringify(attResp)
|
|
146
|
+
}).then(res => res.json());
|
|
147
|
+
if (verification.verified) {
|
|
148
|
+
notify({
|
|
149
|
+
level: 'info',
|
|
150
|
+
message: i18next.t('text.user credential registered successfully')
|
|
151
|
+
});
|
|
178
152
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
const response = credential.response;
|
|
188
|
-
var body = {
|
|
189
|
-
response: {
|
|
190
|
-
clientDataJSON: Buffer.from(response.clientDataJSON).toString('base64'),
|
|
191
|
-
attestationObject: Buffer.from(response.attestationObject).toString('base64')
|
|
153
|
+
else {
|
|
154
|
+
console.error(await verification.text());
|
|
155
|
+
notify({
|
|
156
|
+
level: 'error',
|
|
157
|
+
message: i18next.t('error.user credential registeration not allowed')
|
|
158
|
+
});
|
|
192
159
|
}
|
|
193
|
-
};
|
|
194
|
-
if (response.getTransports) {
|
|
195
|
-
body.response.transports = response.getTransports();
|
|
196
160
|
}
|
|
197
|
-
|
|
198
|
-
method: 'POST',
|
|
199
|
-
headers: {
|
|
200
|
-
'Content-Type': 'application/json',
|
|
201
|
-
Accept: 'application/json'
|
|
202
|
-
},
|
|
203
|
-
body: JSON.stringify(body),
|
|
204
|
-
credentials: 'include'
|
|
205
|
-
});
|
|
206
|
-
if (!signinResponse.ok) {
|
|
161
|
+
catch (error) {
|
|
207
162
|
notify({
|
|
208
163
|
level: 'error',
|
|
209
|
-
message:
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
notify({
|
|
214
|
-
level: 'info',
|
|
215
|
-
message: i18next.t('text.user credential registered successfully')
|
|
164
|
+
message: i18next.t('error.user credential registeration failed')
|
|
216
165
|
});
|
|
217
166
|
}
|
|
218
167
|
}
|
|
@@ -298,10 +247,6 @@ ProfileComponent.styles = [
|
|
|
298
247
|
margin: var(--change-password-field-margin);
|
|
299
248
|
}
|
|
300
249
|
|
|
301
|
-
[danger] {
|
|
302
|
-
--md-theme-primary: var(--md-danger-button-primary-color);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
250
|
footer {
|
|
306
251
|
padding: 20px;
|
|
307
252
|
text-align: center;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile-component.js","sourceRoot":"","sources":["../../client/components/profile-component.ts"],"names":[],"mappings":";AAAA,OAAO,0BAA0B,CAAA;AACjC,OAAO,mCAAmC,CAAA;AAC1C,OAAO,mBAAmB,CAAA;AAC1B,OAAO,qBAAqB,CAAA;AAC5B,OAAO,oBAAoB,CAAA;AAE3B,OAAO,SAAS,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,U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AAI,eAAe,GAA2B,QAAQ,CAAC,aAAa,CAAC,sCAAsC,CAAC,CAAA;QAE5G,OAAO;YACL,IAAI,EAAE,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,KAAI,EAAE;YAC1B,KAAK,EAAE,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,KAAI,gBAAgB;YAC7C,WAAW,EAAE,CAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,OAAO,KAAI,sBAAsB;SAChE,CAAA;IACH,CAAC;;AAjVM,uBAAM,GAAG;IACd,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA0FF;CACF,AA5FY,CA4FZ;AAE2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;gDAAgB;AACf;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;+CAAe;AACd;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CAAc;AAEhC;IAAR,KAAK,EAAE;;mDAAoD;AAE5C;IAAf,KAAK,CAAC,OAAO,CAAC;8BAAU,gBAAgB;gDAAA;AACvB;IAAjB,KAAK,CAAC,SAAS,CAAC;8BAAY,gBAAgB;kDAAA;AAtGlC,gBAAgB;IAD5B,aAAa,CAAC,mBAAmB,CAAC;GACtB,gBAAgB,CAmV5B","sourcesContent":["import '@operato/i18n/ox-i18n.js'\nimport '@operato/i18n/ox-i18n-selector.js'\nimport './change-password'\nimport './delete-user-popup'\nimport './my-login-history'\n\nimport base64url from 'base64url'\nimport { css, html, LitElement, nothing } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\n\nimport { i18next, localize } from '@operato/i18n'\nimport { notify, openPopup } from '@operato/layout'\nimport { auth, getLanguages } from '@things-factory/auth-base/dist-client'\n\nconst isAvailableWebauthn = 'PublicKeyCredential' in window\n@customElement('profile-component')\nexport class ProfileComponent extends localize(i18next)(LitElement) {\n static styles = [\n css`\n :host {\n display: block;\n background-color: var(--md-sys-color-background);\n padding: 15px 0;\n }\n .wrap {\n max-width: var(--profile-wrap-max-width, 400px);\n margin: auto;\n display: grid;\n grid-template-columns: 1fr 1fr;\n }\n\n * {\n box-sizing: border-box;\n }\n\n *:focus {\n outline: none;\n }\n\n input {\n margin: var(--margin-narrow) 0;\n border: 1px solid rgba(0, 0, 0, 0.2);\n padding: 9px;\n border-radius: var(--border-radius);\n font: var(--auth-input-field-font);\n width: var(--auth-input-field-width);\n }\n input:focus {\n border: 1px solid var(--focus-background-color);\n }\n\n .user {\n background: url(/assets/images/icon-profile.png) center top no-repeat;\n margin: var(--profile-icon-margin);\n padding: 180px 20px 20px 20px;\n color: var(--md-sys-color-secondary);\n font: var(--header-bar-title);\n text-align: center;\n }\n\n hr {\n width: 100%;\n border: dotted 1px rgba(0, 0, 0, 0.1);\n }\n\n .wrap * {\n grid-column: span 2;\n }\n\n label {\n font: bold 14px var(--theme-font);\n color: var(--md-sys-color-primary);\n text-transform: capitalize;\n grid-column: 1;\n }\n\n .wrap *.inline {\n grid-column: unset;\n }\n\n ox-i18n-selector {\n --i18n-selector-field-width: var(--auth-input-field-width);\n --i18n-selector-field-margin: var(--change-password-field-margin);\n --i18n-selector-field-padding: var(--padding-default);\n --i18n-selector-field-border-radius: var(--border-radius);\n margin: var(--change-password-field-margin);\n }\n\n [danger] {\n --md-theme-primary: var(--md-danger-button-primary-color);\n }\n\n footer {\n padding: 20px;\n text-align: center;\n }\n\n footer p {\n font-size: 14px;\n margin-bottom: 5px;\n color: var(--md-sys-color-on-background);\n }\n\n footer a {\n color: var(--md-sys-color-primary);\n text-decoration: none;\n font-weight: bold;\n }\n `\n ]\n\n @property({ type: String }) userId?: string\n @property({ type: String }) email?: string\n @property({ type: String }) name?: string\n\n @state() languages: { code: string; display: string }[] = []\n\n @query('#name') nameEl!: HTMLInputElement\n @query('#locale') localeEl!: HTMLInputElement\n\n async firstUpdated() {\n auth.on('profile', ({ credential }) => {\n this.setCredential(credential)\n })\n\n this.setCredential(auth.credential)\n\n this.languages = await getLanguages()\n }\n\n setCredential(credential) {\n if (credential) {\n this.userId = credential.id\n this.name = credential.name\n this.email = credential.email\n } else {\n this.userId = ''\n this.name = ''\n this.email = ''\n }\n }\n\n render() {\n return html`\n <div class=\"wrap\">\n <div class=\"user\">${this.email || ''}</div>\n\n <label for=\"name\"><ox-i18n slot=\"title\" msgid=\"label.name\"></ox-i18n></label>\n <input id=\"name\" @change=${e => this.onNameChanged(e.target.value)} .value=${this.name || ''} />\n\n <hr />\n\n <label for=\"locale\"><ox-i18n slot=\"title\" msgid=\"label.language\"></ox-i18n></label>\n <ox-i18n-selector\n id=\"locale\"\n @change=${e => this.onLocaleChanged(e.detail)}\n value=${i18next.language || 'en-US'}\n .languages=${this.languages}\n ></ox-i18n-selector>\n\n <hr />\n\n <label for=\"change-password\">\n <ox-i18n msgid=\"label.password\"></ox-i18n>\n </label>\n\n <change-password id=\"change-password\"></change-password>\n\n ${isAvailableWebauthn\n ? html`\n <md-text-button @click=${() => this.registerWebAuthn()}\n >${i18next.t('button.security-key registration')}</md-text-button\n >\n `\n : nothing}\n\n <footer>\n <p>\n ${i18next.t('text.click login history')}\n <a href=\"javascript:void(0);\" @click=${this.openLoginHistory.bind(this)}\n >${i18next.t('label.login_history')}</a\n >\n </p>\n </footer>\n </div>\n `\n }\n\n async onNameChanged(name) {\n if (!name) return\n\n var oldName = this.name\n\n try {\n const message = await auth.updateProfile({\n name\n })\n\n notify({\n level: 'info',\n message\n })\n } catch (e: any) {\n this.nameEl.value = oldName || ''\n\n notify({\n level: 'error',\n message: 'message' in e ? e.message : e\n })\n }\n }\n\n async onLocaleChanged(value) {\n if (!value) return\n\n var oldLocale = i18next.language\n\n try {\n const message = await auth.updateProfile({\n locale: value\n })\n\n i18next.changeLanguage(value)\n\n notify({\n level: 'info',\n message\n })\n } catch (e: any) {\n this.localeEl.value = oldLocale\n\n notify({\n level: 'error',\n message: 'message' in e ? e.message : e\n })\n }\n }\n\n openLoginHistory() {\n openPopup(html` <my-login-history></my-login-history> `, {\n title: i18next.t('label.login_history')\n })\n }\n\n deleteUser() {\n openPopup(html` <delete-user-popup></delete-user-popup> `, {\n title: i18next.t('label.delete account')\n })\n }\n\n async registerWebAuthn() {\n const challenge = await fetch('/auth/register-webauthn/challenge', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Accept: 'application/json'\n },\n body: JSON.stringify({ id: this.userId }),\n credentials: 'include'\n })\n\n if (!challenge.ok) {\n notify({\n level: 'error',\n message: await challenge.text()\n })\n\n return\n }\n\n const options = await challenge.json()\n\n const credential = (await navigator.credentials.create({\n publicKey: {\n rp: {\n name: this.applicationMeta.title\n },\n user: {\n id: Uint8Array.from(base64url.toBuffer(options.user.id)).buffer,\n name: options.user.name,\n displayName: options.user.displayName\n },\n challenge: Uint8Array.from(atob(options.challenge), c => c.charCodeAt(0)),\n pubKeyCredParams: [\n {\n type: 'public-key',\n alg: -7 // ES256\n },\n {\n type: 'public-key',\n alg: -257 // RS256\n }\n ],\n authenticatorSelection: {\n userVerification: 'preferred'\n }\n }\n })) as PublicKeyCredential\n\n if (!credential) {\n notify({\n level: 'error',\n message: 'can not get user credential'\n })\n\n return\n }\n\n const response = credential.response as AuthenticatorAttestationResponse\n\n var body = {\n response: {\n clientDataJSON: Buffer.from(response.clientDataJSON).toString('base64'),\n attestationObject: Buffer.from(response.attestationObject).toString('base64')\n } as any\n }\n\n if (response.getTransports) {\n body.response.transports = response.getTransports()\n }\n\n const signinResponse = await fetch('/auth/signin-webauthn', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Accept: 'application/json'\n },\n body: JSON.stringify(body),\n credentials: 'include'\n })\n\n if (!signinResponse.ok) {\n notify({\n level: 'error',\n message: await signinResponse.text()\n })\n } else {\n notify({\n level: 'info',\n message: i18next.t('text.user credential registered successfully')\n })\n }\n }\n\n get applicationMeta() {\n var iconLink: HTMLLinkElement | null = document.querySelector('link[rel=\"application-icon\"]')\n var titleMeta: HTMLMetaElement | null = document.querySelector('meta[name=\"application-name\"]')\n var descriptionMeta: HTMLMetaElement | null = document.querySelector('meta[name=\"application-description\"]')\n\n return {\n icon: iconLink?.href || '',\n title: titleMeta?.content || 'Things Factory',\n description: descriptionMeta?.content || 'Reimagining Software'\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"profile-component.js","sourceRoot":"","sources":["../../client/components/profile-component.ts"],"names":[],"mappings":";AAAA,OAAO,0BAA0B,CAAA;AACjC,OAAO,mCAAmC,CAAA;AAC1C,OAAO,mBAAmB,CAAA;AAC1B,OAAO,qBAAqB,CAAA;AAC5B,OAAO,oBAAoB,CAAA;AAG3B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAE3D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAA;AAE1E,MAAM,mBAAmB,GAAG,qBAAqB,IAAI,MAAM,CAAA;AAEpD,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;IAA5D;;QA+FI,cAAS,GAAwC,EAAE,CAAA;IAmL9D,CAAC;IA9KC,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,UAAU,E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AAC,SAAS,CAAC;8BAAY,gBAAgB;kDAAA;AAlGlC,gBAAgB;IAD5B,aAAa,CAAC,mBAAmB,CAAC;GACtB,gBAAgB,CAkR5B","sourcesContent":["import '@operato/i18n/ox-i18n.js'\nimport '@operato/i18n/ox-i18n-selector.js'\nimport './change-password'\nimport './delete-user-popup'\nimport './my-login-history'\n\nimport base64url from 'base64url'\nimport { css, html, LitElement, nothing } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\nimport { startRegistration } from '@simplewebauthn/browser'\n\nimport { i18next, localize } from '@operato/i18n'\nimport { notify, openPopup } from '@operato/layout'\nimport { auth, getLanguages } from '@things-factory/auth-base/dist-client'\n\nconst isAvailableWebauthn = 'PublicKeyCredential' in window\n@customElement('profile-component')\nexport class ProfileComponent extends localize(i18next)(LitElement) {\n static styles = [\n css`\n :host {\n display: block;\n background-color: var(--md-sys-color-background);\n padding: 15px 0;\n }\n .wrap {\n max-width: var(--profile-wrap-max-width, 400px);\n margin: auto;\n display: grid;\n grid-template-columns: 1fr 1fr;\n }\n\n * {\n box-sizing: border-box;\n }\n\n *:focus {\n outline: none;\n }\n\n input {\n margin: var(--margin-narrow) 0;\n border: 1px solid rgba(0, 0, 0, 0.2);\n padding: 9px;\n border-radius: var(--border-radius);\n font: var(--auth-input-field-font);\n width: var(--auth-input-field-width);\n }\n input:focus {\n border: 1px solid var(--focus-background-color);\n }\n\n .user {\n background: url(/assets/images/icon-profile.png) center top no-repeat;\n margin: var(--profile-icon-margin);\n padding: 180px 20px 20px 20px;\n color: var(--md-sys-color-secondary);\n font: var(--header-bar-title);\n text-align: center;\n }\n\n hr {\n width: 100%;\n border: dotted 1px rgba(0, 0, 0, 0.1);\n }\n\n .wrap * {\n grid-column: span 2;\n }\n\n label {\n font: bold 14px var(--theme-font);\n color: var(--md-sys-color-primary);\n text-transform: capitalize;\n grid-column: 1;\n }\n\n .wrap *.inline {\n grid-column: unset;\n }\n\n ox-i18n-selector {\n --i18n-selector-field-width: var(--auth-input-field-width);\n --i18n-selector-field-margin: var(--change-password-field-margin);\n --i18n-selector-field-padding: var(--padding-default);\n --i18n-selector-field-border-radius: var(--border-radius);\n margin: var(--change-password-field-margin);\n }\n\n footer {\n padding: 20px;\n text-align: center;\n }\n\n footer p {\n font-size: 14px;\n margin-bottom: 5px;\n color: var(--md-sys-color-on-background);\n }\n\n footer a {\n color: var(--md-sys-color-primary);\n text-decoration: none;\n font-weight: bold;\n }\n `\n ]\n\n @property({ type: String }) userId?: string\n @property({ type: String }) email?: string\n @property({ type: String }) name?: string\n\n @state() languages: { code: string; display: string }[] = []\n\n @query('#name') nameEl!: HTMLInputElement\n @query('#locale') localeEl!: HTMLInputElement\n\n async firstUpdated() {\n auth.on('profile', ({ credential }) => {\n this.setCredential(credential)\n })\n\n this.setCredential(auth.credential)\n\n this.languages = await getLanguages()\n }\n\n setCredential(credential) {\n if (credential) {\n this.userId = credential.id\n this.name = credential.name\n this.email = credential.email\n } else {\n this.userId = ''\n this.name = ''\n this.email = ''\n }\n }\n\n render() {\n return html`\n <div class=\"wrap\">\n <div class=\"user\">${this.email || ''}</div>\n\n <label for=\"name\"><ox-i18n slot=\"title\" msgid=\"label.name\"></ox-i18n></label>\n <input id=\"name\" @change=${e => this.onNameChanged(e.target.value)} .value=${this.name || ''} />\n\n <hr />\n\n <label for=\"locale\"><ox-i18n slot=\"title\" msgid=\"label.language\"></ox-i18n></label>\n <ox-i18n-selector\n id=\"locale\"\n @change=${e => this.onLocaleChanged(e.detail)}\n value=${i18next.language || 'en-US'}\n .languages=${this.languages}\n ></ox-i18n-selector>\n\n <hr />\n\n <label for=\"change-password\">\n <ox-i18n msgid=\"label.password\"></ox-i18n>\n </label>\n\n <change-password id=\"change-password\"></change-password>\n\n ${isAvailableWebauthn\n ? html`\n <md-text-button @click=${() => this.registerUser()}\n >${i18next.t('button.security-key registration')}</md-text-button\n >\n `\n : nothing}\n\n <footer>\n <p>\n ${i18next.t('text.click login history')}\n <a href=\"javascript:void(0);\" @click=${this.openLoginHistory.bind(this)}\n >${i18next.t('label.login_history')}</a\n >\n </p>\n </footer>\n </div>\n `\n }\n\n async onNameChanged(name) {\n if (!name) return\n\n var oldName = this.name\n\n try {\n const message = await auth.updateProfile({\n name\n })\n\n notify({\n level: 'info',\n message\n })\n } catch (e: any) {\n this.nameEl.value = oldName || ''\n\n notify({\n level: 'error',\n message: 'message' in e ? e.message : e\n })\n }\n }\n\n async onLocaleChanged(value) {\n if (!value) return\n\n var oldLocale = i18next.language\n\n try {\n const message = await auth.updateProfile({\n locale: value\n })\n\n i18next.changeLanguage(value)\n\n notify({\n level: 'info',\n message\n })\n } catch (e: any) {\n this.localeEl.value = oldLocale\n\n notify({\n level: 'error',\n message: 'message' in e ? e.message : e\n })\n }\n }\n\n openLoginHistory() {\n openPopup(html` <my-login-history></my-login-history> `, {\n title: i18next.t('label.login_history')\n })\n }\n\n deleteUser() {\n openPopup(html` <delete-user-popup></delete-user-popup> `, {\n title: i18next.t('label.delete account')\n })\n }\n\n async registerUser() {\n try {\n const options = await fetch('/auth/register-webauthn/challenge').then(res => res.json())\n const attResp = await startRegistration(options)\n const verification = await fetch('/auth/verify-registration', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify(attResp)\n }).then(res => res.json())\n\n if (verification.verified) {\n notify({\n level: 'info',\n message: i18next.t('text.user credential registered successfully')\n })\n } else {\n console.error(await verification.text())\n\n notify({\n level: 'error',\n message: i18next.t('error.user credential registeration not allowed')\n })\n }\n } catch (error) {\n notify({\n level: 'error',\n message: i18next.t('error.user credential registeration failed')\n })\n }\n }\n\n get applicationMeta() {\n var iconLink: HTMLLinkElement | null = document.querySelector('link[rel=\"application-icon\"]')\n var titleMeta: HTMLMetaElement | null = document.querySelector('meta[name=\"application-name\"]')\n var descriptionMeta: HTMLMetaElement | null = document.querySelector('meta[name=\"application-description\"]')\n\n return {\n icon: iconLink?.href || '',\n title: titleMeta?.content || 'Things Factory',\n description: descriptionMeta?.content || 'Reimagining Software'\n }\n }\n}\n"]}
|
|
@@ -200,9 +200,6 @@ RolePrivilegeEditor.styles = [
|
|
|
200
200
|
background-color: var(--md-sys-color-surface-variant);
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
[danger] {
|
|
204
|
-
--md-theme-primary: var(--md-danger-button-primary-color);
|
|
205
|
-
}
|
|
206
203
|
md-outlined-button {
|
|
207
204
|
background-color: var(--md-sys-color-surface-variant);
|
|
208
205
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role-privilege-editor.js","sourceRoot":"","sources":["../../client/components/role-privilege-editor.ts"],"names":[],"mappings":";AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAGvD,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;IAA/D;;QAgE6B,kBAAa,GAAU,EAAE,CAAA;QACzB,eAAU,GAAU,EAAE,CAAA;IAuKnD,CAAC;IApKC,MAAM;QACJ,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,EAAE,CAAA;QAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,EAAE,CAAA;QAExC,OAAO,IAAI,CAAA;;uDAEwC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;;;;;UAKpE,aAAa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AC,IAAI,CAAC,IAAI,0CAAE,UAAU,CAAA;IACvC,CAAC;IAED,SAAS,CAAC,OAAO;QACf,QAAQ,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;IACrG,CAAC;;AAtOM,0BAAM,GAAG;IACd,qBAAqB;IACrB,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAyDF;CACF,AA5DY,CA4DZ;AAE2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;iDAAU;AACV;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;0DAA0B;AACzB;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;uDAAuB;AACrB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;0DAAmB;AAlE1C,mBAAmB;IADxB,aAAa,CAAC,uBAAuB,CAAC;GACjC,mBAAmB,CAwOxB","sourcesContent":["import gql from 'graphql-tag'\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { client, gqlContext } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { OxPrompt } from '@operato/popup/ox-prompt.js'\nimport { ButtonContainerStyles } from '@operato/styles'\n\n@customElement('role-privilege-editor')\nclass RolePrivilegeEditor extends localize(i18next)(LitElement) {\n static styles = [\n ButtonContainerStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n\n border: 1px solid var(--md-sys-color-primary);\n font: normal 15px var(--theme-font);\n color: var(--md-sys-color-secondary);\n }\n div {\n margin: var(--margin-default);\n }\n ul {\n flex: 1;\n background-color: var(--md-sys-color-surface-variant);\n overflow: auto;\n display: grid;\n grid-template-columns: 1fr 1fr;\n margin: 0;\n padding: var(--padding-default);\n list-style: none;\n border: 1px dashed rgba(0, 0, 0, 0.1);\n border-width: 1px 0;\n }\n\n input[type='checkbox'] {\n display: inline;\n }\n\n li {\n padding: var(--padding-narrow);\n }\n\n #checkAll,\n [for='checkAll'] {\n margin-bottom: var(--margin-default);\n padding-bottom: var(--padding-narrow);\n font-weight: bold;\n }\n\n md-elevated-button {\n margin: 5px;\n background-color: var(--md-sys-color-surface-variant);\n }\n\n [danger] {\n --md-theme-primary: var(--md-danger-button-primary-color);\n }\n md-outlined-button {\n background-color: var(--md-sys-color-surface-variant);\n }\n\n @media screen and (max-width: 480px) {\n ul {\n grid-template-columns: 1fr;\n }\n }\n `\n ]\n\n @property({ type: Object }) role: any\n @property({ type: Array }) allPrivileges: any[] = []\n @property({ type: Array }) privileges: any[] = []\n @property({ type: Object }) updateRoleObj: any\n\n render() {\n const allPrivileges = this.allPrivileges || []\n const privileges = this.privileges || []\n\n return html`\n <div>\n <input id=\"checkAll\" type=\"checkbox\" @change=${e => this.oncheckAll(e)} />\n <label for=\"checkAll\">Check all</label>\n </div>\n\n <ul privileges>\n ${allPrivileges.map(\n privilege => html`\n <li>\n <input\n type=\"checkbox\"\n id=\"${privilege.id}\"\n .checked=${privileges.map(p => p.id).indexOf(privilege.id) > -1}\n .data-privilege=${privilege}\n />\n <label for=\"${privilege.id}\">${privilege.description}</label>\n </li>\n `\n )}\n </ul>\n\n <div class=\"button-container\">\n <md-elevated-button @click=${e => this.onSave()}>${String(i18next.t('button.save'))}</md-elevated-button>\n <md-elevated-button @click=${e => this.onDeleteRole()} danger\n >${String(i18next.t('button.delete role'))}</md-elevated-button\n >\n </div>\n `\n }\n\n async firstUpdated() {\n this.allPrivileges = await this.fetchPrivileges()\n }\n\n async updated(changes) {\n if (changes.has('role')) {\n this.privileges = await this.fetchPrivilegesOnRole(this.role.name)\n }\n }\n\n checkAll(checked) {\n Array.from(this.renderRoot.querySelectorAll('ul[privileges] input[type=checkbox]')).forEach(\n checkbox => ((checkbox as HTMLInputElement).checked = checked)\n )\n }\n\n oncheckAll(e) {\n this.checkAll(e.target.checked)\n }\n\n async onSave() {\n const updateRoleObj = this.updateRoleObj\n const privileges = Array.from(this.renderRoot.querySelectorAll('ul[privileges] input[type=checkbox]:checked')).map(\n e => e['data-privilege']\n )\n\n const patch = { ...updateRoleObj, privileges: privileges }\n\n if (this.role) {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!, $patch: RolePatch!) {\n updateRole(id: $id, patch: $patch) {\n id\n name\n description\n privileges {\n id\n description\n }\n }\n }\n `,\n variables: { id: this.role.id, patch },\n context: gqlContext()\n })\n\n if (!response.errors) {\n await this.dispatchEvent(new CustomEvent('fetch-roles'))\n this.showToast(i18next.t('text.data_updated_successfully'))\n }\n }\n }\n\n async onDeleteRole() {\n if (\n await OxPrompt.open({\n title: i18next.t('text.are_you_sure'),\n text: i18next.t('text.are_you_sure_to_delete_x', { x: i18next.t('label.role') }),\n confirmButton: { text: i18next.t('button.delete') },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n ) {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!) {\n deleteRole(id: $id)\n }\n `,\n variables: { id: this.role.id },\n context: gqlContext()\n })\n\n if (!response.errors) {\n await this.dispatchEvent(new CustomEvent('fetch-roles'))\n\n await OxPrompt.open({\n type: 'success',\n title: i18next.t('text.completed'),\n text: i18next.t('text.x_deleted_successfully', { x: i18next.t('label.role') }),\n confirmButton: { text: i18next.t('button.confirm') }\n })\n }\n }\n }\n\n async fetchPrivileges() {\n const response = await client.query({\n query: gql`\n query privileges {\n privileges {\n items {\n id\n name\n description\n }\n total\n }\n }\n `\n })\n\n return response.data.privileges.items\n }\n\n async fetchPrivilegesOnRole(name) {\n const response = await client.query({\n query: gql`\n query ($name: String!) {\n role(name: $name) {\n id\n name\n privileges {\n id\n description\n }\n }\n }\n `,\n variables: { name },\n context: gqlContext()\n })\n\n return response.data.role?.privileges\n }\n\n showToast(message) {\n document.dispatchEvent(new CustomEvent('notify', { detail: { message, option: { timer: 1000 } } }))\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"role-privilege-editor.js","sourceRoot":"","sources":["../../client/components/role-privilege-editor.ts"],"names":[],"mappings":";AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAGvD,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;IAA/D;;QA6D6B,kBAAa,GAAU,EAAE,CAAA;QACzB,eAAU,GAAU,EAAE,CAAA;IAuKnD,CAAC;IApKC,MAAM;QACJ,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,EAAE,CAAA;QAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,EAAE,CAAA;QAExC,OAAO,IAAI,CAAA;;uDAEwC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;;;;;UAKpE,aAAa,CAAC,GAAG,CACjB,SAAS,CAAC,EAAE,CAAC,IAAI,CAAA;;;;sBAIL,SAAS,CAAC,EAAE;2BACP,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,CAA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,EAAE,CAAC,CAAC,CAAA;IACrG,CAAC;;AAnOM,0BAAM,GAAG;IACd,qBAAqB;IACrB,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsDF;CACF,AAzDY,CAyDZ;AAE2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;iDAAU;AACV;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;0DAA0B;AACzB;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;uDAAuB;AACrB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;0DAAmB;AA/D1C,mBAAmB;IADxB,aAAa,CAAC,uBAAuB,CAAC;GACjC,mBAAmB,CAqOxB","sourcesContent":["import gql from 'graphql-tag'\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { client, gqlContext } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { OxPrompt } from '@operato/popup/ox-prompt.js'\nimport { ButtonContainerStyles } from '@operato/styles'\n\n@customElement('role-privilege-editor')\nclass RolePrivilegeEditor extends localize(i18next)(LitElement) {\n static styles = [\n ButtonContainerStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n\n border: 1px solid var(--md-sys-color-primary);\n font: normal 15px var(--theme-font);\n color: var(--md-sys-color-secondary);\n }\n div {\n margin: var(--margin-default);\n }\n ul {\n flex: 1;\n background-color: var(--md-sys-color-surface-variant);\n overflow: auto;\n display: grid;\n grid-template-columns: 1fr 1fr;\n margin: 0;\n padding: var(--padding-default);\n list-style: none;\n border: 1px dashed rgba(0, 0, 0, 0.1);\n border-width: 1px 0;\n }\n\n input[type='checkbox'] {\n display: inline;\n }\n\n li {\n padding: var(--padding-narrow);\n }\n\n #checkAll,\n [for='checkAll'] {\n margin-bottom: var(--margin-default);\n padding-bottom: var(--padding-narrow);\n font-weight: bold;\n }\n\n md-elevated-button {\n margin: 5px;\n background-color: var(--md-sys-color-surface-variant);\n }\n\n md-outlined-button {\n background-color: var(--md-sys-color-surface-variant);\n }\n\n @media screen and (max-width: 480px) {\n ul {\n grid-template-columns: 1fr;\n }\n }\n `\n ]\n\n @property({ type: Object }) role: any\n @property({ type: Array }) allPrivileges: any[] = []\n @property({ type: Array }) privileges: any[] = []\n @property({ type: Object }) updateRoleObj: any\n\n render() {\n const allPrivileges = this.allPrivileges || []\n const privileges = this.privileges || []\n\n return html`\n <div>\n <input id=\"checkAll\" type=\"checkbox\" @change=${e => this.oncheckAll(e)} />\n <label for=\"checkAll\">Check all</label>\n </div>\n\n <ul privileges>\n ${allPrivileges.map(\n privilege => html`\n <li>\n <input\n type=\"checkbox\"\n id=\"${privilege.id}\"\n .checked=${privileges.map(p => p.id).indexOf(privilege.id) > -1}\n .data-privilege=${privilege}\n />\n <label for=\"${privilege.id}\">${privilege.description}</label>\n </li>\n `\n )}\n </ul>\n\n <div class=\"button-container\">\n <md-elevated-button @click=${e => this.onSave()}>${String(i18next.t('button.save'))}</md-elevated-button>\n <md-elevated-button @click=${e => this.onDeleteRole()} danger\n >${String(i18next.t('button.delete role'))}</md-elevated-button\n >\n </div>\n `\n }\n\n async firstUpdated() {\n this.allPrivileges = await this.fetchPrivileges()\n }\n\n async updated(changes) {\n if (changes.has('role')) {\n this.privileges = await this.fetchPrivilegesOnRole(this.role.name)\n }\n }\n\n checkAll(checked) {\n Array.from(this.renderRoot.querySelectorAll('ul[privileges] input[type=checkbox]')).forEach(\n checkbox => ((checkbox as HTMLInputElement).checked = checked)\n )\n }\n\n oncheckAll(e) {\n this.checkAll(e.target.checked)\n }\n\n async onSave() {\n const updateRoleObj = this.updateRoleObj\n const privileges = Array.from(this.renderRoot.querySelectorAll('ul[privileges] input[type=checkbox]:checked')).map(\n e => e['data-privilege']\n )\n\n const patch = { ...updateRoleObj, privileges: privileges }\n\n if (this.role) {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!, $patch: RolePatch!) {\n updateRole(id: $id, patch: $patch) {\n id\n name\n description\n privileges {\n id\n description\n }\n }\n }\n `,\n variables: { id: this.role.id, patch },\n context: gqlContext()\n })\n\n if (!response.errors) {\n await this.dispatchEvent(new CustomEvent('fetch-roles'))\n this.showToast(i18next.t('text.data_updated_successfully'))\n }\n }\n }\n\n async onDeleteRole() {\n if (\n await OxPrompt.open({\n title: i18next.t('text.are_you_sure'),\n text: i18next.t('text.are_you_sure_to_delete_x', { x: i18next.t('label.role') }),\n confirmButton: { text: i18next.t('button.delete') },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n ) {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!) {\n deleteRole(id: $id)\n }\n `,\n variables: { id: this.role.id },\n context: gqlContext()\n })\n\n if (!response.errors) {\n await this.dispatchEvent(new CustomEvent('fetch-roles'))\n\n await OxPrompt.open({\n type: 'success',\n title: i18next.t('text.completed'),\n text: i18next.t('text.x_deleted_successfully', { x: i18next.t('label.role') }),\n confirmButton: { text: i18next.t('button.confirm') }\n })\n }\n }\n }\n\n async fetchPrivileges() {\n const response = await client.query({\n query: gql`\n query privileges {\n privileges {\n items {\n id\n name\n description\n }\n total\n }\n }\n `\n })\n\n return response.data.privileges.items\n }\n\n async fetchPrivilegesOnRole(name) {\n const response = await client.query({\n query: gql`\n query ($name: String!) {\n role(name: $name) {\n id\n name\n privileges {\n id\n description\n }\n }\n }\n `,\n variables: { name },\n context: gqlContext()\n })\n\n return response.data.role?.privileges\n }\n\n showToast(message) {\n document.dispatchEvent(new CustomEvent('notify', { detail: { message, option: { timer: 1000 } } }))\n }\n}\n"]}
|