mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 07:30:20 +00:00
feat(infisical-pg): new org role routes completed
This commit is contained in:
@@ -19,7 +19,8 @@
|
||||
"migration:latest": "knex --knexfile ./src/db/knexfile.ts --client pg migrate:latest",
|
||||
"migration:rollback": "knex --knexfile ./src/db/knexfile.ts migrate:rollback",
|
||||
"seed:new": "tsx ./scripts/create-seed-file.ts",
|
||||
"seed:run": "knex --knexfile ./src/db/knexfile.ts --client pg seed:run"
|
||||
"seed:run": "knex --knexfile ./src/db/knexfile.ts --client pg seed:run",
|
||||
"db:reset": "npm run migration:rollback -- --all && npm run migration:latest && npm run seed:run"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
||||
@@ -12,7 +12,7 @@ export async function up(knex: Knex): Promise<void> {
|
||||
t.string("name").notNullable();
|
||||
t.string("description");
|
||||
t.string("slug").notNullable();
|
||||
t.json("permissions").notNullable();
|
||||
t.jsonb("permissions").notNullable();
|
||||
// does not need update trigger we will do it manually
|
||||
t.timestamps(true, true, true);
|
||||
t.uuid("orgId").notNullable();
|
||||
|
||||
@@ -17,7 +17,6 @@ export const registerOrgRoleRouter = async (server: FastifyZodProvider) => {
|
||||
name: z.string().trim(),
|
||||
description: z.string().trim().optional(),
|
||||
workspaceId: z.string().trim().optional(),
|
||||
orgId: z.string().trim(),
|
||||
permissions: z.any().array()
|
||||
}),
|
||||
response: {
|
||||
@@ -31,7 +30,7 @@ export const registerOrgRoleRouter = async (server: FastifyZodProvider) => {
|
||||
const role = await server.services.orgRole.createRole(
|
||||
req.auth.userId,
|
||||
req.params.organizationId,
|
||||
{ ...req.body, permissions: JSON.stringify(req.body.permissions) }
|
||||
req.body
|
||||
);
|
||||
return { role };
|
||||
}
|
||||
@@ -49,8 +48,6 @@ export const registerOrgRoleRouter = async (server: FastifyZodProvider) => {
|
||||
slug: z.string().trim().optional(),
|
||||
name: z.string().trim().optional(),
|
||||
description: z.string().trim().optional(),
|
||||
workspaceId: z.string().trim().optional(),
|
||||
orgId: z.string().trim(),
|
||||
permissions: z.any().array()
|
||||
}),
|
||||
response: {
|
||||
@@ -108,9 +105,11 @@ export const registerOrgRoleRouter = async (server: FastifyZodProvider) => {
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
roles: OrgRolesSchema.omit({ permissions: true })
|
||||
.merge(z.object({ permissions: z.unknown() }))
|
||||
.array()
|
||||
data: z.object({
|
||||
roles: OrgRolesSchema.omit({ permissions: true })
|
||||
.merge(z.object({ permissions: z.unknown() }))
|
||||
.array()
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
@@ -120,7 +119,7 @@ export const registerOrgRoleRouter = async (server: FastifyZodProvider) => {
|
||||
req.auth.userId,
|
||||
req.params.organizationId
|
||||
);
|
||||
return { roles };
|
||||
return { data: { roles } };
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -36,8 +36,11 @@ export const orgRoleServiceFactory = ({
|
||||
);
|
||||
const existingRole = await orgRoleDal.findOne({ slug: data.slug, orgId });
|
||||
if (existingRole) throw new BadRequestError({ name: "Create Role", message: "Duplicate role" });
|
||||
|
||||
const role = await orgRoleDal.create({ ...data, orgId });
|
||||
const role = await orgRoleDal.create({
|
||||
...data,
|
||||
orgId,
|
||||
permissions: JSON.stringify(data.permissions)
|
||||
});
|
||||
return role;
|
||||
};
|
||||
|
||||
@@ -83,8 +86,8 @@ export const orgRoleServiceFactory = ({
|
||||
const customRoles = await orgRoleDal.find({ orgId });
|
||||
const roles = [
|
||||
{
|
||||
id: "admin",
|
||||
orgId: "",
|
||||
id: "b11b49a9-09a9-4443-916a-4246f9ff2c69", // dummy userid
|
||||
orgId,
|
||||
name: "Admin",
|
||||
slug: "admin",
|
||||
description: "Complete administration access over the organization",
|
||||
@@ -93,8 +96,8 @@ export const orgRoleServiceFactory = ({
|
||||
updatedAt: new Date()
|
||||
},
|
||||
{
|
||||
id: "member",
|
||||
orgId: "",
|
||||
id: "b11b49a9-09a9-4443-916a-4246f9ff2c70", // dummy user for zod validation in response
|
||||
orgId,
|
||||
name: "Member",
|
||||
slug: "member",
|
||||
description: "Non-administrative role in an organization",
|
||||
|
||||
Reference in New Issue
Block a user