Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+4
-39
@@ -1,10 +1,9 @@
|
||||
import { db } from "../../db.server";
|
||||
import { Entity, Permission, Role, RolePermission } from "@toolctrl/db/prisma-browser";
|
||||
import { getAllRolesNames, getRoleByName } from "./roles.db.server";
|
||||
import { Permission, Role, RolePermission } from "@hivegrid/db/prisma-browser";
|
||||
import { getRoleByName } from "./roles.db.server";
|
||||
import { createRolePermission, getAllRolePermissions } from "./rolePermissions.db.server";
|
||||
import RowFiltersHelper from "~/utils/helpers/RowFiltersHelper";
|
||||
import { FiltersDto } from "~/application/dtos/data/FiltersDto";
|
||||
import { getEntityPermissions } from "~/utils/helpers/PermissionsHelper";
|
||||
import { cachified, clearCacheKey } from "~/utils/cache.server";
|
||||
import { createScopedLogger } from "~/utils/logger.server";
|
||||
|
||||
@@ -45,7 +44,6 @@ export async function getAllPermissions(type?: string, filters?: FiltersDto): Pr
|
||||
orderBy: [{ type: "asc" }, { name: "asc" }],
|
||||
});
|
||||
}
|
||||
|
||||
export async function getAllPermissionsIdsAndNames(): Promise<{ id: string; name: string }[]> {
|
||||
return await db.permission.findMany({
|
||||
select: { id: true, name: true },
|
||||
@@ -134,7 +132,7 @@ export async function getNextPermissionsOrder(type?: string): Promise<number> {
|
||||
}
|
||||
|
||||
export async function createPermissions(
|
||||
permissions: { inRoles: string[]; name: string; description: string; type: string; entityId?: string | null }[],
|
||||
permissions: { inRoles: string[]; name: string; description: string; type: string }[],
|
||||
fromOrder: number = 0
|
||||
) {
|
||||
const allRolePermissions = await getAllRolePermissions();
|
||||
@@ -155,7 +153,6 @@ export async function createPermissions(
|
||||
description: data.description,
|
||||
type: data.type,
|
||||
isDefault: true,
|
||||
entityId: data.entityId ?? null,
|
||||
}));
|
||||
createdPermissionNames.add(permission.name);
|
||||
if (existing) {
|
||||
@@ -184,7 +181,7 @@ export async function createPermissions(
|
||||
}
|
||||
}
|
||||
|
||||
export async function createPermission(data: { order: number; name: string; description: string; type: string; isDefault: boolean; entityId: string | null }) {
|
||||
export async function createPermission(data: { order: number; name: string; description: string; type: string; isDefault: boolean }) {
|
||||
return await db.permission.create({
|
||||
data,
|
||||
});
|
||||
@@ -220,35 +217,3 @@ export async function deletePermission(id: string) {
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteEntityPermissions(entity: Entity) {
|
||||
const entityPermissions = await getEntityPermissions(entity);
|
||||
const names = entityPermissions.map((p) => p.name);
|
||||
if (names.length > 0) {
|
||||
return await db.permission.deleteMany({
|
||||
where: {
|
||||
name: {
|
||||
in: names,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function createEntityPermissions(entity: Entity) {
|
||||
const allUserRoles = await getAllRolesNames();
|
||||
// const assignToAllUserRoles = allUserRoles.filter((f) => f.assignToNewUsers);
|
||||
const entityPermissions = await getEntityPermissions(entity);
|
||||
await Promise.all(
|
||||
entityPermissions.map(async (permission, idx) => {
|
||||
const entityPermission = {
|
||||
inRoles: allUserRoles.map((f) => f.name),
|
||||
name: permission.name,
|
||||
description: permission.description,
|
||||
type: "app",
|
||||
entityId: entity.id,
|
||||
};
|
||||
return await createPermissions([entityPermission], allUserRoles.length + idx);
|
||||
})
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user