@fishawack/lab-velocity 2.0.0-beta.11 → 2.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -6
- package/_Build/vue/components/layout/Alert.vue +5 -5
- package/_Build/vue/{modules/AuthModule/components/VBreadcrumbs.vue → components/layout/Breadcrumbs.vue} +4 -4
- package/_Build/vue/{modules/AuthModule/components → components/layout}/Chips.vue +2 -2
- package/_Build/vue/components/layout/Footer.vue +11 -10
- package/_Build/vue/{modules/AuthModule/components/VFormFooter.vue → components/layout/FormFooter.vue} +2 -2
- package/_Build/vue/{modules/AuthModule/components → components/layout}/FormRole.vue +7 -7
- package/_Build/vue/components/layout/Layout.vue +74 -0
- package/_Build/vue/components/layout/Navigation.vue +77 -0
- package/_Build/vue/{modules/AuthModule/components/VPageHeader.vue → components/layout/PageHeader.vue} +7 -2
- package/_Build/vue/components/layout/SideBar.vue +26 -0
- package/_Build/vue/{modules/AuthModule/components/VTable.vue → components/layout/Table.vue} +6 -15
- package/_Build/vue/{modules/AuthModule/components/VTableSorter.vue → components/layout/TableSorter.vue} +15 -17
- package/_Build/vue/components/layout/pageTitle.vue +1 -1
- package/_Build/vue/components/navigation/MenuItem.vue +7 -2
- package/_Build/vue/components/navigation/MenuItemGroup.vue +7 -2
- package/_Build/vue/modules/AuthModule/js/router.js +21 -89
- package/_Build/vue/modules/AuthModule/js/store.js +13 -4
- package/_Build/vue/modules/AuthModule/{adminRoutes/PCompanies/Children/partials → routes/PCompanies}/form.vue +15 -8
- package/_Build/vue/modules/AuthModule/routes/PCompanies/resource.js +180 -0
- package/_Build/vue/modules/AuthModule/{adminRoutes/PUsers/Children/partials → routes/PUsers}/form.vue +15 -8
- package/_Build/vue/modules/AuthModule/routes/PUsers/resource.js +214 -0
- package/_Build/vue/modules/AuthModule/routes/change-password.vue +9 -8
- package/_Build/vue/modules/AuthModule/routes/container.vue +2 -11
- package/_Build/vue/modules/AuthModule/routes/force-reset.vue +9 -8
- package/_Build/vue/modules/AuthModule/routes/register.vue +9 -8
- package/_Build/vue/modules/AuthModule/routes/reset.vue +9 -8
- package/components/_descriptions.scss +2 -0
- package/components/_footer.scss +1 -0
- package/components/_header.scss +3 -27
- package/components/_layout.scss +56 -0
- package/components/_sidebar.scss +12 -27
- package/index.js +7 -1
- package/package.json +1 -1
- package/_Build/vue/components/layout/sideBar.vue +0 -25
- package/_Build/vue/modules/AuthModule/adminRoutes/PCompanies/Children/Upload/upload.vue +0 -259
- package/_Build/vue/modules/AuthModule/adminRoutes/PCompanies/Children/create.vue +0 -62
- package/_Build/vue/modules/AuthModule/adminRoutes/PCompanies/Children/edit.vue +0 -98
- package/_Build/vue/modules/AuthModule/adminRoutes/PCompanies/Children/index.vue +0 -90
- package/_Build/vue/modules/AuthModule/adminRoutes/PCompanies/Children/show.vue +0 -267
- package/_Build/vue/modules/AuthModule/adminRoutes/PCompanies/parent.vue +0 -36
- package/_Build/vue/modules/AuthModule/adminRoutes/PUsers/Children/create.vue +0 -113
- package/_Build/vue/modules/AuthModule/adminRoutes/PUsers/Children/edit.vue +0 -101
- package/_Build/vue/modules/AuthModule/adminRoutes/PUsers/Children/index.vue +0 -112
- package/_Build/vue/modules/AuthModule/adminRoutes/PUsers/Children/show.vue +0 -123
- package/_Build/vue/modules/AuthModule/adminRoutes/PUsers/parent.vue +0 -36
- /package/_Build/vue/{modules/AuthModule/components → components/layout}/AuthModal.vue +0 -0
- /package/_Build/vue/{modules/AuthModule/components → components/layout}/Chip.vue +0 -0
- /package/_Build/vue/{modules/AuthModule/components/VPasswordValidation.vue → components/layout/PasswordValidation.vue} +0 -0
- /package/_Build/vue/{modules/AuthModule/components/VRoleLegend.vue → components/layout/RoleLegend.vue} +0 -0
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import { merge } from "lodash";
|
|
4
|
+
|
|
3
5
|
import { h } from "vue";
|
|
4
6
|
import { RouterView } from "vue-router";
|
|
5
7
|
|
|
8
|
+
import { routes as resourceRoutes } from "../../resource/index.js";
|
|
9
|
+
|
|
10
|
+
import userResource from "../routes/PUsers/resource.js";
|
|
11
|
+
import companyResource from "../routes/PCompanies/resource.js";
|
|
12
|
+
|
|
6
13
|
// Admin routes export - minimal auth flow (headless login only)
|
|
7
|
-
export function adminRoutes(node) {
|
|
14
|
+
export function adminRoutes(node, overrides = {}) {
|
|
15
|
+
const {
|
|
16
|
+
userResource: overrideUserResource = {},
|
|
17
|
+
companyResource: overrideCompanyResource = {},
|
|
18
|
+
} = overrides;
|
|
19
|
+
|
|
8
20
|
return [
|
|
9
21
|
{
|
|
10
22
|
path: "/auth",
|
|
@@ -39,94 +51,14 @@ export function adminRoutes(node) {
|
|
|
39
51
|
},
|
|
40
52
|
],
|
|
41
53
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
component: node
|
|
51
|
-
? ""
|
|
52
|
-
: require("../adminRoutes/PUsers/Children/index.vue")
|
|
53
|
-
.default,
|
|
54
|
-
name: "users.index",
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
path: "create",
|
|
58
|
-
component: node
|
|
59
|
-
? ""
|
|
60
|
-
: require("../adminRoutes/PUsers/Children/create.vue")
|
|
61
|
-
.default,
|
|
62
|
-
name: "users.create",
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
path: ":id",
|
|
66
|
-
component: node
|
|
67
|
-
? ""
|
|
68
|
-
: require("../adminRoutes/PUsers/Children/show.vue")
|
|
69
|
-
.default,
|
|
70
|
-
name: "users.show",
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
path: ":id/edit",
|
|
74
|
-
component: node
|
|
75
|
-
? ""
|
|
76
|
-
: require("../adminRoutes/PUsers/Children/edit.vue")
|
|
77
|
-
.default,
|
|
78
|
-
name: "users.edit",
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
path: "/companies",
|
|
84
|
-
component: node
|
|
85
|
-
? ""
|
|
86
|
-
: require("../adminRoutes/PCompanies/parent.vue").default,
|
|
87
|
-
children: [
|
|
88
|
-
{
|
|
89
|
-
path: "",
|
|
90
|
-
component: node
|
|
91
|
-
? ""
|
|
92
|
-
: require("../adminRoutes/PCompanies/Children/index.vue")
|
|
93
|
-
.default,
|
|
94
|
-
name: "companies.index",
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
path: "create",
|
|
98
|
-
component: node
|
|
99
|
-
? ""
|
|
100
|
-
: require("../adminRoutes/PCompanies/Children/create.vue")
|
|
101
|
-
.default,
|
|
102
|
-
name: "companies.create",
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
path: ":id",
|
|
106
|
-
component: node
|
|
107
|
-
? ""
|
|
108
|
-
: require("../adminRoutes/PCompanies/Children/show.vue")
|
|
109
|
-
.default,
|
|
110
|
-
name: "companies.show",
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
path: ":id/edit",
|
|
114
|
-
component: node
|
|
115
|
-
? ""
|
|
116
|
-
: require("../adminRoutes/PCompanies/Children/edit.vue")
|
|
117
|
-
.default,
|
|
118
|
-
name: "companies.edit",
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
path: ":id/upload",
|
|
122
|
-
component: node
|
|
123
|
-
? ""
|
|
124
|
-
: require("../adminRoutes/PCompanies/Children/Upload/upload.vue")
|
|
125
|
-
.default,
|
|
126
|
-
name: "companies.upload",
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
|
-
},
|
|
54
|
+
...resourceRoutes(
|
|
55
|
+
node,
|
|
56
|
+
...merge(userResource, [undefined, overrideUserResource]),
|
|
57
|
+
),
|
|
58
|
+
...resourceRoutes(
|
|
59
|
+
node,
|
|
60
|
+
...merge(companyResource, [undefined, overrideCompanyResource]),
|
|
61
|
+
),
|
|
130
62
|
];
|
|
131
63
|
}
|
|
132
64
|
|
|
@@ -7,6 +7,9 @@ const store = {
|
|
|
7
7
|
intended: null,
|
|
8
8
|
user: null,
|
|
9
9
|
redirect: process.env.HYDRATE_REDIRECT ?? "index",
|
|
10
|
+
logo: process.env.HYDRATE_LOGO ?? "example-logo",
|
|
11
|
+
logoReverse:
|
|
12
|
+
process.env.HYDRATE_LOGO_REVERSE ?? process.env.HYDRATE_LOGO,
|
|
10
13
|
contact:
|
|
11
14
|
process.env.HYDRATE_CONTACT ?? "mailto:det@avalerehealth.com",
|
|
12
15
|
};
|
|
@@ -15,12 +18,18 @@ const store = {
|
|
|
15
18
|
getters: {
|
|
16
19
|
authenticated: (state) => !!state.user,
|
|
17
20
|
can: (state) => (permission) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
const arr = Array.isArray(permission) ? permission : [permission];
|
|
22
|
+
const userPermissions = state.user?.permissions.map(
|
|
23
|
+
({ name }) => name,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return arr.every((name) => userPermissions?.includes(name));
|
|
21
27
|
},
|
|
22
28
|
hasRole: (state) => (role) => {
|
|
23
|
-
|
|
29
|
+
const arr = Array.isArray(role) ? role : [role];
|
|
30
|
+
const userRoles = state.user?.roles.map(({ name }) => name);
|
|
31
|
+
|
|
32
|
+
return arr.every((name) => userRoles?.includes(name));
|
|
24
33
|
},
|
|
25
34
|
},
|
|
26
35
|
|
|
@@ -66,14 +66,19 @@
|
|
|
66
66
|
<VelButton @click="form.domains.push('')">
|
|
67
67
|
Add Domain
|
|
68
68
|
|
|
69
|
-
<GIcon
|
|
69
|
+
<GIcon
|
|
70
|
+
name="icon-plus"
|
|
71
|
+
embed
|
|
72
|
+
asis
|
|
73
|
+
class="fill-0 icon--0.5 ml"
|
|
74
|
+
/>
|
|
70
75
|
</VelButton>
|
|
71
76
|
</div>
|
|
72
77
|
|
|
73
78
|
<hr class="my-5 hr-muted" />
|
|
74
79
|
|
|
75
80
|
<template v-if="$store.getters.can('edit roles')">
|
|
76
|
-
<
|
|
81
|
+
<VelFormRole :form="form" />
|
|
77
82
|
|
|
78
83
|
<hr class="my-5 hr-muted" />
|
|
79
84
|
</template>
|
|
@@ -127,22 +132,24 @@
|
|
|
127
132
|
<hr class="my-3 hr-muted" />
|
|
128
133
|
</template>
|
|
129
134
|
|
|
130
|
-
<
|
|
135
|
+
<VelFormFooter :form="form" />
|
|
131
136
|
</form>
|
|
132
137
|
</template>
|
|
133
138
|
|
|
134
139
|
<!-- eslint-disable vue/no-mutating-props -->
|
|
135
140
|
<script>
|
|
136
141
|
import axios from "axios";
|
|
137
|
-
import VelButton from "
|
|
138
|
-
import VelSelect from "
|
|
139
|
-
import VelBasic from "
|
|
142
|
+
import VelButton from "../../../../components/basic/Button.vue";
|
|
143
|
+
import VelSelect from "../../../../components/form/Select.vue";
|
|
144
|
+
import VelBasic from "../../../../components/form/basic.vue";
|
|
145
|
+
import VelFormRole from "../../../../components/layout/FormRole.vue";
|
|
146
|
+
import VelFormFooter from "../../../../components/layout/FormFooter.vue";
|
|
140
147
|
import { ElInput } from "element-plus";
|
|
141
148
|
|
|
142
149
|
export default {
|
|
143
150
|
components: {
|
|
144
|
-
|
|
145
|
-
|
|
151
|
+
VelFormFooter,
|
|
152
|
+
VelFormRole,
|
|
146
153
|
VelButton,
|
|
147
154
|
VelSelect,
|
|
148
155
|
VelBasic,
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import VelFormRole from "../../../../components/layout/FormRole.vue";
|
|
2
|
+
import VelButton from "../../../../components/basic/Button.vue";
|
|
3
|
+
import Chip from "../../../../components/layout/Chip.vue";
|
|
4
|
+
import Chips from "../../../../components/layout/Chips.vue";
|
|
5
|
+
import VelTableSorter from "../../../../components/layout/TableSorter.vue";
|
|
6
|
+
import VelRoleLegend from "../../../../components/layout/RoleLegend.vue";
|
|
7
|
+
import component from "./form.vue";
|
|
8
|
+
import userResource from "../PUsers/resource.js";
|
|
9
|
+
import { meta } from "../../../resource/index.js";
|
|
10
|
+
|
|
11
|
+
import { ElNotification } from "element-plus";
|
|
12
|
+
import { h } from "vue";
|
|
13
|
+
import axios from "axios";
|
|
14
|
+
|
|
15
|
+
export default [
|
|
16
|
+
"companies",
|
|
17
|
+
{
|
|
18
|
+
defaults: "include=primary_contact",
|
|
19
|
+
singular: "company",
|
|
20
|
+
icon: "icon-cases",
|
|
21
|
+
form: {
|
|
22
|
+
component,
|
|
23
|
+
fields: ({ model }) => ({
|
|
24
|
+
name: model?.name || null,
|
|
25
|
+
primary_contact: model?.primary_contact?.id || null,
|
|
26
|
+
domains: model?.domains || [],
|
|
27
|
+
roles: model?.roles.map((val) => val.id) || [],
|
|
28
|
+
sso_client_id: model?.sso_client_id || undefined,
|
|
29
|
+
sso_tenant: model?.sso_tenant || undefined,
|
|
30
|
+
sso_client_secret: model?.sso_client_secret || undefined,
|
|
31
|
+
sso_type: model?.sso_type || undefined,
|
|
32
|
+
}),
|
|
33
|
+
},
|
|
34
|
+
table: {
|
|
35
|
+
structure: [
|
|
36
|
+
{
|
|
37
|
+
label: "Name",
|
|
38
|
+
key: "name",
|
|
39
|
+
sortable: true,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
label: "Total users",
|
|
43
|
+
key: "user_count",
|
|
44
|
+
sortable: false,
|
|
45
|
+
width: "150",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
label: "Role",
|
|
49
|
+
render: (row) =>
|
|
50
|
+
h(
|
|
51
|
+
row.roles.length === 1 ? Chip : Chips,
|
|
52
|
+
row.roles.length === 1
|
|
53
|
+
? {
|
|
54
|
+
name: row.roles[0].name,
|
|
55
|
+
label: row.roles[0].label,
|
|
56
|
+
}
|
|
57
|
+
: { array: row.roles },
|
|
58
|
+
),
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
index: {
|
|
63
|
+
structure: [
|
|
64
|
+
{
|
|
65
|
+
render: ({ resource, $store }) =>
|
|
66
|
+
h(VelTableSorter, {
|
|
67
|
+
key: "PIndex",
|
|
68
|
+
"json-data": {
|
|
69
|
+
...resource,
|
|
70
|
+
tableStructure: resource.table.structure,
|
|
71
|
+
},
|
|
72
|
+
defaults: resource.defaults,
|
|
73
|
+
"fixed-height": false,
|
|
74
|
+
"display-edit-action":
|
|
75
|
+
$store.getters.can("write companies"),
|
|
76
|
+
}),
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
render: () =>
|
|
80
|
+
h(VelRoleLegend, {
|
|
81
|
+
class: "mt-5",
|
|
82
|
+
}),
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
show: {
|
|
87
|
+
actions: [
|
|
88
|
+
{
|
|
89
|
+
render: ({ model }) =>
|
|
90
|
+
model.primary_contact &&
|
|
91
|
+
h(
|
|
92
|
+
VelButton,
|
|
93
|
+
{
|
|
94
|
+
type: "primary",
|
|
95
|
+
async onClick() {
|
|
96
|
+
try {
|
|
97
|
+
const res = await axios.post(
|
|
98
|
+
`/api/companies/${model.id}/welcome`,
|
|
99
|
+
);
|
|
100
|
+
ElNotification({
|
|
101
|
+
title: "Success",
|
|
102
|
+
message: res.data.message,
|
|
103
|
+
type: "success",
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
model.primary_contact_contacted = true;
|
|
107
|
+
} catch (e) {
|
|
108
|
+
ElNotification({
|
|
109
|
+
title: "Warning",
|
|
110
|
+
message:
|
|
111
|
+
e.response?.data?.message ||
|
|
112
|
+
e.message,
|
|
113
|
+
type: "warning",
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
"Send welcome email",
|
|
119
|
+
),
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
structure: [
|
|
123
|
+
[
|
|
124
|
+
{
|
|
125
|
+
label: "Domains",
|
|
126
|
+
render: ({ model }) =>
|
|
127
|
+
h("span", model.domains.join(", ")),
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
label: "SSO Enabled",
|
|
131
|
+
key: "sso_enabled",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
label: "Primary Contact",
|
|
135
|
+
render: ({ model }) =>
|
|
136
|
+
h("span", model.primary_contact?.name),
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
label: "Primary Contact Email",
|
|
140
|
+
render: ({ model }) =>
|
|
141
|
+
h("span", model.primary_contact?.email),
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
label: "Primary Contact Contacted",
|
|
145
|
+
render: ({ model }) =>
|
|
146
|
+
h("span", !!model.primary_contact_contacted),
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
label: "Total users",
|
|
150
|
+
key: "user_count",
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
{
|
|
154
|
+
render: ({ model }) =>
|
|
155
|
+
h(VelFormRole, {
|
|
156
|
+
overrides: model.overrides_roles_and_permissions,
|
|
157
|
+
form: { roles: model.roles.map((d) => d.id) },
|
|
158
|
+
readonly: true,
|
|
159
|
+
}),
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
render: ({ model, $store }) => {
|
|
163
|
+
const resource = meta(...userResource);
|
|
164
|
+
return h(VelTableSorter, {
|
|
165
|
+
key: "PIndex",
|
|
166
|
+
"json-data": {
|
|
167
|
+
...resource,
|
|
168
|
+
tableStructure: resource.table.structure,
|
|
169
|
+
},
|
|
170
|
+
defaults: `include=company&filter[company_id]=${model.id}`,
|
|
171
|
+
"fixed-height": false,
|
|
172
|
+
"display-edit-action":
|
|
173
|
+
$store.getters.can("write users"),
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
];
|
|
@@ -74,11 +74,16 @@
|
|
|
74
74
|
>
|
|
75
75
|
Reset roles
|
|
76
76
|
</VelButton>
|
|
77
|
-
<
|
|
77
|
+
<VelFormRole :form="form" />
|
|
78
78
|
</template>
|
|
79
79
|
<template v-else>
|
|
80
80
|
<VelButton @click="enableRoles = true">
|
|
81
|
-
<GIcon
|
|
81
|
+
<GIcon
|
|
82
|
+
name="icon-plus"
|
|
83
|
+
embed
|
|
84
|
+
asis
|
|
85
|
+
class="fill-0 icon--0.5 mr"
|
|
86
|
+
/>
|
|
82
87
|
Override roles
|
|
83
88
|
</VelButton>
|
|
84
89
|
<p class="mt-2">
|
|
@@ -88,21 +93,23 @@
|
|
|
88
93
|
<hr class="my-5 hr-muted" />
|
|
89
94
|
</template>
|
|
90
95
|
|
|
91
|
-
<
|
|
96
|
+
<VelFormFooter :loading="form.processing" />
|
|
92
97
|
</form>
|
|
93
98
|
</template>
|
|
94
99
|
|
|
95
100
|
<script>
|
|
96
101
|
import axios from "axios";
|
|
97
102
|
import { debounce } from "lodash";
|
|
98
|
-
import VelButton from "
|
|
99
|
-
import VelCheckbox from "
|
|
100
|
-
import VelBasic from "
|
|
103
|
+
import VelButton from "../../../../components/basic/Button.vue";
|
|
104
|
+
import VelCheckbox from "../../../../components/form/Checkbox.vue";
|
|
105
|
+
import VelBasic from "../../../../components/form/basic.vue";
|
|
106
|
+
import VelFormRole from "../../../../components/layout/FormRole.vue";
|
|
107
|
+
import VelFormFooter from "../../../../components/layout/FormFooter.vue";
|
|
101
108
|
|
|
102
109
|
export default {
|
|
103
110
|
components: {
|
|
104
|
-
|
|
105
|
-
|
|
111
|
+
VelFormFooter,
|
|
112
|
+
VelFormRole,
|
|
106
113
|
VelCheckbox,
|
|
107
114
|
VelButton,
|
|
108
115
|
VelBasic,
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import VelFormRole from "../../../../components/layout/FormRole.vue";
|
|
2
|
+
import Chip from "../../../../components/layout/Chip.vue";
|
|
3
|
+
import Chips from "../../../../components/layout/Chips.vue";
|
|
4
|
+
import VelTableSorter from "../../../../components/layout/TableSorter.vue";
|
|
5
|
+
import VelRoleLegend from "../../../../components/layout/RoleLegend.vue";
|
|
6
|
+
import component from "./form.vue";
|
|
7
|
+
|
|
8
|
+
import { ElMessageBox } from "element-plus";
|
|
9
|
+
import { ElNotification } from "element-plus";
|
|
10
|
+
import { h, resolveComponent } from "vue";
|
|
11
|
+
|
|
12
|
+
function generatePassword(
|
|
13
|
+
length = 20,
|
|
14
|
+
characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~!@-#$",
|
|
15
|
+
) {
|
|
16
|
+
return (
|
|
17
|
+
Array.from(crypto.getRandomValues(new Uint32Array(length)))
|
|
18
|
+
.map((x) => characters[x % characters.length])
|
|
19
|
+
.join("") + Math.floor(Math.random() * 10)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default [
|
|
24
|
+
"users",
|
|
25
|
+
{
|
|
26
|
+
defaults: "include=company",
|
|
27
|
+
searchable: {
|
|
28
|
+
value: "email",
|
|
29
|
+
},
|
|
30
|
+
form: {
|
|
31
|
+
async submit({ model, form, $router, $store, method }) {
|
|
32
|
+
try {
|
|
33
|
+
if (method === "post") {
|
|
34
|
+
if (form.set_password) {
|
|
35
|
+
const password = generatePassword();
|
|
36
|
+
form.password = password;
|
|
37
|
+
form.password_confirmation = password;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let res = await form.post(`/api/users`);
|
|
41
|
+
|
|
42
|
+
if (form.set_password && !form.notify_user) {
|
|
43
|
+
ElMessageBox.alert(
|
|
44
|
+
`<p>The password below will not be shown again. Ensure you've taken a copy if you plan to send manually. <br><br><strong>Email</strong>: ${form.email}<br> <strong>Password</strong>: ${form.password}</p>`,
|
|
45
|
+
"User Created",
|
|
46
|
+
{
|
|
47
|
+
confirmButtonText: "Ok",
|
|
48
|
+
dangerouslyUseHTMLString: true,
|
|
49
|
+
},
|
|
50
|
+
)
|
|
51
|
+
.then(() => {
|
|
52
|
+
$router.replace({
|
|
53
|
+
name: "users.show",
|
|
54
|
+
params: { id: res.data.id },
|
|
55
|
+
});
|
|
56
|
+
})
|
|
57
|
+
.catch(() => {});
|
|
58
|
+
} else {
|
|
59
|
+
ElNotification({
|
|
60
|
+
title: "Success",
|
|
61
|
+
message:
|
|
62
|
+
"User created a notified of their new account",
|
|
63
|
+
type: "success",
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
$router.replace({
|
|
67
|
+
name: "users.show",
|
|
68
|
+
params: { id: res.data.id },
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
let res = await form.patch(`/api/users/${model.id}`);
|
|
73
|
+
|
|
74
|
+
// if changing ourselves, re-fetch user data
|
|
75
|
+
if (res.data.id === $store.state.auth.user.id) {
|
|
76
|
+
await $store.dispatch("getUser");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
$router.replace({
|
|
80
|
+
name: "users.show",
|
|
81
|
+
params: { id: res.data.id },
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
} catch (e) {
|
|
85
|
+
console.log(e);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
component,
|
|
89
|
+
fields: ({ model, method }) => ({
|
|
90
|
+
...{
|
|
91
|
+
name: model?.name ?? null,
|
|
92
|
+
email: model?.email ?? null,
|
|
93
|
+
roles: model?.overrides_roles_and_permissions
|
|
94
|
+
? model?.roles.map((val) => {
|
|
95
|
+
return val.id;
|
|
96
|
+
})
|
|
97
|
+
: [],
|
|
98
|
+
company_id: model?.company_id ?? null,
|
|
99
|
+
},
|
|
100
|
+
...(method === "post"
|
|
101
|
+
? {
|
|
102
|
+
notify_user: true,
|
|
103
|
+
force_password_change: true,
|
|
104
|
+
set_password: true,
|
|
105
|
+
password: null,
|
|
106
|
+
password_confirmation: null,
|
|
107
|
+
}
|
|
108
|
+
: {}),
|
|
109
|
+
}),
|
|
110
|
+
},
|
|
111
|
+
table: {
|
|
112
|
+
structure: [
|
|
113
|
+
{
|
|
114
|
+
label: "Name",
|
|
115
|
+
key: "name",
|
|
116
|
+
sortable: true,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
label: "Email",
|
|
120
|
+
key: "email",
|
|
121
|
+
sortable: true,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
label: "Company",
|
|
125
|
+
sortable: true,
|
|
126
|
+
render: (model) =>
|
|
127
|
+
h(resolveComponent("router-link"), {
|
|
128
|
+
class: "underline",
|
|
129
|
+
to: {
|
|
130
|
+
name: "companies.show",
|
|
131
|
+
params: { id: model.company_id },
|
|
132
|
+
},
|
|
133
|
+
text: model.company.name,
|
|
134
|
+
}),
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
label: "Role",
|
|
138
|
+
render: (row) =>
|
|
139
|
+
h(
|
|
140
|
+
!row.overrides_roles_and_permissions ||
|
|
141
|
+
row.roles.length === 1
|
|
142
|
+
? Chip
|
|
143
|
+
: Chips,
|
|
144
|
+
!row.overrides_roles_and_permissions
|
|
145
|
+
? {
|
|
146
|
+
name: "inherited",
|
|
147
|
+
label: "Inherited",
|
|
148
|
+
}
|
|
149
|
+
: row.roles.length === 1
|
|
150
|
+
? {
|
|
151
|
+
name: row.roles[0].name,
|
|
152
|
+
label: row.roles[0].label,
|
|
153
|
+
}
|
|
154
|
+
: { array: row.roles },
|
|
155
|
+
),
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
index: {
|
|
160
|
+
structure: [
|
|
161
|
+
{
|
|
162
|
+
render: ({ resource, $store }) =>
|
|
163
|
+
h(VelTableSorter, {
|
|
164
|
+
key: "PIndex",
|
|
165
|
+
"json-data": {
|
|
166
|
+
...resource,
|
|
167
|
+
tableStructure: resource.table.structure,
|
|
168
|
+
},
|
|
169
|
+
defaults: resource.defaults,
|
|
170
|
+
"fixed-height": false,
|
|
171
|
+
"display-edit-action":
|
|
172
|
+
$store.getters.can("write users"),
|
|
173
|
+
}),
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
render: () =>
|
|
177
|
+
h(VelRoleLegend, {
|
|
178
|
+
class: "mt-5",
|
|
179
|
+
}),
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
show: {
|
|
184
|
+
structure: [
|
|
185
|
+
[
|
|
186
|
+
{
|
|
187
|
+
label: "Email",
|
|
188
|
+
key: "email",
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
label: "Company",
|
|
192
|
+
render: ({ model }) =>
|
|
193
|
+
h(resolveComponent("router-link"), {
|
|
194
|
+
class: "underline",
|
|
195
|
+
to: {
|
|
196
|
+
name: "companies.show",
|
|
197
|
+
params: { id: model.company_id },
|
|
198
|
+
},
|
|
199
|
+
text: model.company.name,
|
|
200
|
+
}),
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
{
|
|
204
|
+
render: ({ model }) =>
|
|
205
|
+
h(VelFormRole, {
|
|
206
|
+
overrides: model.overrides_roles_and_permissions,
|
|
207
|
+
form: { roles: model.roles.map((d) => d.id) },
|
|
208
|
+
readonly: true,
|
|
209
|
+
}),
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
];
|