@tanglemedia/directus-core-settings 0.0.8 → 0.0.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.
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createPermission } from "./helpers/permission.mjs";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export async function up(knex) {
|
|
5
|
+
await createPermission(knex, "directus_folders", "Staff", ["create", "read", "update", "delete", "share"]);
|
|
6
|
+
await createPermission(knex, "directus_dashboards", "Staff", ["read"]);
|
|
7
|
+
await createPermission(knex, "directus_panels", "Staff", ["read"]);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function down(knex) {}
|
package/migrations/20260617S-tngl_directus_core-~-give-staff-permission-to-edit-own-profile_info.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createPermission } from "./helpers/permission.mjs";
|
|
2
|
+
import { getPolicyID } from "./helpers/policy.mjs";
|
|
3
|
+
|
|
4
|
+
export async function up(knex) {
|
|
5
|
+
// allow staff user to edit the following fields in their own profile
|
|
6
|
+
await createPermission(knex, "directus_users", "Staff", ["update"]);
|
|
7
|
+
const policy = await getPolicyID(knex, "Staff");
|
|
8
|
+
|
|
9
|
+
const fieldsToAllow = [
|
|
10
|
+
"first_name",
|
|
11
|
+
"last_name",
|
|
12
|
+
"password",
|
|
13
|
+
"avatar",
|
|
14
|
+
"location",
|
|
15
|
+
"title",
|
|
16
|
+
"description",
|
|
17
|
+
"tags",
|
|
18
|
+
];
|
|
19
|
+
const permission = { _and: [{ id: { _eq: "$CURRENT_USER" } }] };
|
|
20
|
+
|
|
21
|
+
const permissionExists = await knex("directus_permissions").where({
|
|
22
|
+
collection: "directus_users",
|
|
23
|
+
action: "update",
|
|
24
|
+
policy: policy,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
for (const existing of permissionExists) {
|
|
28
|
+
await knex("directus_permissions")
|
|
29
|
+
.where({ id: existing.id })
|
|
30
|
+
.update({
|
|
31
|
+
fields: fieldsToAllow.join(","),
|
|
32
|
+
permissions: JSON.stringify(permission),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function down(knex) {}
|
|
@@ -43,3 +43,18 @@ export async function createPermission(knex, collectionName, policyName, actions
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
|
|
47
|
+
export async function removePermission(knex, collectionName, policyName, actions) {
|
|
48
|
+
const policy = await getPolicyID(knex, policyName);
|
|
49
|
+
|
|
50
|
+
for (const action of actions) {
|
|
51
|
+
await knex("directus_permissions")
|
|
52
|
+
.where({
|
|
53
|
+
collection: collectionName,
|
|
54
|
+
action: action,
|
|
55
|
+
policy: policy,
|
|
56
|
+
})
|
|
57
|
+
.del();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|