@zealamic/payload-auth-rbac-plugin 1.0.1 → 1.0.2
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 +17 -2
- package/dist/collections/users/index.js +11 -8
- package/dist/collections/users/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.js.map +1 -1
- package/package.json +20 -16
- package/assets/cover-photo.jpg +0 -0
- package/docs/COLLECTIONS.md +0 -440
- package/docs/TRANSLATIONS.md +0 -469
- package/docs/UTILS.md +0 -226
- package/src/collections/permission-actions/default-data.ts +0 -36
- package/src/collections/permission-actions/index.ts +0 -144
- package/src/collections/permission-actions/types.ts +0 -56
- package/src/collections/permission-features/default-data.ts +0 -30
- package/src/collections/permission-features/index.ts +0 -122
- package/src/collections/permission-features/types.ts +0 -47
- package/src/collections/permissions/default-data.ts +0 -38
- package/src/collections/permissions/index.ts +0 -160
- package/src/collections/permissions/types.ts +0 -57
- package/src/collections/roles/default-data.ts +0 -44
- package/src/collections/roles/hooks/sync-permission-matrix-draft.ts +0 -73
- package/src/collections/roles/index.ts +0 -178
- package/src/collections/roles/types.ts +0 -56
- package/src/collections/roles-permissions/default-data.ts +0 -28
- package/src/collections/roles-permissions/index.ts +0 -107
- package/src/collections/roles-permissions/types.ts +0 -42
- package/src/collections/users/default-data.ts +0 -19
- package/src/collections/users/index.ts +0 -148
- package/src/collections/users/parent-path.ts +0 -310
- package/src/collections/users/types.ts +0 -25
- package/src/components/role-permission-matrix-client/default-data.ts +0 -25
- package/src/components/role-permission-matrix-client/index.tsx +0 -369
- package/src/components/role-permission-matrix-client/matrix.module.scss +0 -66
- package/src/components/role-permission-matrix-client/types.ts +0 -16
- package/src/endpoints/customEndpointHandler.ts +0 -5
- package/src/exports/client.ts +0 -1
- package/src/exports/rsc.ts +0 -0
- package/src/index.ts +0 -249
- package/src/lib/constants/general.ts +0 -1
- package/src/lib/constants/index.ts +0 -15
- package/src/lib/constants/permission-action.ts +0 -9
- package/src/lib/constants/permission-feature.ts +0 -4
- package/src/lib/constants/permission.ts +0 -4
- package/src/lib/constants/role.ts +0 -10
- package/src/lib/constants/user.ts +0 -1
- package/src/lib/utils/access.ts +0 -611
- package/src/lib/utils/data.ts +0 -7
- package/src/lib/utils/fields.ts +0 -62
- package/src/lib/utils/index.ts +0 -4
- package/src/lib/utils/localization.ts +0 -106
- package/src/styles/variables.scss +0 -1
- package/src/types.ts +0 -64
- /package/{src → dist}/general-types.d.ts +0 -0
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { PermissionActionsCollectionTranslations } from "./types.js";
|
|
2
|
-
|
|
3
|
-
export const permissionActionsDefaultTranslations: PermissionActionsCollectionTranslations =
|
|
4
|
-
{
|
|
5
|
-
en: {
|
|
6
|
-
labels: {
|
|
7
|
-
singular: "Permission Action",
|
|
8
|
-
plural: "Permission Actions",
|
|
9
|
-
},
|
|
10
|
-
admin: {
|
|
11
|
-
group: "System",
|
|
12
|
-
},
|
|
13
|
-
fields: {
|
|
14
|
-
code: {
|
|
15
|
-
label: "Code",
|
|
16
|
-
placeholder: "Enter code",
|
|
17
|
-
},
|
|
18
|
-
type: {
|
|
19
|
-
label: "Type",
|
|
20
|
-
placeholder: "Select type",
|
|
21
|
-
mainLabel: "Main",
|
|
22
|
-
subLabel: "Sub",
|
|
23
|
-
},
|
|
24
|
-
sortOrder: {
|
|
25
|
-
label: "Sort Order",
|
|
26
|
-
placeholder: "Enter sort order",
|
|
27
|
-
},
|
|
28
|
-
status: {
|
|
29
|
-
label: "Status",
|
|
30
|
-
placeholder: "Select status",
|
|
31
|
-
activeLabel: "Active",
|
|
32
|
-
inactiveLabel: "Inactive",
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
};
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig } from "payload";
|
|
2
|
-
import { STATUS, TYPE } from "../../lib/constants/permission-action.js";
|
|
3
|
-
import {
|
|
4
|
-
getArrayOfMergedFieldAffectingData,
|
|
5
|
-
getSuperAdminAccess,
|
|
6
|
-
toLocaleRecord,
|
|
7
|
-
toSelectPlaceholder,
|
|
8
|
-
} from "../../lib/utils/index.js";
|
|
9
|
-
import type { PermissionActionsCollectionParams } from "./types.js";
|
|
10
|
-
|
|
11
|
-
export const getPermissionActionsCollection = (
|
|
12
|
-
params: PermissionActionsCollectionParams,
|
|
13
|
-
) => {
|
|
14
|
-
const {
|
|
15
|
-
translations = {},
|
|
16
|
-
access = {},
|
|
17
|
-
fields = [],
|
|
18
|
-
labels = {},
|
|
19
|
-
admin = {},
|
|
20
|
-
} = params || {};
|
|
21
|
-
const arrTranslationsKeys = Object.keys(translations);
|
|
22
|
-
const permissionActions: CollectionConfig = {
|
|
23
|
-
slug: "permission-actions",
|
|
24
|
-
labels: {
|
|
25
|
-
singular: toLocaleRecord(
|
|
26
|
-
arrTranslationsKeys,
|
|
27
|
-
(locale) => translations[locale]?.labels?.singular,
|
|
28
|
-
),
|
|
29
|
-
plural: toLocaleRecord(
|
|
30
|
-
arrTranslationsKeys,
|
|
31
|
-
(locale) => translations[locale]?.labels?.plural,
|
|
32
|
-
),
|
|
33
|
-
...labels,
|
|
34
|
-
},
|
|
35
|
-
admin: {
|
|
36
|
-
group: toLocaleRecord(
|
|
37
|
-
arrTranslationsKeys,
|
|
38
|
-
(locale) => translations[locale]?.admin?.group,
|
|
39
|
-
),
|
|
40
|
-
useAsTitle: "code",
|
|
41
|
-
defaultColumns: ["code", "type", "status", "updatedAt"],
|
|
42
|
-
...admin,
|
|
43
|
-
},
|
|
44
|
-
access: {
|
|
45
|
-
create: getSuperAdminAccess,
|
|
46
|
-
update: getSuperAdminAccess,
|
|
47
|
-
delete: getSuperAdminAccess,
|
|
48
|
-
read: getSuperAdminAccess,
|
|
49
|
-
readVersions: getSuperAdminAccess,
|
|
50
|
-
unlock: getSuperAdminAccess,
|
|
51
|
-
admin: ({ req }) => {
|
|
52
|
-
return getSuperAdminAccess({ req });
|
|
53
|
-
},
|
|
54
|
-
...access,
|
|
55
|
-
},
|
|
56
|
-
fields: getArrayOfMergedFieldAffectingData({
|
|
57
|
-
fields,
|
|
58
|
-
defaultFields: [
|
|
59
|
-
{
|
|
60
|
-
name: "code",
|
|
61
|
-
type: "text",
|
|
62
|
-
required: true,
|
|
63
|
-
unique: true,
|
|
64
|
-
index: true,
|
|
65
|
-
label: toLocaleRecord(
|
|
66
|
-
arrTranslationsKeys,
|
|
67
|
-
(locale) => translations[locale]?.fields?.code?.label,
|
|
68
|
-
),
|
|
69
|
-
admin: {
|
|
70
|
-
placeholder: toLocaleRecord(
|
|
71
|
-
arrTranslationsKeys,
|
|
72
|
-
(locale) => translations[locale]?.fields?.code?.placeholder,
|
|
73
|
-
),
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
name: "type",
|
|
78
|
-
type: "select",
|
|
79
|
-
required: true,
|
|
80
|
-
label: toLocaleRecord(
|
|
81
|
-
arrTranslationsKeys,
|
|
82
|
-
(locale) => translations[locale]?.fields?.type?.label,
|
|
83
|
-
),
|
|
84
|
-
options: Object.values(TYPE).map((type) => ({
|
|
85
|
-
label: toLocaleRecord(
|
|
86
|
-
arrTranslationsKeys,
|
|
87
|
-
(locale) => translations[locale]?.fields?.type?.[`${type}Label`],
|
|
88
|
-
),
|
|
89
|
-
value: type,
|
|
90
|
-
})),
|
|
91
|
-
admin: {
|
|
92
|
-
placeholder: toSelectPlaceholder(
|
|
93
|
-
arrTranslationsKeys,
|
|
94
|
-
(locale) => translations[locale]?.fields?.type?.placeholder,
|
|
95
|
-
),
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
name: "sortOrder",
|
|
100
|
-
type: "number",
|
|
101
|
-
required: false,
|
|
102
|
-
defaultValue: 0,
|
|
103
|
-
label: toLocaleRecord(
|
|
104
|
-
arrTranslationsKeys,
|
|
105
|
-
(locale) => translations[locale]?.fields?.sortOrder?.label,
|
|
106
|
-
),
|
|
107
|
-
admin: {
|
|
108
|
-
placeholder: toLocaleRecord(
|
|
109
|
-
arrTranslationsKeys,
|
|
110
|
-
(locale) => translations[locale]?.fields?.sortOrder?.placeholder,
|
|
111
|
-
),
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
name: "status",
|
|
116
|
-
type: "select",
|
|
117
|
-
required: true,
|
|
118
|
-
label: toLocaleRecord(
|
|
119
|
-
arrTranslationsKeys,
|
|
120
|
-
(locale) => translations[locale]?.fields?.status?.label,
|
|
121
|
-
),
|
|
122
|
-
defaultValue: STATUS.ACTIVE,
|
|
123
|
-
options: Object.values(STATUS).map((status) => ({
|
|
124
|
-
label: toLocaleRecord(
|
|
125
|
-
arrTranslationsKeys,
|
|
126
|
-
(locale) =>
|
|
127
|
-
translations[locale]?.fields?.status?.[`${status}Label`],
|
|
128
|
-
),
|
|
129
|
-
value: status,
|
|
130
|
-
})),
|
|
131
|
-
admin: {
|
|
132
|
-
placeholder: toSelectPlaceholder(
|
|
133
|
-
arrTranslationsKeys,
|
|
134
|
-
(locale) => translations[locale]?.fields?.status?.placeholder,
|
|
135
|
-
),
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
}),
|
|
140
|
-
timestamps: true,
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
return permissionActions;
|
|
144
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig, Field } from "payload";
|
|
2
|
-
import { STATUS, TYPE } from "../../lib/constants/permission-action.js";
|
|
3
|
-
|
|
4
|
-
export type PermissionActionsCollectionTranslations = {
|
|
5
|
-
[locale: string]: {
|
|
6
|
-
labels?: {
|
|
7
|
-
singular?: string;
|
|
8
|
-
plural?: string;
|
|
9
|
-
};
|
|
10
|
-
admin?: {
|
|
11
|
-
group?: string;
|
|
12
|
-
};
|
|
13
|
-
fields?: {
|
|
14
|
-
code?: {
|
|
15
|
-
label?: string;
|
|
16
|
-
placeholder?: string;
|
|
17
|
-
};
|
|
18
|
-
type?: {
|
|
19
|
-
label?: string;
|
|
20
|
-
placeholder?: string;
|
|
21
|
-
mainLabel?: string;
|
|
22
|
-
subLabel?: string;
|
|
23
|
-
};
|
|
24
|
-
sortOrder?: {
|
|
25
|
-
label?: string;
|
|
26
|
-
placeholder?: string;
|
|
27
|
-
};
|
|
28
|
-
status?: {
|
|
29
|
-
label?: string;
|
|
30
|
-
placeholder?: string;
|
|
31
|
-
activeLabel?: string;
|
|
32
|
-
inactiveLabel?: string;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export type PermissionActionsCollectionParams = {
|
|
39
|
-
translations?: PermissionActionsCollectionTranslations;
|
|
40
|
-
fields?: Field[];
|
|
41
|
-
access?: CollectionConfig["access"];
|
|
42
|
-
labels?: CollectionConfig["labels"];
|
|
43
|
-
admin?: CollectionConfig["admin"];
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export type PermissionActionStatus = (typeof STATUS)[keyof typeof STATUS];
|
|
47
|
-
|
|
48
|
-
export type PermissionActionType = (typeof TYPE)[keyof typeof TYPE];
|
|
49
|
-
|
|
50
|
-
export type PermissionAction = {
|
|
51
|
-
id: string | number;
|
|
52
|
-
code?: string | null;
|
|
53
|
-
sortOrder?: number | null;
|
|
54
|
-
type?: PermissionActionType | null;
|
|
55
|
-
status?: PermissionActionStatus | null;
|
|
56
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { PermissionFeaturesCollectionTranslations } from "./types.js";
|
|
2
|
-
|
|
3
|
-
export const permissionFeaturesDefaultTranslations: PermissionFeaturesCollectionTranslations =
|
|
4
|
-
{
|
|
5
|
-
en: {
|
|
6
|
-
labels: {
|
|
7
|
-
singular: "Permission Feature",
|
|
8
|
-
plural: "Permission Features",
|
|
9
|
-
},
|
|
10
|
-
admin: {
|
|
11
|
-
group: "System",
|
|
12
|
-
},
|
|
13
|
-
fields: {
|
|
14
|
-
code: {
|
|
15
|
-
label: "Code",
|
|
16
|
-
placeholder: "Enter code",
|
|
17
|
-
},
|
|
18
|
-
sortOrder: {
|
|
19
|
-
label: "Sort Order",
|
|
20
|
-
placeholder: "Enter sort order",
|
|
21
|
-
},
|
|
22
|
-
status: {
|
|
23
|
-
label: "Status",
|
|
24
|
-
placeholder: "Select status",
|
|
25
|
-
activeLabel: "Active",
|
|
26
|
-
inactiveLabel: "Inactive",
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
};
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig } from "payload";
|
|
2
|
-
import { STATUS } from "../../lib/constants/permission-feature.js";
|
|
3
|
-
import {
|
|
4
|
-
getArrayOfMergedFieldAffectingData,
|
|
5
|
-
getSuperAdminAccess,
|
|
6
|
-
toLocaleRecord,
|
|
7
|
-
toSelectPlaceholder,
|
|
8
|
-
} from "../../lib/utils/index.js";
|
|
9
|
-
import type { PermissionFeaturesCollectionParams } from "./types.js";
|
|
10
|
-
|
|
11
|
-
export const getPermissionFeaturesCollection = (
|
|
12
|
-
params: PermissionFeaturesCollectionParams,
|
|
13
|
-
) => {
|
|
14
|
-
const {
|
|
15
|
-
translations = {},
|
|
16
|
-
access = {},
|
|
17
|
-
fields = [],
|
|
18
|
-
labels = {},
|
|
19
|
-
admin = {},
|
|
20
|
-
} = params || {};
|
|
21
|
-
const arrTranslationsKeys = Object.keys(translations);
|
|
22
|
-
const permissionFeatures: CollectionConfig = {
|
|
23
|
-
slug: "permission-features",
|
|
24
|
-
labels: {
|
|
25
|
-
singular: toLocaleRecord(
|
|
26
|
-
arrTranslationsKeys,
|
|
27
|
-
(locale) => translations[locale]?.labels?.singular,
|
|
28
|
-
),
|
|
29
|
-
plural: toLocaleRecord(
|
|
30
|
-
arrTranslationsKeys,
|
|
31
|
-
(locale) => translations[locale]?.labels?.plural,
|
|
32
|
-
),
|
|
33
|
-
...labels,
|
|
34
|
-
},
|
|
35
|
-
admin: {
|
|
36
|
-
group: toLocaleRecord(
|
|
37
|
-
arrTranslationsKeys,
|
|
38
|
-
(locale) => translations[locale]?.admin?.group,
|
|
39
|
-
),
|
|
40
|
-
useAsTitle: "code",
|
|
41
|
-
defaultColumns: ["code", "status", "updatedAt"],
|
|
42
|
-
...admin,
|
|
43
|
-
},
|
|
44
|
-
access: {
|
|
45
|
-
create: getSuperAdminAccess,
|
|
46
|
-
update: getSuperAdminAccess,
|
|
47
|
-
delete: getSuperAdminAccess,
|
|
48
|
-
read: getSuperAdminAccess,
|
|
49
|
-
readVersions: getSuperAdminAccess,
|
|
50
|
-
unlock: getSuperAdminAccess,
|
|
51
|
-
admin: ({ req }) => {
|
|
52
|
-
return getSuperAdminAccess({ req });
|
|
53
|
-
},
|
|
54
|
-
...access,
|
|
55
|
-
},
|
|
56
|
-
fields: getArrayOfMergedFieldAffectingData({
|
|
57
|
-
fields,
|
|
58
|
-
defaultFields: [
|
|
59
|
-
{
|
|
60
|
-
name: "code",
|
|
61
|
-
type: "text",
|
|
62
|
-
required: true,
|
|
63
|
-
unique: true,
|
|
64
|
-
index: true,
|
|
65
|
-
label: toLocaleRecord(
|
|
66
|
-
arrTranslationsKeys,
|
|
67
|
-
(locale) => translations[locale]?.fields?.code?.label,
|
|
68
|
-
),
|
|
69
|
-
admin: {
|
|
70
|
-
placeholder: toLocaleRecord(
|
|
71
|
-
arrTranslationsKeys,
|
|
72
|
-
(locale) => translations[locale]?.fields?.code?.placeholder,
|
|
73
|
-
),
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
name: "sortOrder",
|
|
78
|
-
type: "number",
|
|
79
|
-
required: false,
|
|
80
|
-
defaultValue: 0,
|
|
81
|
-
label: toLocaleRecord(
|
|
82
|
-
arrTranslationsKeys,
|
|
83
|
-
(locale) => translations[locale]?.fields?.sortOrder?.label,
|
|
84
|
-
),
|
|
85
|
-
admin: {
|
|
86
|
-
placeholder: toLocaleRecord(
|
|
87
|
-
arrTranslationsKeys,
|
|
88
|
-
(locale) => translations[locale]?.fields?.sortOrder?.placeholder,
|
|
89
|
-
),
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
name: "status",
|
|
94
|
-
type: "select",
|
|
95
|
-
required: true,
|
|
96
|
-
label: toLocaleRecord(
|
|
97
|
-
arrTranslationsKeys,
|
|
98
|
-
(locale) => translations[locale]?.fields?.status?.label,
|
|
99
|
-
),
|
|
100
|
-
defaultValue: STATUS.ACTIVE,
|
|
101
|
-
options: Object.values(STATUS).map((status) => ({
|
|
102
|
-
label: toLocaleRecord(
|
|
103
|
-
arrTranslationsKeys,
|
|
104
|
-
(locale) =>
|
|
105
|
-
translations[locale]?.fields?.status?.[`${status}Label`],
|
|
106
|
-
),
|
|
107
|
-
value: status,
|
|
108
|
-
})),
|
|
109
|
-
admin: {
|
|
110
|
-
placeholder: toSelectPlaceholder(
|
|
111
|
-
arrTranslationsKeys,
|
|
112
|
-
(locale) => translations[locale]?.fields?.status?.placeholder,
|
|
113
|
-
),
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
],
|
|
117
|
-
}),
|
|
118
|
-
timestamps: true,
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
return permissionFeatures;
|
|
122
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig, Field } from "payload";
|
|
2
|
-
import { STATUS } from "../../lib/constants/permission-feature.js";
|
|
3
|
-
|
|
4
|
-
export type PermissionFeaturesCollectionTranslations = {
|
|
5
|
-
[locale: string]: {
|
|
6
|
-
labels?: {
|
|
7
|
-
singular?: string;
|
|
8
|
-
plural?: string;
|
|
9
|
-
};
|
|
10
|
-
admin?: {
|
|
11
|
-
group?: string;
|
|
12
|
-
};
|
|
13
|
-
fields?: {
|
|
14
|
-
code?: {
|
|
15
|
-
label?: string;
|
|
16
|
-
placeholder?: string;
|
|
17
|
-
};
|
|
18
|
-
sortOrder?: {
|
|
19
|
-
label?: string;
|
|
20
|
-
placeholder?: string;
|
|
21
|
-
};
|
|
22
|
-
status?: {
|
|
23
|
-
label?: string;
|
|
24
|
-
placeholder?: string;
|
|
25
|
-
activeLabel?: string;
|
|
26
|
-
inactiveLabel?: string;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type PermissionFeaturesCollectionParams = {
|
|
33
|
-
translations?: PermissionFeaturesCollectionTranslations;
|
|
34
|
-
fields?: Field[];
|
|
35
|
-
access?: CollectionConfig["access"];
|
|
36
|
-
labels?: CollectionConfig["labels"];
|
|
37
|
-
admin?: CollectionConfig["admin"];
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export type PermissionFeatureStatus = (typeof STATUS)[keyof typeof STATUS];
|
|
41
|
-
|
|
42
|
-
export type PermissionFeature = {
|
|
43
|
-
id: string | number;
|
|
44
|
-
code?: string | null;
|
|
45
|
-
sortOrder?: number | null;
|
|
46
|
-
status?: PermissionFeatureStatus | null;
|
|
47
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { PermissionsCollectionTranslations } from "./types.js";
|
|
2
|
-
|
|
3
|
-
export const permissionsDefaultTranslations: PermissionsCollectionTranslations =
|
|
4
|
-
{
|
|
5
|
-
en: {
|
|
6
|
-
labels: {
|
|
7
|
-
singular: "Permission",
|
|
8
|
-
plural: "Permissions",
|
|
9
|
-
},
|
|
10
|
-
admin: {
|
|
11
|
-
group: "System",
|
|
12
|
-
},
|
|
13
|
-
fields: {
|
|
14
|
-
name: {
|
|
15
|
-
label: "Name",
|
|
16
|
-
placeholder: "Enter name",
|
|
17
|
-
},
|
|
18
|
-
permissionFeature: {
|
|
19
|
-
label: "Permission Feature",
|
|
20
|
-
placeholder: "Select permission feature",
|
|
21
|
-
},
|
|
22
|
-
permissionAction: {
|
|
23
|
-
label: "Permission Action",
|
|
24
|
-
placeholder: "Select permission action",
|
|
25
|
-
},
|
|
26
|
-
sortOrder: {
|
|
27
|
-
label: "Sort Order",
|
|
28
|
-
placeholder: "Enter sort order",
|
|
29
|
-
},
|
|
30
|
-
status: {
|
|
31
|
-
label: "Status",
|
|
32
|
-
placeholder: "Select status",
|
|
33
|
-
activeLabel: "Active",
|
|
34
|
-
inactiveLabel: "Inactive",
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
};
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig } from "payload";
|
|
2
|
-
import { STATUS } from "../../lib/constants/permission.js";
|
|
3
|
-
import {
|
|
4
|
-
getArrayOfMergedFieldAffectingData,
|
|
5
|
-
getSuperAdminAccess,
|
|
6
|
-
toLocaleRecord,
|
|
7
|
-
toSelectPlaceholder,
|
|
8
|
-
} from "../../lib/utils/index.js";
|
|
9
|
-
import type { PermissionsCollectionParams } from "./types.js";
|
|
10
|
-
|
|
11
|
-
export const getPermissionsCollection = (
|
|
12
|
-
params: PermissionsCollectionParams,
|
|
13
|
-
) => {
|
|
14
|
-
const {
|
|
15
|
-
translations = {},
|
|
16
|
-
access = {},
|
|
17
|
-
fields = [],
|
|
18
|
-
labels = {},
|
|
19
|
-
admin = {},
|
|
20
|
-
} = params || {};
|
|
21
|
-
const arrTranslationsKeys = Object.keys(translations);
|
|
22
|
-
const permissions: CollectionConfig = {
|
|
23
|
-
slug: "permissions",
|
|
24
|
-
labels: {
|
|
25
|
-
singular: toLocaleRecord(
|
|
26
|
-
arrTranslationsKeys,
|
|
27
|
-
(locale) => translations[locale]?.labels?.singular,
|
|
28
|
-
),
|
|
29
|
-
plural: toLocaleRecord(
|
|
30
|
-
arrTranslationsKeys,
|
|
31
|
-
(locale) => translations[locale]?.labels?.plural,
|
|
32
|
-
),
|
|
33
|
-
...labels,
|
|
34
|
-
},
|
|
35
|
-
admin: {
|
|
36
|
-
group: toLocaleRecord(
|
|
37
|
-
arrTranslationsKeys,
|
|
38
|
-
(locale) => translations[locale]?.admin?.group,
|
|
39
|
-
),
|
|
40
|
-
useAsTitle: "name",
|
|
41
|
-
defaultColumns: [
|
|
42
|
-
"name",
|
|
43
|
-
"permissionFeature",
|
|
44
|
-
"permissionAction",
|
|
45
|
-
"status",
|
|
46
|
-
"updatedAt",
|
|
47
|
-
],
|
|
48
|
-
...admin,
|
|
49
|
-
},
|
|
50
|
-
access: {
|
|
51
|
-
create: getSuperAdminAccess,
|
|
52
|
-
update: getSuperAdminAccess,
|
|
53
|
-
delete: getSuperAdminAccess,
|
|
54
|
-
read: getSuperAdminAccess,
|
|
55
|
-
readVersions: getSuperAdminAccess,
|
|
56
|
-
unlock: getSuperAdminAccess,
|
|
57
|
-
admin: ({ req }) => {
|
|
58
|
-
return getSuperAdminAccess({ req });
|
|
59
|
-
},
|
|
60
|
-
...access,
|
|
61
|
-
},
|
|
62
|
-
fields: getArrayOfMergedFieldAffectingData({
|
|
63
|
-
fields,
|
|
64
|
-
defaultFields: [
|
|
65
|
-
{
|
|
66
|
-
name: "name",
|
|
67
|
-
type: "text",
|
|
68
|
-
required: true,
|
|
69
|
-
label: toLocaleRecord(
|
|
70
|
-
arrTranslationsKeys,
|
|
71
|
-
(locale) => translations[locale]?.fields?.name?.label,
|
|
72
|
-
),
|
|
73
|
-
admin: {
|
|
74
|
-
placeholder: toLocaleRecord(
|
|
75
|
-
arrTranslationsKeys,
|
|
76
|
-
(locale) => translations[locale]?.fields?.name?.placeholder,
|
|
77
|
-
),
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
name: "permissionFeature",
|
|
82
|
-
type: "relationship",
|
|
83
|
-
required: true,
|
|
84
|
-
relationTo: "permission-features",
|
|
85
|
-
label: toLocaleRecord(
|
|
86
|
-
arrTranslationsKeys,
|
|
87
|
-
(locale) => translations[locale]?.fields?.permissionFeature?.label,
|
|
88
|
-
),
|
|
89
|
-
admin: {
|
|
90
|
-
placeholder: toSelectPlaceholder(
|
|
91
|
-
arrTranslationsKeys,
|
|
92
|
-
(locale) =>
|
|
93
|
-
translations[locale]?.fields?.permissionFeature?.placeholder,
|
|
94
|
-
),
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
name: "permissionAction",
|
|
99
|
-
type: "relationship",
|
|
100
|
-
required: true,
|
|
101
|
-
relationTo: "permission-actions",
|
|
102
|
-
label: toLocaleRecord(
|
|
103
|
-
arrTranslationsKeys,
|
|
104
|
-
(locale) => translations[locale]?.fields?.permissionAction?.label,
|
|
105
|
-
),
|
|
106
|
-
admin: {
|
|
107
|
-
placeholder: toSelectPlaceholder(
|
|
108
|
-
arrTranslationsKeys,
|
|
109
|
-
(locale) =>
|
|
110
|
-
translations[locale]?.fields?.permissionAction?.placeholder,
|
|
111
|
-
),
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
name: "sortOrder",
|
|
116
|
-
type: "number",
|
|
117
|
-
required: false,
|
|
118
|
-
defaultValue: 0,
|
|
119
|
-
label: toLocaleRecord(
|
|
120
|
-
arrTranslationsKeys,
|
|
121
|
-
(locale) => translations[locale]?.fields?.sortOrder?.label,
|
|
122
|
-
),
|
|
123
|
-
admin: {
|
|
124
|
-
placeholder: toLocaleRecord(
|
|
125
|
-
arrTranslationsKeys,
|
|
126
|
-
(locale) => translations[locale]?.fields?.sortOrder?.placeholder,
|
|
127
|
-
),
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
name: "status",
|
|
132
|
-
type: "select",
|
|
133
|
-
required: true,
|
|
134
|
-
label: toLocaleRecord(
|
|
135
|
-
arrTranslationsKeys,
|
|
136
|
-
(locale) => translations[locale]?.fields?.status?.label,
|
|
137
|
-
),
|
|
138
|
-
defaultValue: STATUS.ACTIVE,
|
|
139
|
-
options: Object.values(STATUS).map((status) => ({
|
|
140
|
-
label: toLocaleRecord(
|
|
141
|
-
arrTranslationsKeys,
|
|
142
|
-
(locale) =>
|
|
143
|
-
translations[locale]?.fields?.status?.[`${status}Label`],
|
|
144
|
-
),
|
|
145
|
-
value: status,
|
|
146
|
-
})),
|
|
147
|
-
admin: {
|
|
148
|
-
placeholder: toSelectPlaceholder(
|
|
149
|
-
arrTranslationsKeys,
|
|
150
|
-
(locale) => translations[locale]?.fields?.status?.placeholder,
|
|
151
|
-
),
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
],
|
|
155
|
-
}),
|
|
156
|
-
timestamps: true,
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
return permissions;
|
|
160
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig, Field } from "payload";
|
|
2
|
-
import { STATUS } from "src/lib/constants/permission.js";
|
|
3
|
-
|
|
4
|
-
export type PermissionsCollectionTranslations = {
|
|
5
|
-
[locale: string]: {
|
|
6
|
-
labels?: {
|
|
7
|
-
singular?: string;
|
|
8
|
-
plural?: string;
|
|
9
|
-
};
|
|
10
|
-
admin?: {
|
|
11
|
-
group?: string;
|
|
12
|
-
};
|
|
13
|
-
fields?: {
|
|
14
|
-
name?: {
|
|
15
|
-
label?: string;
|
|
16
|
-
placeholder?: string;
|
|
17
|
-
};
|
|
18
|
-
permissionFeature?: {
|
|
19
|
-
label?: string;
|
|
20
|
-
placeholder?: string;
|
|
21
|
-
};
|
|
22
|
-
permissionAction?: {
|
|
23
|
-
label?: string;
|
|
24
|
-
placeholder?: string;
|
|
25
|
-
};
|
|
26
|
-
sortOrder?: {
|
|
27
|
-
label?: string;
|
|
28
|
-
placeholder?: string;
|
|
29
|
-
};
|
|
30
|
-
status?: {
|
|
31
|
-
label?: string;
|
|
32
|
-
placeholder?: string;
|
|
33
|
-
activeLabel?: string;
|
|
34
|
-
inactiveLabel?: string;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export type PermissionsCollectionParams = {
|
|
41
|
-
translations?: PermissionsCollectionTranslations;
|
|
42
|
-
fields?: Field[];
|
|
43
|
-
access?: CollectionConfig["access"];
|
|
44
|
-
labels?: CollectionConfig["labels"];
|
|
45
|
-
admin?: CollectionConfig["admin"];
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type PermissionItemRef = string | number | { id?: string | number };
|
|
49
|
-
|
|
50
|
-
export type PermissionStatus = (typeof STATUS)[keyof typeof STATUS];
|
|
51
|
-
|
|
52
|
-
export type Permission = {
|
|
53
|
-
id: string | number;
|
|
54
|
-
permissionFeature?: PermissionItemRef;
|
|
55
|
-
permissionAction?: PermissionItemRef;
|
|
56
|
-
status?: PermissionStatus | null;
|
|
57
|
-
};
|