@adminforth/user-soft-delete 1.1.0 → 1.2.1
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/build.log +3 -2
- package/custom/DisableButton.vue +18 -44
- package/custom/UserSoftDeleteFilterSetter.vue +20 -0
- package/dist/custom/DisableButton.vue +18 -44
- package/dist/custom/UserSoftDeleteFilterSetter.vue +20 -0
- package/dist/index.js +14 -6
- package/index.ts +19 -6
- package/package.json +1 -1
package/build.log
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
sending incremental file list
|
|
6
6
|
custom/
|
|
7
7
|
custom/DisableButton.vue
|
|
8
|
+
custom/UserSoftDeleteFilterSetter.vue
|
|
8
9
|
custom/tsconfig.json
|
|
9
10
|
|
|
10
|
-
sent
|
|
11
|
-
total size is 2,
|
|
11
|
+
sent 2,942 bytes received 77 bytes 6,038.00 bytes/sec
|
|
12
|
+
total size is 2,640 speedup is 0.87
|
package/custom/DisableButton.vue
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
<
|
|
4
|
-
|
|
2
|
+
<Tooltip>
|
|
3
|
+
<button
|
|
4
|
+
@click="openDialog()"
|
|
5
|
+
>
|
|
6
|
+
<IconUserRemoveSolid class="w-5 h-5 me-2"/>
|
|
7
|
+
</button>
|
|
8
|
+
|
|
9
|
+
<template v-slot:tooltip>
|
|
10
|
+
{{ $t('Deactivate user') }}
|
|
11
|
+
</template>
|
|
12
|
+
</Tooltip>
|
|
5
13
|
<Dialog
|
|
6
14
|
ref="confirmDialog"
|
|
7
15
|
class="w-96"
|
|
@@ -19,36 +27,16 @@
|
|
|
19
27
|
|
|
20
28
|
<script lang="ts" setup>
|
|
21
29
|
import { Dialog, Tooltip } from '@/afcl';
|
|
22
|
-
import { ref
|
|
30
|
+
import { ref } from 'vue';
|
|
23
31
|
import { AdminUser, type AdminForthResourceCommon } from '@/types';
|
|
24
32
|
import adminforth from "@/adminforth"
|
|
25
33
|
import { callAdminForthApi } from '@/utils';
|
|
26
|
-
import {
|
|
27
|
-
|
|
34
|
+
import { IconUserRemoveSolid } from '@iconify-prerendered/vue-flowbite';
|
|
28
35
|
|
|
29
36
|
const confirmDialog = ref(null);
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
onMounted(async () => {
|
|
33
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
34
|
-
|
|
35
|
-
adminforth?.list?.updateFilter?.({
|
|
36
|
-
field: props.meta.field,
|
|
37
|
-
operator: AdminForthFilterOperators.EQ,
|
|
38
|
-
value: true,
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
38
|
function openDialog() {
|
|
43
|
-
|
|
44
|
-
if (props.checkboxes.length > 1) {
|
|
45
|
-
adminforth.alert({message: "Select only one account to deactivate", variant: "warning"})
|
|
46
|
-
} else {
|
|
47
|
-
adminforth.alert({message: "Select at least one account to deactivate", variant: "warning"})
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
confirmDialog.value.open()
|
|
51
|
-
}
|
|
39
|
+
confirmDialog.value.open();
|
|
52
40
|
}
|
|
53
41
|
|
|
54
42
|
async function deactivateUser() {
|
|
@@ -57,7 +45,7 @@ async function deactivateUser() {
|
|
|
57
45
|
path: `/plugin/${props.meta.pluginInstanceId}/deactivateUser`,
|
|
58
46
|
method: 'POST',
|
|
59
47
|
body: {
|
|
60
|
-
record: props.
|
|
48
|
+
record: props.record,
|
|
61
49
|
},
|
|
62
50
|
});
|
|
63
51
|
if (!res || res.ok === false || res.error) {
|
|
@@ -66,33 +54,19 @@ async function deactivateUser() {
|
|
|
66
54
|
}
|
|
67
55
|
throw new Error("")
|
|
68
56
|
}
|
|
69
|
-
props.
|
|
57
|
+
props.updateRecords();
|
|
70
58
|
} catch (e) {
|
|
71
59
|
adminforth.alert({message: `Error deactivating user. ${e}`, variant: "warning"});
|
|
72
60
|
}
|
|
73
61
|
}
|
|
74
62
|
|
|
75
63
|
const props = defineProps<{
|
|
76
|
-
checkboxes: any,
|
|
77
64
|
meta: any,
|
|
78
65
|
resource: AdminForthResourceCommon,
|
|
79
66
|
adminUser: AdminUser,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
required: true
|
|
83
|
-
},
|
|
84
|
-
clearCheckboxes: {
|
|
85
|
-
type: Function
|
|
86
|
-
}
|
|
67
|
+
record: any,
|
|
68
|
+
updateRecords: Function,
|
|
87
69
|
}>();
|
|
88
70
|
|
|
89
|
-
defineExpose({
|
|
90
|
-
click
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
function click() {
|
|
94
|
-
openDialog();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
71
|
|
|
98
72
|
</script>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script lang="ts" setup>
|
|
6
|
+
import { onMounted } from 'vue';
|
|
7
|
+
import { AdminForthFilterOperators } from '@/types/Common';
|
|
8
|
+
import adminforth from "@/adminforth"
|
|
9
|
+
onMounted(async () => {
|
|
10
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
11
|
+
adminforth?.list?.updateFilter?.({
|
|
12
|
+
field: props.meta.field,
|
|
13
|
+
operator: AdminForthFilterOperators.EQ,
|
|
14
|
+
value: true,
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
const props = defineProps<{
|
|
18
|
+
meta: any
|
|
19
|
+
}>();
|
|
20
|
+
</script>
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
<
|
|
4
|
-
|
|
2
|
+
<Tooltip>
|
|
3
|
+
<button
|
|
4
|
+
@click="openDialog()"
|
|
5
|
+
>
|
|
6
|
+
<IconUserRemoveSolid class="w-5 h-5 me-2"/>
|
|
7
|
+
</button>
|
|
8
|
+
|
|
9
|
+
<template v-slot:tooltip>
|
|
10
|
+
{{ $t('Deactivate user') }}
|
|
11
|
+
</template>
|
|
12
|
+
</Tooltip>
|
|
5
13
|
<Dialog
|
|
6
14
|
ref="confirmDialog"
|
|
7
15
|
class="w-96"
|
|
@@ -19,36 +27,16 @@
|
|
|
19
27
|
|
|
20
28
|
<script lang="ts" setup>
|
|
21
29
|
import { Dialog, Tooltip } from '@/afcl';
|
|
22
|
-
import { ref
|
|
30
|
+
import { ref } from 'vue';
|
|
23
31
|
import { AdminUser, type AdminForthResourceCommon } from '@/types';
|
|
24
32
|
import adminforth from "@/adminforth"
|
|
25
33
|
import { callAdminForthApi } from '@/utils';
|
|
26
|
-
import {
|
|
27
|
-
|
|
34
|
+
import { IconUserRemoveSolid } from '@iconify-prerendered/vue-flowbite';
|
|
28
35
|
|
|
29
36
|
const confirmDialog = ref(null);
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
onMounted(async () => {
|
|
33
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
34
|
-
|
|
35
|
-
adminforth?.list?.updateFilter?.({
|
|
36
|
-
field: props.meta.field,
|
|
37
|
-
operator: AdminForthFilterOperators.EQ,
|
|
38
|
-
value: true,
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
38
|
function openDialog() {
|
|
43
|
-
|
|
44
|
-
if (props.checkboxes.length > 1) {
|
|
45
|
-
adminforth.alert({message: "Select only one account to deactivate", variant: "warning"})
|
|
46
|
-
} else {
|
|
47
|
-
adminforth.alert({message: "Select at least one account to deactivate", variant: "warning"})
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
confirmDialog.value.open()
|
|
51
|
-
}
|
|
39
|
+
confirmDialog.value.open();
|
|
52
40
|
}
|
|
53
41
|
|
|
54
42
|
async function deactivateUser() {
|
|
@@ -57,7 +45,7 @@ async function deactivateUser() {
|
|
|
57
45
|
path: `/plugin/${props.meta.pluginInstanceId}/deactivateUser`,
|
|
58
46
|
method: 'POST',
|
|
59
47
|
body: {
|
|
60
|
-
record: props.
|
|
48
|
+
record: props.record,
|
|
61
49
|
},
|
|
62
50
|
});
|
|
63
51
|
if (!res || res.ok === false || res.error) {
|
|
@@ -66,33 +54,19 @@ async function deactivateUser() {
|
|
|
66
54
|
}
|
|
67
55
|
throw new Error("")
|
|
68
56
|
}
|
|
69
|
-
props.
|
|
57
|
+
props.updateRecords();
|
|
70
58
|
} catch (e) {
|
|
71
59
|
adminforth.alert({message: `Error deactivating user. ${e}`, variant: "warning"});
|
|
72
60
|
}
|
|
73
61
|
}
|
|
74
62
|
|
|
75
63
|
const props = defineProps<{
|
|
76
|
-
checkboxes: any,
|
|
77
64
|
meta: any,
|
|
78
65
|
resource: AdminForthResourceCommon,
|
|
79
66
|
adminUser: AdminUser,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
required: true
|
|
83
|
-
},
|
|
84
|
-
clearCheckboxes: {
|
|
85
|
-
type: Function
|
|
86
|
-
}
|
|
67
|
+
record: any,
|
|
68
|
+
updateRecords: Function,
|
|
87
69
|
}>();
|
|
88
70
|
|
|
89
|
-
defineExpose({
|
|
90
|
-
click
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
function click() {
|
|
94
|
-
openDialog();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
71
|
|
|
98
72
|
</script>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script lang="ts" setup>
|
|
6
|
+
import { onMounted } from 'vue';
|
|
7
|
+
import { AdminForthFilterOperators } from '@/types/Common';
|
|
8
|
+
import adminforth from "@/adminforth"
|
|
9
|
+
onMounted(async () => {
|
|
10
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
11
|
+
adminforth?.list?.updateFilter?.({
|
|
12
|
+
field: props.meta.field,
|
|
13
|
+
operator: AdminForthFilterOperators.EQ,
|
|
14
|
+
value: true,
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
const props = defineProps<{
|
|
18
|
+
meta: any
|
|
19
|
+
}>();
|
|
20
|
+
</script>
|
package/dist/index.js
CHANGED
|
@@ -41,12 +41,12 @@ export default class UserSoftDelete extends AdminForthPlugin {
|
|
|
41
41
|
body: {
|
|
42
42
|
allowedLogin: false,
|
|
43
43
|
redirectTo: '/login',
|
|
44
|
-
}
|
|
45
|
-
ok: true
|
|
44
|
+
}
|
|
46
45
|
};
|
|
47
46
|
if (adminUser.dbUser[this.options.activeFieldName] === false) {
|
|
48
47
|
return rejectResult;
|
|
49
48
|
}
|
|
49
|
+
return { body: { allowedLogin: true } };
|
|
50
50
|
}));
|
|
51
51
|
const adminUserAuthorize = this.adminforth.config.auth.adminUserAuthorize;
|
|
52
52
|
const adminUserAuthorizeArray = Array.isArray(adminUserAuthorize) ? adminUserAuthorize : [adminUserAuthorize];
|
|
@@ -58,6 +58,7 @@ export default class UserSoftDelete extends AdminForthPlugin {
|
|
|
58
58
|
if (adminUser.dbUser[this.options.activeFieldName] === false) {
|
|
59
59
|
return rejectResult;
|
|
60
60
|
}
|
|
61
|
+
return { allowed: true };
|
|
61
62
|
}));
|
|
62
63
|
if (!resourceConfig.options.pageInjections) {
|
|
63
64
|
resourceConfig.options.pageInjections = {};
|
|
@@ -65,10 +66,14 @@ export default class UserSoftDelete extends AdminForthPlugin {
|
|
|
65
66
|
if (!resourceConfig.options.pageInjections.list) {
|
|
66
67
|
resourceConfig.options.pageInjections.list = {};
|
|
67
68
|
}
|
|
68
|
-
if (!resourceConfig.options.pageInjections.list.
|
|
69
|
-
resourceConfig.options.pageInjections.list.
|
|
69
|
+
if (!resourceConfig.options.pageInjections.list.customActionIcons) {
|
|
70
|
+
resourceConfig.options.pageInjections.list.customActionIcons = [];
|
|
70
71
|
}
|
|
71
|
-
resourceConfig.options.pageInjections.list.
|
|
72
|
+
resourceConfig.options.pageInjections.list.customActionIcons.push({ file: this.componentPath('DisableButton.vue'), meta: { pluginInstanceId: this.pluginInstanceId, field: this.options.activeFieldName } });
|
|
73
|
+
if (!resourceConfig.options.pageInjections.list.afterBreadcrumbs) {
|
|
74
|
+
resourceConfig.options.pageInjections.list.afterBreadcrumbs = [];
|
|
75
|
+
}
|
|
76
|
+
resourceConfig.options.pageInjections.list.afterBreadcrumbs.push({ file: this.componentPath('UserSoftDeleteFilterSetter.vue'), meta: { pluginInstanceId: this.pluginInstanceId, field: this.options.activeFieldName } });
|
|
72
77
|
// simply modify resourceConfig or adminforth.config. You can get access to plugin options via this.options;
|
|
73
78
|
});
|
|
74
79
|
}
|
|
@@ -102,8 +107,8 @@ export default class UserSoftDelete extends AdminForthPlugin {
|
|
|
102
107
|
if (isAllowedToDeactivate === false) {
|
|
103
108
|
return { ok: false, error: "Not allowed to deactivate user" };
|
|
104
109
|
}
|
|
105
|
-
const id = body.record;
|
|
106
110
|
const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
|
|
111
|
+
const id = body.record[primaryKeyColumn.name];
|
|
107
112
|
const oldUser = yield this.adminforth
|
|
108
113
|
.resource(this.resourceConfig.resourceId)
|
|
109
114
|
.get([Filters.EQ(primaryKeyColumn.name, id)]);
|
|
@@ -113,6 +118,9 @@ export default class UserSoftDelete extends AdminForthPlugin {
|
|
|
113
118
|
if (oldUser[this.options.activeFieldName] === false) {
|
|
114
119
|
return { ok: false, error: "User is already deactivated" };
|
|
115
120
|
}
|
|
121
|
+
if (oldUser[primaryKeyColumn.name] === adminUser.dbUser[primaryKeyColumn.name]) {
|
|
122
|
+
return { ok: false, error: "You cannot deactivate your own account" };
|
|
123
|
+
}
|
|
116
124
|
const newUser = Object.assign(Object.assign({}, oldUser), { [this.options.activeFieldName]: false });
|
|
117
125
|
yield this.adminforth.updateResourceRecord({
|
|
118
126
|
resource: this.resourceConfig,
|
package/index.ts
CHANGED
|
@@ -35,12 +35,12 @@ export default class UserSoftDelete extends AdminForthPlugin {
|
|
|
35
35
|
body:{
|
|
36
36
|
allowedLogin: false,
|
|
37
37
|
redirectTo: '/login',
|
|
38
|
-
}
|
|
39
|
-
ok: true
|
|
38
|
+
}
|
|
40
39
|
};
|
|
41
40
|
if (adminUser.dbUser[this.options.activeFieldName] === false) {
|
|
42
41
|
return rejectResult;
|
|
43
42
|
}
|
|
43
|
+
return { body: {allowedLogin: true} };
|
|
44
44
|
}
|
|
45
45
|
);
|
|
46
46
|
|
|
@@ -55,6 +55,7 @@ export default class UserSoftDelete extends AdminForthPlugin {
|
|
|
55
55
|
if (adminUser.dbUser[this.options.activeFieldName] === false) {
|
|
56
56
|
return rejectResult;
|
|
57
57
|
}
|
|
58
|
+
return { allowed: true };
|
|
58
59
|
}
|
|
59
60
|
);
|
|
60
61
|
|
|
@@ -64,13 +65,20 @@ export default class UserSoftDelete extends AdminForthPlugin {
|
|
|
64
65
|
if ( !resourceConfig.options.pageInjections.list ) {
|
|
65
66
|
resourceConfig.options.pageInjections.list = {};
|
|
66
67
|
}
|
|
67
|
-
if ( !resourceConfig.options.pageInjections.list.
|
|
68
|
-
resourceConfig.options.pageInjections.list.
|
|
68
|
+
if ( !resourceConfig.options.pageInjections.list.customActionIcons ) {
|
|
69
|
+
resourceConfig.options.pageInjections.list.customActionIcons = [];
|
|
69
70
|
}
|
|
70
|
-
(resourceConfig.options.pageInjections.list.
|
|
71
|
+
(resourceConfig.options.pageInjections.list.customActionIcons as AdminForthComponentDeclaration[]).push(
|
|
71
72
|
{ file: this.componentPath('DisableButton.vue'), meta: { pluginInstanceId: this.pluginInstanceId, field: this.options.activeFieldName } }
|
|
72
73
|
);
|
|
73
74
|
|
|
75
|
+
if ( !resourceConfig.options.pageInjections.list.afterBreadcrumbs ) {
|
|
76
|
+
resourceConfig.options.pageInjections.list.afterBreadcrumbs = [];
|
|
77
|
+
}
|
|
78
|
+
(resourceConfig.options.pageInjections.list.afterBreadcrumbs as AdminForthComponentDeclaration[]).push(
|
|
79
|
+
{ file: this.componentPath('UserSoftDeleteFilterSetter.vue'), meta: { pluginInstanceId: this.pluginInstanceId, field: this.options.activeFieldName } }
|
|
80
|
+
);
|
|
81
|
+
|
|
74
82
|
// simply modify resourceConfig or adminforth.config. You can get access to plugin options via this.options;
|
|
75
83
|
}
|
|
76
84
|
|
|
@@ -106,8 +114,9 @@ export default class UserSoftDelete extends AdminForthPlugin {
|
|
|
106
114
|
if ( isAllowedToDeactivate === false ) {
|
|
107
115
|
return {ok: false, error: "Not allowed to deactivate user"}
|
|
108
116
|
}
|
|
109
|
-
|
|
117
|
+
|
|
110
118
|
const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
|
|
119
|
+
const id = body.record[primaryKeyColumn.name];
|
|
111
120
|
|
|
112
121
|
const oldUser = await this.adminforth
|
|
113
122
|
.resource(this.resourceConfig.resourceId)
|
|
@@ -120,6 +129,10 @@ export default class UserSoftDelete extends AdminForthPlugin {
|
|
|
120
129
|
if (oldUser[this.options.activeFieldName] === false) {
|
|
121
130
|
return {ok: false, error: "User is already deactivated"}
|
|
122
131
|
}
|
|
132
|
+
|
|
133
|
+
if (oldUser[primaryKeyColumn.name] === adminUser.dbUser[primaryKeyColumn.name]) {
|
|
134
|
+
return {ok: false, error: "You cannot deactivate your own account"}
|
|
135
|
+
}
|
|
123
136
|
|
|
124
137
|
const newUser = { ...oldUser, [this.options.activeFieldName]: false };
|
|
125
138
|
|