Merge remote-tracking branch 'origin' into feature/est-simpleenroll
@@ -34,9 +34,9 @@
|
|||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"dev": "tsx watch --clear-screen=false ./src/main.ts | pino-pretty --colorize --colorizeObjects --singleLine",
|
"dev": "tsx watch --clear-screen=false ./src/main.ts | pino-pretty --colorize --colorizeObjects --singleLine",
|
||||||
"dev:docker": "nodemon",
|
"dev:docker": "nodemon",
|
||||||
"build": "tsup",
|
"build": "tsup --sourcemap",
|
||||||
"build:frontend": "npm run build --prefix ../frontend",
|
"build:frontend": "npm run build --prefix ../frontend",
|
||||||
"start": "node dist/main.mjs",
|
"start": "node --enable-source-maps dist/main.mjs",
|
||||||
"type:check": "tsc --noEmit",
|
"type:check": "tsc --noEmit",
|
||||||
"lint:fix": "eslint --fix --ext js,ts ./src",
|
"lint:fix": "eslint --fix --ext js,ts ./src",
|
||||||
"lint": "eslint 'src/**/*.ts'",
|
"lint": "eslint 'src/**/*.ts'",
|
||||||
|
|||||||
@@ -0,0 +1,294 @@
|
|||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
import { TableName } from "../schemas";
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
// ---------- ACCESS APPROVAL POLICY APPROVER ------------
|
||||||
|
const hasApproverUserId = await knex.schema.hasColumn(TableName.AccessApprovalPolicyApprover, "approverUserId");
|
||||||
|
const hasApproverId = await knex.schema.hasColumn(TableName.AccessApprovalPolicyApprover, "approverId");
|
||||||
|
|
||||||
|
if (!hasApproverUserId) {
|
||||||
|
// add the new fields
|
||||||
|
await knex.schema.alterTable(TableName.AccessApprovalPolicyApprover, (tb) => {
|
||||||
|
// if (hasApproverId) tb.setNullable("approverId");
|
||||||
|
tb.uuid("approverUserId");
|
||||||
|
tb.foreign("approverUserId").references("id").inTable(TableName.Users).onDelete("CASCADE");
|
||||||
|
});
|
||||||
|
|
||||||
|
// convert project membership id => user id
|
||||||
|
await knex(TableName.AccessApprovalPolicyApprover).update({
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// @ts-ignore because generate schema happens after this
|
||||||
|
approverUserId: knex(TableName.ProjectMembership)
|
||||||
|
.select("userId")
|
||||||
|
.where("id", knex.raw("??", [`${TableName.AccessApprovalPolicyApprover}.approverId`]))
|
||||||
|
});
|
||||||
|
// drop the old field
|
||||||
|
await knex.schema.alterTable(TableName.AccessApprovalPolicyApprover, (tb) => {
|
||||||
|
if (hasApproverId) tb.dropColumn("approverId");
|
||||||
|
tb.uuid("approverUserId").notNullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- ACCESS APPROVAL REQUEST ------------
|
||||||
|
const hasAccessApprovalRequestTable = await knex.schema.hasTable(TableName.AccessApprovalRequest);
|
||||||
|
const hasRequestedByUserId = await knex.schema.hasColumn(TableName.AccessApprovalRequest, "requestedByUserId");
|
||||||
|
const hasRequestedBy = await knex.schema.hasColumn(TableName.AccessApprovalRequest, "requestedBy");
|
||||||
|
|
||||||
|
if (hasAccessApprovalRequestTable) {
|
||||||
|
// new fields
|
||||||
|
await knex.schema.alterTable(TableName.AccessApprovalRequest, (tb) => {
|
||||||
|
if (!hasRequestedByUserId) {
|
||||||
|
tb.uuid("requestedByUserId");
|
||||||
|
tb.foreign("requestedByUserId").references("id").inTable(TableName.Users).onDelete("SET NULL");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// copy the assigned project membership => user id to new fields
|
||||||
|
await knex(TableName.AccessApprovalRequest).update({
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// @ts-ignore because generate schema happens after this
|
||||||
|
requestedByUserId: knex(TableName.ProjectMembership)
|
||||||
|
.select("userId")
|
||||||
|
.where("id", knex.raw("??", [`${TableName.AccessApprovalRequest}.requestedBy`]))
|
||||||
|
});
|
||||||
|
// drop old fields
|
||||||
|
await knex.schema.alterTable(TableName.AccessApprovalRequest, (tb) => {
|
||||||
|
if (hasRequestedBy) {
|
||||||
|
// DROP AT A LATER TIME
|
||||||
|
// tb.dropColumn("requestedBy");
|
||||||
|
|
||||||
|
// ADD ALLOW NULLABLE FOR NOW
|
||||||
|
tb.uuid("requestedBy").nullable().alter();
|
||||||
|
}
|
||||||
|
tb.uuid("requestedByUserId").notNullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- ACCESS APPROVAL REQUEST REVIEWER ------------
|
||||||
|
const hasMemberId = await knex.schema.hasColumn(TableName.AccessApprovalRequestReviewer, "member");
|
||||||
|
const hasReviewerUserId = await knex.schema.hasColumn(TableName.AccessApprovalRequestReviewer, "reviewerUserId");
|
||||||
|
if (!hasReviewerUserId) {
|
||||||
|
// new fields
|
||||||
|
await knex.schema.alterTable(TableName.AccessApprovalRequestReviewer, (tb) => {
|
||||||
|
// if (hasMemberId) tb.setNullable("member");
|
||||||
|
tb.uuid("reviewerUserId");
|
||||||
|
tb.foreign("reviewerUserId").references("id").inTable(TableName.Users).onDelete("SET NULL");
|
||||||
|
});
|
||||||
|
// copy project membership => user id to new fields
|
||||||
|
await knex(TableName.AccessApprovalRequestReviewer).update({
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// @ts-ignore because generate schema happens after this
|
||||||
|
reviewerUserId: knex(TableName.ProjectMembership)
|
||||||
|
.select("userId")
|
||||||
|
.where("id", knex.raw("??", [`${TableName.AccessApprovalRequestReviewer}.member`]))
|
||||||
|
});
|
||||||
|
// drop table
|
||||||
|
await knex.schema.alterTable(TableName.AccessApprovalRequestReviewer, (tb) => {
|
||||||
|
if (hasMemberId) {
|
||||||
|
// DROP AT A LATER TIME
|
||||||
|
// tb.dropColumn("member");
|
||||||
|
|
||||||
|
// ADD ALLOW NULLABLE FOR NOW
|
||||||
|
tb.uuid("member").nullable().alter();
|
||||||
|
}
|
||||||
|
tb.uuid("reviewerUserId").notNullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- PROJECT USER ADDITIONAL PRIVILEGE ------------
|
||||||
|
const projectUserAdditionalPrivilegeHasProjectMembershipId = await knex.schema.hasColumn(
|
||||||
|
TableName.ProjectUserAdditionalPrivilege,
|
||||||
|
"projectMembershipId"
|
||||||
|
);
|
||||||
|
|
||||||
|
const projectUserAdditionalPrivilegeHasUserId = await knex.schema.hasColumn(
|
||||||
|
TableName.ProjectUserAdditionalPrivilege,
|
||||||
|
"userId"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!projectUserAdditionalPrivilegeHasUserId) {
|
||||||
|
await knex.schema.alterTable(TableName.ProjectUserAdditionalPrivilege, (tb) => {
|
||||||
|
tb.uuid("userId");
|
||||||
|
tb.foreign("userId").references("id").inTable(TableName.Users).onDelete("CASCADE");
|
||||||
|
|
||||||
|
tb.string("projectId");
|
||||||
|
tb.foreign("projectId").references("id").inTable(TableName.Project).onDelete("CASCADE");
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex(TableName.ProjectUserAdditionalPrivilege)
|
||||||
|
.update({
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// @ts-ignore because generate schema happens after this
|
||||||
|
userId: knex(TableName.ProjectMembership)
|
||||||
|
.select("userId")
|
||||||
|
.where("id", knex.raw("??", [`${TableName.ProjectUserAdditionalPrivilege}.projectMembershipId`])),
|
||||||
|
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// @ts-ignore because generate schema happens after this
|
||||||
|
projectId: knex(TableName.ProjectMembership)
|
||||||
|
.select("projectId")
|
||||||
|
.where("id", knex.raw("??", [`${TableName.ProjectUserAdditionalPrivilege}.projectMembershipId`]))
|
||||||
|
})
|
||||||
|
.whereNotNull("projectMembershipId");
|
||||||
|
|
||||||
|
await knex.schema.alterTable(TableName.ProjectUserAdditionalPrivilege, (tb) => {
|
||||||
|
tb.uuid("userId").notNullable().alter();
|
||||||
|
tb.string("projectId").notNullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (projectUserAdditionalPrivilegeHasProjectMembershipId) {
|
||||||
|
await knex.schema.alterTable(TableName.ProjectUserAdditionalPrivilege, (tb) => {
|
||||||
|
// DROP AT A LATER TIME
|
||||||
|
// tb.dropColumn("projectMembershipId");
|
||||||
|
|
||||||
|
// ADD ALLOW NULLABLE FOR NOW
|
||||||
|
tb.uuid("projectMembershipId").nullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
// We remove project user additional privileges first, because it may delete records in the database where the project membership is not found.
|
||||||
|
// The project membership won't be found on records created by group members. In those cades we just delete the record and continue.
|
||||||
|
// When the additionl privilege record is deleted, it will cascade delete the access request created by the group member.
|
||||||
|
|
||||||
|
// ---------- PROJECT USER ADDITIONAL PRIVILEGE ------------
|
||||||
|
const hasUserId = await knex.schema.hasColumn(TableName.ProjectUserAdditionalPrivilege, "userId");
|
||||||
|
const hasProjectMembershipId = await knex.schema.hasColumn(
|
||||||
|
TableName.ProjectUserAdditionalPrivilege,
|
||||||
|
"projectMembershipId"
|
||||||
|
);
|
||||||
|
|
||||||
|
// If it doesn't have the userId field, then the up migration has not run
|
||||||
|
if (!hasUserId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await knex.schema.alterTable(TableName.ProjectUserAdditionalPrivilege, (tb) => {
|
||||||
|
if (!hasProjectMembershipId) {
|
||||||
|
tb.uuid("projectMembershipId");
|
||||||
|
tb.foreign("projectMembershipId").references("id").inTable(TableName.ProjectMembership).onDelete("CASCADE");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!hasProjectMembershipId) {
|
||||||
|
// First, update records where a matching project membership exists
|
||||||
|
await knex(TableName.ProjectUserAdditionalPrivilege).update({
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// @ts-ignore because generate schema happens after this
|
||||||
|
projectMembershipId: knex(TableName.ProjectMembership)
|
||||||
|
.select("id")
|
||||||
|
.where("userId", knex.raw("??", [`${TableName.ProjectUserAdditionalPrivilege}.userId`]))
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex(TableName.AccessApprovalRequest).update({
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// @ts-ignore because generate schema happens after this
|
||||||
|
projectMembershipId: knex(TableName.ProjectMembership)
|
||||||
|
.select("id")
|
||||||
|
.where("userId", knex.raw("??", [`${TableName.SecretApprovalRequest}.userId`]))
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex.schema.alterTable(TableName.ProjectUserAdditionalPrivilege, (tb) => {
|
||||||
|
tb.dropColumn("userId");
|
||||||
|
tb.dropColumn("projectId");
|
||||||
|
|
||||||
|
tb.uuid("projectMembershipId").notNullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then, delete records where no matching project membership was found
|
||||||
|
await knex(TableName.ProjectUserAdditionalPrivilege).whereNull("projectMembershipId").delete();
|
||||||
|
await knex(TableName.AccessApprovalRequest).whereNull("requestedBy").delete();
|
||||||
|
|
||||||
|
// ---------- ACCESS APPROVAL POLICY APPROVER ------------
|
||||||
|
const hasApproverUserId = await knex.schema.hasColumn(TableName.AccessApprovalPolicyApprover, "approverUserId");
|
||||||
|
const hasApproverId = await knex.schema.hasColumn(TableName.AccessApprovalPolicyApprover, "approverId");
|
||||||
|
|
||||||
|
if (hasApproverUserId) {
|
||||||
|
await knex.schema.alterTable(TableName.AccessApprovalPolicyApprover, (tb) => {
|
||||||
|
if (!hasApproverId) {
|
||||||
|
tb.uuid("approverId");
|
||||||
|
tb.foreign("approverId").references("id").inTable(TableName.ProjectMembership).onDelete("CASCADE");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!hasApproverId) {
|
||||||
|
await knex(TableName.AccessApprovalPolicyApprover).update({
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// @ts-ignore because generate schema happens after this
|
||||||
|
approverId: knex(TableName.ProjectMembership)
|
||||||
|
.select("id")
|
||||||
|
.where("userId", knex.raw("??", [`${TableName.AccessApprovalPolicyApprover}.approverUserId`]))
|
||||||
|
});
|
||||||
|
await knex.schema.alterTable(TableName.AccessApprovalPolicyApprover, (tb) => {
|
||||||
|
tb.dropColumn("approverUserId");
|
||||||
|
|
||||||
|
tb.uuid("approverId").notNullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- ACCESS APPROVAL REQUEST ------------
|
||||||
|
const hasAccessApprovalRequestTable = await knex.schema.hasTable(TableName.AccessApprovalRequest);
|
||||||
|
const hasRequestedByUserId = await knex.schema.hasColumn(TableName.AccessApprovalRequest, "requestedByUserId");
|
||||||
|
const hasRequestedBy = await knex.schema.hasColumn(TableName.AccessApprovalRequest, "requestedBy");
|
||||||
|
|
||||||
|
if (hasAccessApprovalRequestTable) {
|
||||||
|
await knex.schema.alterTable(TableName.AccessApprovalRequest, (tb) => {
|
||||||
|
if (!hasRequestedBy) {
|
||||||
|
tb.uuid("requestedBy");
|
||||||
|
tb.foreign("requestedBy").references("id").inTable(TableName.ProjectMembership).onDelete("CASCADE");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Try to find a project membership based on the AccessApprovalRequest.requestedByUserId and AccessApprovalRequest.policyId(reference to AccessApprovalRequestPolicy).envId(reference to Environment).projectId(reference to Project)
|
||||||
|
// If a project membership is found, set the AccessApprovalRequest.requestedBy to the project membership id
|
||||||
|
// If a project membership is not found, remove the AccessApprovalRequest record
|
||||||
|
|
||||||
|
await knex(TableName.AccessApprovalRequest).update({
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// @ts-ignore because generate schema happens after this
|
||||||
|
requestedBy: knex(TableName.ProjectMembership)
|
||||||
|
.select("id")
|
||||||
|
.where("userId", knex.raw("??", [`${TableName.AccessApprovalRequest}.requestedByUserId`]))
|
||||||
|
});
|
||||||
|
|
||||||
|
// Then, delete records where no matching project membership was found
|
||||||
|
await knex(TableName.AccessApprovalRequest).whereNull("requestedBy").delete();
|
||||||
|
|
||||||
|
await knex.schema.alterTable(TableName.AccessApprovalRequest, (tb) => {
|
||||||
|
if (hasRequestedByUserId) {
|
||||||
|
tb.dropColumn("requestedByUserId");
|
||||||
|
}
|
||||||
|
if (hasRequestedBy) tb.uuid("requestedBy").notNullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- ACCESS APPROVAL REQUEST REVIEWER ------------
|
||||||
|
const hasMemberId = await knex.schema.hasColumn(TableName.AccessApprovalRequestReviewer, "member");
|
||||||
|
const hasReviewerUserId = await knex.schema.hasColumn(TableName.AccessApprovalRequestReviewer, "reviewerUserId");
|
||||||
|
|
||||||
|
if (hasReviewerUserId) {
|
||||||
|
if (!hasMemberId) {
|
||||||
|
await knex.schema.alterTable(TableName.AccessApprovalRequestReviewer, (tb) => {
|
||||||
|
tb.uuid("member");
|
||||||
|
tb.foreign("member").references("id").inTable(TableName.ProjectMembership).onDelete("CASCADE");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await knex(TableName.AccessApprovalRequestReviewer).update({
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// @ts-ignore because generate schema happens after this
|
||||||
|
member: knex(TableName.ProjectMembership)
|
||||||
|
.select("id")
|
||||||
|
.where("userId", knex.raw("??", [`${TableName.AccessApprovalRequestReviewer}.reviewerUserId`]))
|
||||||
|
});
|
||||||
|
await knex.schema.alterTable(TableName.AccessApprovalRequestReviewer, (tb) => {
|
||||||
|
tb.dropColumn("reviewerUserId");
|
||||||
|
|
||||||
|
tb.uuid("member").notNullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,10 +9,10 @@ import { TImmutableDBKeys } from "./models";
|
|||||||
|
|
||||||
export const AccessApprovalPoliciesApproversSchema = z.object({
|
export const AccessApprovalPoliciesApproversSchema = z.object({
|
||||||
id: z.string().uuid(),
|
id: z.string().uuid(),
|
||||||
approverId: z.string().uuid(),
|
|
||||||
policyId: z.string().uuid(),
|
policyId: z.string().uuid(),
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date()
|
updatedAt: z.date(),
|
||||||
|
approverUserId: z.string().uuid()
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TAccessApprovalPoliciesApprovers = z.infer<typeof AccessApprovalPoliciesApproversSchema>;
|
export type TAccessApprovalPoliciesApprovers = z.infer<typeof AccessApprovalPoliciesApproversSchema>;
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import { TImmutableDBKeys } from "./models";
|
|||||||
|
|
||||||
export const AccessApprovalRequestsReviewersSchema = z.object({
|
export const AccessApprovalRequestsReviewersSchema = z.object({
|
||||||
id: z.string().uuid(),
|
id: z.string().uuid(),
|
||||||
member: z.string().uuid(),
|
|
||||||
status: z.string(),
|
status: z.string(),
|
||||||
requestId: z.string().uuid(),
|
requestId: z.string().uuid(),
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date()
|
updatedAt: z.date(),
|
||||||
|
reviewerUserId: z.string().uuid()
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TAccessApprovalRequestsReviewers = z.infer<typeof AccessApprovalRequestsReviewersSchema>;
|
export type TAccessApprovalRequestsReviewers = z.infer<typeof AccessApprovalRequestsReviewersSchema>;
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ export const AccessApprovalRequestsSchema = z.object({
|
|||||||
id: z.string().uuid(),
|
id: z.string().uuid(),
|
||||||
policyId: z.string().uuid(),
|
policyId: z.string().uuid(),
|
||||||
privilegeId: z.string().uuid().nullable().optional(),
|
privilegeId: z.string().uuid().nullable().optional(),
|
||||||
requestedBy: z.string().uuid(),
|
|
||||||
isTemporary: z.boolean(),
|
isTemporary: z.boolean(),
|
||||||
temporaryRange: z.string().nullable().optional(),
|
temporaryRange: z.string().nullable().optional(),
|
||||||
permissions: z.unknown(),
|
permissions: z.unknown(),
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date()
|
updatedAt: z.date(),
|
||||||
|
requestedByUserId: z.string().uuid()
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TAccessApprovalRequests = z.infer<typeof AccessApprovalRequestsSchema>;
|
export type TAccessApprovalRequests = z.infer<typeof AccessApprovalRequestsSchema>;
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import { TImmutableDBKeys } from "./models";
|
|||||||
export const ProjectUserAdditionalPrivilegeSchema = z.object({
|
export const ProjectUserAdditionalPrivilegeSchema = z.object({
|
||||||
id: z.string().uuid(),
|
id: z.string().uuid(),
|
||||||
slug: z.string(),
|
slug: z.string(),
|
||||||
projectMembershipId: z.string().uuid(),
|
|
||||||
isTemporary: z.boolean().default(false),
|
isTemporary: z.boolean().default(false),
|
||||||
temporaryMode: z.string().nullable().optional(),
|
temporaryMode: z.string().nullable().optional(),
|
||||||
temporaryRange: z.string().nullable().optional(),
|
temporaryRange: z.string().nullable().optional(),
|
||||||
@@ -18,7 +17,9 @@ export const ProjectUserAdditionalPrivilegeSchema = z.object({
|
|||||||
temporaryAccessEndTime: z.date().nullable().optional(),
|
temporaryAccessEndTime: z.date().nullable().optional(),
|
||||||
permissions: z.unknown(),
|
permissions: z.unknown(),
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date()
|
updatedAt: z.date(),
|
||||||
|
userId: z.string().uuid(),
|
||||||
|
projectId: z.string()
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TProjectUserAdditionalPrivilege = z.infer<typeof ProjectUserAdditionalPrivilegeSchema>;
|
export type TProjectUserAdditionalPrivilege = z.infer<typeof ProjectUserAdditionalPrivilegeSchema>;
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ export const registerAccessApprovalPolicyRouter = async (server: FastifyZodProvi
|
|||||||
name: z.string().optional(),
|
name: z.string().optional(),
|
||||||
secretPath: z.string().trim().default("/"),
|
secretPath: z.string().trim().default("/"),
|
||||||
environment: z.string(),
|
environment: z.string(),
|
||||||
approvers: z.string().array().min(1),
|
approverUserIds: z.string().array().min(1),
|
||||||
approvals: z.number().min(1).default(1),
|
approvals: z.number().min(1).default(1),
|
||||||
enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard)
|
enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard)
|
||||||
})
|
})
|
||||||
.refine((data) => data.approvals <= data.approvers.length, {
|
.refine((data) => data.approvals <= data.approverUserIds.length, {
|
||||||
path: ["approvals"],
|
path: ["approvals"],
|
||||||
message: "The number of approvals should be lower than the number of approvers."
|
message: "The number of approvals should be lower than the number of approvers."
|
||||||
}),
|
}),
|
||||||
@@ -56,7 +56,16 @@ export const registerAccessApprovalPolicyRouter = async (server: FastifyZodProvi
|
|||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
approvals: sapPubSchema.extend({ approvers: z.string().array(), secretPath: z.string().optional() }).array()
|
approvals: sapPubSchema
|
||||||
|
.extend({
|
||||||
|
userApprovers: z
|
||||||
|
.object({
|
||||||
|
userId: z.string()
|
||||||
|
})
|
||||||
|
.array(),
|
||||||
|
secretPath: z.string().optional().nullable()
|
||||||
|
})
|
||||||
|
.array()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -69,6 +78,7 @@ export const registerAccessApprovalPolicyRouter = async (server: FastifyZodProvi
|
|||||||
actorOrgId: req.permission.orgId,
|
actorOrgId: req.permission.orgId,
|
||||||
projectSlug: req.query.projectSlug
|
projectSlug: req.query.projectSlug
|
||||||
});
|
});
|
||||||
|
|
||||||
return { approvals };
|
return { approvals };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -117,11 +127,11 @@ export const registerAccessApprovalPolicyRouter = async (server: FastifyZodProvi
|
|||||||
.trim()
|
.trim()
|
||||||
.optional()
|
.optional()
|
||||||
.transform((val) => (val === "" ? "/" : val)),
|
.transform((val) => (val === "" ? "/" : val)),
|
||||||
approvers: z.string().array().min(1),
|
approverUserIds: z.string().array().min(1),
|
||||||
approvals: z.number().min(1).default(1),
|
approvals: z.number().min(1).default(1),
|
||||||
enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard)
|
enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard)
|
||||||
})
|
})
|
||||||
.refine((data) => data.approvals <= data.approvers.length, {
|
.refine((data) => data.approvals <= data.approverUserIds.length, {
|
||||||
path: ["approvals"],
|
path: ["approvals"],
|
||||||
message: "The number of approvals should be lower than the number of approvers."
|
message: "The number of approvals should be lower than the number of approvers."
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { AccessApprovalRequestsReviewersSchema, AccessApprovalRequestsSchema } from "@app/db/schemas";
|
import { AccessApprovalRequestsReviewersSchema, AccessApprovalRequestsSchema, UsersSchema } from "@app/db/schemas";
|
||||||
import { ApprovalStatus } from "@app/ee/services/access-approval-request/access-approval-request-types";
|
import { ApprovalStatus } from "@app/ee/services/access-approval-request/access-approval-request-types";
|
||||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
|
|
||||||
|
const approvalRequestUser = z.object({ userId: z.string() }).merge(
|
||||||
|
UsersSchema.pick({
|
||||||
|
email: true,
|
||||||
|
firstName: true,
|
||||||
|
lastName: true,
|
||||||
|
username: true
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
export const registerAccessApprovalRequestRouter = async (server: FastifyZodProvider) => {
|
export const registerAccessApprovalRequestRouter = async (server: FastifyZodProvider) => {
|
||||||
server.route({
|
server.route({
|
||||||
url: "/",
|
url: "/",
|
||||||
@@ -104,10 +113,11 @@ export const registerAccessApprovalRequestRouter = async (server: FastifyZodProv
|
|||||||
}),
|
}),
|
||||||
reviewers: z
|
reviewers: z
|
||||||
.object({
|
.object({
|
||||||
member: z.string(),
|
userId: z.string(),
|
||||||
status: z.string()
|
status: z.string()
|
||||||
})
|
})
|
||||||
.array()
|
.array(),
|
||||||
|
requestedByUser: approvalRequestUser
|
||||||
}).array()
|
}).array()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { Knex } from "knex";
|
import { Knex } from "knex";
|
||||||
|
|
||||||
import { TDbClient } from "@app/db";
|
import { TDbClient } from "@app/db";
|
||||||
import { TableName, TAccessApprovalPolicies } from "@app/db/schemas";
|
import { AccessApprovalPoliciesSchema, TableName, TAccessApprovalPolicies } from "@app/db/schemas";
|
||||||
import { DatabaseError } from "@app/lib/errors";
|
import { DatabaseError } from "@app/lib/errors";
|
||||||
import { buildFindFilter, mergeOneToManyRelation, ormify, selectAllTableCols, TFindFilter } from "@app/lib/knex";
|
import { buildFindFilter, ormify, selectAllTableCols, sqlNestRelationships, TFindFilter } from "@app/lib/knex";
|
||||||
|
|
||||||
export type TAccessApprovalPolicyDALFactory = ReturnType<typeof accessApprovalPolicyDALFactory>;
|
export type TAccessApprovalPolicyDALFactory = ReturnType<typeof accessApprovalPolicyDALFactory>;
|
||||||
|
|
||||||
@@ -15,12 +15,12 @@ export const accessApprovalPolicyDALFactory = (db: TDbClient) => {
|
|||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
.where(buildFindFilter(filter))
|
.where(buildFindFilter(filter))
|
||||||
.join(TableName.Environment, `${TableName.AccessApprovalPolicy}.envId`, `${TableName.Environment}.id`)
|
.join(TableName.Environment, `${TableName.AccessApprovalPolicy}.envId`, `${TableName.Environment}.id`)
|
||||||
.join(
|
.leftJoin(
|
||||||
TableName.AccessApprovalPolicyApprover,
|
TableName.AccessApprovalPolicyApprover,
|
||||||
`${TableName.AccessApprovalPolicy}.id`,
|
`${TableName.AccessApprovalPolicy}.id`,
|
||||||
`${TableName.AccessApprovalPolicyApprover}.policyId`
|
`${TableName.AccessApprovalPolicyApprover}.policyId`
|
||||||
)
|
)
|
||||||
.select(tx.ref("approverId").withSchema(TableName.AccessApprovalPolicyApprover))
|
.select(tx.ref("approverUserId").withSchema(TableName.AccessApprovalPolicyApprover))
|
||||||
.select(tx.ref("name").withSchema(TableName.Environment).as("envName"))
|
.select(tx.ref("name").withSchema(TableName.Environment).as("envName"))
|
||||||
.select(tx.ref("slug").withSchema(TableName.Environment).as("envSlug"))
|
.select(tx.ref("slug").withSchema(TableName.Environment).as("envSlug"))
|
||||||
.select(tx.ref("id").withSchema(TableName.Environment).as("envId"))
|
.select(tx.ref("id").withSchema(TableName.Environment).as("envId"))
|
||||||
@@ -35,18 +35,30 @@ export const accessApprovalPolicyDALFactory = (db: TDbClient) => {
|
|||||||
const doc = await accessApprovalPolicyFindQuery(tx || db.replicaNode(), {
|
const doc = await accessApprovalPolicyFindQuery(tx || db.replicaNode(), {
|
||||||
[`${TableName.AccessApprovalPolicy}.id` as "id"]: id
|
[`${TableName.AccessApprovalPolicy}.id` as "id"]: id
|
||||||
});
|
});
|
||||||
const formatedDoc = mergeOneToManyRelation(
|
const formattedDoc = sqlNestRelationships({
|
||||||
doc,
|
data: doc,
|
||||||
"id",
|
key: "id",
|
||||||
({ approverId, envId, envName: name, envSlug: slug, ...el }) => ({
|
parentMapper: (data) => ({
|
||||||
...el,
|
environment: {
|
||||||
envId,
|
id: data.envId,
|
||||||
environment: { id: envId, name, slug }
|
name: data.envName,
|
||||||
|
slug: data.envSlug
|
||||||
|
},
|
||||||
|
projectId: data.projectId,
|
||||||
|
...AccessApprovalPoliciesSchema.parse(data)
|
||||||
}),
|
}),
|
||||||
({ approverId }) => approverId,
|
childrenMapper: [
|
||||||
"approvers"
|
{
|
||||||
);
|
key: "approverUserId",
|
||||||
return formatedDoc?.[0];
|
label: "userApprovers" as const,
|
||||||
|
mapper: ({ approverUserId }) => ({
|
||||||
|
userId: approverUserId
|
||||||
|
})
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
return formattedDoc?.[0];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ error, name: "FindById" });
|
throw new DatabaseError({ error, name: "FindById" });
|
||||||
}
|
}
|
||||||
@@ -55,18 +67,32 @@ export const accessApprovalPolicyDALFactory = (db: TDbClient) => {
|
|||||||
const find = async (filter: TFindFilter<TAccessApprovalPolicies & { projectId: string }>, tx?: Knex) => {
|
const find = async (filter: TFindFilter<TAccessApprovalPolicies & { projectId: string }>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await accessApprovalPolicyFindQuery(tx || db.replicaNode(), filter);
|
const docs = await accessApprovalPolicyFindQuery(tx || db.replicaNode(), filter);
|
||||||
const formatedDoc = mergeOneToManyRelation(
|
|
||||||
docs,
|
const formattedDocs = sqlNestRelationships({
|
||||||
"id",
|
data: docs,
|
||||||
({ approverId, envId, envName: name, envSlug: slug, ...el }) => ({
|
key: "id",
|
||||||
...el,
|
parentMapper: (data) => ({
|
||||||
envId,
|
environment: {
|
||||||
environment: { id: envId, name, slug }
|
id: data.envId,
|
||||||
|
name: data.envName,
|
||||||
|
slug: data.envSlug
|
||||||
|
},
|
||||||
|
projectId: data.projectId,
|
||||||
|
...AccessApprovalPoliciesSchema.parse(data)
|
||||||
|
// secretPath: data.secretPath || undefined,
|
||||||
}),
|
}),
|
||||||
({ approverId }) => approverId,
|
childrenMapper: [
|
||||||
"approvers"
|
{
|
||||||
);
|
key: "approverUserId",
|
||||||
return formatedDoc.map((policy) => ({ ...policy, secretPath: policy.secretPath || undefined }));
|
label: "userApprovers" as const,
|
||||||
|
mapper: ({ approverUserId }) => ({
|
||||||
|
userId: approverUserId
|
||||||
|
})
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
return formattedDocs;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ error, name: "Find" });
|
throw new DatabaseError({ error, name: "Find" });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,7 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
accessApprovalPolicyApproverDAL,
|
accessApprovalPolicyApproverDAL,
|
||||||
permissionService,
|
permissionService,
|
||||||
projectEnvDAL,
|
projectEnvDAL,
|
||||||
projectDAL,
|
projectDAL
|
||||||
projectMembershipDAL
|
|
||||||
}: TSecretApprovalPolicyServiceFactoryDep) => {
|
}: TSecretApprovalPolicyServiceFactoryDep) => {
|
||||||
const createAccessApprovalPolicy = async ({
|
const createAccessApprovalPolicy = async ({
|
||||||
name,
|
name,
|
||||||
@@ -45,7 +44,7 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
secretPath,
|
secretPath,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
approvals,
|
approvals,
|
||||||
approvers,
|
approverUserIds,
|
||||||
projectSlug,
|
projectSlug,
|
||||||
environment,
|
environment,
|
||||||
enforcementLevel
|
enforcementLevel
|
||||||
@@ -53,7 +52,7 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
const project = await projectDAL.findProjectBySlug(projectSlug, actorOrgId);
|
const project = await projectDAL.findProjectBySlug(projectSlug, actorOrgId);
|
||||||
if (!project) throw new BadRequestError({ message: "Project not found" });
|
if (!project) throw new BadRequestError({ message: "Project not found" });
|
||||||
|
|
||||||
if (approvals > approvers.length)
|
if (approvals > approverUserIds.length)
|
||||||
throw new BadRequestError({ message: "Approvals cannot be greater than approvers" });
|
throw new BadRequestError({ message: "Approvals cannot be greater than approvers" });
|
||||||
|
|
||||||
const { permission } = await permissionService.getProjectPermission(
|
const { permission } = await permissionService.getProjectPermission(
|
||||||
@@ -70,15 +69,6 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
const env = await projectEnvDAL.findOne({ slug: environment, projectId: project.id });
|
const env = await projectEnvDAL.findOne({ slug: environment, projectId: project.id });
|
||||||
if (!env) throw new BadRequestError({ message: "Environment not found" });
|
if (!env) throw new BadRequestError({ message: "Environment not found" });
|
||||||
|
|
||||||
const secretApprovers = await projectMembershipDAL.find({
|
|
||||||
projectId: project.id,
|
|
||||||
$in: { id: approvers }
|
|
||||||
});
|
|
||||||
|
|
||||||
if (secretApprovers.length !== approvers.length) {
|
|
||||||
throw new BadRequestError({ message: "Approver not found in project" });
|
|
||||||
}
|
|
||||||
|
|
||||||
await verifyApprovers({
|
await verifyApprovers({
|
||||||
projectId: project.id,
|
projectId: project.id,
|
||||||
orgId: actorOrgId,
|
orgId: actorOrgId,
|
||||||
@@ -86,7 +76,7 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
secretPath,
|
secretPath,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
permissionService,
|
permissionService,
|
||||||
userIds: secretApprovers.map((approver) => approver.userId)
|
userIds: approverUserIds
|
||||||
});
|
});
|
||||||
|
|
||||||
const accessApproval = await accessApprovalPolicyDAL.transaction(async (tx) => {
|
const accessApproval = await accessApprovalPolicyDAL.transaction(async (tx) => {
|
||||||
@@ -101,8 +91,8 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
await accessApprovalPolicyApproverDAL.insertMany(
|
await accessApprovalPolicyApproverDAL.insertMany(
|
||||||
secretApprovers.map(({ id }) => ({
|
approverUserIds.map((userId) => ({
|
||||||
approverId: id,
|
approverUserId: userId,
|
||||||
policyId: doc.id
|
policyId: doc.id
|
||||||
})),
|
})),
|
||||||
tx
|
tx
|
||||||
@@ -138,7 +128,7 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
|
|
||||||
const updateAccessApprovalPolicy = async ({
|
const updateAccessApprovalPolicy = async ({
|
||||||
policyId,
|
policyId,
|
||||||
approvers,
|
approverUserIds,
|
||||||
secretPath,
|
secretPath,
|
||||||
name,
|
name,
|
||||||
actorId,
|
actorId,
|
||||||
@@ -171,16 +161,7 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
},
|
},
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
if (approvers) {
|
if (approverUserIds) {
|
||||||
// Find the workspace project memberships of the users passed in the approvers array
|
|
||||||
const secretApprovers = await projectMembershipDAL.find(
|
|
||||||
{
|
|
||||||
projectId: accessApprovalPolicy.projectId,
|
|
||||||
$in: { id: approvers }
|
|
||||||
},
|
|
||||||
{ tx }
|
|
||||||
);
|
|
||||||
|
|
||||||
await verifyApprovers({
|
await verifyApprovers({
|
||||||
projectId: accessApprovalPolicy.projectId,
|
projectId: accessApprovalPolicy.projectId,
|
||||||
orgId: actorOrgId,
|
orgId: actorOrgId,
|
||||||
@@ -188,15 +169,13 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
secretPath: doc.secretPath!,
|
secretPath: doc.secretPath!,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
permissionService,
|
permissionService,
|
||||||
userIds: secretApprovers.map((approver) => approver.userId)
|
userIds: approverUserIds
|
||||||
});
|
});
|
||||||
|
|
||||||
if (secretApprovers.length !== approvers.length)
|
|
||||||
throw new BadRequestError({ message: "Approvals cannot be greater than approvers" });
|
|
||||||
await accessApprovalPolicyApproverDAL.delete({ policyId: doc.id }, tx);
|
await accessApprovalPolicyApproverDAL.delete({ policyId: doc.id }, tx);
|
||||||
await accessApprovalPolicyApproverDAL.insertMany(
|
await accessApprovalPolicyApproverDAL.insertMany(
|
||||||
secretApprovers.map(({ id }) => ({
|
approverUserIds.map((userId) => ({
|
||||||
approverId: id,
|
approverUserId: userId,
|
||||||
policyId: doc.id
|
policyId: doc.id
|
||||||
})),
|
})),
|
||||||
tx
|
tx
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export type TCreateAccessApprovalPolicy = {
|
|||||||
approvals: number;
|
approvals: number;
|
||||||
secretPath: string;
|
secretPath: string;
|
||||||
environment: string;
|
environment: string;
|
||||||
approvers: string[];
|
approverUserIds: string[];
|
||||||
projectSlug: string;
|
projectSlug: string;
|
||||||
name: string;
|
name: string;
|
||||||
enforcementLevel: EnforcementLevel;
|
enforcementLevel: EnforcementLevel;
|
||||||
@@ -26,7 +26,7 @@ export type TCreateAccessApprovalPolicy = {
|
|||||||
export type TUpdateAccessApprovalPolicy = {
|
export type TUpdateAccessApprovalPolicy = {
|
||||||
policyId: string;
|
policyId: string;
|
||||||
approvals?: number;
|
approvals?: number;
|
||||||
approvers?: string[];
|
approverUserIds?: string[];
|
||||||
secretPath?: string;
|
secretPath?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
enforcementLevel?: EnforcementLevel;
|
enforcementLevel?: EnforcementLevel;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Knex } from "knex";
|
import { Knex } from "knex";
|
||||||
|
|
||||||
import { TDbClient } from "@app/db";
|
import { TDbClient } from "@app/db";
|
||||||
import { AccessApprovalRequestsSchema, TableName, TAccessApprovalRequests } from "@app/db/schemas";
|
import { AccessApprovalRequestsSchema, TableName, TAccessApprovalRequests, TUsers } from "@app/db/schemas";
|
||||||
import { DatabaseError } from "@app/lib/errors";
|
import { DatabaseError } from "@app/lib/errors";
|
||||||
import { ormify, selectAllTableCols, sqlNestRelationships, TFindFilter } from "@app/lib/knex";
|
import { ormify, selectAllTableCols, sqlNestRelationships, TFindFilter } from "@app/lib/knex";
|
||||||
|
|
||||||
@@ -40,6 +40,12 @@ export const accessApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
`${TableName.AccessApprovalPolicyApprover}.policyId`
|
`${TableName.AccessApprovalPolicyApprover}.policyId`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
.join<TUsers>(
|
||||||
|
db(TableName.Users).as("requestedByUser"),
|
||||||
|
`${TableName.AccessApprovalRequest}.requestedByUserId`,
|
||||||
|
`requestedByUser.id`
|
||||||
|
)
|
||||||
|
|
||||||
.leftJoin(TableName.Environment, `${TableName.AccessApprovalPolicy}.envId`, `${TableName.Environment}.id`)
|
.leftJoin(TableName.Environment, `${TableName.AccessApprovalPolicy}.envId`, `${TableName.Environment}.id`)
|
||||||
|
|
||||||
.select(selectAllTableCols(TableName.AccessApprovalRequest))
|
.select(selectAllTableCols(TableName.AccessApprovalRequest))
|
||||||
@@ -52,7 +58,7 @@ export const accessApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
db.ref("envId").withSchema(TableName.AccessApprovalPolicy).as("policyEnvId")
|
db.ref("envId").withSchema(TableName.AccessApprovalPolicy).as("policyEnvId")
|
||||||
)
|
)
|
||||||
|
|
||||||
.select(db.ref("approverId").withSchema(TableName.AccessApprovalPolicyApprover))
|
.select(db.ref("approverUserId").withSchema(TableName.AccessApprovalPolicyApprover))
|
||||||
|
|
||||||
.select(
|
.select(
|
||||||
db.ref("projectId").withSchema(TableName.Environment),
|
db.ref("projectId").withSchema(TableName.Environment),
|
||||||
@@ -61,15 +67,20 @@ export const accessApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
.select(
|
.select(
|
||||||
db.ref("member").withSchema(TableName.AccessApprovalRequestReviewer).as("reviewerMemberId"),
|
db.ref("reviewerUserId").withSchema(TableName.AccessApprovalRequestReviewer).as("reviewerUserId"),
|
||||||
db.ref("status").withSchema(TableName.AccessApprovalRequestReviewer).as("reviewerStatus")
|
db.ref("status").withSchema(TableName.AccessApprovalRequestReviewer).as("reviewerStatus")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: ADD SUPPORT FOR GROUPS!!!!
|
||||||
.select(
|
.select(
|
||||||
db
|
db.ref("email").withSchema("requestedByUser").as("requestedByUserEmail"),
|
||||||
.ref("projectMembershipId")
|
db.ref("username").withSchema("requestedByUser").as("requestedByUserUsername"),
|
||||||
.withSchema(TableName.ProjectUserAdditionalPrivilege)
|
db.ref("firstName").withSchema("requestedByUser").as("requestedByUserFirstName"),
|
||||||
.as("privilegeMembershipId"),
|
db.ref("lastName").withSchema("requestedByUser").as("requestedByUserLastName"),
|
||||||
|
|
||||||
|
db.ref("userId").withSchema(TableName.ProjectUserAdditionalPrivilege).as("privilegeUserId"),
|
||||||
|
db.ref("projectId").withSchema(TableName.ProjectUserAdditionalPrivilege).as("privilegeMembershipId"),
|
||||||
|
|
||||||
db.ref("isTemporary").withSchema(TableName.ProjectUserAdditionalPrivilege).as("privilegeIsTemporary"),
|
db.ref("isTemporary").withSchema(TableName.ProjectUserAdditionalPrivilege).as("privilegeIsTemporary"),
|
||||||
db.ref("temporaryMode").withSchema(TableName.ProjectUserAdditionalPrivilege).as("privilegeTemporaryMode"),
|
db.ref("temporaryMode").withSchema(TableName.ProjectUserAdditionalPrivilege).as("privilegeTemporaryMode"),
|
||||||
db.ref("temporaryRange").withSchema(TableName.ProjectUserAdditionalPrivilege).as("privilegeTemporaryRange"),
|
db.ref("temporaryRange").withSchema(TableName.ProjectUserAdditionalPrivilege).as("privilegeTemporaryRange"),
|
||||||
@@ -102,9 +113,18 @@ export const accessApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
enforcementLevel: doc.policyEnforcementLevel,
|
enforcementLevel: doc.policyEnforcementLevel,
|
||||||
envId: doc.policyEnvId
|
envId: doc.policyEnvId
|
||||||
},
|
},
|
||||||
|
requestedByUser: {
|
||||||
|
userId: doc.requestedByUserId,
|
||||||
|
email: doc.requestedByUserEmail,
|
||||||
|
firstName: doc.requestedByUserFirstName,
|
||||||
|
lastName: doc.requestedByUserLastName,
|
||||||
|
username: doc.requestedByUserUsername
|
||||||
|
},
|
||||||
privilege: doc.privilegeId
|
privilege: doc.privilegeId
|
||||||
? {
|
? {
|
||||||
membershipId: doc.privilegeMembershipId,
|
membershipId: doc.privilegeMembershipId,
|
||||||
|
userId: doc.privilegeUserId,
|
||||||
|
projectId: doc.projectId,
|
||||||
isTemporary: doc.privilegeIsTemporary,
|
isTemporary: doc.privilegeIsTemporary,
|
||||||
temporaryMode: doc.privilegeTemporaryMode,
|
temporaryMode: doc.privilegeTemporaryMode,
|
||||||
temporaryRange: doc.privilegeTemporaryRange,
|
temporaryRange: doc.privilegeTemporaryRange,
|
||||||
@@ -118,11 +138,11 @@ export const accessApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
}),
|
}),
|
||||||
childrenMapper: [
|
childrenMapper: [
|
||||||
{
|
{
|
||||||
key: "reviewerMemberId",
|
key: "reviewerUserId",
|
||||||
label: "reviewers" as const,
|
label: "reviewers" as const,
|
||||||
mapper: ({ reviewerMemberId: member, reviewerStatus: status }) => (member ? { member, status } : undefined)
|
mapper: ({ reviewerUserId: userId, reviewerStatus: status }) => (userId ? { userId, status } : undefined)
|
||||||
},
|
},
|
||||||
{ key: "approverId", label: "approvers" as const, mapper: ({ approverId }) => approverId }
|
{ key: "approverUserId", label: "approvers" as const, mapper: ({ approverUserId }) => approverUserId }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -146,30 +166,65 @@ export const accessApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
`${TableName.AccessApprovalPolicy}.id`
|
`${TableName.AccessApprovalPolicy}.id`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
.join<TUsers>(
|
||||||
|
db(TableName.Users).as("requestedByUser"),
|
||||||
|
`${TableName.AccessApprovalRequest}.requestedByUserId`,
|
||||||
|
`requestedByUser.id`
|
||||||
|
)
|
||||||
|
|
||||||
.join(
|
.join(
|
||||||
TableName.AccessApprovalPolicyApprover,
|
TableName.AccessApprovalPolicyApprover,
|
||||||
`${TableName.AccessApprovalPolicy}.id`,
|
`${TableName.AccessApprovalPolicy}.id`,
|
||||||
`${TableName.AccessApprovalPolicyApprover}.policyId`
|
`${TableName.AccessApprovalPolicyApprover}.policyId`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
.join<TUsers>(
|
||||||
|
db(TableName.Users).as("accessApprovalPolicyApproverUser"),
|
||||||
|
`${TableName.AccessApprovalPolicyApprover}.approverUserId`,
|
||||||
|
"accessApprovalPolicyApproverUser.id"
|
||||||
|
)
|
||||||
|
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
TableName.AccessApprovalRequestReviewer,
|
TableName.AccessApprovalRequestReviewer,
|
||||||
`${TableName.AccessApprovalRequest}.id`,
|
`${TableName.AccessApprovalRequest}.id`,
|
||||||
`${TableName.AccessApprovalRequestReviewer}.requestId`
|
`${TableName.AccessApprovalRequestReviewer}.requestId`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
.leftJoin<TUsers>(
|
||||||
|
db(TableName.Users).as("accessApprovalReviewerUser"),
|
||||||
|
`${TableName.AccessApprovalRequestReviewer}.reviewerUserId`,
|
||||||
|
`accessApprovalReviewerUser.id`
|
||||||
|
)
|
||||||
|
|
||||||
.leftJoin(TableName.Environment, `${TableName.AccessApprovalPolicy}.envId`, `${TableName.Environment}.id`)
|
.leftJoin(TableName.Environment, `${TableName.AccessApprovalPolicy}.envId`, `${TableName.Environment}.id`)
|
||||||
.select(selectAllTableCols(TableName.AccessApprovalRequest))
|
.select(selectAllTableCols(TableName.AccessApprovalRequest))
|
||||||
.select(
|
.select(
|
||||||
tx.ref("member").withSchema(TableName.AccessApprovalRequestReviewer).as("reviewerMemberId"),
|
tx.ref("approverUserId").withSchema(TableName.AccessApprovalPolicyApprover),
|
||||||
|
tx.ref("email").withSchema("accessApprovalPolicyApproverUser").as("approverEmail"),
|
||||||
|
tx.ref("username").withSchema("accessApprovalPolicyApproverUser").as("approverUsername"),
|
||||||
|
tx.ref("firstName").withSchema("accessApprovalPolicyApproverUser").as("approverFirstName"),
|
||||||
|
tx.ref("lastName").withSchema("accessApprovalPolicyApproverUser").as("approverLastName"),
|
||||||
|
tx.ref("email").withSchema("requestedByUser").as("requestedByUserEmail"),
|
||||||
|
tx.ref("username").withSchema("requestedByUser").as("requestedByUserUsername"),
|
||||||
|
tx.ref("firstName").withSchema("requestedByUser").as("requestedByUserFirstName"),
|
||||||
|
tx.ref("lastName").withSchema("requestedByUser").as("requestedByUserLastName"),
|
||||||
|
|
||||||
|
tx.ref("reviewerUserId").withSchema(TableName.AccessApprovalRequestReviewer),
|
||||||
|
|
||||||
tx.ref("status").withSchema(TableName.AccessApprovalRequestReviewer).as("reviewerStatus"),
|
tx.ref("status").withSchema(TableName.AccessApprovalRequestReviewer).as("reviewerStatus"),
|
||||||
|
|
||||||
|
tx.ref("email").withSchema("accessApprovalReviewerUser").as("reviewerEmail"),
|
||||||
|
tx.ref("username").withSchema("accessApprovalReviewerUser").as("reviewerUsername"),
|
||||||
|
tx.ref("firstName").withSchema("accessApprovalReviewerUser").as("reviewerFirstName"),
|
||||||
|
tx.ref("lastName").withSchema("accessApprovalReviewerUser").as("reviewerLastName"),
|
||||||
|
|
||||||
tx.ref("id").withSchema(TableName.AccessApprovalPolicy).as("policyId"),
|
tx.ref("id").withSchema(TableName.AccessApprovalPolicy).as("policyId"),
|
||||||
tx.ref("name").withSchema(TableName.AccessApprovalPolicy).as("policyName"),
|
tx.ref("name").withSchema(TableName.AccessApprovalPolicy).as("policyName"),
|
||||||
tx.ref("projectId").withSchema(TableName.Environment),
|
tx.ref("projectId").withSchema(TableName.Environment),
|
||||||
tx.ref("slug").withSchema(TableName.Environment).as("environment"),
|
tx.ref("slug").withSchema(TableName.Environment).as("environment"),
|
||||||
tx.ref("secretPath").withSchema(TableName.AccessApprovalPolicy).as("policySecretPath"),
|
tx.ref("secretPath").withSchema(TableName.AccessApprovalPolicy).as("policySecretPath"),
|
||||||
tx.ref("enforcementLevel").withSchema(TableName.AccessApprovalPolicy).as("policyEnforcementLevel"),
|
tx.ref("enforcementLevel").withSchema(TableName.AccessApprovalPolicy).as("policyEnforcementLevel"),
|
||||||
tx.ref("approvals").withSchema(TableName.AccessApprovalPolicy).as("policyApprovals"),
|
tx.ref("approvals").withSchema(TableName.AccessApprovalPolicy).as("policyApprovals")
|
||||||
tx.ref("approverId").withSchema(TableName.AccessApprovalPolicyApprover)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const findById = async (id: string, tx?: Knex) => {
|
const findById = async (id: string, tx?: Knex) => {
|
||||||
@@ -189,15 +244,45 @@ export const accessApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
approvals: el.policyApprovals,
|
approvals: el.policyApprovals,
|
||||||
secretPath: el.policySecretPath,
|
secretPath: el.policySecretPath,
|
||||||
enforcementLevel: el.policyEnforcementLevel
|
enforcementLevel: el.policyEnforcementLevel
|
||||||
|
},
|
||||||
|
requestedByUser: {
|
||||||
|
userId: el.requestedByUserId,
|
||||||
|
email: el.requestedByUserEmail,
|
||||||
|
firstName: el.requestedByUserFirstName,
|
||||||
|
lastName: el.requestedByUserLastName,
|
||||||
|
username: el.requestedByUserUsername
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
childrenMapper: [
|
childrenMapper: [
|
||||||
{
|
{
|
||||||
key: "reviewerMemberId",
|
key: "reviewerUserId",
|
||||||
label: "reviewers" as const,
|
label: "reviewers" as const,
|
||||||
mapper: ({ reviewerMemberId: member, reviewerStatus: status }) => (member ? { member, status } : undefined)
|
mapper: ({
|
||||||
|
reviewerUserId: userId,
|
||||||
|
reviewerStatus: status,
|
||||||
|
reviewerEmail: email,
|
||||||
|
reviewerLastName: lastName,
|
||||||
|
reviewerUsername: username,
|
||||||
|
reviewerFirstName: firstName
|
||||||
|
}) => (userId ? { userId, status, email, firstName, lastName, username } : undefined)
|
||||||
},
|
},
|
||||||
{ key: "approverId", label: "approvers" as const, mapper: ({ approverId }) => approverId }
|
{
|
||||||
|
key: "approverUserId",
|
||||||
|
label: "approvers" as const,
|
||||||
|
mapper: ({
|
||||||
|
approverUserId,
|
||||||
|
approverEmail: email,
|
||||||
|
approverUsername: username,
|
||||||
|
approverLastName: lastName,
|
||||||
|
approverFirstName: firstName
|
||||||
|
}) => ({
|
||||||
|
userId: approverUserId,
|
||||||
|
email,
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
username
|
||||||
|
})
|
||||||
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
if (!formatedDoc?.[0]) return;
|
if (!formatedDoc?.[0]) return;
|
||||||
@@ -235,7 +320,7 @@ export const accessApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
.where(`${TableName.Environment}.projectId`, projectId)
|
.where(`${TableName.Environment}.projectId`, projectId)
|
||||||
.select(selectAllTableCols(TableName.AccessApprovalRequest))
|
.select(selectAllTableCols(TableName.AccessApprovalRequest))
|
||||||
.select(db.ref("status").withSchema(TableName.AccessApprovalRequestReviewer).as("reviewerStatus"))
|
.select(db.ref("status").withSchema(TableName.AccessApprovalRequestReviewer).as("reviewerStatus"))
|
||||||
.select(db.ref("member").withSchema(TableName.AccessApprovalRequestReviewer).as("reviewerMemberId"));
|
.select(db.ref("reviewerUserId").withSchema(TableName.AccessApprovalRequestReviewer).as("reviewerUserId"));
|
||||||
|
|
||||||
const formattedRequests = sqlNestRelationships({
|
const formattedRequests = sqlNestRelationships({
|
||||||
data: accessRequests,
|
data: accessRequests,
|
||||||
@@ -245,9 +330,10 @@ export const accessApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
}),
|
}),
|
||||||
childrenMapper: [
|
childrenMapper: [
|
||||||
{
|
{
|
||||||
key: "reviewerMemberId",
|
key: "reviewerUserId",
|
||||||
label: "reviewers" as const,
|
label: "reviewers" as const,
|
||||||
mapper: ({ reviewerMemberId: member, reviewerStatus: status }) => (member ? { member, status } : undefined)
|
mapper: ({ reviewerUserId: reviewer, reviewerStatus: status }) =>
|
||||||
|
reviewer ? { reviewer, status } : undefined
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -52,7 +52,10 @@ type TSecretApprovalRequestServiceFactoryDep = {
|
|||||||
>;
|
>;
|
||||||
projectMembershipDAL: Pick<TProjectMembershipDALFactory, "findById">;
|
projectMembershipDAL: Pick<TProjectMembershipDALFactory, "findById">;
|
||||||
smtpService: Pick<TSmtpService, "sendMail">;
|
smtpService: Pick<TSmtpService, "sendMail">;
|
||||||
userDAL: Pick<TUserDALFactory, "findUserByProjectMembershipId" | "findUsersByProjectMembershipIds">;
|
userDAL: Pick<
|
||||||
|
TUserDALFactory,
|
||||||
|
"findUserByProjectMembershipId" | "findUsersByProjectMembershipIds" | "find" | "findById"
|
||||||
|
>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TAccessApprovalRequestServiceFactory = ReturnType<typeof accessApprovalRequestServiceFactory>;
|
export type TAccessApprovalRequestServiceFactory = ReturnType<typeof accessApprovalRequestServiceFactory>;
|
||||||
@@ -94,7 +97,7 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
);
|
);
|
||||||
if (!membership) throw new UnauthorizedError({ message: "You are not a member of this project" });
|
if (!membership) throw new UnauthorizedError({ message: "You are not a member of this project" });
|
||||||
|
|
||||||
const requestedByUser = await userDAL.findUserByProjectMembershipId(membership.id);
|
const requestedByUser = await userDAL.findById(actorId);
|
||||||
if (!requestedByUser) throw new UnauthorizedError({ message: "User not found" });
|
if (!requestedByUser) throw new UnauthorizedError({ message: "User not found" });
|
||||||
|
|
||||||
await projectDAL.checkProjectUpgradeStatus(project.id);
|
await projectDAL.checkProjectUpgradeStatus(project.id);
|
||||||
@@ -114,13 +117,15 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
policyId: policy.id
|
policyId: policy.id
|
||||||
});
|
});
|
||||||
|
|
||||||
const approverUsers = await userDAL.findUsersByProjectMembershipIds(
|
const approverUsers = await userDAL.find({
|
||||||
approvers.map((approver) => approver.approverId)
|
$in: {
|
||||||
);
|
id: approvers.map((approver) => approver.approverUserId)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const duplicateRequests = await accessApprovalRequestDAL.find({
|
const duplicateRequests = await accessApprovalRequestDAL.find({
|
||||||
policyId: policy.id,
|
policyId: policy.id,
|
||||||
requestedBy: membership.id,
|
requestedByUserId: actorId,
|
||||||
permissions: JSON.stringify(requestedPermissions),
|
permissions: JSON.stringify(requestedPermissions),
|
||||||
isTemporary
|
isTemporary
|
||||||
});
|
});
|
||||||
@@ -153,7 +158,7 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
const approvalRequest = await accessApprovalRequestDAL.create(
|
const approvalRequest = await accessApprovalRequestDAL.create(
|
||||||
{
|
{
|
||||||
policyId: policy.id,
|
policyId: policy.id,
|
||||||
requestedBy: membership.id,
|
requestedByUserId: actorId,
|
||||||
temporaryRange: temporaryRange || null,
|
temporaryRange: temporaryRange || null,
|
||||||
permissions: JSON.stringify(requestedPermissions),
|
permissions: JSON.stringify(requestedPermissions),
|
||||||
isTemporary
|
isTemporary
|
||||||
@@ -212,7 +217,7 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
let requests = await accessApprovalRequestDAL.findRequestsWithPrivilegeByPolicyIds(policies.map((p) => p.id));
|
let requests = await accessApprovalRequestDAL.findRequestsWithPrivilegeByPolicyIds(policies.map((p) => p.id));
|
||||||
|
|
||||||
if (authorProjectMembershipId) {
|
if (authorProjectMembershipId) {
|
||||||
requests = requests.filter((request) => request.requestedBy === authorProjectMembershipId);
|
requests = requests.filter((request) => request.requestedByUserId === actorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (envSlug) {
|
if (envSlug) {
|
||||||
@@ -246,8 +251,8 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
!hasRole(ProjectMembershipRole.Admin) &&
|
!hasRole(ProjectMembershipRole.Admin) &&
|
||||||
accessApprovalRequest.requestedBy !== membership.id && // The request wasn't made by the current user
|
accessApprovalRequest.requestedByUserId !== actorId && // The request wasn't made by the current user
|
||||||
!policy.approvers.find((approverId) => approverId === membership.id) // The request isn't performed by an assigned approver
|
!policy.approvers.find((approver) => approver.userId === actorId) // The request isn't performed by an assigned approver
|
||||||
) {
|
) {
|
||||||
throw new UnauthorizedError({ message: "You are not authorized to approve this request" });
|
throw new UnauthorizedError({ message: "You are not authorized to approve this request" });
|
||||||
}
|
}
|
||||||
@@ -273,7 +278,7 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
const review = await accessApprovalRequestReviewerDAL.findOne(
|
const review = await accessApprovalRequestReviewerDAL.findOne(
|
||||||
{
|
{
|
||||||
requestId: accessApprovalRequest.id,
|
requestId: accessApprovalRequest.id,
|
||||||
member: membership.id
|
reviewerUserId: actorId
|
||||||
},
|
},
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
@@ -282,7 +287,7 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
{
|
{
|
||||||
status,
|
status,
|
||||||
requestId: accessApprovalRequest.id,
|
requestId: accessApprovalRequest.id,
|
||||||
member: membership.id
|
reviewerUserId: actorId
|
||||||
},
|
},
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
@@ -303,7 +308,8 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
// Permanent access
|
// Permanent access
|
||||||
const privilege = await additionalPrivilegeDAL.create(
|
const privilege = await additionalPrivilegeDAL.create(
|
||||||
{
|
{
|
||||||
projectMembershipId: accessApprovalRequest.requestedBy,
|
userId: accessApprovalRequest.requestedByUserId,
|
||||||
|
projectId: accessApprovalRequest.projectId,
|
||||||
slug: `requested-privilege-${slugify(alphaNumericNanoId(12))}`,
|
slug: `requested-privilege-${slugify(alphaNumericNanoId(12))}`,
|
||||||
permissions: JSON.stringify(accessApprovalRequest.permissions)
|
permissions: JSON.stringify(accessApprovalRequest.permissions)
|
||||||
},
|
},
|
||||||
@@ -317,7 +323,8 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
|
|
||||||
const privilege = await additionalPrivilegeDAL.create(
|
const privilege = await additionalPrivilegeDAL.create(
|
||||||
{
|
{
|
||||||
projectMembershipId: accessApprovalRequest.requestedBy,
|
userId: accessApprovalRequest.requestedByUserId,
|
||||||
|
projectId: accessApprovalRequest.projectId,
|
||||||
slug: `requested-privilege-${slugify(alphaNumericNanoId(12))}`,
|
slug: `requested-privilege-${slugify(alphaNumericNanoId(12))}`,
|
||||||
permissions: JSON.stringify(accessApprovalRequest.permissions),
|
permissions: JSON.stringify(accessApprovalRequest.permissions),
|
||||||
isTemporary: true,
|
isTemporary: true,
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ export const permissionDALFactory = (db: TDbClient) => {
|
|||||||
`${TableName.GroupProjectMembershipRole}.projectMembershipId`,
|
`${TableName.GroupProjectMembershipRole}.projectMembershipId`,
|
||||||
`${TableName.GroupProjectMembership}.id`
|
`${TableName.GroupProjectMembership}.id`
|
||||||
)
|
)
|
||||||
|
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
TableName.ProjectRoles,
|
TableName.ProjectRoles,
|
||||||
`${TableName.GroupProjectMembershipRole}.customRoleId`,
|
`${TableName.GroupProjectMembershipRole}.customRoleId`,
|
||||||
@@ -73,6 +74,12 @@ export const permissionDALFactory = (db: TDbClient) => {
|
|||||||
)
|
)
|
||||||
.join(TableName.Project, `${TableName.GroupProjectMembership}.projectId`, `${TableName.Project}.id`)
|
.join(TableName.Project, `${TableName.GroupProjectMembership}.projectId`, `${TableName.Project}.id`)
|
||||||
.join(TableName.Organization, `${TableName.Project}.orgId`, `${TableName.Organization}.id`)
|
.join(TableName.Organization, `${TableName.Project}.orgId`, `${TableName.Organization}.id`)
|
||||||
|
|
||||||
|
.leftJoin(
|
||||||
|
TableName.ProjectUserAdditionalPrivilege,
|
||||||
|
`${TableName.GroupProjectMembership}.projectId`,
|
||||||
|
`${TableName.Project}.id`
|
||||||
|
)
|
||||||
.select(selectAllTableCols(TableName.GroupProjectMembershipRole))
|
.select(selectAllTableCols(TableName.GroupProjectMembershipRole))
|
||||||
.select(
|
.select(
|
||||||
db.ref("id").withSchema(TableName.GroupProjectMembership).as("membershipId"),
|
db.ref("id").withSchema(TableName.GroupProjectMembership).as("membershipId"),
|
||||||
@@ -81,9 +88,30 @@ export const permissionDALFactory = (db: TDbClient) => {
|
|||||||
db.ref("projectId").withSchema(TableName.GroupProjectMembership),
|
db.ref("projectId").withSchema(TableName.GroupProjectMembership),
|
||||||
db.ref("authEnforced").withSchema(TableName.Organization).as("orgAuthEnforced"),
|
db.ref("authEnforced").withSchema(TableName.Organization).as("orgAuthEnforced"),
|
||||||
db.ref("orgId").withSchema(TableName.Project),
|
db.ref("orgId").withSchema(TableName.Project),
|
||||||
db.ref("slug").withSchema(TableName.ProjectRoles).as("customRoleSlug")
|
db.ref("slug").withSchema(TableName.ProjectRoles).as("customRoleSlug"),
|
||||||
)
|
|
||||||
.select("permissions");
|
db.ref("permissions").withSchema(TableName.ProjectRoles).as("permissions"),
|
||||||
|
// db.ref("permissions").withSchema(TableName.ProjectUserAdditionalPrivilege).as("apPermissions")
|
||||||
|
// Additional Privileges
|
||||||
|
db.ref("id").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApId"),
|
||||||
|
db.ref("permissions").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApPermissions"),
|
||||||
|
db.ref("temporaryMode").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApTemporaryMode"),
|
||||||
|
db.ref("isTemporary").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApIsTemporary"),
|
||||||
|
db.ref("temporaryRange").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApTemporaryRange"),
|
||||||
|
|
||||||
|
db.ref("projectId").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApProjectId"),
|
||||||
|
db.ref("userId").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApUserId"),
|
||||||
|
|
||||||
|
db
|
||||||
|
.ref("temporaryAccessStartTime")
|
||||||
|
.withSchema(TableName.ProjectUserAdditionalPrivilege)
|
||||||
|
.as("userApTemporaryAccessStartTime"),
|
||||||
|
db
|
||||||
|
.ref("temporaryAccessEndTime")
|
||||||
|
.withSchema(TableName.ProjectUserAdditionalPrivilege)
|
||||||
|
.as("userApTemporaryAccessEndTime")
|
||||||
|
);
|
||||||
|
// .select(`${TableName.ProjectRoles}.permissions`);
|
||||||
|
|
||||||
const docs = await db(TableName.ProjectMembership)
|
const docs = await db(TableName.ProjectMembership)
|
||||||
.join(
|
.join(
|
||||||
@@ -98,12 +126,13 @@ export const permissionDALFactory = (db: TDbClient) => {
|
|||||||
)
|
)
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
TableName.ProjectUserAdditionalPrivilege,
|
TableName.ProjectUserAdditionalPrivilege,
|
||||||
`${TableName.ProjectUserAdditionalPrivilege}.projectMembershipId`,
|
`${TableName.ProjectUserAdditionalPrivilege}.projectId`,
|
||||||
`${TableName.ProjectMembership}.id`
|
`${TableName.ProjectMembership}.projectId`
|
||||||
)
|
)
|
||||||
|
|
||||||
.join(TableName.Project, `${TableName.ProjectMembership}.projectId`, `${TableName.Project}.id`)
|
.join(TableName.Project, `${TableName.ProjectMembership}.projectId`, `${TableName.Project}.id`)
|
||||||
.join(TableName.Organization, `${TableName.Project}.orgId`, `${TableName.Organization}.id`)
|
.join(TableName.Organization, `${TableName.Project}.orgId`, `${TableName.Organization}.id`)
|
||||||
.where("userId", userId)
|
.where(`${TableName.ProjectMembership}.userId`, userId)
|
||||||
.where(`${TableName.ProjectMembership}.projectId`, projectId)
|
.where(`${TableName.ProjectMembership}.projectId`, projectId)
|
||||||
.select(selectAllTableCols(TableName.ProjectUserMembershipRole))
|
.select(selectAllTableCols(TableName.ProjectUserMembershipRole))
|
||||||
.select(
|
.select(
|
||||||
@@ -120,6 +149,10 @@ export const permissionDALFactory = (db: TDbClient) => {
|
|||||||
db.ref("temporaryMode").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApTemporaryMode"),
|
db.ref("temporaryMode").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApTemporaryMode"),
|
||||||
db.ref("isTemporary").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApIsTemporary"),
|
db.ref("isTemporary").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApIsTemporary"),
|
||||||
db.ref("temporaryRange").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApTemporaryRange"),
|
db.ref("temporaryRange").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApTemporaryRange"),
|
||||||
|
|
||||||
|
db.ref("projectId").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApProjectId"),
|
||||||
|
db.ref("userId").withSchema(TableName.ProjectUserAdditionalPrivilege).as("userApUserId"),
|
||||||
|
|
||||||
db
|
db
|
||||||
.ref("temporaryAccessStartTime")
|
.ref("temporaryAccessStartTime")
|
||||||
.withSchema(TableName.ProjectUserAdditionalPrivilege)
|
.withSchema(TableName.ProjectUserAdditionalPrivilege)
|
||||||
@@ -198,6 +231,31 @@ export const permissionDALFactory = (db: TDbClient) => {
|
|||||||
permissions: z.unknown(),
|
permissions: z.unknown(),
|
||||||
customRoleSlug: z.string().optional().nullable()
|
customRoleSlug: z.string().optional().nullable()
|
||||||
}).parse(data)
|
}).parse(data)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "userApId",
|
||||||
|
label: "additionalPrivileges" as const,
|
||||||
|
mapper: ({
|
||||||
|
userApId,
|
||||||
|
userApProjectId,
|
||||||
|
userApUserId,
|
||||||
|
userApPermissions,
|
||||||
|
userApIsTemporary,
|
||||||
|
userApTemporaryMode,
|
||||||
|
userApTemporaryRange,
|
||||||
|
userApTemporaryAccessEndTime,
|
||||||
|
userApTemporaryAccessStartTime
|
||||||
|
}) => ({
|
||||||
|
id: userApId,
|
||||||
|
userId: userApUserId,
|
||||||
|
projectId: userApProjectId,
|
||||||
|
permissions: userApPermissions,
|
||||||
|
temporaryRange: userApTemporaryRange,
|
||||||
|
temporaryMode: userApTemporaryMode,
|
||||||
|
temporaryAccessEndTime: userApTemporaryAccessEndTime,
|
||||||
|
temporaryAccessStartTime: userApTemporaryAccessStartTime,
|
||||||
|
isTemporary: userApIsTemporary
|
||||||
|
})
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
@@ -218,15 +276,24 @@ export const permissionDALFactory = (db: TDbClient) => {
|
|||||||
!isTemporary || (isTemporary && temporaryAccessEndTime && new Date() < temporaryAccessEndTime)
|
!isTemporary || (isTemporary && temporaryAccessEndTime && new Date() < temporaryAccessEndTime)
|
||||||
) ?? [];
|
) ?? [];
|
||||||
|
|
||||||
const activeAdditionalPrivileges = permission?.[0]?.additionalPrivileges?.filter(
|
const activeAdditionalPrivileges =
|
||||||
({ isTemporary, temporaryAccessEndTime }) =>
|
permission?.[0]?.additionalPrivileges?.filter(
|
||||||
!isTemporary || (isTemporary && temporaryAccessEndTime && new Date() < temporaryAccessEndTime)
|
({ isTemporary, temporaryAccessEndTime }) =>
|
||||||
);
|
!isTemporary || (isTemporary && temporaryAccessEndTime && new Date() < temporaryAccessEndTime)
|
||||||
|
) ?? [];
|
||||||
|
|
||||||
|
const activeGroupAdditionalPrivileges =
|
||||||
|
groupPermission?.[0]?.additionalPrivileges?.filter(
|
||||||
|
({ isTemporary, temporaryAccessEndTime, userId: apUserId, projectId: apProjectId }) =>
|
||||||
|
apProjectId === projectId &&
|
||||||
|
apUserId === userId &&
|
||||||
|
(!isTemporary || (isTemporary && temporaryAccessEndTime && new Date() < temporaryAccessEndTime))
|
||||||
|
) ?? [];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...(permission[0] || groupPermission[0]),
|
...(permission[0] || groupPermission[0]),
|
||||||
roles: [...activeRoles, ...activeGroupRoles],
|
roles: [...activeRoles, ...activeGroupRoles],
|
||||||
additionalPrivileges: activeAdditionalPrivileges
|
additionalPrivileges: [...activeAdditionalPrivileges, ...activeGroupAdditionalPrivileges]
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ error, name: "GetProjectPermission" });
|
throw new DatabaseError({ error, name: "GetProjectPermission" });
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
|
|
||||||
type TProjectUserAdditionalPrivilegeServiceFactoryDep = {
|
type TProjectUserAdditionalPrivilegeServiceFactoryDep = {
|
||||||
projectUserAdditionalPrivilegeDAL: TProjectUserAdditionalPrivilegeDALFactory;
|
projectUserAdditionalPrivilegeDAL: TProjectUserAdditionalPrivilegeDALFactory;
|
||||||
projectMembershipDAL: Pick<TProjectMembershipDALFactory, "findById">;
|
projectMembershipDAL: Pick<TProjectMembershipDALFactory, "findById" | "findOne">;
|
||||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,12 +53,17 @@ export const projectUserAdditionalPrivilegeServiceFactory = ({
|
|||||||
);
|
);
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.Member);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.Member);
|
||||||
|
|
||||||
const existingSlug = await projectUserAdditionalPrivilegeDAL.findOne({ slug, projectMembershipId });
|
const existingSlug = await projectUserAdditionalPrivilegeDAL.findOne({
|
||||||
|
slug,
|
||||||
|
projectId: projectMembership.projectId,
|
||||||
|
userId: projectMembership.userId
|
||||||
|
});
|
||||||
if (existingSlug) throw new BadRequestError({ message: "Additional privilege of provided slug exist" });
|
if (existingSlug) throw new BadRequestError({ message: "Additional privilege of provided slug exist" });
|
||||||
|
|
||||||
if (!dto.isTemporary) {
|
if (!dto.isTemporary) {
|
||||||
const additionalPrivilege = await projectUserAdditionalPrivilegeDAL.create({
|
const additionalPrivilege = await projectUserAdditionalPrivilegeDAL.create({
|
||||||
projectMembershipId,
|
userId: projectMembership.userId,
|
||||||
|
projectId: projectMembership.projectId,
|
||||||
slug,
|
slug,
|
||||||
permissions: customPermission
|
permissions: customPermission
|
||||||
});
|
});
|
||||||
@@ -67,7 +72,8 @@ export const projectUserAdditionalPrivilegeServiceFactory = ({
|
|||||||
|
|
||||||
const relativeTempAllocatedTimeInMs = ms(dto.temporaryRange);
|
const relativeTempAllocatedTimeInMs = ms(dto.temporaryRange);
|
||||||
const additionalPrivilege = await projectUserAdditionalPrivilegeDAL.create({
|
const additionalPrivilege = await projectUserAdditionalPrivilegeDAL.create({
|
||||||
projectMembershipId,
|
projectId: projectMembership.projectId,
|
||||||
|
userId: projectMembership.userId,
|
||||||
slug,
|
slug,
|
||||||
permissions: customPermission,
|
permissions: customPermission,
|
||||||
isTemporary: true,
|
isTemporary: true,
|
||||||
@@ -90,7 +96,11 @@ export const projectUserAdditionalPrivilegeServiceFactory = ({
|
|||||||
const userPrivilege = await projectUserAdditionalPrivilegeDAL.findById(privilegeId);
|
const userPrivilege = await projectUserAdditionalPrivilegeDAL.findById(privilegeId);
|
||||||
if (!userPrivilege) throw new BadRequestError({ message: "User additional privilege not found" });
|
if (!userPrivilege) throw new BadRequestError({ message: "User additional privilege not found" });
|
||||||
|
|
||||||
const projectMembership = await projectMembershipDAL.findById(userPrivilege.projectMembershipId);
|
const projectMembership = await projectMembershipDAL.findOne({
|
||||||
|
userId: userPrivilege.userId,
|
||||||
|
projectId: userPrivilege.projectId
|
||||||
|
});
|
||||||
|
|
||||||
if (!projectMembership) throw new BadRequestError({ message: "Project membership not found" });
|
if (!projectMembership) throw new BadRequestError({ message: "Project membership not found" });
|
||||||
|
|
||||||
const { permission } = await permissionService.getProjectPermission(
|
const { permission } = await permissionService.getProjectPermission(
|
||||||
@@ -105,7 +115,8 @@ export const projectUserAdditionalPrivilegeServiceFactory = ({
|
|||||||
if (dto?.slug) {
|
if (dto?.slug) {
|
||||||
const existingSlug = await projectUserAdditionalPrivilegeDAL.findOne({
|
const existingSlug = await projectUserAdditionalPrivilegeDAL.findOne({
|
||||||
slug: dto.slug,
|
slug: dto.slug,
|
||||||
projectMembershipId: projectMembership.id
|
userId: projectMembership.id,
|
||||||
|
projectId: projectMembership.projectId
|
||||||
});
|
});
|
||||||
if (existingSlug && existingSlug.id !== userPrivilege.id)
|
if (existingSlug && existingSlug.id !== userPrivilege.id)
|
||||||
throw new BadRequestError({ message: "Additional privilege of provided slug exist" });
|
throw new BadRequestError({ message: "Additional privilege of provided slug exist" });
|
||||||
@@ -138,7 +149,10 @@ export const projectUserAdditionalPrivilegeServiceFactory = ({
|
|||||||
const userPrivilege = await projectUserAdditionalPrivilegeDAL.findById(privilegeId);
|
const userPrivilege = await projectUserAdditionalPrivilegeDAL.findById(privilegeId);
|
||||||
if (!userPrivilege) throw new BadRequestError({ message: "User additional privilege not found" });
|
if (!userPrivilege) throw new BadRequestError({ message: "User additional privilege not found" });
|
||||||
|
|
||||||
const projectMembership = await projectMembershipDAL.findById(userPrivilege.projectMembershipId);
|
const projectMembership = await projectMembershipDAL.findOne({
|
||||||
|
userId: userPrivilege.userId,
|
||||||
|
projectId: userPrivilege.projectId
|
||||||
|
});
|
||||||
if (!projectMembership) throw new BadRequestError({ message: "Project membership not found" });
|
if (!projectMembership) throw new BadRequestError({ message: "Project membership not found" });
|
||||||
|
|
||||||
const { permission } = await permissionService.getProjectPermission(
|
const { permission } = await permissionService.getProjectPermission(
|
||||||
@@ -164,7 +178,10 @@ export const projectUserAdditionalPrivilegeServiceFactory = ({
|
|||||||
const userPrivilege = await projectUserAdditionalPrivilegeDAL.findById(privilegeId);
|
const userPrivilege = await projectUserAdditionalPrivilegeDAL.findById(privilegeId);
|
||||||
if (!userPrivilege) throw new BadRequestError({ message: "User additional privilege not found" });
|
if (!userPrivilege) throw new BadRequestError({ message: "User additional privilege not found" });
|
||||||
|
|
||||||
const projectMembership = await projectMembershipDAL.findById(userPrivilege.projectMembershipId);
|
const projectMembership = await projectMembershipDAL.findOne({
|
||||||
|
userId: userPrivilege.userId,
|
||||||
|
projectId: userPrivilege.projectId
|
||||||
|
});
|
||||||
if (!projectMembership) throw new BadRequestError({ message: "Project membership not found" });
|
if (!projectMembership) throw new BadRequestError({ message: "Project membership not found" });
|
||||||
|
|
||||||
const { permission } = await permissionService.getProjectPermission(
|
const { permission } = await permissionService.getProjectPermission(
|
||||||
@@ -198,7 +215,10 @@ export const projectUserAdditionalPrivilegeServiceFactory = ({
|
|||||||
);
|
);
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Member);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Member);
|
||||||
|
|
||||||
const userPrivileges = await projectUserAdditionalPrivilegeDAL.find({ projectMembershipId });
|
const userPrivileges = await projectUserAdditionalPrivilegeDAL.find({
|
||||||
|
userId: projectMembership.userId,
|
||||||
|
projectId: projectMembership.projectId
|
||||||
|
});
|
||||||
return userPrivileges;
|
return userPrivileges;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import { UserAliasType } from "@app/services/user-alias/user-alias-types";
|
|||||||
import { TLicenseServiceFactory } from "../license/license-service";
|
import { TLicenseServiceFactory } from "../license/license-service";
|
||||||
import { OrgPermissionActions, OrgPermissionSubjects } from "../permission/org-permission";
|
import { OrgPermissionActions, OrgPermissionSubjects } from "../permission/org-permission";
|
||||||
import { TPermissionServiceFactory } from "../permission/permission-service";
|
import { TPermissionServiceFactory } from "../permission/permission-service";
|
||||||
|
import { TProjectUserAdditionalPrivilegeDALFactory } from "../project-user-additional-privilege/project-user-additional-privilege-dal";
|
||||||
import {
|
import {
|
||||||
buildScimGroup,
|
buildScimGroup,
|
||||||
buildScimGroupList,
|
buildScimGroupList,
|
||||||
@@ -93,6 +94,7 @@ type TScimServiceFactoryDep = {
|
|||||||
licenseService: Pick<TLicenseServiceFactory, "getPlan" | "updateSubscriptionOrgMemberCount">;
|
licenseService: Pick<TLicenseServiceFactory, "getPlan" | "updateSubscriptionOrgMemberCount">;
|
||||||
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
|
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
|
||||||
smtpService: Pick<TSmtpService, "sendMail">;
|
smtpService: Pick<TSmtpService, "sendMail">;
|
||||||
|
projectUserAdditionalPrivilegeDAL: Pick<TProjectUserAdditionalPrivilegeDALFactory, "delete">;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TScimServiceFactory = ReturnType<typeof scimServiceFactory>;
|
export type TScimServiceFactory = ReturnType<typeof scimServiceFactory>;
|
||||||
@@ -112,6 +114,7 @@ export const scimServiceFactory = ({
|
|||||||
projectKeyDAL,
|
projectKeyDAL,
|
||||||
projectBotDAL,
|
projectBotDAL,
|
||||||
permissionService,
|
permissionService,
|
||||||
|
projectUserAdditionalPrivilegeDAL,
|
||||||
smtpService
|
smtpService
|
||||||
}: TScimServiceFactoryDep) => {
|
}: TScimServiceFactoryDep) => {
|
||||||
const createScimToken = async ({
|
const createScimToken = async ({
|
||||||
@@ -558,6 +561,7 @@ export const scimServiceFactory = ({
|
|||||||
orgId: membership.orgId,
|
orgId: membership.orgId,
|
||||||
orgDAL,
|
orgDAL,
|
||||||
projectMembershipDAL,
|
projectMembershipDAL,
|
||||||
|
projectUserAdditionalPrivilegeDAL,
|
||||||
projectKeyDAL,
|
projectKeyDAL,
|
||||||
userAliasDAL,
|
userAliasDAL,
|
||||||
licenseService
|
licenseService
|
||||||
|
|||||||
@@ -19,11 +19,15 @@ export const KeyStorePrefixes = {
|
|||||||
SyncSecretIntegrationLock: (projectId: string, environmentSlug: string, secretPath: string) =>
|
SyncSecretIntegrationLock: (projectId: string, environmentSlug: string, secretPath: string) =>
|
||||||
`sync-integration-mutex-${projectId}-${environmentSlug}-${secretPath}` as const,
|
`sync-integration-mutex-${projectId}-${environmentSlug}-${secretPath}` as const,
|
||||||
SyncSecretIntegrationLastRunTimestamp: (projectId: string, environmentSlug: string, secretPath: string) =>
|
SyncSecretIntegrationLastRunTimestamp: (projectId: string, environmentSlug: string, secretPath: string) =>
|
||||||
`sync-integration-last-run-${projectId}-${environmentSlug}-${secretPath}` as const
|
`sync-integration-last-run-${projectId}-${environmentSlug}-${secretPath}` as const,
|
||||||
|
IdentityAccessTokenStatusUpdate: (identityAccessTokenId: string) =>
|
||||||
|
`identity-access-token-status:${identityAccessTokenId}`,
|
||||||
|
ServiceTokenStatusUpdate: (serviceTokenId: string) => `service-token-status:${serviceTokenId}`
|
||||||
};
|
};
|
||||||
|
|
||||||
export const KeyStoreTtls = {
|
export const KeyStoreTtls = {
|
||||||
SetSyncSecretIntegrationLastRunTimestampInSeconds: 10
|
SetSyncSecretIntegrationLastRunTimestampInSeconds: 10,
|
||||||
|
AccessTokenStatusUpdateInSeconds: 120
|
||||||
};
|
};
|
||||||
|
|
||||||
type TWaitTillReady = {
|
type TWaitTillReady = {
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
export const daysToMillisecond = (days: number) => days * 24 * 60 * 60 * 1000;
|
export const daysToMillisecond = (days: number) => days * 24 * 60 * 60 * 1000;
|
||||||
|
|
||||||
export const secondsToMillis = (seconds: number) => seconds * 1000;
|
export const secondsToMillis = (seconds: number) => seconds * 1000;
|
||||||
|
|
||||||
|
export const applyJitter = (delayMs: number, jitterMs: number) => {
|
||||||
|
const jitter = Math.floor(Math.random() * (2 * jitterMs)) - jitterMs;
|
||||||
|
return delayMs + jitter;
|
||||||
|
};
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ export enum QueueName {
|
|||||||
CaCrlRotation = "ca-crl-rotation",
|
CaCrlRotation = "ca-crl-rotation",
|
||||||
SecretReplication = "secret-replication",
|
SecretReplication = "secret-replication",
|
||||||
SecretSync = "secret-sync", // parent queue to push integration sync, webhook, and secret replication
|
SecretSync = "secret-sync", // parent queue to push integration sync, webhook, and secret replication
|
||||||
ProjectV3Migration = "project-v3-migration"
|
ProjectV3Migration = "project-v3-migration",
|
||||||
|
AccessTokenStatusUpdate = "access-token-status-update"
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum QueueJobs {
|
export enum QueueJobs {
|
||||||
@@ -48,7 +49,9 @@ export enum QueueJobs {
|
|||||||
CaCrlRotation = "ca-crl-rotation-job",
|
CaCrlRotation = "ca-crl-rotation-job",
|
||||||
SecretReplication = "secret-replication",
|
SecretReplication = "secret-replication",
|
||||||
SecretSync = "secret-sync", // parent queue to push integration sync, webhook, and secret replication
|
SecretSync = "secret-sync", // parent queue to push integration sync, webhook, and secret replication
|
||||||
ProjectV3Migration = "project-v3-migration"
|
ProjectV3Migration = "project-v3-migration",
|
||||||
|
IdentityAccessTokenStatusUpdate = "identity-access-token-status-update",
|
||||||
|
ServiceTokenStatusUpdate = "service-token-status-update"
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TQueueJobTypes = {
|
export type TQueueJobTypes = {
|
||||||
@@ -148,6 +151,15 @@ export type TQueueJobTypes = {
|
|||||||
name: QueueJobs.ProjectV3Migration;
|
name: QueueJobs.ProjectV3Migration;
|
||||||
payload: { projectId: string };
|
payload: { projectId: string };
|
||||||
};
|
};
|
||||||
|
[QueueName.AccessTokenStatusUpdate]:
|
||||||
|
| {
|
||||||
|
name: QueueJobs.IdentityAccessTokenStatusUpdate;
|
||||||
|
payload: { identityAccessTokenId: string; numberOfUses: number };
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
name: QueueJobs.ServiceTokenStatusUpdate;
|
||||||
|
payload: { serviceTokenId: string };
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TQueueServiceFactory = ReturnType<typeof queueServiceFactory>;
|
export type TQueueServiceFactory = ReturnType<typeof queueServiceFactory>;
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ import { TKeyStoreFactory } from "@app/keystore/keystore";
|
|||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { TQueueServiceFactory } from "@app/queue";
|
import { TQueueServiceFactory } from "@app/queue";
|
||||||
import { readLimit } from "@app/server/config/rateLimiter";
|
import { readLimit } from "@app/server/config/rateLimiter";
|
||||||
|
import { accessTokenQueueServiceFactory } from "@app/services/access-token-queue/access-token-queue";
|
||||||
import { apiKeyDALFactory } from "@app/services/api-key/api-key-dal";
|
import { apiKeyDALFactory } from "@app/services/api-key/api-key-dal";
|
||||||
import { apiKeyServiceFactory } from "@app/services/api-key/api-key-service";
|
import { apiKeyServiceFactory } from "@app/services/api-key/api-key-service";
|
||||||
import { authDALFactory } from "@app/services/auth/auth-dal";
|
import { authDALFactory } from "@app/services/auth/auth-dal";
|
||||||
@@ -415,6 +416,7 @@ export const registerRoutes = async (
|
|||||||
orgDAL,
|
orgDAL,
|
||||||
orgMembershipDAL,
|
orgMembershipDAL,
|
||||||
projectDAL,
|
projectDAL,
|
||||||
|
projectUserAdditionalPrivilegeDAL,
|
||||||
projectMembershipDAL,
|
projectMembershipDAL,
|
||||||
groupDAL,
|
groupDAL,
|
||||||
groupProjectDAL,
|
groupProjectDAL,
|
||||||
@@ -480,6 +482,7 @@ export const registerRoutes = async (
|
|||||||
orgDAL,
|
orgDAL,
|
||||||
incidentContactDAL,
|
incidentContactDAL,
|
||||||
tokenService,
|
tokenService,
|
||||||
|
projectUserAdditionalPrivilegeDAL,
|
||||||
projectDAL,
|
projectDAL,
|
||||||
projectMembershipDAL,
|
projectMembershipDAL,
|
||||||
orgMembershipDAL,
|
orgMembershipDAL,
|
||||||
@@ -552,10 +555,12 @@ export const registerRoutes = async (
|
|||||||
projectBotDAL,
|
projectBotDAL,
|
||||||
orgDAL,
|
orgDAL,
|
||||||
userDAL,
|
userDAL,
|
||||||
|
projectUserAdditionalPrivilegeDAL,
|
||||||
userGroupMembershipDAL,
|
userGroupMembershipDAL,
|
||||||
smtpService,
|
smtpService,
|
||||||
projectKeyDAL,
|
projectKeyDAL,
|
||||||
projectRoleDAL,
|
projectRoleDAL,
|
||||||
|
groupProjectDAL,
|
||||||
licenseService
|
licenseService
|
||||||
});
|
});
|
||||||
const projectUserAdditionalPrivilegeService = projectUserAdditionalPrivilegeServiceFactory({
|
const projectUserAdditionalPrivilegeService = projectUserAdditionalPrivilegeServiceFactory({
|
||||||
@@ -966,12 +971,20 @@ export const registerRoutes = async (
|
|||||||
kmsService
|
kmsService
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const accessTokenQueue = accessTokenQueueServiceFactory({
|
||||||
|
keyStore,
|
||||||
|
identityAccessTokenDAL,
|
||||||
|
queueService,
|
||||||
|
serviceTokenDAL
|
||||||
|
});
|
||||||
|
|
||||||
const serviceTokenService = serviceTokenServiceFactory({
|
const serviceTokenService = serviceTokenServiceFactory({
|
||||||
projectEnvDAL,
|
projectEnvDAL,
|
||||||
serviceTokenDAL,
|
serviceTokenDAL,
|
||||||
userDAL,
|
userDAL,
|
||||||
permissionService,
|
permissionService,
|
||||||
projectDAL
|
projectDAL,
|
||||||
|
accessTokenQueue
|
||||||
});
|
});
|
||||||
|
|
||||||
const identityService = identityServiceFactory({
|
const identityService = identityServiceFactory({
|
||||||
@@ -981,10 +994,13 @@ export const registerRoutes = async (
|
|||||||
identityProjectDAL,
|
identityProjectDAL,
|
||||||
licenseService
|
licenseService
|
||||||
});
|
});
|
||||||
|
|
||||||
const identityAccessTokenService = identityAccessTokenServiceFactory({
|
const identityAccessTokenService = identityAccessTokenServiceFactory({
|
||||||
identityAccessTokenDAL,
|
identityAccessTokenDAL,
|
||||||
identityOrgMembershipDAL
|
identityOrgMembershipDAL,
|
||||||
|
accessTokenQueue
|
||||||
});
|
});
|
||||||
|
|
||||||
const identityProjectService = identityProjectServiceFactory({
|
const identityProjectService = identityProjectServiceFactory({
|
||||||
permissionService,
|
permissionService,
|
||||||
projectDAL,
|
projectDAL,
|
||||||
|
|||||||
@@ -59,12 +59,19 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
|
|||||||
rateLimit: readLimit
|
rateLimit: readLimit
|
||||||
},
|
},
|
||||||
schema: {
|
schema: {
|
||||||
|
querystring: z.object({
|
||||||
|
includeGroupMembers: z
|
||||||
|
.enum(["true", "false"])
|
||||||
|
.default("false")
|
||||||
|
.transform((value) => value === "true")
|
||||||
|
}),
|
||||||
params: z.object({
|
params: z.object({
|
||||||
workspaceId: z.string().trim()
|
workspaceId: z.string().trim()
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
users: ProjectMembershipsSchema.extend({
|
users: ProjectMembershipsSchema.extend({
|
||||||
|
isGroupMember: z.boolean(),
|
||||||
user: UsersSchema.pick({
|
user: UsersSchema.pick({
|
||||||
email: true,
|
email: true,
|
||||||
username: true,
|
username: true,
|
||||||
@@ -99,9 +106,11 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
|
|||||||
actorId: req.permission.id,
|
actorId: req.permission.id,
|
||||||
actor: req.permission.type,
|
actor: req.permission.type,
|
||||||
actorAuthMethod: req.permission.authMethod,
|
actorAuthMethod: req.permission.authMethod,
|
||||||
|
includeGroupMembers: req.query.includeGroupMembers,
|
||||||
projectId: req.params.workspaceId,
|
projectId: req.params.workspaceId,
|
||||||
actorOrgId: req.permission.orgId
|
actorOrgId: req.permission.orgId
|
||||||
});
|
});
|
||||||
|
|
||||||
return { users };
|
return { users };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { KeyStorePrefixes, KeyStoreTtls, TKeyStoreFactory } from "@app/keystore/keystore";
|
||||||
|
import { applyJitter, secondsToMillis } from "@app/lib/dates";
|
||||||
|
import { logger } from "@app/lib/logger";
|
||||||
|
import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
|
||||||
|
|
||||||
|
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
|
||||||
|
import { TServiceTokenDALFactory } from "../service-token/service-token-dal";
|
||||||
|
|
||||||
|
type TAccessTokenQueueServiceFactoryDep = {
|
||||||
|
queueService: TQueueServiceFactory;
|
||||||
|
keyStore: Pick<TKeyStoreFactory, "getItem" | "setItemWithExpiry">;
|
||||||
|
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "updateById">;
|
||||||
|
serviceTokenDAL: Pick<TServiceTokenDALFactory, "updateById">;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TAccessTokenQueueServiceFactory = ReturnType<typeof accessTokenQueueServiceFactory>;
|
||||||
|
|
||||||
|
export const AccessTokenStatusSchema = z.object({
|
||||||
|
lastUpdatedAt: z.string().datetime(),
|
||||||
|
numberOfUses: z.number()
|
||||||
|
});
|
||||||
|
|
||||||
|
export const accessTokenQueueServiceFactory = ({
|
||||||
|
queueService,
|
||||||
|
keyStore,
|
||||||
|
identityAccessTokenDAL,
|
||||||
|
serviceTokenDAL
|
||||||
|
}: TAccessTokenQueueServiceFactoryDep) => {
|
||||||
|
const getIdentityTokenDetailsInCache = async (identityAccessTokenId: string) => {
|
||||||
|
const tokenDetailsInCache = await keyStore.getItem(
|
||||||
|
KeyStorePrefixes.IdentityAccessTokenStatusUpdate(identityAccessTokenId)
|
||||||
|
);
|
||||||
|
if (tokenDetailsInCache) {
|
||||||
|
return AccessTokenStatusSchema.parseAsync(JSON.parse(tokenDetailsInCache));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateServiceTokenStatus = async (serviceTokenId: string) => {
|
||||||
|
await keyStore.setItemWithExpiry(
|
||||||
|
KeyStorePrefixes.ServiceTokenStatusUpdate(serviceTokenId),
|
||||||
|
KeyStoreTtls.AccessTokenStatusUpdateInSeconds,
|
||||||
|
JSON.stringify({ lastUpdatedAt: new Date() })
|
||||||
|
);
|
||||||
|
await queueService.queue(
|
||||||
|
QueueName.AccessTokenStatusUpdate,
|
||||||
|
QueueJobs.ServiceTokenStatusUpdate,
|
||||||
|
{
|
||||||
|
serviceTokenId
|
||||||
|
},
|
||||||
|
{
|
||||||
|
delay: applyJitter(secondsToMillis(KeyStoreTtls.AccessTokenStatusUpdateInSeconds / 2), secondsToMillis(10)),
|
||||||
|
// https://docs.bullmq.io/guide/jobs/job-ids
|
||||||
|
jobId: KeyStorePrefixes.ServiceTokenStatusUpdate(serviceTokenId).replaceAll(":", "_"),
|
||||||
|
removeOnFail: true,
|
||||||
|
removeOnComplete: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateIdentityAccessTokenStatus = async (identityAccessTokenId: string, numberOfUses: number) => {
|
||||||
|
await keyStore.setItemWithExpiry(
|
||||||
|
KeyStorePrefixes.IdentityAccessTokenStatusUpdate(identityAccessTokenId),
|
||||||
|
KeyStoreTtls.AccessTokenStatusUpdateInSeconds,
|
||||||
|
JSON.stringify({ lastUpdatedAt: new Date(), numberOfUses })
|
||||||
|
);
|
||||||
|
await queueService.queue(
|
||||||
|
QueueName.AccessTokenStatusUpdate,
|
||||||
|
QueueJobs.IdentityAccessTokenStatusUpdate,
|
||||||
|
{
|
||||||
|
identityAccessTokenId,
|
||||||
|
numberOfUses
|
||||||
|
},
|
||||||
|
{
|
||||||
|
delay: applyJitter(secondsToMillis(KeyStoreTtls.AccessTokenStatusUpdateInSeconds / 2), secondsToMillis(10)),
|
||||||
|
jobId: KeyStorePrefixes.IdentityAccessTokenStatusUpdate(identityAccessTokenId).replaceAll(":", "_"),
|
||||||
|
removeOnFail: true,
|
||||||
|
removeOnComplete: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
queueService.start(QueueName.AccessTokenStatusUpdate, async (job) => {
|
||||||
|
// for identity token update
|
||||||
|
if (job.name === QueueJobs.IdentityAccessTokenStatusUpdate && "identityAccessTokenId" in job.data) {
|
||||||
|
const { identityAccessTokenId } = job.data;
|
||||||
|
const tokenDetails = { lastUpdatedAt: new Date(job.timestamp), numberOfUses: job.data.numberOfUses };
|
||||||
|
const tokenDetailsInCache = await getIdentityTokenDetailsInCache(identityAccessTokenId);
|
||||||
|
if (tokenDetailsInCache) {
|
||||||
|
tokenDetails.numberOfUses = tokenDetailsInCache.numberOfUses;
|
||||||
|
tokenDetails.lastUpdatedAt = new Date(tokenDetailsInCache.lastUpdatedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
await identityAccessTokenDAL.updateById(identityAccessTokenId, {
|
||||||
|
accessTokenLastUsedAt: tokenDetails.lastUpdatedAt,
|
||||||
|
accessTokenNumUses: tokenDetails.numberOfUses
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for service token
|
||||||
|
if (job.name === QueueJobs.ServiceTokenStatusUpdate && "serviceTokenId" in job.data) {
|
||||||
|
const { serviceTokenId } = job.data;
|
||||||
|
const tokenDetailsInCache = await keyStore.getItem(KeyStorePrefixes.ServiceTokenStatusUpdate(serviceTokenId));
|
||||||
|
let lastUsed = new Date(job.timestamp);
|
||||||
|
if (tokenDetailsInCache) {
|
||||||
|
const tokenDetails = await AccessTokenStatusSchema.pick({ lastUpdatedAt: true }).parseAsync(
|
||||||
|
JSON.parse(tokenDetailsInCache)
|
||||||
|
);
|
||||||
|
lastUsed = new Date(tokenDetails.lastUpdatedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
await serviceTokenDAL.updateById(serviceTokenId, {
|
||||||
|
lastUsed
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
queueService.listen(QueueName.AccessTokenStatusUpdate, "failed", (_, err) => {
|
||||||
|
logger.error(err, `${QueueName.AccessTokenStatusUpdate}: Failed to updated access token status`);
|
||||||
|
});
|
||||||
|
|
||||||
|
return { updateIdentityAccessTokenStatus, updateServiceTokenStatus, getIdentityTokenDetailsInCache };
|
||||||
|
};
|
||||||
@@ -368,7 +368,6 @@ export const certificateAuthorityServiceFactory = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (ca.type === CaType.ROOT) throw new BadRequestError({ message: "Root CA cannot generate CSR" });
|
if (ca.type === CaType.ROOT) throw new BadRequestError({ message: "Root CA cannot generate CSR" });
|
||||||
if (ca.activeCaCertId) throw new BadRequestError({ message: "CA already has a certificate installed" });
|
|
||||||
|
|
||||||
const { caPrivateKey, caPublicKey } = await getCaCredentials({
|
const { caPrivateKey, caPublicKey } = await getCaCredentials({
|
||||||
caId,
|
caId,
|
||||||
@@ -407,7 +406,8 @@ export const certificateAuthorityServiceFactory = ({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Renew certificate for CA with id [caId]
|
* Renew certificate for CA with id [caId]
|
||||||
* Note: Currently implements CA renewal with same key-pair only
|
* Note 1: This CA renewal method is only applicable to CAs with internal parent CAs
|
||||||
|
* Note 2: Currently implements CA renewal with same key-pair only
|
||||||
*/
|
*/
|
||||||
const renewCaCert = async ({ caId, notAfter, actorId, actorAuthMethod, actor, actorOrgId }: TRenewCaCertDTO) => {
|
const renewCaCert = async ({ caId, notAfter, actorId, actorAuthMethod, actor, actorOrgId }: TRenewCaCertDTO) => {
|
||||||
const ca = await certificateAuthorityDAL.findById(caId);
|
const ca = await certificateAuthorityDAL.findById(caId);
|
||||||
@@ -888,9 +888,9 @@ export const certificateAuthorityServiceFactory = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Import certificate for (un-installed) CA with id [caId].
|
* Import certificate for CA with id [caId].
|
||||||
* Note: Can be used to import an external certificate and certificate chain
|
* Note: Can be used to import an external certificate and certificate chain
|
||||||
* to be installed into the CA.
|
* to be into an installed or uninstalled CA.
|
||||||
*/
|
*/
|
||||||
const importCertToCa = async ({
|
const importCertToCa = async ({
|
||||||
caId,
|
caId,
|
||||||
@@ -917,7 +917,18 @@ export const certificateAuthorityServiceFactory = ({
|
|||||||
ProjectPermissionSub.CertificateAuthorities
|
ProjectPermissionSub.CertificateAuthorities
|
||||||
);
|
);
|
||||||
|
|
||||||
if (ca.activeCaCertId) throw new BadRequestError({ message: "CA has already imported a certificate" });
|
if (ca.parentCaId) {
|
||||||
|
/**
|
||||||
|
* re-evaluate in the future if we should allow users to import a new CA certificate for an intermediate
|
||||||
|
* CA chained to an internal parent CA. Doing so would allow users to re-chain the CA to a different
|
||||||
|
* internal CA.
|
||||||
|
*/
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: "Cannot import certificate to intermediate CA chained to internal parent CA"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const caCert = ca.activeCaCertId ? await certificateAuthorityCertDAL.findById(ca.activeCaCertId) : undefined;
|
||||||
|
|
||||||
const certObj = new x509.X509Certificate(certificate);
|
const certObj = new x509.X509Certificate(certificate);
|
||||||
const maxPathLength = certObj.getExtension(x509.BasicConstraintsExtension)?.pathLength;
|
const maxPathLength = certObj.getExtension(x509.BasicConstraintsExtension)?.pathLength;
|
||||||
@@ -988,7 +999,7 @@ export const certificateAuthorityServiceFactory = ({
|
|||||||
caId: ca.id,
|
caId: ca.id,
|
||||||
encryptedCertificate,
|
encryptedCertificate,
|
||||||
encryptedCertificateChain,
|
encryptedCertificateChain,
|
||||||
version: 1,
|
version: caCert ? caCert.version + 1 : 1,
|
||||||
caSecretId: caSecret.id
|
caSecretId: caSecret.id
|
||||||
},
|
},
|
||||||
tx
|
tx
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Knex } from "knex";
|
import { Knex } from "knex";
|
||||||
|
|
||||||
import { TDbClient } from "@app/db";
|
import { TDbClient } from "@app/db";
|
||||||
import { TableName } from "@app/db/schemas";
|
import { TableName, TUserEncryptionKeys } from "@app/db/schemas";
|
||||||
import { DatabaseError } from "@app/lib/errors";
|
import { DatabaseError } from "@app/lib/errors";
|
||||||
import { ormify, sqlNestRelationships } from "@app/lib/knex";
|
import { ormify, sqlNestRelationships } from "@app/lib/knex";
|
||||||
|
|
||||||
@@ -95,5 +95,107 @@ export const groupProjectDALFactory = (db: TDbClient) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return { ...groupProjectOrm, findByProjectId };
|
// The GroupProjectMembership table has a reference to the project (projectId) AND the group (groupId).
|
||||||
|
// We need to join the GroupProjectMembership table with the Groups table to get the group name and slug.
|
||||||
|
// We also need to join the GroupProjectMembershipRole table to get the role of the group in the project.
|
||||||
|
const findAllProjectGroupMembers = async (projectId: string) => {
|
||||||
|
const docs = await db(TableName.UserGroupMembership)
|
||||||
|
// Join the GroupProjectMembership table with the Groups table to get the group name and slug.
|
||||||
|
.join(
|
||||||
|
TableName.GroupProjectMembership,
|
||||||
|
`${TableName.UserGroupMembership}.groupId`,
|
||||||
|
`${TableName.GroupProjectMembership}.groupId` // this gives us access to the project id in the group membership
|
||||||
|
)
|
||||||
|
|
||||||
|
.join(TableName.Project, `${TableName.GroupProjectMembership}.projectId`, `${TableName.Project}.id`)
|
||||||
|
|
||||||
|
.where(`${TableName.GroupProjectMembership}.projectId`, projectId)
|
||||||
|
|
||||||
|
.join(TableName.Users, `${TableName.UserGroupMembership}.userId`, `${TableName.Users}.id`)
|
||||||
|
.join<TUserEncryptionKeys>(
|
||||||
|
TableName.UserEncryptionKey,
|
||||||
|
`${TableName.UserEncryptionKey}.userId`,
|
||||||
|
`${TableName.Users}.id`
|
||||||
|
)
|
||||||
|
.join(
|
||||||
|
TableName.GroupProjectMembershipRole,
|
||||||
|
`${TableName.GroupProjectMembershipRole}.projectMembershipId`,
|
||||||
|
`${TableName.GroupProjectMembership}.id`
|
||||||
|
)
|
||||||
|
.leftJoin(
|
||||||
|
TableName.ProjectRoles,
|
||||||
|
`${TableName.GroupProjectMembershipRole}.customRoleId`,
|
||||||
|
`${TableName.ProjectRoles}.id`
|
||||||
|
)
|
||||||
|
.select(
|
||||||
|
db.ref("id").withSchema(TableName.GroupProjectMembership),
|
||||||
|
db.ref("isGhost").withSchema(TableName.Users),
|
||||||
|
db.ref("username").withSchema(TableName.Users),
|
||||||
|
db.ref("email").withSchema(TableName.Users),
|
||||||
|
db.ref("publicKey").withSchema(TableName.UserEncryptionKey),
|
||||||
|
db.ref("firstName").withSchema(TableName.Users),
|
||||||
|
db.ref("lastName").withSchema(TableName.Users),
|
||||||
|
db.ref("id").withSchema(TableName.Users).as("userId"),
|
||||||
|
db.ref("role").withSchema(TableName.GroupProjectMembershipRole),
|
||||||
|
db.ref("id").withSchema(TableName.GroupProjectMembershipRole).as("membershipRoleId"),
|
||||||
|
db.ref("customRoleId").withSchema(TableName.GroupProjectMembershipRole),
|
||||||
|
db.ref("name").withSchema(TableName.ProjectRoles).as("customRoleName"),
|
||||||
|
db.ref("slug").withSchema(TableName.ProjectRoles).as("customRoleSlug"),
|
||||||
|
db.ref("temporaryMode").withSchema(TableName.GroupProjectMembershipRole),
|
||||||
|
db.ref("isTemporary").withSchema(TableName.GroupProjectMembershipRole),
|
||||||
|
db.ref("temporaryRange").withSchema(TableName.GroupProjectMembershipRole),
|
||||||
|
db.ref("temporaryAccessStartTime").withSchema(TableName.GroupProjectMembershipRole),
|
||||||
|
db.ref("temporaryAccessEndTime").withSchema(TableName.GroupProjectMembershipRole),
|
||||||
|
db.ref("name").as("projectName").withSchema(TableName.Project)
|
||||||
|
)
|
||||||
|
.where({ isGhost: false });
|
||||||
|
|
||||||
|
const members = sqlNestRelationships({
|
||||||
|
data: docs,
|
||||||
|
parentMapper: ({ email, firstName, username, lastName, publicKey, isGhost, id, userId, projectName }) => ({
|
||||||
|
isGroupMember: true,
|
||||||
|
id,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
project: {
|
||||||
|
id: projectId,
|
||||||
|
name: projectName
|
||||||
|
},
|
||||||
|
user: { email, username, firstName, lastName, id: userId, publicKey, isGhost }
|
||||||
|
}),
|
||||||
|
key: "id",
|
||||||
|
childrenMapper: [
|
||||||
|
{
|
||||||
|
label: "roles" as const,
|
||||||
|
key: "membershipRoleId",
|
||||||
|
mapper: ({
|
||||||
|
role,
|
||||||
|
customRoleId,
|
||||||
|
customRoleName,
|
||||||
|
customRoleSlug,
|
||||||
|
membershipRoleId,
|
||||||
|
temporaryRange,
|
||||||
|
temporaryMode,
|
||||||
|
temporaryAccessEndTime,
|
||||||
|
temporaryAccessStartTime,
|
||||||
|
isTemporary
|
||||||
|
}) => ({
|
||||||
|
id: membershipRoleId,
|
||||||
|
role,
|
||||||
|
customRoleId,
|
||||||
|
customRoleName,
|
||||||
|
customRoleSlug,
|
||||||
|
temporaryRange,
|
||||||
|
temporaryMode,
|
||||||
|
temporaryAccessEndTime,
|
||||||
|
temporaryAccessStartTime,
|
||||||
|
isTemporary
|
||||||
|
})
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
return members;
|
||||||
|
};
|
||||||
|
|
||||||
|
return { ...groupProjectOrm, findByProjectId, findAllProjectGroupMembers };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { getConfig } from "@app/lib/config/env";
|
|||||||
import { BadRequestError, UnauthorizedError } from "@app/lib/errors";
|
import { BadRequestError, UnauthorizedError } from "@app/lib/errors";
|
||||||
import { checkIPAgainstBlocklist, TIp } from "@app/lib/ip";
|
import { checkIPAgainstBlocklist, TIp } from "@app/lib/ip";
|
||||||
|
|
||||||
|
import { TAccessTokenQueueServiceFactory } from "../access-token-queue/access-token-queue";
|
||||||
import { AuthTokenType } from "../auth/auth-type";
|
import { AuthTokenType } from "../auth/auth-type";
|
||||||
import { TIdentityOrgDALFactory } from "../identity/identity-org-dal";
|
import { TIdentityOrgDALFactory } from "../identity/identity-org-dal";
|
||||||
import { TIdentityAccessTokenDALFactory } from "./identity-access-token-dal";
|
import { TIdentityAccessTokenDALFactory } from "./identity-access-token-dal";
|
||||||
@@ -13,19 +14,24 @@ import { TIdentityAccessTokenJwtPayload, TRenewAccessTokenDTO } from "./identity
|
|||||||
type TIdentityAccessTokenServiceFactoryDep = {
|
type TIdentityAccessTokenServiceFactoryDep = {
|
||||||
identityAccessTokenDAL: TIdentityAccessTokenDALFactory;
|
identityAccessTokenDAL: TIdentityAccessTokenDALFactory;
|
||||||
identityOrgMembershipDAL: TIdentityOrgDALFactory;
|
identityOrgMembershipDAL: TIdentityOrgDALFactory;
|
||||||
|
accessTokenQueue: Pick<
|
||||||
|
TAccessTokenQueueServiceFactory,
|
||||||
|
"updateIdentityAccessTokenStatus" | "getIdentityTokenDetailsInCache"
|
||||||
|
>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TIdentityAccessTokenServiceFactory = ReturnType<typeof identityAccessTokenServiceFactory>;
|
export type TIdentityAccessTokenServiceFactory = ReturnType<typeof identityAccessTokenServiceFactory>;
|
||||||
|
|
||||||
export const identityAccessTokenServiceFactory = ({
|
export const identityAccessTokenServiceFactory = ({
|
||||||
identityAccessTokenDAL,
|
identityAccessTokenDAL,
|
||||||
identityOrgMembershipDAL
|
identityOrgMembershipDAL,
|
||||||
|
accessTokenQueue
|
||||||
}: TIdentityAccessTokenServiceFactoryDep) => {
|
}: TIdentityAccessTokenServiceFactoryDep) => {
|
||||||
const validateAccessTokenExp = async (identityAccessToken: TIdentityAccessTokens) => {
|
const validateAccessTokenExp = async (identityAccessToken: TIdentityAccessTokens) => {
|
||||||
const {
|
const {
|
||||||
id: tokenId,
|
id: tokenId,
|
||||||
accessTokenTTL,
|
|
||||||
accessTokenNumUses,
|
accessTokenNumUses,
|
||||||
|
accessTokenTTL,
|
||||||
accessTokenNumUsesLimit,
|
accessTokenNumUsesLimit,
|
||||||
accessTokenLastRenewedAt,
|
accessTokenLastRenewedAt,
|
||||||
createdAt: accessTokenCreatedAt
|
createdAt: accessTokenCreatedAt
|
||||||
@@ -83,7 +89,12 @@ export const identityAccessTokenServiceFactory = ({
|
|||||||
});
|
});
|
||||||
if (!identityAccessToken) throw new UnauthorizedError();
|
if (!identityAccessToken) throw new UnauthorizedError();
|
||||||
|
|
||||||
await validateAccessTokenExp(identityAccessToken);
|
let { accessTokenNumUses } = identityAccessToken;
|
||||||
|
const tokenStatusInCache = await accessTokenQueue.getIdentityTokenDetailsInCache(identityAccessToken.id);
|
||||||
|
if (tokenStatusInCache) {
|
||||||
|
accessTokenNumUses = tokenStatusInCache.numberOfUses;
|
||||||
|
}
|
||||||
|
await validateAccessTokenExp({ ...identityAccessToken, accessTokenNumUses });
|
||||||
|
|
||||||
const { accessTokenMaxTTL, createdAt: accessTokenCreatedAt, accessTokenTTL } = identityAccessToken;
|
const { accessTokenMaxTTL, createdAt: accessTokenCreatedAt, accessTokenTTL } = identityAccessToken;
|
||||||
|
|
||||||
@@ -164,14 +175,14 @@ export const identityAccessTokenServiceFactory = ({
|
|||||||
throw new UnauthorizedError({ message: "Identity does not belong to any organization" });
|
throw new UnauthorizedError({ message: "Identity does not belong to any organization" });
|
||||||
}
|
}
|
||||||
|
|
||||||
await validateAccessTokenExp(identityAccessToken);
|
let { accessTokenNumUses } = identityAccessToken;
|
||||||
|
const tokenStatusInCache = await accessTokenQueue.getIdentityTokenDetailsInCache(identityAccessToken.id);
|
||||||
|
if (tokenStatusInCache) {
|
||||||
|
accessTokenNumUses = tokenStatusInCache.numberOfUses;
|
||||||
|
}
|
||||||
|
await validateAccessTokenExp({ ...identityAccessToken, accessTokenNumUses });
|
||||||
|
|
||||||
await identityAccessTokenDAL.updateById(identityAccessToken.id, {
|
await accessTokenQueue.updateIdentityAccessTokenStatus(identityAccessToken.id, Number(accessTokenNumUses) + 1);
|
||||||
accessTokenLastUsedAt: new Date(),
|
|
||||||
$incr: {
|
|
||||||
accessTokenNumUses: 1
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return { ...identityAccessToken, orgId: identityOrgMembership.orgId };
|
return { ...identityAccessToken, orgId: identityOrgMembership.orgId };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export const identityAwsAuthServiceFactory = ({
|
|||||||
}
|
}
|
||||||
}: { data: TGetCallerIdentityResponse } = await axios({
|
}: { data: TGetCallerIdentityResponse } = await axios({
|
||||||
method: iamHttpRequestMethod,
|
method: iamHttpRequestMethod,
|
||||||
url: identityAwsAuth.stsEndpoint,
|
url: headers?.Host ? `https://${headers.Host}` : identityAwsAuth.stsEndpoint,
|
||||||
headers,
|
headers,
|
||||||
data: body
|
data: body
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
|
import { TProjectUserAdditionalPrivilegeDALFactory } from "@app/ee/services/project-user-additional-privilege/project-user-additional-privilege-dal";
|
||||||
import { TOrgDALFactory } from "@app/services/org/org-dal";
|
import { TOrgDALFactory } from "@app/services/org/org-dal";
|
||||||
import { TProjectKeyDALFactory } from "@app/services/project-key/project-key-dal";
|
import { TProjectKeyDALFactory } from "@app/services/project-key/project-key-dal";
|
||||||
import { TProjectMembershipDALFactory } from "@app/services/project-membership/project-membership-dal";
|
import { TProjectMembershipDALFactory } from "@app/services/project-membership/project-membership-dal";
|
||||||
@@ -12,6 +13,7 @@ type TDeleteOrgMembership = {
|
|||||||
projectKeyDAL: Pick<TProjectKeyDALFactory, "find" | "delete">;
|
projectKeyDAL: Pick<TProjectKeyDALFactory, "find" | "delete">;
|
||||||
userAliasDAL: Pick<TUserAliasDALFactory, "delete">;
|
userAliasDAL: Pick<TUserAliasDALFactory, "delete">;
|
||||||
licenseService: Pick<TLicenseServiceFactory, "updateSubscriptionOrgMemberCount">;
|
licenseService: Pick<TLicenseServiceFactory, "updateSubscriptionOrgMemberCount">;
|
||||||
|
projectUserAdditionalPrivilegeDAL: Pick<TProjectUserAdditionalPrivilegeDALFactory, "delete">;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteOrgMembershipFn = async ({
|
export const deleteOrgMembershipFn = async ({
|
||||||
@@ -19,6 +21,7 @@ export const deleteOrgMembershipFn = async ({
|
|||||||
orgId,
|
orgId,
|
||||||
orgDAL,
|
orgDAL,
|
||||||
projectMembershipDAL,
|
projectMembershipDAL,
|
||||||
|
projectUserAdditionalPrivilegeDAL,
|
||||||
projectKeyDAL,
|
projectKeyDAL,
|
||||||
userAliasDAL,
|
userAliasDAL,
|
||||||
licenseService
|
licenseService
|
||||||
@@ -39,6 +42,13 @@ export const deleteOrgMembershipFn = async ({
|
|||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await projectUserAdditionalPrivilegeDAL.delete(
|
||||||
|
{
|
||||||
|
userId: orgMembership.userId
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
|
||||||
// Get all the project memberships of the user in the organization
|
// Get all the project memberships of the user in the organization
|
||||||
const projectMemberships = await projectMembershipDAL.findProjectMembershipsByUserId(orgId, orgMembership.userId);
|
const projectMemberships = await projectMembershipDAL.findProjectMembershipsByUserId(orgId, orgMembership.userId);
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { TGroupDALFactory } from "@app/ee/services/group/group-dal";
|
|||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
||||||
|
import { TProjectUserAdditionalPrivilegeDALFactory } from "@app/ee/services/project-user-additional-privilege/project-user-additional-privilege-dal";
|
||||||
import { TSamlConfigDALFactory } from "@app/ee/services/saml-config/saml-config-dal";
|
import { TSamlConfigDALFactory } from "@app/ee/services/saml-config/saml-config-dal";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { generateAsymmetricKeyPair } from "@app/lib/crypto";
|
import { generateAsymmetricKeyPair } from "@app/lib/crypto";
|
||||||
@@ -67,6 +68,7 @@ type TOrgServiceFactoryDep = {
|
|||||||
TLicenseServiceFactory,
|
TLicenseServiceFactory,
|
||||||
"getPlan" | "updateSubscriptionOrgMemberCount" | "generateOrgCustomerId" | "removeOrgCustomer"
|
"getPlan" | "updateSubscriptionOrgMemberCount" | "generateOrgCustomerId" | "removeOrgCustomer"
|
||||||
>;
|
>;
|
||||||
|
projectUserAdditionalPrivilegeDAL: Pick<TProjectUserAdditionalPrivilegeDALFactory, "delete">;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TOrgServiceFactory = ReturnType<typeof orgServiceFactory>;
|
export type TOrgServiceFactory = ReturnType<typeof orgServiceFactory>;
|
||||||
@@ -84,6 +86,7 @@ export const orgServiceFactory = ({
|
|||||||
projectMembershipDAL,
|
projectMembershipDAL,
|
||||||
projectKeyDAL,
|
projectKeyDAL,
|
||||||
orgMembershipDAL,
|
orgMembershipDAL,
|
||||||
|
projectUserAdditionalPrivilegeDAL,
|
||||||
tokenService,
|
tokenService,
|
||||||
orgBotDAL,
|
orgBotDAL,
|
||||||
licenseService,
|
licenseService,
|
||||||
@@ -632,6 +635,7 @@ export const orgServiceFactory = ({
|
|||||||
orgId,
|
orgId,
|
||||||
orgDAL,
|
orgDAL,
|
||||||
projectMembershipDAL,
|
projectMembershipDAL,
|
||||||
|
projectUserAdditionalPrivilegeDAL,
|
||||||
projectKeyDAL,
|
projectKeyDAL,
|
||||||
userAliasDAL,
|
userAliasDAL,
|
||||||
licenseService
|
licenseService
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||||
|
import { TProjectUserAdditionalPrivilegeDALFactory } from "@app/ee/services/project-user-additional-privilege/project-user-additional-privilege-dal";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
import { infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
||||||
import { BadRequestError } from "@app/lib/errors";
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
@@ -19,6 +20,7 @@ import { groupBy } from "@app/lib/fn";
|
|||||||
|
|
||||||
import { TUserGroupMembershipDALFactory } from "../../ee/services/group/user-group-membership-dal";
|
import { TUserGroupMembershipDALFactory } from "../../ee/services/group/user-group-membership-dal";
|
||||||
import { ActorType } from "../auth/auth-type";
|
import { ActorType } from "../auth/auth-type";
|
||||||
|
import { TGroupProjectDALFactory } from "../group-project/group-project-dal";
|
||||||
import { TOrgDALFactory } from "../org/org-dal";
|
import { TOrgDALFactory } from "../org/org-dal";
|
||||||
import { TProjectDALFactory } from "../project/project-dal";
|
import { TProjectDALFactory } from "../project/project-dal";
|
||||||
import { assignWorkspaceKeysToMembers } from "../project/project-fns";
|
import { assignWorkspaceKeysToMembers } from "../project/project-fns";
|
||||||
@@ -54,6 +56,8 @@ type TProjectMembershipServiceFactoryDep = {
|
|||||||
projectDAL: Pick<TProjectDALFactory, "findById" | "findProjectGhostUser" | "transaction">;
|
projectDAL: Pick<TProjectDALFactory, "findById" | "findProjectGhostUser" | "transaction">;
|
||||||
projectKeyDAL: Pick<TProjectKeyDALFactory, "findLatestProjectKey" | "delete" | "insertMany">;
|
projectKeyDAL: Pick<TProjectKeyDALFactory, "findLatestProjectKey" | "delete" | "insertMany">;
|
||||||
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
|
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
|
||||||
|
projectUserAdditionalPrivilegeDAL: Pick<TProjectUserAdditionalPrivilegeDALFactory, "delete">;
|
||||||
|
groupProjectDAL: TGroupProjectDALFactory;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TProjectMembershipServiceFactory = ReturnType<typeof projectMembershipServiceFactory>;
|
export type TProjectMembershipServiceFactory = ReturnType<typeof projectMembershipServiceFactory>;
|
||||||
@@ -66,8 +70,10 @@ export const projectMembershipServiceFactory = ({
|
|||||||
projectRoleDAL,
|
projectRoleDAL,
|
||||||
projectBotDAL,
|
projectBotDAL,
|
||||||
orgDAL,
|
orgDAL,
|
||||||
|
projectUserAdditionalPrivilegeDAL,
|
||||||
userDAL,
|
userDAL,
|
||||||
userGroupMembershipDAL,
|
userGroupMembershipDAL,
|
||||||
|
groupProjectDAL,
|
||||||
projectDAL,
|
projectDAL,
|
||||||
projectKeyDAL,
|
projectKeyDAL,
|
||||||
licenseService
|
licenseService
|
||||||
@@ -77,6 +83,7 @@ export const projectMembershipServiceFactory = ({
|
|||||||
actor,
|
actor,
|
||||||
actorOrgId,
|
actorOrgId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
|
includeGroupMembers,
|
||||||
projectId
|
projectId
|
||||||
}: TGetProjectMembershipDTO) => {
|
}: TGetProjectMembershipDTO) => {
|
||||||
const { permission } = await permissionService.getProjectPermission(
|
const { permission } = await permissionService.getProjectPermission(
|
||||||
@@ -88,7 +95,25 @@ export const projectMembershipServiceFactory = ({
|
|||||||
);
|
);
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Member);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Member);
|
||||||
|
|
||||||
return projectMembershipDAL.findAllProjectMembers(projectId);
|
const projectMembers = await projectMembershipDAL.findAllProjectMembers(projectId);
|
||||||
|
|
||||||
|
// projectMembers[0].project
|
||||||
|
if (includeGroupMembers) {
|
||||||
|
const groupMembers = await groupProjectDAL.findAllProjectGroupMembers(projectId);
|
||||||
|
|
||||||
|
const allMembers = [
|
||||||
|
...projectMembers.map((m) => ({ ...m, isGroupMember: false })),
|
||||||
|
...groupMembers.map((m) => ({ ...m, isGroupMember: true }))
|
||||||
|
];
|
||||||
|
|
||||||
|
// Ensure the userId is unique
|
||||||
|
const membersIds = new Set(allMembers.map((entity) => entity.user.id));
|
||||||
|
const uniqueMembers = allMembers.filter((entity) => membersIds.has(entity.user.id));
|
||||||
|
|
||||||
|
return uniqueMembers;
|
||||||
|
}
|
||||||
|
|
||||||
|
return projectMembers.map((m) => ({ ...m, isGroupMember: false }));
|
||||||
};
|
};
|
||||||
|
|
||||||
const getProjectMembershipByUsername = async ({
|
const getProjectMembershipByUsername = async ({
|
||||||
@@ -502,6 +527,16 @@ export const projectMembershipServiceFactory = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const memberships = await projectMembershipDAL.transaction(async (tx) => {
|
const memberships = await projectMembershipDAL.transaction(async (tx) => {
|
||||||
|
await projectUserAdditionalPrivilegeDAL.delete(
|
||||||
|
{
|
||||||
|
projectId,
|
||||||
|
$in: {
|
||||||
|
userId: projectMembers.map((membership) => membership.user.id)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
|
||||||
const deletedMemberships = await projectMembershipDAL.delete(
|
const deletedMemberships = await projectMembershipDAL.delete(
|
||||||
{
|
{
|
||||||
projectId,
|
projectId,
|
||||||
@@ -564,12 +599,25 @@ export const projectMembershipServiceFactory = ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const deletedMembership = (
|
const deletedMembership = await projectMembershipDAL.transaction(async (tx) => {
|
||||||
await projectMembershipDAL.delete({
|
await projectUserAdditionalPrivilegeDAL.delete(
|
||||||
projectId: project.id,
|
{
|
||||||
userId: actorId
|
projectId: project.id,
|
||||||
})
|
userId: actorId
|
||||||
)?.[0];
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
const membership = (
|
||||||
|
await projectMembershipDAL.delete(
|
||||||
|
{
|
||||||
|
projectId: project.id,
|
||||||
|
userId: actorId
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
)
|
||||||
|
)?.[0];
|
||||||
|
return membership;
|
||||||
|
});
|
||||||
|
|
||||||
if (!deletedMembership) {
|
if (!deletedMembership) {
|
||||||
throw new BadRequestError({ message: "Failed to leave project" });
|
throw new BadRequestError({ message: "Failed to leave project" });
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { TProjectPermission } from "@app/lib/types";
|
import { TProjectPermission } from "@app/lib/types";
|
||||||
|
|
||||||
export type TGetProjectMembershipDTO = TProjectPermission;
|
export type TGetProjectMembershipDTO = { includeGroupMembers?: boolean } & TProjectPermission;
|
||||||
export type TLeaveProjectDTO = Omit<TProjectPermission, "actorOrgId" | "actorAuthMethod">;
|
export type TLeaveProjectDTO = Omit<TProjectPermission, "actorOrgId" | "actorAuthMethod">;
|
||||||
export enum ProjectUserMembershipTemporaryMode {
|
export enum ProjectUserMembershipTemporaryMode {
|
||||||
Relative = "relative"
|
Relative = "relative"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services
|
|||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { BadRequestError, UnauthorizedError } from "@app/lib/errors";
|
import { BadRequestError, UnauthorizedError } from "@app/lib/errors";
|
||||||
|
|
||||||
|
import { TAccessTokenQueueServiceFactory } from "../access-token-queue/access-token-queue";
|
||||||
import { ActorType } from "../auth/auth-type";
|
import { ActorType } from "../auth/auth-type";
|
||||||
import { TProjectDALFactory } from "../project/project-dal";
|
import { TProjectDALFactory } from "../project/project-dal";
|
||||||
import { TProjectEnvDALFactory } from "../project-env/project-env-dal";
|
import { TProjectEnvDALFactory } from "../project-env/project-env-dal";
|
||||||
@@ -26,6 +27,7 @@ type TServiceTokenServiceFactoryDep = {
|
|||||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||||
projectEnvDAL: Pick<TProjectEnvDALFactory, "findBySlugs">;
|
projectEnvDAL: Pick<TProjectEnvDALFactory, "findBySlugs">;
|
||||||
projectDAL: Pick<TProjectDALFactory, "findById">;
|
projectDAL: Pick<TProjectDALFactory, "findById">;
|
||||||
|
accessTokenQueue: Pick<TAccessTokenQueueServiceFactory, "updateServiceTokenStatus">;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TServiceTokenServiceFactory = ReturnType<typeof serviceTokenServiceFactory>;
|
export type TServiceTokenServiceFactory = ReturnType<typeof serviceTokenServiceFactory>;
|
||||||
@@ -35,7 +37,8 @@ export const serviceTokenServiceFactory = ({
|
|||||||
userDAL,
|
userDAL,
|
||||||
permissionService,
|
permissionService,
|
||||||
projectEnvDAL,
|
projectEnvDAL,
|
||||||
projectDAL
|
projectDAL,
|
||||||
|
accessTokenQueue
|
||||||
}: TServiceTokenServiceFactoryDep) => {
|
}: TServiceTokenServiceFactoryDep) => {
|
||||||
const createServiceToken = async ({
|
const createServiceToken = async ({
|
||||||
iv,
|
iv,
|
||||||
@@ -166,11 +169,9 @@ export const serviceTokenServiceFactory = ({
|
|||||||
|
|
||||||
const isMatch = await bcrypt.compare(TOKEN_SECRET, serviceToken.secretHash);
|
const isMatch = await bcrypt.compare(TOKEN_SECRET, serviceToken.secretHash);
|
||||||
if (!isMatch) throw new UnauthorizedError();
|
if (!isMatch) throw new UnauthorizedError();
|
||||||
const updatedToken = await serviceTokenDAL.updateById(serviceToken.id, {
|
await accessTokenQueue.updateServiceTokenStatus(serviceToken.id);
|
||||||
lastUsed: new Date()
|
|
||||||
});
|
|
||||||
|
|
||||||
return { ...serviceToken, lastUsed: updatedToken.lastUsed, orgId: project.orgId };
|
return { ...serviceToken, lastUsed: new Date(), orgId: project.orgId };
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ graph TD
|
|||||||
|
|
||||||
A typical workflow for setting up a Private CA hierarchy consists of the following steps:
|
A typical workflow for setting up a Private CA hierarchy consists of the following steps:
|
||||||
|
|
||||||
1. Configuring a root CA with details like name, validity period, and path length.
|
1. Configuring an Infisical root CA with details like name, validity period, and path length — This step is optional if you wish to use an external root CA.
|
||||||
2. Configuring and chaining intermediate CA(s) with details like name, validity period, path length, and imported certificate.
|
2. Configuring and chaining intermediate CA(s) with details like name, validity period, path length, and imported certificate to your Root CA.
|
||||||
3. Managing the CA lifecycle events such as CA succession.
|
3. Managing the CA lifecycle events such as CA succession.
|
||||||
|
|
||||||
<Note>
|
<Note>
|
||||||
@@ -39,19 +39,21 @@ A typical workflow for setting up a Private CA hierarchy consists of the followi
|
|||||||
## Guide to Creating a CA Hierarchy
|
## Guide to Creating a CA Hierarchy
|
||||||
|
|
||||||
In the following steps, we explore how to create a simple Private CA hierarchy
|
In the following steps, we explore how to create a simple Private CA hierarchy
|
||||||
consisting of a root CA and an intermediate CA.
|
consisting of an (optional) root CA and an intermediate CA.
|
||||||
|
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<Tab title="Infisical UI">
|
<Tab title="Infisical UI">
|
||||||
<Steps>
|
<Steps>
|
||||||
<Step title="Creating a root CA">
|
<Step title="Creating a root CA">
|
||||||
|
If you wish to use an external root CA, you can skip this step and head to step 2 to create an intermediate CA.
|
||||||
|
|
||||||
To create a root CA, head to your Project > Internal PKI > Certificate Authorities and press **Create CA**.
|
To create a root CA, head to your Project > Internal PKI > Certificate Authorities and press **Create CA**.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Here, set the **CA Type** to **Root** and fill out details for the root CA.
|
Here, set the **CA Type** to **Root** and fill out details for the root CA.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Here's some guidance on each field:
|
Here's some guidance on each field:
|
||||||
|
|
||||||
@@ -71,17 +73,19 @@ consisting of a root CA and an intermediate CA.
|
|||||||
</Note>
|
</Note>
|
||||||
</Step>
|
</Step>
|
||||||
<Step title="Creating an intermediate CA">
|
<Step title="Creating an intermediate CA">
|
||||||
1.1. To create an intermediate CA, press **Create CA** again but this time specifying the **CA Type** to be **Intermediate**. Fill out the details for the intermediate CA.
|
2.1. To create an intermediate CA, press **Create CA** again but this time specifying the **CA Type** to be **Intermediate**. Fill out the details for the intermediate CA.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
1.2. Next, press the **Install Certificate** option on the intermediate CA from step 1.1.
|
2.2. Next, press the **Install Certificate** option on the intermediate CA from step 1.1.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Here, set the **Parent CA** to the root CA created in step 1 and configure the intended **Valid Until** and **Path Length** fields on the intermediate CA; feel free to use the prefilled values.
|
2.3a. If you created a root CA in step 1, select **Infisical CA** for the **Parent CA Type** field.
|
||||||
|
|
||||||

|
Next, set the **Parent CA** to the root CA created in step 1 and configure the intended **Valid Until** and **Path Length** fields on the intermediate CA; feel free to use the prefilled values.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
Here's some guidance on each field:
|
Here's some guidance on each field:
|
||||||
|
|
||||||
@@ -91,17 +95,30 @@ consisting of a root CA and an intermediate CA.
|
|||||||
|
|
||||||
Finally, press **Install** to chain the intermediate CA to the root CA; this creates a Certificate Signing Request (CSR) for the intermediate CA, creates an intermediate certificate using the root CA private key and CSR, and imports the signed certificate back to the intermediate CA.
|
Finally, press **Install** to chain the intermediate CA to the root CA; this creates a Certificate Signing Request (CSR) for the intermediate CA, creates an intermediate certificate using the root CA private key and CSR, and imports the signed certificate back to the intermediate CA.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Great! You've successfully created a Private CA hierarchy with a root CA and an intermediate CA.
|
Great! You've successfully created a Private CA hierarchy with a root CA and an intermediate CA.
|
||||||
Now check out the [Certificates](/documentation/platform/pki/certificates) page to learn more about how to issue X.509 certificates using the intermediate CA.
|
Now check out the [Certificates](/documentation/platform/pki/certificates) page to learn more about how to issue X.509 certificates using the intermediate CA.
|
||||||
|
|
||||||
|
2.3b. If you have an external root CA, select **External CA** for the **Parent CA Type** field.
|
||||||
|
|
||||||
|
Next, use the provided intermediate CSR to generate a certificate from your external root CA and paste the PEM-encoded certificate back into the **Certificate Body** field; the PEM-encoded external root CA certificate should be pasted under the **Certificate Chain** field.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Finally, press **Install** to import the certificate and certificate chain as part of the installation step for the intermediate CA
|
||||||
|
|
||||||
|
Great! You've successfully created a Private CA hierarchy with an intermediate CA chained to an external root CA.
|
||||||
|
Now check out the [Certificates](/documentation/platform/pki/certificates) page to learn more about how to issue X.509 certificates using the intermediate CA.
|
||||||
|
|
||||||
</Step>
|
</Step>
|
||||||
</Steps>
|
</Steps>
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab title="API">
|
<Tab title="API">
|
||||||
<Steps>
|
<Steps>
|
||||||
<Step title="Creating a root CA">
|
<Step title="Creating a root CA">
|
||||||
|
If you wish to use an external root CA, you can skip this step and head to step 2 to create an intermediate CA.
|
||||||
|
|
||||||
To create a root CA, make an API request to the [Create CA](/api-reference/endpoints/certificate-authorities/create) API endpoint, specifying the `type` as `root`.
|
To create a root CA, make an API request to the [Create CA](/api-reference/endpoints/certificate-authorities/create) API endpoint, specifying the `type` as `root`.
|
||||||
|
|
||||||
### Sample request
|
### Sample request
|
||||||
@@ -181,6 +198,8 @@ consisting of a root CA and an intermediate CA.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If using an external root CA, then use the CSR to generate a certificate for the intermediate CA using your external root CA and skip to step 2.4.
|
||||||
|
|
||||||
2.3. Next, create an intermediate certificate by making an API request to the [Sign Intermediate](/api-reference/endpoints/certificate-authorities/sign-intermediate) API endpoint
|
2.3. Next, create an intermediate certificate by making an API request to the [Sign Intermediate](/api-reference/endpoints/certificate-authorities/sign-intermediate) API endpoint
|
||||||
containing the CSR from step 2.2, referencing the root CA created in step 1.
|
containing the CSR from step 2.2, referencing the root CA created in step 1.
|
||||||
|
|
||||||
@@ -212,6 +231,8 @@ consisting of a root CA and an intermediate CA.
|
|||||||
|
|
||||||
2.4. Finally, import the intermediate certificate and certificate chain from step 2.3 back to the intermediate CA by making an API request to the [Import Certificate](/api-reference/endpoints/certificate-authorities/import-cert) API endpoint.
|
2.4. Finally, import the intermediate certificate and certificate chain from step 2.3 back to the intermediate CA by making an API request to the [Import Certificate](/api-reference/endpoints/certificate-authorities/import-cert) API endpoint.
|
||||||
|
|
||||||
|
If using an external root CA, then import the generated certificate and root CA certificate under certificate chain back into the intermediate CA.
|
||||||
|
|
||||||
### Sample request
|
### Sample request
|
||||||
|
|
||||||
```bash Request
|
```bash Request
|
||||||
@@ -242,7 +263,17 @@ consisting of a root CA and an intermediate CA.
|
|||||||
|
|
||||||
## Guide to CA Renewal
|
## Guide to CA Renewal
|
||||||
|
|
||||||
In the following steps, we explore how to renew a CA certificate via same key pair.
|
In the following steps, we explore how to renew a CA certificate.
|
||||||
|
|
||||||
|
<Note>
|
||||||
|
If renewing an intermediate CA chained to an Infisical CA, then Infisical will
|
||||||
|
automate the process of generating a new certificate for the intermediate CA for you.
|
||||||
|
|
||||||
|
If renewing an intermediate CA chained to an external parent CA, you'll be
|
||||||
|
required to generate a new certificate from the external parent CA and manually import
|
||||||
|
the certificate back to the intermediate CA.
|
||||||
|
|
||||||
|
</Note>
|
||||||
|
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<Tab title="Infisical UI">
|
<Tab title="Infisical UI">
|
||||||
@@ -296,4 +327,10 @@ In the following steps, we explore how to renew a CA certificate via same key pa
|
|||||||
At the moment, Infisical only supports CA renewal via same key pair. We
|
At the moment, Infisical only supports CA renewal via same key pair. We
|
||||||
anticipate supporting CA renewal via new key pair in the coming month.
|
anticipate supporting CA renewal via new key pair in the coming month.
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
<Accordion title="Does Infisical support chaining an Intermediate CA to an external Root CA?">
|
||||||
|
Yes. You may obtain a CSR from the Intermediate CA and use it to generate a
|
||||||
|
certificate from your external Root CA. The certificate, along with the Root
|
||||||
|
CA certificate, can be imported back to the Intermediate CA as part of the
|
||||||
|
CA installation step.
|
||||||
|
</Accordion>
|
||||||
</AccordionGroup>
|
</AccordionGroup>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 396 KiB |
|
Before Width: | Height: | Size: 416 KiB |
|
Before Width: | Height: | Size: 584 KiB |
|
Before Width: | Height: | Size: 618 KiB |
|
Before Width: | Height: | Size: 380 KiB |
|
After Width: | Height: | Size: 439 KiB |
|
After Width: | Height: | Size: 417 KiB |
|
After Width: | Height: | Size: 671 KiB |
|
After Width: | Height: | Size: 775 KiB |
|
After Width: | Height: | Size: 693 KiB |
|
After Width: | Height: | Size: 370 KiB |
|
After Width: | Height: | Size: 488 KiB |
|
Before Width: | Height: | Size: 492 KiB |
@@ -11,7 +11,7 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const textAreaVariants = cva(
|
const textAreaVariants = cva(
|
||||||
"textarea w-full p-2 focus:ring-2 ring-primary-800 outline-none border border-solid text-gray-400 font-inter placeholder-gray-500 placeholder-opacity-50",
|
"textarea w-full p-2 focus:ring-2 ring-primary-800 outline-none border text-gray-400 font-inter placeholder-gray-500 placeholder-opacity-50",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
size: {
|
size: {
|
||||||
@@ -25,13 +25,13 @@ const textAreaVariants = cva(
|
|||||||
false: ""
|
false: ""
|
||||||
},
|
},
|
||||||
variant: {
|
variant: {
|
||||||
filled: ["bg-bunker-800", "text-gray-400"],
|
filled: ["bg-mineshaft-900", "text-gray-400"],
|
||||||
outline: ["bg-transparent"],
|
outline: ["bg-transparent"],
|
||||||
plain: "bg-transparent outline-none"
|
plain: "bg-transparent outline-none"
|
||||||
},
|
},
|
||||||
isError: {
|
isError: {
|
||||||
true: "focus:ring-red/50 placeholder-red-300 border-red",
|
true: "focus:ring-red/50 placeholder-red-300 border-red",
|
||||||
false: "focus:ring-primary/50 border-mineshaft-400"
|
false: "focus:ring-primary-400/50 focus:ring-1 border-mineshaft-500"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
compoundVariants: [
|
compoundVariants: [
|
||||||
|
|||||||
@@ -44,6 +44,13 @@ export type ProjectPermissionSet =
|
|||||||
ProjectPermissionActions,
|
ProjectPermissionActions,
|
||||||
ProjectPermissionSub.Secrets | (ForcedSubject<ProjectPermissionSub.Secrets> & SubjectFields)
|
ProjectPermissionSub.Secrets | (ForcedSubject<ProjectPermissionSub.Secrets> & SubjectFields)
|
||||||
]
|
]
|
||||||
|
| [
|
||||||
|
ProjectPermissionActions,
|
||||||
|
(
|
||||||
|
| ProjectPermissionSub.SecretFolders
|
||||||
|
| (ForcedSubject<ProjectPermissionSub.SecretFolders> & SubjectFields)
|
||||||
|
)
|
||||||
|
]
|
||||||
| [ProjectPermissionActions, ProjectPermissionSub.Role]
|
| [ProjectPermissionActions, ProjectPermissionSub.Role]
|
||||||
| [ProjectPermissionActions, ProjectPermissionSub.Tags]
|
| [ProjectPermissionActions, ProjectPermissionSub.Tags]
|
||||||
| [ProjectPermissionActions, ProjectPermissionSub.Member]
|
| [ProjectPermissionActions, ProjectPermissionSub.Member]
|
||||||
|
|||||||
@@ -16,12 +16,20 @@ export const useCreateAccessApprovalPolicy = () => {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
return useMutation<{}, {}, TCreateAccessPolicyDTO>({
|
return useMutation<{}, {}, TCreateAccessPolicyDTO>({
|
||||||
mutationFn: async ({ environment, projectSlug, approvals, approvers, name, secretPath, enforcementLevel }) => {
|
mutationFn: async ({
|
||||||
|
environment,
|
||||||
|
projectSlug,
|
||||||
|
approvals,
|
||||||
|
approverUserIds,
|
||||||
|
name,
|
||||||
|
secretPath,
|
||||||
|
enforcementLevel
|
||||||
|
}) => {
|
||||||
const { data } = await apiRequest.post("/api/v1/access-approvals/policies", {
|
const { data } = await apiRequest.post("/api/v1/access-approvals/policies", {
|
||||||
environment,
|
environment,
|
||||||
projectSlug,
|
projectSlug,
|
||||||
approvals,
|
approvals,
|
||||||
approvers,
|
approverUserIds,
|
||||||
secretPath,
|
secretPath,
|
||||||
name,
|
name,
|
||||||
enforcementLevel
|
enforcementLevel
|
||||||
|
|||||||
@@ -23,7 +23,14 @@ export type TAccessApprovalRequest = {
|
|||||||
id: string;
|
id: string;
|
||||||
policyId: string;
|
policyId: string;
|
||||||
privilegeId: string | null;
|
privilegeId: string | null;
|
||||||
requestedBy: string;
|
requestedByUserId: string;
|
||||||
|
requestedByUser: {
|
||||||
|
email: string;
|
||||||
|
firstName?: string;
|
||||||
|
lastName?: string;
|
||||||
|
userId: string;
|
||||||
|
username: string;
|
||||||
|
};
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
isTemporary: boolean;
|
isTemporary: boolean;
|
||||||
@@ -123,7 +130,7 @@ export type TCreateAccessPolicyDTO = {
|
|||||||
projectSlug: string;
|
projectSlug: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
environment: string;
|
environment: string;
|
||||||
approvers?: string[];
|
approverUserIds?: string[];
|
||||||
approvals?: number;
|
approvals?: number;
|
||||||
secretPath?: string;
|
secretPath?: string;
|
||||||
enforcementLevel?: EnforcementLevel;
|
enforcementLevel?: EnforcementLevel;
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export const ERROR_NOT_ALLOWED_READ_SECRETS = "You are not allowed to read on secrets";
|
||||||
@@ -7,6 +7,7 @@ import { createNotification } from "@app/components/notifications";
|
|||||||
import { apiRequest } from "@app/config/request";
|
import { apiRequest } from "@app/config/request";
|
||||||
import { useToggle } from "@app/hooks/useToggle";
|
import { useToggle } from "@app/hooks/useToggle";
|
||||||
|
|
||||||
|
import { ERROR_NOT_ALLOWED_READ_SECRETS } from "./constants";
|
||||||
import {
|
import {
|
||||||
GetSecretVersionsDTO,
|
GetSecretVersionsDTO,
|
||||||
SecretType,
|
SecretType,
|
||||||
@@ -135,11 +136,13 @@ export const useGetProjectSecretsAllEnv = ({
|
|||||||
onError: (error: unknown) => {
|
onError: (error: unknown) => {
|
||||||
if (axios.isAxiosError(error) && !isErrorHandled) {
|
if (axios.isAxiosError(error) && !isErrorHandled) {
|
||||||
const serverResponse = error.response?.data as { message: string };
|
const serverResponse = error.response?.data as { message: string };
|
||||||
createNotification({
|
if (serverResponse.message !== ERROR_NOT_ALLOWED_READ_SECRETS) {
|
||||||
title: "Error fetching secrets",
|
createNotification({
|
||||||
type: "error",
|
title: "Error fetching secrets",
|
||||||
text: serverResponse.message
|
type: "error",
|
||||||
});
|
text: serverResponse.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
setIsErrorHandled.on();
|
setIsErrorHandled.on();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ export type TWorkspaceUser = {
|
|||||||
publicKey: string;
|
publicKey: string;
|
||||||
};
|
};
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
isGroupMember: boolean;
|
||||||
project: {
|
project: {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|||||||
@@ -377,14 +377,19 @@ export const useDeleteWsEnvironment = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useGetWorkspaceUsers = (workspaceId: string) => {
|
export const useGetWorkspaceUsers = (workspaceId: string, includeGroupMembers?: boolean) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: workspaceKeys.getWorkspaceUsers(workspaceId),
|
queryKey: workspaceKeys.getWorkspaceUsers(workspaceId),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const {
|
const {
|
||||||
data: { users }
|
data: { users }
|
||||||
} = await apiRequest.get<{ users: TWorkspaceUser[] }>(
|
} = await apiRequest.get<{ users: TWorkspaceUser[] }>(
|
||||||
`/api/v1/workspace/${workspaceId}/users`
|
`/api/v1/workspace/${workspaceId}/users`,
|
||||||
|
{
|
||||||
|
params: {
|
||||||
|
includeGroupMembers
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
return users;
|
return users;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { ProjectPermissionCan } from "@app/components/permissions";
|
|||||||
import { Button, IconButton, Tooltip } from "@app/components/v2";
|
import { Button, IconButton, Tooltip } from "@app/components/v2";
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context";
|
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context";
|
||||||
import { useTimedReset } from "@app/hooks";
|
import { useTimedReset } from "@app/hooks";
|
||||||
import { CaStatus, useGetCaById } from "@app/hooks/api";
|
import { CaStatus, CaType, useGetCaById } from "@app/hooks/api";
|
||||||
import { caStatusToNameMap, caTypeToNameMap } from "@app/hooks/api/ca/constants";
|
import { caStatusToNameMap, caTypeToNameMap } from "@app/hooks/api/ca/constants";
|
||||||
import { certKeyAlgorithmToNameMap } from "@app/hooks/api/certificates/constants";
|
import { certKeyAlgorithmToNameMap } from "@app/hooks/api/certificates/constants";
|
||||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||||
@@ -35,6 +35,10 @@ export const CaDetailsSection = ({ caId, handlePopUpOpen }: Props) => {
|
|||||||
<h3 className="text-lg font-semibold text-mineshaft-100">CA Details</h3>
|
<h3 className="text-lg font-semibold text-mineshaft-100">CA Details</h3>
|
||||||
</div>
|
</div>
|
||||||
<div className="pt-4">
|
<div className="pt-4">
|
||||||
|
<div className="mb-4">
|
||||||
|
<p className="text-sm font-semibold text-mineshaft-300">CA Type</p>
|
||||||
|
<p className="text-sm text-mineshaft-300">{caTypeToNameMap[ca.type]}</p>
|
||||||
|
</div>
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<p className="text-sm font-semibold text-mineshaft-300">CA ID</p>
|
<p className="text-sm font-semibold text-mineshaft-300">CA ID</p>
|
||||||
<div className="group flex align-top">
|
<div className="group flex align-top">
|
||||||
@@ -56,26 +60,30 @@ export const CaDetailsSection = ({ caId, handlePopUpOpen }: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{ca.parentCaId && (
|
{ca.type === CaType.INTERMEDIATE && ca.status !== CaStatus.PENDING_CERTIFICATE && (
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<p className="text-sm font-semibold text-mineshaft-300">Parent CA ID</p>
|
<p className="text-sm font-semibold text-mineshaft-300">Parent CA ID</p>
|
||||||
<div className="group flex align-top">
|
<div className="group flex align-top">
|
||||||
<p className="text-sm text-mineshaft-300">{ca.parentCaId}</p>
|
<p className="text-sm text-mineshaft-300">
|
||||||
<div className="opacity-0 transition-opacity duration-300 group-hover:opacity-100">
|
{ca.parentCaId ? ca.parentCaId : "N/A - External Parent CA"}
|
||||||
<Tooltip content={copyTextParentId}>
|
</p>
|
||||||
<IconButton
|
{ca.parentCaId && (
|
||||||
ariaLabel="copy icon"
|
<div className="opacity-0 transition-opacity duration-300 group-hover:opacity-100">
|
||||||
variant="plain"
|
<Tooltip content={copyTextParentId}>
|
||||||
className="group relative ml-2"
|
<IconButton
|
||||||
onClick={() => {
|
ariaLabel="copy icon"
|
||||||
navigator.clipboard.writeText(ca.parentCaId as string);
|
variant="plain"
|
||||||
setCopyTextParentId("Copied");
|
className="group relative ml-2"
|
||||||
}}
|
onClick={() => {
|
||||||
>
|
navigator.clipboard.writeText(ca.parentCaId as string);
|
||||||
<FontAwesomeIcon icon={isCopyingParentId ? faCheck : faCopy} />
|
setCopyTextParentId("Copied");
|
||||||
</IconButton>
|
}}
|
||||||
</Tooltip>
|
>
|
||||||
</div>
|
<FontAwesomeIcon icon={isCopyingParentId ? faCheck : faCopy} />
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -83,10 +91,6 @@ export const CaDetailsSection = ({ caId, handlePopUpOpen }: Props) => {
|
|||||||
<p className="text-sm font-semibold text-mineshaft-300">Friendly Name</p>
|
<p className="text-sm font-semibold text-mineshaft-300">Friendly Name</p>
|
||||||
<p className="text-sm text-mineshaft-300">{ca.friendlyName}</p>
|
<p className="text-sm text-mineshaft-300">{ca.friendlyName}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="mb-4">
|
|
||||||
<p className="text-sm font-semibold text-mineshaft-300">CA Type</p>
|
|
||||||
<p className="text-sm text-mineshaft-300">{caTypeToNameMap[ca.type]}</p>
|
|
||||||
</div>
|
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<p className="text-sm font-semibold text-mineshaft-300">Status</p>
|
<p className="text-sm font-semibold text-mineshaft-300">Status</p>
|
||||||
<p className="text-sm text-mineshaft-300">{caStatusToNameMap[ca.status]}</p>
|
<p className="text-sm text-mineshaft-300">{caStatusToNameMap[ca.status]}</p>
|
||||||
@@ -124,6 +128,15 @@ export const CaDetailsSection = ({ caId, handlePopUpOpen }: Props) => {
|
|||||||
colorSchema="primary"
|
colorSchema="primary"
|
||||||
type="submit"
|
type="submit"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
if (ca.type === CaType.INTERMEDIATE && !ca.parentCaId) {
|
||||||
|
// intermediate CA with external parent CA
|
||||||
|
handlePopUpOpen("installCaCert", {
|
||||||
|
caId,
|
||||||
|
isParentCaExternal: true
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
handlePopUpOpen("renewCa", {
|
handlePopUpOpen("renewCa", {
|
||||||
caId
|
caId
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,53 +1,10 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
|
||||||
import { format } from "date-fns";
|
|
||||||
import { z } from "zod";
|
|
||||||
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
import { FormControl, Modal, ModalContent, Select, SelectItem } from "@app/components/v2";
|
||||||
import {
|
|
||||||
// DatePicker,
|
|
||||||
Button,
|
|
||||||
FormControl,
|
|
||||||
Input,
|
|
||||||
Modal,
|
|
||||||
ModalContent,
|
|
||||||
Select,
|
|
||||||
SelectItem
|
|
||||||
} from "@app/components/v2";
|
|
||||||
import { useWorkspace } from "@app/context";
|
|
||||||
import {
|
|
||||||
CaStatus,
|
|
||||||
useGetCaById,
|
|
||||||
useGetCaCsr,
|
|
||||||
useImportCaCertificate,
|
|
||||||
useListWorkspaceCas,
|
|
||||||
useSignIntermediate
|
|
||||||
} from "@app/hooks/api";
|
|
||||||
import { caTypeToNameMap } from "@app/hooks/api/ca/constants";
|
|
||||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||||
|
|
||||||
const isValidDate = (dateString: string) => {
|
import { ExternalCaInstallForm } from "./ExternalCaInstallForm";
|
||||||
const date = new Date(dateString);
|
import { InternalCaInstallForm } from "./InternalCaInstallForm";
|
||||||
return !Number.isNaN(date.getTime());
|
|
||||||
};
|
|
||||||
|
|
||||||
const getMiddleDate = (date1: Date, date2: Date) => {
|
|
||||||
const timestamp1 = date1.getTime();
|
|
||||||
const timestamp2 = date2.getTime();
|
|
||||||
|
|
||||||
const middleTimestamp = (timestamp1 + timestamp2) / 2;
|
|
||||||
|
|
||||||
return new Date(middleTimestamp);
|
|
||||||
};
|
|
||||||
|
|
||||||
const schema = z.object({
|
|
||||||
parentCaId: z.string(),
|
|
||||||
notAfter: z.string().trim().refine(isValidDate, { message: "Invalid date format" }),
|
|
||||||
maxPathLength: z.string()
|
|
||||||
});
|
|
||||||
|
|
||||||
export type FormData = z.infer<typeof schema>;
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
popUp: UsePopUpState<["installCaCert"]>;
|
popUp: UsePopUpState<["installCaCert"]>;
|
||||||
@@ -60,234 +17,23 @@ enum ParentCaType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const CaInstallCertModal = ({ popUp, handlePopUpToggle }: Props) => {
|
export const CaInstallCertModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||||
const [parentCaType] = useState<ParentCaType>(ParentCaType.Internal);
|
const popupData = popUp?.installCaCert?.data;
|
||||||
const { currentWorkspace } = useWorkspace();
|
const caId = popupData?.caId || "";
|
||||||
const caId = (popUp?.installCaCert?.data as { caId: string })?.caId || "";
|
const isParentCaExternal = popupData?.isParentCaExternal || false;
|
||||||
|
const [parentCaType, setParentCaType] = useState<ParentCaType>(ParentCaType.Internal);
|
||||||
// const [isStartDatePickerOpen, setIsStartDatePickerOpen] = useState(false);
|
|
||||||
const { data: cas } = useListWorkspaceCas({
|
|
||||||
projectSlug: currentWorkspace?.slug ?? "",
|
|
||||||
status: CaStatus.ACTIVE
|
|
||||||
});
|
|
||||||
const { data: ca } = useGetCaById(caId);
|
|
||||||
const { data: csr } = useGetCaCsr(caId);
|
|
||||||
|
|
||||||
const { mutateAsync: signIntermediate } = useSignIntermediate();
|
|
||||||
const { mutateAsync: importCaCertificate } = useImportCaCertificate();
|
|
||||||
|
|
||||||
const {
|
|
||||||
control,
|
|
||||||
handleSubmit,
|
|
||||||
reset,
|
|
||||||
formState: { isSubmitting },
|
|
||||||
setValue,
|
|
||||||
watch
|
|
||||||
} = useForm<FormData>({
|
|
||||||
resolver: zodResolver(schema),
|
|
||||||
defaultValues: {
|
|
||||||
maxPathLength: "0"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (cas?.length) {
|
if (popupData?.isParentCaExternal) {
|
||||||
setValue("parentCaId", cas[0].id);
|
setParentCaType(ParentCaType.External);
|
||||||
}
|
}
|
||||||
}, [cas, setValue]);
|
}, [popupData]);
|
||||||
|
|
||||||
const parentCaId = watch("parentCaId");
|
|
||||||
const { data: parentCa } = useGetCaById(parentCaId);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (parentCa?.maxPathLength) {
|
|
||||||
setValue(
|
|
||||||
"maxPathLength",
|
|
||||||
(parentCa.maxPathLength === -1 ? 3 : parentCa.maxPathLength - 1).toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parentCa?.notAfter) {
|
|
||||||
const parentCaNotAfter = new Date(parentCa.notAfter);
|
|
||||||
const middleDate = getMiddleDate(new Date(), parentCaNotAfter);
|
|
||||||
setValue("notAfter", format(middleDate, "yyyy-MM-dd"));
|
|
||||||
}
|
|
||||||
}, [parentCa]);
|
|
||||||
|
|
||||||
const onFormSubmit = async ({ notAfter, maxPathLength }: FormData) => {
|
|
||||||
try {
|
|
||||||
if (!csr || !caId || !currentWorkspace?.slug) return;
|
|
||||||
|
|
||||||
const { certificate, certificateChain } = await signIntermediate({
|
|
||||||
caId: parentCaId,
|
|
||||||
csr,
|
|
||||||
maxPathLength: Number(maxPathLength),
|
|
||||||
notAfter,
|
|
||||||
notBefore: new Date().toISOString()
|
|
||||||
});
|
|
||||||
|
|
||||||
await importCaCertificate({
|
|
||||||
caId,
|
|
||||||
projectSlug: currentWorkspace?.slug,
|
|
||||||
certificate,
|
|
||||||
certificateChain
|
|
||||||
});
|
|
||||||
|
|
||||||
reset();
|
|
||||||
|
|
||||||
createNotification({
|
|
||||||
text: "Successfully installed certificate for CA",
|
|
||||||
type: "success"
|
|
||||||
});
|
|
||||||
handlePopUpToggle("installCaCert", false);
|
|
||||||
} catch (err) {
|
|
||||||
createNotification({
|
|
||||||
text: "Failed to install certificate for CA",
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function generatePathLengthOpts(parentCaMaxPathLength: number): number[] {
|
|
||||||
if (parentCaMaxPathLength === -1) {
|
|
||||||
return [-1, 0, 1, 2, 3];
|
|
||||||
}
|
|
||||||
|
|
||||||
return Array.from({ length: parentCaMaxPathLength }, (_, index) => index);
|
|
||||||
}
|
|
||||||
|
|
||||||
const renderForm = (parentCaTypeInput: ParentCaType) => {
|
const renderForm = (parentCaTypeInput: ParentCaType) => {
|
||||||
switch (parentCaTypeInput) {
|
switch (parentCaTypeInput) {
|
||||||
case ParentCaType.Internal:
|
case ParentCaType.Internal:
|
||||||
return (
|
return <InternalCaInstallForm caId={caId} handlePopUpToggle={handlePopUpToggle} />;
|
||||||
<form onSubmit={handleSubmit(onFormSubmit)}>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="parentCaId"
|
|
||||||
defaultValue=""
|
|
||||||
render={({ field: { onChange, ...field }, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
label="Parent CA"
|
|
||||||
errorText={error?.message}
|
|
||||||
isError={Boolean(error)}
|
|
||||||
className="mt-4"
|
|
||||||
isRequired
|
|
||||||
>
|
|
||||||
<Select
|
|
||||||
defaultValue={field.value}
|
|
||||||
{...field}
|
|
||||||
onValueChange={(e) => onChange(e)}
|
|
||||||
className="w-full"
|
|
||||||
>
|
|
||||||
{(cas || [])
|
|
||||||
.filter((c) => {
|
|
||||||
const isParentCaNotSelf = c.id !== ca?.id;
|
|
||||||
const isParentCaActive = c.status === CaStatus.ACTIVE;
|
|
||||||
const isParentCaAllowedChildrenCas =
|
|
||||||
c.maxPathLength && c.maxPathLength !== 0;
|
|
||||||
|
|
||||||
return (
|
|
||||||
isParentCaNotSelf && isParentCaActive && isParentCaAllowedChildrenCas
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.map(({ id, type, dn }) => (
|
|
||||||
<SelectItem value={id} key={`parent-ca-${id}`}>
|
|
||||||
{`${caTypeToNameMap[type]}: ${dn}`}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
{/* <Controller
|
|
||||||
name="notAfter"
|
|
||||||
control={control}
|
|
||||||
defaultValue={getDefaultNotAfterDate()}
|
|
||||||
render={({ field: { onChange, ...field }, fieldState: { error } }) => {
|
|
||||||
return (
|
|
||||||
<FormControl
|
|
||||||
label="Validity"
|
|
||||||
errorText={error?.message}
|
|
||||||
isError={Boolean(error)}
|
|
||||||
className="mr-4"
|
|
||||||
>
|
|
||||||
<DatePicker
|
|
||||||
value={field.value || undefined}
|
|
||||||
onChange={(date) => {
|
|
||||||
onChange(date);
|
|
||||||
setIsStartDatePickerOpen(false);
|
|
||||||
}}
|
|
||||||
popUpProps={{
|
|
||||||
open: isStartDatePickerOpen,
|
|
||||||
onOpenChange: setIsStartDatePickerOpen
|
|
||||||
}}
|
|
||||||
popUpContentProps={{}}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/> */}
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="notAfter"
|
|
||||||
render={({ field, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
label="Valid Until"
|
|
||||||
isError={Boolean(error)}
|
|
||||||
errorText={error?.message}
|
|
||||||
isRequired
|
|
||||||
>
|
|
||||||
<Input {...field} placeholder="YYYY-MM-DD" />
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="maxPathLength"
|
|
||||||
// defaultValue="0"
|
|
||||||
render={({ field: { onChange, ...field }, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
label="Path Length"
|
|
||||||
errorText={error?.message}
|
|
||||||
isError={Boolean(error)}
|
|
||||||
className="mt-4"
|
|
||||||
>
|
|
||||||
<Select
|
|
||||||
defaultValue={field.value}
|
|
||||||
{...field}
|
|
||||||
onValueChange={(e) => onChange(e)}
|
|
||||||
className="w-full"
|
|
||||||
>
|
|
||||||
{generatePathLengthOpts(parentCa?.maxPathLength || 0).map((value) => (
|
|
||||||
<SelectItem value={String(value)} key={`ca-path-length-${value}`}>
|
|
||||||
{`${value}`}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<Button
|
|
||||||
className="mr-4"
|
|
||||||
size="sm"
|
|
||||||
type="submit"
|
|
||||||
isLoading={isSubmitting}
|
|
||||||
isDisabled={isSubmitting}
|
|
||||||
>
|
|
||||||
Install
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
colorSchema="secondary"
|
|
||||||
variant="plain"
|
|
||||||
onClick={() => handlePopUpToggle("installCaCert", false)}
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
);
|
|
||||||
default:
|
default:
|
||||||
return <div>External TODO</div>;
|
return <ExternalCaInstallForm caId={caId} handlePopUpToggle={handlePopUpToggle} />;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -296,31 +42,32 @@ export const CaInstallCertModal = ({ popUp, handlePopUpToggle }: Props) => {
|
|||||||
isOpen={popUp?.installCaCert?.isOpen}
|
isOpen={popUp?.installCaCert?.isOpen}
|
||||||
onOpenChange={(isOpen) => {
|
onOpenChange={(isOpen) => {
|
||||||
handlePopUpToggle("installCaCert", isOpen);
|
handlePopUpToggle("installCaCert", isOpen);
|
||||||
reset();
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ModalContent title="Install Intermediate CA certificate">
|
<ModalContent
|
||||||
{/* <FormControl label="Parent CA Type" className="mt-4">
|
title={`${isParentCaExternal ? "Renew" : "Install"} Intermediate CA certificate`}
|
||||||
|
>
|
||||||
|
<FormControl label="Parent CA Type">
|
||||||
<Select
|
<Select
|
||||||
defaultValue={ParentCaType.Internal}
|
|
||||||
value={parentCaType}
|
value={parentCaType}
|
||||||
onValueChange={(e) => setParentCaType(e as ParentCaType)}
|
onValueChange={(e) => setParentCaType(e as ParentCaType)}
|
||||||
className="w-full"
|
className="w-full"
|
||||||
|
isDisabled={isParentCaExternal}
|
||||||
>
|
>
|
||||||
<SelectItem
|
<SelectItem
|
||||||
value={ParentCaType.Internal}
|
value={ParentCaType.Internal}
|
||||||
key={`parent-ca-type-${ParentCaType.Internal}`}
|
key={`parent-ca-type-${ParentCaType.Internal}`}
|
||||||
>
|
>
|
||||||
Infisical Private CA
|
Infisical CA
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
<SelectItem
|
<SelectItem
|
||||||
value={ParentCaType.External}
|
value={ParentCaType.External}
|
||||||
key={`parent-ca-type-${ParentCaType.External}`}
|
key={`parent-ca-type-${ParentCaType.External}`}
|
||||||
>
|
>
|
||||||
External Private CA
|
External CA
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl> */}
|
</FormControl>
|
||||||
{renderForm(parentCaType)}
|
{renderForm(parentCaType)}
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|||||||
@@ -0,0 +1,172 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
|
import { Controller, useForm } from "react-hook-form";
|
||||||
|
import { faCheck, faCopy, faDownload } from "@fortawesome/free-solid-svg-icons";
|
||||||
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import FileSaver from "file-saver";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { createNotification } from "@app/components/notifications";
|
||||||
|
import { Button, FormControl, IconButton,TextArea, Tooltip } from "@app/components/v2";
|
||||||
|
import { useWorkspace } from "@app/context";
|
||||||
|
import { useTimedReset } from "@app/hooks";
|
||||||
|
import { useGetCaCsr, useImportCaCertificate } from "@app/hooks/api";
|
||||||
|
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||||
|
|
||||||
|
const schema = z.object({
|
||||||
|
certificate: z.string().min(1),
|
||||||
|
certificateChain: z.string().min(1)
|
||||||
|
});
|
||||||
|
|
||||||
|
export type FormData = z.infer<typeof schema>;
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
caId: string;
|
||||||
|
handlePopUpToggle: (popUpName: keyof UsePopUpState<["installCaCert"]>, state?: boolean) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ExternalCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
|
||||||
|
const { currentWorkspace } = useWorkspace();
|
||||||
|
const [copyTextCaCsr, isCopyingCaCsr, setCopyTextCaCsr] = useTimedReset<string>({
|
||||||
|
initialState: "Copy to clipboard"
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
control,
|
||||||
|
handleSubmit,
|
||||||
|
reset,
|
||||||
|
formState: { isSubmitting }
|
||||||
|
} = useForm<FormData>({
|
||||||
|
resolver: zodResolver(schema)
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: csr } = useGetCaCsr(caId);
|
||||||
|
const { mutateAsync: importCaCertificate } = useImportCaCertificate();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
reset();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onFormSubmit = async ({ certificate, certificateChain }: FormData) => {
|
||||||
|
try {
|
||||||
|
if (!csr || !caId || !currentWorkspace?.slug) return;
|
||||||
|
|
||||||
|
await importCaCertificate({
|
||||||
|
caId,
|
||||||
|
projectSlug: currentWorkspace?.slug,
|
||||||
|
certificate,
|
||||||
|
certificateChain
|
||||||
|
});
|
||||||
|
|
||||||
|
reset();
|
||||||
|
|
||||||
|
createNotification({
|
||||||
|
text: "Successfully installed certificate for CA",
|
||||||
|
type: "success"
|
||||||
|
});
|
||||||
|
handlePopUpToggle("installCaCert", false);
|
||||||
|
} catch (err) {
|
||||||
|
createNotification({
|
||||||
|
text: "Failed to install certificate for CA",
|
||||||
|
type: "error"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const downloadTxtFile = (filename: string, content: string) => {
|
||||||
|
const blob = new Blob([content], { type: "text/plain;charset=utf-8" });
|
||||||
|
FileSaver.saveAs(blob, filename);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form onSubmit={handleSubmit(onFormSubmit)}>
|
||||||
|
{csr && (
|
||||||
|
<>
|
||||||
|
<div className="my-4 flex items-center justify-between">
|
||||||
|
<h2>CSR for this CA</h2>
|
||||||
|
<div className="flex">
|
||||||
|
<Tooltip content={copyTextCaCsr}>
|
||||||
|
<IconButton
|
||||||
|
ariaLabel="copy icon"
|
||||||
|
colorSchema="secondary"
|
||||||
|
className="group relative"
|
||||||
|
onClick={() => {
|
||||||
|
navigator.clipboard.writeText(csr);
|
||||||
|
setCopyTextCaCsr("Copied");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={isCopyingCaCsr ? faCheck : faCopy} />
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip content="Download">
|
||||||
|
<IconButton
|
||||||
|
ariaLabel="copy icon"
|
||||||
|
colorSchema="secondary"
|
||||||
|
className="group relative ml-2"
|
||||||
|
onClick={() => {
|
||||||
|
downloadTxtFile("csr.pem", csr);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faDownload} />
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mb-8 flex items-center justify-between rounded-md bg-white/[0.07] p-2 text-base text-gray-400">
|
||||||
|
<p className="mr-4 whitespace-pre-wrap break-all">{csr}</p>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="certificate"
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl label="Certificate Body" errorText={error?.message} isError={Boolean(error)}>
|
||||||
|
<TextArea
|
||||||
|
{...field}
|
||||||
|
placeholder="PEM-encoded certificate..."
|
||||||
|
reSize="none"
|
||||||
|
className="h-48"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="certificateChain"
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
label="Certificate Chain"
|
||||||
|
errorText={error?.message}
|
||||||
|
isError={Boolean(error)}
|
||||||
|
>
|
||||||
|
<TextArea
|
||||||
|
{...field}
|
||||||
|
placeholder="PEM-encoded certificate chain..."
|
||||||
|
reSize="none"
|
||||||
|
className="h-48"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<div className="flex items-center">
|
||||||
|
<Button
|
||||||
|
className="mr-4"
|
||||||
|
size="sm"
|
||||||
|
type="submit"
|
||||||
|
isLoading={isSubmitting}
|
||||||
|
isDisabled={isSubmitting}
|
||||||
|
>
|
||||||
|
Install
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
colorSchema="secondary"
|
||||||
|
variant="plain"
|
||||||
|
onClick={() => handlePopUpToggle("installCaCert", false)}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,236 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
|
import { Controller, useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { format } from "date-fns";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { createNotification } from "@app/components/notifications";
|
||||||
|
import { Button, FormControl, Input,Select, SelectItem } from "@app/components/v2";
|
||||||
|
import { useWorkspace } from "@app/context";
|
||||||
|
import {
|
||||||
|
CaStatus,
|
||||||
|
useGetCaById,
|
||||||
|
useGetCaCsr,
|
||||||
|
useImportCaCertificate,
|
||||||
|
useListWorkspaceCas,
|
||||||
|
useSignIntermediate
|
||||||
|
} from "@app/hooks/api";
|
||||||
|
import { caTypeToNameMap } from "@app/hooks/api/ca/constants";
|
||||||
|
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||||
|
|
||||||
|
const isValidDate = (dateString: string) => {
|
||||||
|
const date = new Date(dateString);
|
||||||
|
return !Number.isNaN(date.getTime());
|
||||||
|
};
|
||||||
|
|
||||||
|
const getMiddleDate = (date1: Date, date2: Date) => {
|
||||||
|
const timestamp1 = date1.getTime();
|
||||||
|
const timestamp2 = date2.getTime();
|
||||||
|
|
||||||
|
const middleTimestamp = (timestamp1 + timestamp2) / 2;
|
||||||
|
|
||||||
|
return new Date(middleTimestamp);
|
||||||
|
};
|
||||||
|
|
||||||
|
const schema = z.object({
|
||||||
|
parentCaId: z.string(),
|
||||||
|
notAfter: z.string().trim().refine(isValidDate, { message: "Invalid date format" }),
|
||||||
|
maxPathLength: z.string()
|
||||||
|
});
|
||||||
|
|
||||||
|
export type FormData = z.infer<typeof schema>;
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
caId: string;
|
||||||
|
handlePopUpToggle: (popUpName: keyof UsePopUpState<["installCaCert"]>, state?: boolean) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const InternalCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
|
||||||
|
const { currentWorkspace } = useWorkspace();
|
||||||
|
const { data: cas } = useListWorkspaceCas({
|
||||||
|
projectSlug: currentWorkspace?.slug ?? "",
|
||||||
|
status: CaStatus.ACTIVE
|
||||||
|
});
|
||||||
|
const { data: ca } = useGetCaById(caId);
|
||||||
|
const { data: csr } = useGetCaCsr(caId);
|
||||||
|
|
||||||
|
const { mutateAsync: signIntermediate } = useSignIntermediate();
|
||||||
|
const { mutateAsync: importCaCertificate } = useImportCaCertificate();
|
||||||
|
|
||||||
|
const {
|
||||||
|
control,
|
||||||
|
handleSubmit,
|
||||||
|
reset,
|
||||||
|
formState: { isSubmitting },
|
||||||
|
setValue,
|
||||||
|
watch
|
||||||
|
} = useForm<FormData>({
|
||||||
|
resolver: zodResolver(schema),
|
||||||
|
defaultValues: {
|
||||||
|
maxPathLength: "0"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
reset();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (cas?.length) {
|
||||||
|
setValue("parentCaId", cas[0].id);
|
||||||
|
}
|
||||||
|
}, [cas, setValue]);
|
||||||
|
|
||||||
|
const parentCaId = watch("parentCaId");
|
||||||
|
|
||||||
|
const { data: parentCa } = useGetCaById(parentCaId);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (parentCa?.maxPathLength) {
|
||||||
|
setValue(
|
||||||
|
"maxPathLength",
|
||||||
|
(parentCa.maxPathLength === -1 ? 3 : parentCa.maxPathLength - 1).toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parentCa?.notAfter) {
|
||||||
|
const parentCaNotAfter = new Date(parentCa.notAfter);
|
||||||
|
const middleDate = getMiddleDate(new Date(), parentCaNotAfter);
|
||||||
|
setValue("notAfter", format(middleDate, "yyyy-MM-dd"));
|
||||||
|
}
|
||||||
|
}, [parentCa]);
|
||||||
|
|
||||||
|
const onFormSubmit = async ({ notAfter, maxPathLength }: FormData) => {
|
||||||
|
try {
|
||||||
|
if (!csr || !caId || !currentWorkspace?.slug) return;
|
||||||
|
|
||||||
|
const { certificate, certificateChain } = await signIntermediate({
|
||||||
|
caId: parentCaId,
|
||||||
|
csr,
|
||||||
|
maxPathLength: Number(maxPathLength),
|
||||||
|
notAfter,
|
||||||
|
notBefore: new Date().toISOString()
|
||||||
|
});
|
||||||
|
|
||||||
|
await importCaCertificate({
|
||||||
|
caId,
|
||||||
|
projectSlug: currentWorkspace?.slug,
|
||||||
|
certificate,
|
||||||
|
certificateChain
|
||||||
|
});
|
||||||
|
|
||||||
|
reset();
|
||||||
|
|
||||||
|
createNotification({
|
||||||
|
text: "Successfully installed certificate for CA",
|
||||||
|
type: "success"
|
||||||
|
});
|
||||||
|
handlePopUpToggle("installCaCert", false);
|
||||||
|
} catch (err) {
|
||||||
|
createNotification({
|
||||||
|
text: "Failed to install certificate for CA",
|
||||||
|
type: "error"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function generatePathLengthOpts(parentCaMaxPathLength: number): number[] {
|
||||||
|
if (parentCaMaxPathLength === -1) {
|
||||||
|
return [-1, 0, 1, 2, 3];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from({ length: parentCaMaxPathLength }, (_, index) => index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form onSubmit={handleSubmit(onFormSubmit)}>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="parentCaId"
|
||||||
|
// defaultValue=""
|
||||||
|
render={({ field: { onChange, ...field }, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
label="Parent CA"
|
||||||
|
errorText={error?.message}
|
||||||
|
isError={Boolean(error)}
|
||||||
|
isRequired
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
// defaultValue={field.value}
|
||||||
|
{...field}
|
||||||
|
onValueChange={onChange}
|
||||||
|
className="w-full"
|
||||||
|
>
|
||||||
|
{(cas || [])
|
||||||
|
.filter((c) => {
|
||||||
|
const isParentCaNotSelf = c.id !== ca?.id;
|
||||||
|
const isParentCaActive = c.status === CaStatus.ACTIVE;
|
||||||
|
const isParentCaAllowedChildrenCas = c.maxPathLength && c.maxPathLength !== 0;
|
||||||
|
|
||||||
|
return isParentCaNotSelf && isParentCaActive && isParentCaAllowedChildrenCas;
|
||||||
|
})
|
||||||
|
.map(({ id, type, dn }) => (
|
||||||
|
<SelectItem value={id} key={`parent-ca-${id}`}>
|
||||||
|
{`${caTypeToNameMap[type]}: ${dn}`}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="notAfter"
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
label="Valid Until"
|
||||||
|
isError={Boolean(error)}
|
||||||
|
errorText={error?.message}
|
||||||
|
isRequired
|
||||||
|
>
|
||||||
|
<Input {...field} placeholder="YYYY-MM-DD" />
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="maxPathLength"
|
||||||
|
// defaultValue="0"
|
||||||
|
render={({ field: { onChange, ...field }, fieldState: { error } }) => (
|
||||||
|
<FormControl label="Path Length" errorText={error?.message} isError={Boolean(error)}>
|
||||||
|
<Select
|
||||||
|
// defaultValue={field.value}
|
||||||
|
{...field}
|
||||||
|
onValueChange={onChange}
|
||||||
|
className="w-full"
|
||||||
|
>
|
||||||
|
{generatePathLengthOpts(parentCa?.maxPathLength || 0).map((value) => (
|
||||||
|
<SelectItem value={String(value)} key={`ca-path-length-${value}`}>
|
||||||
|
{`${value}`}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<div className="flex items-center">
|
||||||
|
<Button
|
||||||
|
className="mr-4"
|
||||||
|
size="sm"
|
||||||
|
type="submit"
|
||||||
|
isLoading={isSubmitting}
|
||||||
|
isDisabled={isSubmitting}
|
||||||
|
>
|
||||||
|
Install
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
colorSchema="secondary"
|
||||||
|
variant="plain"
|
||||||
|
onClick={() => handlePopUpToggle("installCaCert", false)}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { faWarning } from "@fortawesome/free-solid-svg-icons";
|
// import { faWarning } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
// import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { motion } from "framer-motion";
|
import { motion } from "framer-motion";
|
||||||
|
|
||||||
import { ServiceTokenSection } from "./components";
|
import { ServiceTokenSection } from "./components";
|
||||||
@@ -14,7 +14,7 @@ export const ServiceTokenTab = () => {
|
|||||||
exit={{ opacity: 0, translateX: 30 }}
|
exit={{ opacity: 0, translateX: 30 }}
|
||||||
>
|
>
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div className="flex w-full flex-row items-center rounded-md border border-primary-600/70 bg-primary/[.07] p-4 text-base text-white">
|
{/* <div className="flex w-full flex-row items-center rounded-md border border-primary-600/70 bg-primary/[.07] p-4 text-base text-white">
|
||||||
<FontAwesomeIcon icon={faWarning} className="pr-6 text-4xl text-white/80" />
|
<FontAwesomeIcon icon={faWarning} className="pr-6 text-4xl text-white/80" />
|
||||||
<div className="flex w-full flex-col text-sm">
|
<div className="flex w-full flex-col text-sm">
|
||||||
<span className="mb-4 text-lg font-semibold">Deprecation Notice</span>
|
<span className="mb-4 text-lg font-semibold">Deprecation Notice</span>
|
||||||
@@ -41,7 +41,7 @@ export const ServiceTokenTab = () => {
|
|||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div> */}
|
||||||
<ServiceTokenSection />
|
<ServiceTokenSection />
|
||||||
</div>
|
</div>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ export const RowPermissionSecretsRow = ({
|
|||||||
<Controller
|
<Controller
|
||||||
name={`permissions.${formName}.${slug}.secretPath`}
|
name={`permissions.${formName}.${slug}.secretPath`}
|
||||||
control={control}
|
control={control}
|
||||||
|
defaultValue="/**"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
/* eslint-disable-next-line no-template-curly-in-string */
|
/* eslint-disable-next-line no-template-curly-in-string */
|
||||||
<FormControl helperText="Supports glob path pattern string">
|
<FormControl helperText="Supports glob path pattern string">
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import {
|
|||||||
ProjectPermissionSub,
|
ProjectPermissionSub,
|
||||||
useProjectPermission,
|
useProjectPermission,
|
||||||
useSubscription,
|
useSubscription,
|
||||||
|
useUser,
|
||||||
useWorkspace
|
useWorkspace
|
||||||
} from "@app/context";
|
} from "@app/context";
|
||||||
import { usePopUp } from "@app/hooks";
|
import { usePopUp } from "@app/hooks";
|
||||||
@@ -47,7 +48,7 @@ import { queryClient } from "@app/reactQuery";
|
|||||||
import { RequestAccessModal } from "./components/RequestAccessModal";
|
import { RequestAccessModal } from "./components/RequestAccessModal";
|
||||||
import { ReviewAccessRequestModal } from "./components/ReviewAccessModal";
|
import { ReviewAccessRequestModal } from "./components/ReviewAccessModal";
|
||||||
|
|
||||||
const generateRequestText = (request: TAccessApprovalRequest, membershipId: string) => {
|
const generateRequestText = (request: TAccessApprovalRequest, userId: string) => {
|
||||||
const { isTemporary } = request;
|
const { isTemporary } = request;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -63,7 +64,7 @@ const generateRequestText = (request: TAccessApprovalRequest, membershipId: stri
|
|||||||
</code>
|
</code>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{request.requestedBy === membershipId && (
|
{request.requestedByUserId === userId && (
|
||||||
<span className="text-xs text-gray-500">
|
<span className="text-xs text-gray-500">
|
||||||
<Badge className="ml-1">Requested By You</Badge>
|
<Badge className="ml-1">Requested By You</Badge>
|
||||||
</span>
|
</span>
|
||||||
@@ -81,11 +82,11 @@ export const AccessApprovalRequest = ({
|
|||||||
projectId: string;
|
projectId: string;
|
||||||
}) => {
|
}) => {
|
||||||
const [selectedRequest, setSelectedRequest] = useState<
|
const [selectedRequest, setSelectedRequest] = useState<
|
||||||
(TAccessApprovalRequest & {
|
| (TAccessApprovalRequest & {
|
||||||
user: TWorkspaceUser["user"] | null;
|
user: TWorkspaceUser["user"] | null;
|
||||||
isRequestedByCurrentUser: boolean;
|
isRequestedByCurrentUser: boolean;
|
||||||
isApprover: boolean;
|
isApprover: boolean;
|
||||||
})
|
})
|
||||||
| null
|
| null
|
||||||
>(null);
|
>(null);
|
||||||
|
|
||||||
@@ -94,16 +95,19 @@ export const AccessApprovalRequest = ({
|
|||||||
"reviewRequest",
|
"reviewRequest",
|
||||||
"upgradePlan"
|
"upgradePlan"
|
||||||
] as const);
|
] as const);
|
||||||
const { membership, permission } = useProjectPermission();
|
const { permission } = useProjectPermission();
|
||||||
|
const { user } = useUser();
|
||||||
const { subscription } = useSubscription();
|
const { subscription } = useSubscription();
|
||||||
const { currentWorkspace } = useWorkspace();
|
const { currentWorkspace } = useWorkspace();
|
||||||
|
|
||||||
const { data: members } = useGetWorkspaceUsers(projectId);
|
const { data: members } = useGetWorkspaceUsers(projectId, true);
|
||||||
const membersGroupById = members?.reduce<Record<string, TWorkspaceUser>>(
|
const membersGroupById = members?.reduce<Record<string, TWorkspaceUser>>(
|
||||||
(prev, curr) => ({ ...prev, [curr.id]: curr }),
|
(prev, curr) => ({ ...prev, [curr.user.id]: curr }),
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
console.log("membersGroupById", membersGroupById);
|
||||||
|
|
||||||
const [statusFilter, setStatusFilter] = useState<"open" | "close">("open");
|
const [statusFilter, setStatusFilter] = useState<"open" | "close">("open");
|
||||||
const [requestedByFilter, setRequestedByFilter] = useState<string | undefined>(undefined);
|
const [requestedByFilter, setRequestedByFilter] = useState<string | undefined>(undefined);
|
||||||
const [envFilter, setEnvFilter] = useState<string | undefined>(undefined);
|
const [envFilter, setEnvFilter] = useState<string | undefined>(undefined);
|
||||||
@@ -140,19 +144,18 @@ export const AccessApprovalRequest = ({
|
|||||||
}, [requests, statusFilter, requestedByFilter, envFilter]);
|
}, [requests, statusFilter, requestedByFilter, envFilter]);
|
||||||
|
|
||||||
const generateRequestDetails = (request: TAccessApprovalRequest) => {
|
const generateRequestDetails = (request: TAccessApprovalRequest) => {
|
||||||
const isReviewedByUser =
|
console.log(request);
|
||||||
request.reviewers.findIndex(({ member }) => member === membership.id) !== -1;
|
|
||||||
|
const isReviewedByUser = request.reviewers.findIndex(({ member }) => member === user.id) !== -1;
|
||||||
const isRejectedByAnyone = request.reviewers.some(
|
const isRejectedByAnyone = request.reviewers.some(
|
||||||
({ status }) => status === ApprovalStatus.REJECTED
|
({ status }) => status === ApprovalStatus.REJECTED
|
||||||
);
|
);
|
||||||
const isApprover = request.policy.approvers.indexOf(membership.id || "") !== -1;
|
const isApprover = request.policy.approvers.indexOf(user.id || "") !== -1;
|
||||||
const isAccepted = request.isApproved;
|
const isAccepted = request.isApproved;
|
||||||
const isSoftEnforcement = request.policy.enforcementLevel === EnforcementLevel.Soft;
|
const isSoftEnforcement = request.policy.enforcementLevel === EnforcementLevel.Soft;
|
||||||
const isRequestedByCurrentUser = request.requestedBy === membership.id;
|
const isRequestedByCurrentUser = request.requestedByUserId === user.id;
|
||||||
|
|
||||||
const userReviewStatus = request.reviewers.find(
|
const userReviewStatus = request.reviewers.find(({ member }) => member === user.id)?.status;
|
||||||
({ member }) => member === membership.id
|
|
||||||
)?.status;
|
|
||||||
|
|
||||||
let displayData: { label: string; type: "primary" | "danger" | "success" } = {
|
let displayData: { label: string; type: "primary" | "danger" | "success" } = {
|
||||||
label: "",
|
label: "",
|
||||||
@@ -303,7 +306,7 @@ export const AccessApprovalRequest = ({
|
|||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
<DropdownMenuLabel>Select an author</DropdownMenuLabel>
|
<DropdownMenuLabel>Select an author</DropdownMenuLabel>
|
||||||
{members?.map(({ user, id }) => (
|
{members?.map(({ user: membershipUser, id }) => (
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setRequestedByFilter((state) => (state === id ? undefined : id))
|
setRequestedByFilter((state) => (state === id ? undefined : id))
|
||||||
@@ -312,7 +315,7 @@ export const AccessApprovalRequest = ({
|
|||||||
icon={requestedByFilter === id && <FontAwesomeIcon icon={faCheckCircle} />}
|
icon={requestedByFilter === id && <FontAwesomeIcon icon={faCheckCircle} />}
|
||||||
iconPos="right"
|
iconPos="right"
|
||||||
>
|
>
|
||||||
{user.username}
|
{membershipUser.username}
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
))}
|
))}
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
@@ -341,22 +344,21 @@ export const AccessApprovalRequest = ({
|
|||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (
|
if (
|
||||||
(
|
(!details.isApprover ||
|
||||||
!details.isApprover
|
details.isReviewedByUser ||
|
||||||
|| details.isReviewedByUser
|
details.isRejectedByAnyone ||
|
||||||
|| details.isRejectedByAnyone
|
details.isAccepted) &&
|
||||||
|| details.isAccepted
|
!(
|
||||||
) && !(
|
details.isSoftEnforcement &&
|
||||||
details.isSoftEnforcement
|
details.isRequestedByCurrentUser &&
|
||||||
&& details.isRequestedByCurrentUser
|
!details.isAccepted
|
||||||
&& !details.isAccepted
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
setSelectedRequest({
|
setSelectedRequest({
|
||||||
...request,
|
...request,
|
||||||
user: membersGroupById?.[request.requestedBy].user!,
|
user: membersGroupById?.[request.requestedByUserId].user!,
|
||||||
isRequestedByCurrentUser: details.isRequestedByCurrentUser,
|
isRequestedByCurrentUser: details.isRequestedByCurrentUser,
|
||||||
isApprover: details.isApprover
|
isApprover: details.isApprover
|
||||||
});
|
});
|
||||||
@@ -373,7 +375,7 @@ export const AccessApprovalRequest = ({
|
|||||||
if (evt.key === "Enter") {
|
if (evt.key === "Enter") {
|
||||||
setSelectedRequest({
|
setSelectedRequest({
|
||||||
...request,
|
...request,
|
||||||
user: membersGroupById?.[request.requestedBy].user!,
|
user: membersGroupById?.[request.requestedByUserId].user!,
|
||||||
isRequestedByCurrentUser: details.isRequestedByCurrentUser,
|
isRequestedByCurrentUser: details.isRequestedByCurrentUser,
|
||||||
isApprover: details.isApprover
|
isApprover: details.isApprover
|
||||||
});
|
});
|
||||||
@@ -385,16 +387,17 @@ export const AccessApprovalRequest = ({
|
|||||||
<div className="flex w-full flex-col justify-between">
|
<div className="flex w-full flex-col justify-between">
|
||||||
<div className="mb-1 flex w-full items-center">
|
<div className="mb-1 flex w-full items-center">
|
||||||
<FontAwesomeIcon icon={faLock} className="mr-2" />
|
<FontAwesomeIcon icon={faLock} className="mr-2" />
|
||||||
{generateRequestText(request, membership.id)}
|
{generateRequestText(request, user.id)}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div className="text-xs text-gray-500">
|
<div className="text-xs text-gray-500">
|
||||||
{membersGroupById?.[request.requestedBy]?.user && (
|
{membersGroupById?.[request.requestedByUserId]?.user && (
|
||||||
<>
|
<>
|
||||||
Requested {formatDistance(new Date(request.createdAt), new Date())}{" "}
|
Requested {formatDistance(new Date(request.createdAt), new Date())}{" "}
|
||||||
ago by {membersGroupById?.[request.requestedBy]?.user?.firstName}{" "}
|
ago by{" "}
|
||||||
{membersGroupById?.[request.requestedBy]?.user?.lastName} (
|
{membersGroupById?.[request.requestedByUserId]?.user?.firstName}{" "}
|
||||||
{membersGroupById?.[request.requestedBy]?.user?.email}){" "}
|
{membersGroupById?.[request.requestedByUserId]?.user?.lastName} (
|
||||||
|
{membersGroupById?.[request.requestedByUserId]?.user?.email}){" "}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
import { useMemo,useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { faCheckCircle,faChevronDown, faFileShield, faPlus } from "@fortawesome/free-solid-svg-icons";
|
import {
|
||||||
|
faCheckCircle,
|
||||||
|
faChevronDown,
|
||||||
|
faFileShield,
|
||||||
|
faPlus
|
||||||
|
} from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
import { createNotification } from "@app/components/notifications";
|
||||||
@@ -32,7 +37,12 @@ import {
|
|||||||
useWorkspace
|
useWorkspace
|
||||||
} from "@app/context";
|
} from "@app/context";
|
||||||
import { usePopUp } from "@app/hooks";
|
import { usePopUp } from "@app/hooks";
|
||||||
import { useDeleteAccessApprovalPolicy, useDeleteSecretApprovalPolicy, useGetSecretApprovalPolicies, useGetWorkspaceUsers } from "@app/hooks/api";
|
import {
|
||||||
|
useDeleteAccessApprovalPolicy,
|
||||||
|
useDeleteSecretApprovalPolicy,
|
||||||
|
useGetSecretApprovalPolicies,
|
||||||
|
useGetWorkspaceUsers
|
||||||
|
} from "@app/hooks/api";
|
||||||
import { useGetAccessApprovalPolicies } from "@app/hooks/api/accessApproval/queries";
|
import { useGetAccessApprovalPolicies } from "@app/hooks/api/accessApproval/queries";
|
||||||
import { PolicyType } from "@app/hooks/api/policies/enums";
|
import { PolicyType } from "@app/hooks/api/policies/enums";
|
||||||
import { TAccessApprovalPolicy, Workspace } from "@app/hooks/api/types";
|
import { TAccessApprovalPolicy, Workspace } from "@app/hooks/api/types";
|
||||||
@@ -45,27 +55,32 @@ interface IProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const useApprovalPolicies = (permission: TProjectPermission, currentWorkspace?: Workspace) => {
|
const useApprovalPolicies = (permission: TProjectPermission, currentWorkspace?: Workspace) => {
|
||||||
const { data: accessPolicies, isLoading: isAccessPoliciesLoading } = useGetAccessApprovalPolicies({
|
const { data: accessPolicies, isLoading: isAccessPoliciesLoading } = useGetAccessApprovalPolicies(
|
||||||
projectSlug: currentWorkspace?.slug as string,
|
{
|
||||||
options: {
|
projectSlug: currentWorkspace?.slug as string,
|
||||||
enabled:
|
options: {
|
||||||
permission.can(ProjectPermissionActions.Read, ProjectPermissionSub.SecretApproval) &&
|
enabled:
|
||||||
!!currentWorkspace?.slug
|
permission.can(ProjectPermissionActions.Read, ProjectPermissionSub.SecretApproval) &&
|
||||||
|
!!currentWorkspace?.slug
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
const { data: secretPolicies, isLoading: isSecretPoliciesLoading } = useGetSecretApprovalPolicies({
|
const { data: secretPolicies, isLoading: isSecretPoliciesLoading } = useGetSecretApprovalPolicies(
|
||||||
workspaceId: currentWorkspace?.id as string,
|
{
|
||||||
options: {
|
workspaceId: currentWorkspace?.id as string,
|
||||||
enabled:
|
options: {
|
||||||
permission.can(ProjectPermissionActions.Read, ProjectPermissionSub.SecretApproval) &&
|
enabled:
|
||||||
!!currentWorkspace?.id
|
permission.can(ProjectPermissionActions.Read, ProjectPermissionSub.SecretApproval) &&
|
||||||
|
!!currentWorkspace?.id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
// merge data sorted by updatedAt
|
// merge data sorted by updatedAt
|
||||||
const policies = [
|
const policies = [
|
||||||
...(accessPolicies?.map(policy => ({ ...policy, policyType: PolicyType.AccessPolicy })) || []),
|
...(accessPolicies?.map((policy) => ({ ...policy, policyType: PolicyType.AccessPolicy })) ||
|
||||||
...(secretPolicies?.map(policy => ({ ...policy, policyType: PolicyType.ChangePolicy })) || [])
|
[]),
|
||||||
|
...(secretPolicies?.map((policy) => ({ ...policy, policyType: PolicyType.ChangePolicy })) || [])
|
||||||
].sort((a, b) => {
|
].sort((a, b) => {
|
||||||
return new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime();
|
return new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime();
|
||||||
});
|
});
|
||||||
@@ -86,15 +101,16 @@ export const ApprovalPolicyList = ({ workspaceId }: IProps) => {
|
|||||||
const { subscription } = useSubscription();
|
const { subscription } = useSubscription();
|
||||||
const { currentWorkspace } = useWorkspace();
|
const { currentWorkspace } = useWorkspace();
|
||||||
|
|
||||||
const { data: members } = useGetWorkspaceUsers(workspaceId);
|
const { data: members } = useGetWorkspaceUsers(workspaceId, true);
|
||||||
const { policies, isLoading: isPoliciesLoading } = useApprovalPolicies(permission, currentWorkspace);
|
const { policies, isLoading: isPoliciesLoading } = useApprovalPolicies(
|
||||||
|
permission,
|
||||||
|
currentWorkspace
|
||||||
|
);
|
||||||
|
|
||||||
const [filterType, setFilterType] = useState<string | null>(null);
|
const [filterType, setFilterType] = useState<string | null>(null);
|
||||||
|
|
||||||
const filteredPolicies = useMemo(() => {
|
const filteredPolicies = useMemo(() => {
|
||||||
return filterType
|
return filterType ? policies.filter((policy) => policy.policyType === filterType) : policies;
|
||||||
? policies.filter(policy => policy.policyType === filterType)
|
|
||||||
: policies;
|
|
||||||
}, [policies, filterType]);
|
}, [policies, filterType]);
|
||||||
|
|
||||||
const { mutateAsync: deleteSecretApprovalPolicy } = useDeleteSecretApprovalPolicy();
|
const { mutateAsync: deleteSecretApprovalPolicy } = useDeleteSecretApprovalPolicy();
|
||||||
@@ -177,8 +193,10 @@ export const ApprovalPolicyList = ({ workspaceId }: IProps) => {
|
|||||||
<Button
|
<Button
|
||||||
variant="plain"
|
variant="plain"
|
||||||
colorSchema="secondary"
|
colorSchema="secondary"
|
||||||
className="text-bunker-300 uppercase text-xs font-semibold"
|
className="text-xs font-semibold uppercase text-bunker-300"
|
||||||
rightIcon={<FontAwesomeIcon icon={faChevronDown} size="sm" className="ml-2" />}
|
rightIcon={
|
||||||
|
<FontAwesomeIcon icon={faChevronDown} size="sm" className="ml-2" />
|
||||||
|
}
|
||||||
>
|
>
|
||||||
Type
|
Type
|
||||||
</Button>
|
</Button>
|
||||||
@@ -194,14 +212,22 @@ export const ApprovalPolicyList = ({ workspaceId }: IProps) => {
|
|||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => setFilterType(PolicyType.AccessPolicy)}
|
onClick={() => setFilterType(PolicyType.AccessPolicy)}
|
||||||
icon={filterType === PolicyType.AccessPolicy && <FontAwesomeIcon icon={faCheckCircle} />}
|
icon={
|
||||||
|
filterType === PolicyType.AccessPolicy && (
|
||||||
|
<FontAwesomeIcon icon={faCheckCircle} />
|
||||||
|
)
|
||||||
|
}
|
||||||
iconPos="right"
|
iconPos="right"
|
||||||
>
|
>
|
||||||
Access Policy
|
Access Policy
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => setFilterType(PolicyType.ChangePolicy)}
|
onClick={() => setFilterType(PolicyType.ChangePolicy)}
|
||||||
icon={filterType === PolicyType.ChangePolicy && <FontAwesomeIcon icon={faCheckCircle} />}
|
icon={
|
||||||
|
filterType === PolicyType.ChangePolicy && (
|
||||||
|
<FontAwesomeIcon icon={faCheckCircle} />
|
||||||
|
)
|
||||||
|
}
|
||||||
iconPos="right"
|
iconPos="right"
|
||||||
>
|
>
|
||||||
Change Policy
|
Change Policy
|
||||||
|
|||||||
@@ -7,363 +7,378 @@ import { z } from "zod";
|
|||||||
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
import { createNotification } from "@app/components/notifications";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuLabel,
|
DropdownMenuLabel,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
FormControl,
|
FormControl,
|
||||||
Input,
|
Input,
|
||||||
Modal,
|
Modal,
|
||||||
ModalContent,
|
ModalContent,
|
||||||
Select,
|
Select,
|
||||||
SelectItem
|
SelectItem
|
||||||
} from "@app/components/v2";
|
} from "@app/components/v2";
|
||||||
import { useWorkspace } from "@app/context";
|
import { useWorkspace } from "@app/context";
|
||||||
import { policyDetails } from "@app/helpers/policies";
|
import { policyDetails } from "@app/helpers/policies";
|
||||||
import { useCreateSecretApprovalPolicy, useUpdateSecretApprovalPolicy } from "@app/hooks/api";
|
import { useCreateSecretApprovalPolicy, useUpdateSecretApprovalPolicy } from "@app/hooks/api";
|
||||||
import {
|
import {
|
||||||
useCreateAccessApprovalPolicy,
|
useCreateAccessApprovalPolicy,
|
||||||
useUpdateAccessApprovalPolicy
|
useUpdateAccessApprovalPolicy
|
||||||
} from "@app/hooks/api/accessApproval";
|
} from "@app/hooks/api/accessApproval";
|
||||||
import { TAccessApprovalPolicy } from "@app/hooks/api/accessApproval/types";
|
import { TAccessApprovalPolicy } from "@app/hooks/api/accessApproval/types";
|
||||||
import { EnforcementLevel, PolicyType } from "@app/hooks/api/policies/enums";
|
import { EnforcementLevel, PolicyType } from "@app/hooks/api/policies/enums";
|
||||||
import { TWorkspaceUser } from "@app/hooks/api/users/types";
|
import { TWorkspaceUser } from "@app/hooks/api/users/types";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
isOpen?: boolean;
|
isOpen?: boolean;
|
||||||
onToggle: (isOpen: boolean) => void;
|
onToggle: (isOpen: boolean) => void;
|
||||||
members?: TWorkspaceUser[];
|
members?: TWorkspaceUser[];
|
||||||
projectSlug: string;
|
projectSlug: string;
|
||||||
editValues?: TAccessApprovalPolicy;
|
editValues?: TAccessApprovalPolicy;
|
||||||
};
|
};
|
||||||
|
|
||||||
const formSchema = z
|
const formSchema = z
|
||||||
.object({
|
.object({
|
||||||
environment: z.string(),
|
environment: z.string(),
|
||||||
name: z.string().optional(),
|
name: z.string().optional(),
|
||||||
secretPath: z.string().optional(),
|
secretPath: z.string().optional(),
|
||||||
approvals: z.number().min(1),
|
approvals: z.number().min(1),
|
||||||
approvers: z.string().array().min(1),
|
approverUserIds: z.string().array().min(1),
|
||||||
policyType: z.nativeEnum(PolicyType),
|
policyType: z.nativeEnum(PolicyType),
|
||||||
enforcementLevel: z.nativeEnum(EnforcementLevel)
|
enforcementLevel: z.nativeEnum(EnforcementLevel)
|
||||||
})
|
})
|
||||||
.refine((data) => data.approvals <= data.approvers.length, {
|
.refine((data) => data.approvals <= data.approverUserIds.length, {
|
||||||
path: ["approvals"],
|
path: ["approvals"],
|
||||||
message: "The number of approvals should be lower than the number of approvers."
|
message: "The number of approvals should be lower than the number of approvers."
|
||||||
});
|
});
|
||||||
|
|
||||||
type TFormSchema = z.infer<typeof formSchema>;
|
type TFormSchema = z.infer<typeof formSchema>;
|
||||||
|
|
||||||
export const AccessPolicyForm = ({
|
export const AccessPolicyForm = ({
|
||||||
isOpen,
|
isOpen,
|
||||||
onToggle,
|
onToggle,
|
||||||
members = [],
|
members = [],
|
||||||
projectSlug,
|
projectSlug,
|
||||||
editValues
|
editValues
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
reset,
|
reset,
|
||||||
watch,
|
watch,
|
||||||
formState: { isSubmitting }
|
formState: { isSubmitting }
|
||||||
} = useForm<TFormSchema>({
|
} = useForm<TFormSchema>({
|
||||||
resolver: zodResolver(formSchema),
|
resolver: zodResolver(formSchema),
|
||||||
values: editValues ? {
|
values: editValues
|
||||||
...editValues,
|
? {
|
||||||
environment: editValues.environment.slug,
|
...editValues,
|
||||||
approvers: editValues?.userApprovers?.map((user) => user.userId) || editValues?.approvers
|
environment: editValues.environment.slug,
|
||||||
} : undefined
|
approverUserIds:
|
||||||
});
|
editValues?.userApprovers?.map((user) => user.userId) || editValues?.approvers
|
||||||
const { currentWorkspace } = useWorkspace();
|
}
|
||||||
|
: undefined
|
||||||
const environments = currentWorkspace?.environments || [];
|
});
|
||||||
const isEditMode = Boolean(editValues);
|
const { currentWorkspace } = useWorkspace();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isOpen || !isEditMode) reset({});
|
|
||||||
}, [isOpen, isEditMode]);
|
|
||||||
|
|
||||||
const { mutateAsync: createAccessApprovalPolicy } = useCreateAccessApprovalPolicy();
|
|
||||||
const { mutateAsync: updateAccessApprovalPolicy } = useUpdateAccessApprovalPolicy();
|
|
||||||
|
|
||||||
const { mutateAsync: createSecretApprovalPolicy } = useCreateSecretApprovalPolicy();
|
|
||||||
const { mutateAsync: updateSecretApprovalPolicy } = useUpdateSecretApprovalPolicy();
|
|
||||||
|
|
||||||
const policyName = policyDetails[watch("policyType")]?.name || "Policy";
|
const environments = currentWorkspace?.environments || [];
|
||||||
|
const isEditMode = Boolean(editValues);
|
||||||
const handleCreatePolicy = async (data: TFormSchema) => {
|
|
||||||
if (!projectSlug) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (data.policyType === PolicyType.ChangePolicy) {
|
|
||||||
await createSecretApprovalPolicy({
|
|
||||||
...data,
|
|
||||||
workspaceId: currentWorkspace?.id || ""
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await createAccessApprovalPolicy({
|
|
||||||
...data,
|
|
||||||
projectSlug
|
|
||||||
});
|
|
||||||
}
|
|
||||||
createNotification({
|
|
||||||
type: "success",
|
|
||||||
text: "Successfully created policy"
|
|
||||||
});
|
|
||||||
onToggle(false);
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
createNotification({
|
|
||||||
type: "error",
|
|
||||||
text: "Failed to create policy"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleUpdatePolicy = async (data: TFormSchema) => {
|
|
||||||
if (!projectSlug) return;
|
|
||||||
if (!editValues?.id) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (data.policyType === PolicyType.ChangePolicy) {
|
|
||||||
await updateSecretApprovalPolicy({
|
|
||||||
id: editValues?.id,
|
|
||||||
...data,
|
|
||||||
workspaceId: currentWorkspace?.id || ""
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await updateAccessApprovalPolicy({
|
|
||||||
id: editValues?.id,
|
|
||||||
...data,
|
|
||||||
projectSlug
|
|
||||||
});
|
|
||||||
}
|
|
||||||
createNotification({
|
|
||||||
type: "success",
|
|
||||||
text: "Successfully updated policy"
|
|
||||||
});
|
|
||||||
onToggle(false);
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
createNotification({
|
|
||||||
type: "error",
|
|
||||||
text: "failed to update policy"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFormSubmit = async (data: TFormSchema) => {
|
|
||||||
if (isEditMode) {
|
|
||||||
await handleUpdatePolicy(data);
|
|
||||||
} else {
|
|
||||||
await handleCreatePolicy(data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const formatEnforcementLevel = (level: EnforcementLevel) => {
|
useEffect(() => {
|
||||||
if (level === EnforcementLevel.Hard) return "Hard";
|
if (!isOpen || !isEditMode) reset({});
|
||||||
if (level === EnforcementLevel.Soft) return "Soft";
|
}, [isOpen, isEditMode]);
|
||||||
return level;
|
|
||||||
};
|
const { mutateAsync: createAccessApprovalPolicy } = useCreateAccessApprovalPolicy();
|
||||||
|
const { mutateAsync: updateAccessApprovalPolicy } = useUpdateAccessApprovalPolicy();
|
||||||
return (
|
|
||||||
<Modal isOpen={isOpen} onOpenChange={onToggle}>
|
const { mutateAsync: createSecretApprovalPolicy } = useCreateSecretApprovalPolicy();
|
||||||
<ModalContent title={isEditMode ? `Edit ${policyName}` : "Create Policy"}>
|
const { mutateAsync: updateSecretApprovalPolicy } = useUpdateSecretApprovalPolicy();
|
||||||
<div className="flex flex-col space-y-3">
|
|
||||||
<form onSubmit={handleSubmit(handleFormSubmit)}>
|
const policyName = policyDetails[watch("policyType")]?.name || "Policy";
|
||||||
<Controller
|
|
||||||
control={control}
|
const handleCreatePolicy = async (data: TFormSchema) => {
|
||||||
name="policyType"
|
if (!projectSlug) return;
|
||||||
defaultValue={PolicyType.ChangePolicy}
|
|
||||||
|
try {
|
||||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
if (data.policyType === PolicyType.ChangePolicy) {
|
||||||
<FormControl
|
await createSecretApprovalPolicy({
|
||||||
label="Policy Type"
|
...data,
|
||||||
isRequired
|
workspaceId: currentWorkspace?.id || ""
|
||||||
isError={Boolean(error)}
|
});
|
||||||
tooltipText="Change polices govern secret changes within a given environment and secret path. Access polices allow underprivileged user to request access to environment/secret path."
|
} else {
|
||||||
errorText={error?.message}
|
await createAccessApprovalPolicy({
|
||||||
>
|
...data,
|
||||||
<Select
|
projectSlug
|
||||||
isDisabled={isEditMode}
|
});
|
||||||
value={value}
|
}
|
||||||
onValueChange={(val) => onChange(val as PolicyType)}
|
createNotification({
|
||||||
className="w-full border border-mineshaft-500"
|
type: "success",
|
||||||
>
|
text: "Successfully created policy"
|
||||||
{Object.values(PolicyType).map((policyType) => {
|
});
|
||||||
return (
|
onToggle(false);
|
||||||
<SelectItem value={policyType} key={`policy-type-${policyType}`}>
|
} catch (err) {
|
||||||
{policyDetails[policyType].name}
|
console.log(err);
|
||||||
</SelectItem>
|
createNotification({
|
||||||
);
|
type: "error",
|
||||||
})}
|
text: "Failed to create policy"
|
||||||
</Select>
|
});
|
||||||
</FormControl>
|
}
|
||||||
)}
|
};
|
||||||
/>
|
|
||||||
<Controller
|
const handleUpdatePolicy = async (data: TFormSchema) => {
|
||||||
control={control}
|
if (!projectSlug) return;
|
||||||
name="name"
|
if (!editValues?.id) return;
|
||||||
render={({ field, fieldState: { error } }) => (
|
|
||||||
<FormControl label="Policy Name" isError={Boolean(error)} errorText={error?.message}>
|
try {
|
||||||
<Input {...field} value={field.value || ""} />
|
if (data.policyType === PolicyType.ChangePolicy) {
|
||||||
</FormControl>
|
await updateSecretApprovalPolicy({
|
||||||
)}
|
id: editValues?.id,
|
||||||
/>
|
...data,
|
||||||
<Controller
|
workspaceId: currentWorkspace?.id || ""
|
||||||
control={control}
|
});
|
||||||
name="environment"
|
} else {
|
||||||
defaultValue={environments[0]?.slug}
|
await updateAccessApprovalPolicy({
|
||||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
id: editValues?.id,
|
||||||
<FormControl
|
...data,
|
||||||
label="Environment"
|
projectSlug
|
||||||
isRequired
|
});
|
||||||
className="mt-4"
|
}
|
||||||
isError={Boolean(error)}
|
createNotification({
|
||||||
errorText={error?.message}
|
type: "success",
|
||||||
>
|
text: "Successfully updated policy"
|
||||||
<Select
|
});
|
||||||
isDisabled={isEditMode}
|
onToggle(false);
|
||||||
value={value}
|
} catch (err) {
|
||||||
onValueChange={(val) => onChange(val)}
|
console.log(err);
|
||||||
className="w-full border border-mineshaft-500"
|
createNotification({
|
||||||
>
|
type: "error",
|
||||||
{environments.map((sourceEnvironment) => (
|
text: "failed to update policy"
|
||||||
<SelectItem
|
});
|
||||||
value={sourceEnvironment.slug}
|
}
|
||||||
key={`azure-key-vault-environment-${sourceEnvironment.slug}`}
|
};
|
||||||
>
|
|
||||||
{sourceEnvironment.name}
|
const handleFormSubmit = async (data: TFormSchema) => {
|
||||||
</SelectItem>
|
if (isEditMode) {
|
||||||
))}
|
await handleUpdatePolicy(data);
|
||||||
</Select>
|
} else {
|
||||||
</FormControl>
|
await handleCreatePolicy(data);
|
||||||
)}
|
}
|
||||||
/>
|
};
|
||||||
<Controller
|
|
||||||
control={control}
|
const formatEnforcementLevel = (level: EnforcementLevel) => {
|
||||||
name="secretPath"
|
if (level === EnforcementLevel.Hard) return "Hard";
|
||||||
render={({ field, fieldState: { error } }) => (
|
if (level === EnforcementLevel.Soft) return "Soft";
|
||||||
<FormControl label="Secret Path" isError={Boolean(error)} errorText={error?.message}>
|
return level;
|
||||||
<Input {...field} value={field.value || ""} />
|
};
|
||||||
</FormControl>
|
|
||||||
)}
|
return (
|
||||||
/>
|
<Modal isOpen={isOpen} onOpenChange={onToggle}>
|
||||||
<Controller
|
<ModalContent title={isEditMode ? `Edit ${policyName}` : "Create Policy"}>
|
||||||
control={control}
|
<div className="flex flex-col space-y-3">
|
||||||
name="approvers"
|
<form onSubmit={handleSubmit(handleFormSubmit)}>
|
||||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
<Controller
|
||||||
<FormControl
|
control={control}
|
||||||
label="Required Approvers"
|
name="policyType"
|
||||||
isRequired
|
defaultValue={PolicyType.ChangePolicy}
|
||||||
isError={Boolean(error)}
|
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||||
errorText={error?.message}
|
<FormControl
|
||||||
>
|
label="Policy Type"
|
||||||
<DropdownMenu>
|
isRequired
|
||||||
<DropdownMenuTrigger asChild>
|
isError={Boolean(error)}
|
||||||
<Input
|
tooltipText="Change polices govern secret changes within a given environment and secret path. Access polices allow underprivileged user to request access to environment/secret path."
|
||||||
isReadOnly
|
errorText={error?.message}
|
||||||
value={value?.length ? `${value.length} selected` : "None"}
|
>
|
||||||
className="text-left"
|
<Select
|
||||||
/>
|
isDisabled={isEditMode}
|
||||||
</DropdownMenuTrigger>
|
value={value}
|
||||||
<DropdownMenuContent
|
onValueChange={(val) => onChange(val as PolicyType)}
|
||||||
style={{ width: "var(--radix-dropdown-menu-trigger-width)" }}
|
className="w-full border border-mineshaft-500"
|
||||||
align="start"
|
>
|
||||||
>
|
{Object.values(PolicyType).map((policyType) => {
|
||||||
<DropdownMenuLabel>
|
return (
|
||||||
Select members that are allowed to approve requests
|
<SelectItem value={policyType} key={`policy-type-${policyType}`}>
|
||||||
</DropdownMenuLabel>
|
{policyDetails[policyType].name}
|
||||||
{members.map(({ id, user }) => {
|
</SelectItem>
|
||||||
const userId = watch("policyType") === PolicyType.ChangePolicy ? user.id : id;
|
);
|
||||||
const isChecked = value?.includes(userId);
|
})}
|
||||||
return (
|
</Select>
|
||||||
<DropdownMenuItem
|
</FormControl>
|
||||||
onClick={(evt) => {
|
)}
|
||||||
evt.preventDefault();
|
/>
|
||||||
onChange(
|
<Controller
|
||||||
isChecked ? value?.filter((el: string) => el !== userId) : [...(value || []), userId]
|
control={control}
|
||||||
);
|
name="name"
|
||||||
}}
|
render={({ field, fieldState: { error } }) => (
|
||||||
key={`create-policy-members-${userId}`}
|
<FormControl
|
||||||
iconPos="right"
|
label="Policy Name"
|
||||||
icon={isChecked && <FontAwesomeIcon icon={faCheckCircle} />}
|
isError={Boolean(error)}
|
||||||
>
|
errorText={error?.message}
|
||||||
{user.username}
|
>
|
||||||
</DropdownMenuItem>
|
<Input {...field} value={field.value || ""} />
|
||||||
);
|
</FormControl>
|
||||||
})}
|
)}
|
||||||
</DropdownMenuContent>
|
/>
|
||||||
</DropdownMenu>
|
<Controller
|
||||||
</FormControl>
|
control={control}
|
||||||
)}
|
name="environment"
|
||||||
/>
|
defaultValue={environments[0]?.slug}
|
||||||
<Controller
|
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||||
control={control}
|
<FormControl
|
||||||
name="approvals"
|
label="Environment"
|
||||||
defaultValue={1}
|
isRequired
|
||||||
render={({ field, fieldState: { error } }) => (
|
className="mt-4"
|
||||||
<FormControl
|
isError={Boolean(error)}
|
||||||
label="Minimum Approvals Required"
|
errorText={error?.message}
|
||||||
isError={Boolean(error)}
|
>
|
||||||
errorText={error?.message}
|
<Select
|
||||||
>
|
isDisabled={isEditMode}
|
||||||
<Input
|
value={value}
|
||||||
{...field}
|
onValueChange={(val) => onChange(val)}
|
||||||
type="number"
|
className="w-full border border-mineshaft-500"
|
||||||
min={1}
|
>
|
||||||
onChange={(el) => field.onChange(parseInt(el.target.value, 10))}
|
{environments.map((sourceEnvironment) => (
|
||||||
/>
|
<SelectItem
|
||||||
</FormControl>
|
value={sourceEnvironment.slug}
|
||||||
)}
|
key={`azure-key-vault-environment-${sourceEnvironment.slug}`}
|
||||||
/>
|
>
|
||||||
<Controller
|
{sourceEnvironment.name}
|
||||||
control={control}
|
</SelectItem>
|
||||||
name="enforcementLevel"
|
))}
|
||||||
defaultValue={EnforcementLevel.Hard}
|
</Select>
|
||||||
render={({ field, fieldState: { error } }) => (
|
</FormControl>
|
||||||
<FormControl
|
)}
|
||||||
label="Enforcement Level"
|
/>
|
||||||
isError={Boolean(error)}
|
<Controller
|
||||||
errorText={error?.message}
|
control={control}
|
||||||
tooltipText="Determines the level of enforcement for required approvers of a request"
|
name="secretPath"
|
||||||
helperText={
|
render={({ field, fieldState: { error } }) => (
|
||||||
field.value === EnforcementLevel.Hard
|
<FormControl
|
||||||
? "All approvers must approve the request."
|
label="Secret Path"
|
||||||
: "All approvers must approve the request; however, the requester can bypass approval requirements in emergencies."
|
isError={Boolean(error)}
|
||||||
}
|
errorText={error?.message}
|
||||||
>
|
>
|
||||||
<Select
|
<Input {...field} value={field.value || ""} />
|
||||||
value={field.value}
|
</FormControl>
|
||||||
onValueChange={(val) => field.onChange(val as EnforcementLevel)}
|
)}
|
||||||
className="w-full border border-mineshaft-500"
|
/>
|
||||||
>
|
<Controller
|
||||||
{Object.values(EnforcementLevel).map((level) => {
|
control={control}
|
||||||
return (
|
name="approverUserIds"
|
||||||
<SelectItem value={level} key={`enforcement-level-${level}`} className="text-xs">
|
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||||
{formatEnforcementLevel(level)}
|
<FormControl
|
||||||
</SelectItem>
|
label="Required Approvers"
|
||||||
);
|
isRequired
|
||||||
})}
|
isError={Boolean(error)}
|
||||||
</Select>
|
errorText={error?.message}
|
||||||
</FormControl>
|
>
|
||||||
)}
|
<DropdownMenu>
|
||||||
/>
|
<DropdownMenuTrigger asChild>
|
||||||
<div className="mt-8 flex items-center space-x-4">
|
<Input
|
||||||
<Button type="submit" isLoading={isSubmitting} isDisabled={isSubmitting}>
|
isReadOnly
|
||||||
Save
|
value={value?.length ? `${value.length} selected` : "None"}
|
||||||
</Button>
|
className="text-left"
|
||||||
<Button onClick={() => onToggle(false)} variant="outline_bg">
|
/>
|
||||||
Close
|
</DropdownMenuTrigger>
|
||||||
</Button>
|
<DropdownMenuContent
|
||||||
</div>
|
style={{ width: "var(--radix-dropdown-menu-trigger-width)" }}
|
||||||
</form>
|
align="start"
|
||||||
</div>
|
>
|
||||||
</ModalContent>
|
<DropdownMenuLabel>
|
||||||
</Modal>
|
Select members that are allowed to approve requests
|
||||||
);
|
</DropdownMenuLabel>
|
||||||
|
{members.map(({ user }) => {
|
||||||
|
const { id: userId } = user;
|
||||||
|
const isChecked = value?.includes(userId);
|
||||||
|
return (
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={(evt) => {
|
||||||
|
evt.preventDefault();
|
||||||
|
onChange(
|
||||||
|
isChecked
|
||||||
|
? value?.filter((el: string) => el !== userId)
|
||||||
|
: [...(value || []), userId]
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
key={`create-policy-members-${userId}`}
|
||||||
|
iconPos="right"
|
||||||
|
icon={isChecked && <FontAwesomeIcon icon={faCheckCircle} />}
|
||||||
|
>
|
||||||
|
{user.username}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="approvals"
|
||||||
|
defaultValue={1}
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
label="Minimum Approvals Required"
|
||||||
|
isError={Boolean(error)}
|
||||||
|
errorText={error?.message}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
type="number"
|
||||||
|
min={1}
|
||||||
|
onChange={(el) => field.onChange(parseInt(el.target.value, 10))}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="enforcementLevel"
|
||||||
|
defaultValue={EnforcementLevel.Hard}
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
label="Enforcement Level"
|
||||||
|
isError={Boolean(error)}
|
||||||
|
errorText={error?.message}
|
||||||
|
tooltipText="Determines the level of enforcement for required approvers of a request"
|
||||||
|
helperText={
|
||||||
|
field.value === EnforcementLevel.Hard
|
||||||
|
? "All approvers must approve the request."
|
||||||
|
: "All approvers must approve the request; however, the requester can bypass approval requirements in emergencies."
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
value={field.value}
|
||||||
|
onValueChange={(val) => field.onChange(val as EnforcementLevel)}
|
||||||
|
className="w-full border border-mineshaft-500"
|
||||||
|
>
|
||||||
|
{Object.values(EnforcementLevel).map((level) => {
|
||||||
|
return (
|
||||||
|
<SelectItem
|
||||||
|
value={level}
|
||||||
|
key={`enforcement-level-${level}`}
|
||||||
|
className="text-xs"
|
||||||
|
>
|
||||||
|
{formatEnforcementLevel(level)}
|
||||||
|
</SelectItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<div className="mt-8 flex items-center space-x-4">
|
||||||
|
<Button type="submit" isLoading={isSubmitting} isDisabled={isSubmitting}>
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
<Button onClick={() => onToggle(false)} variant="outline_bg">
|
||||||
|
Close
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -405,8 +405,21 @@ export const SecretOverviewPage = () => {
|
|||||||
const pathSegment = secretPath.split("/").filter(Boolean);
|
const pathSegment = secretPath.split("/").filter(Boolean);
|
||||||
const parentPath = `/${pathSegment.slice(0, -1).join("/")}`;
|
const parentPath = `/${pathSegment.slice(0, -1).join("/")}`;
|
||||||
const folderName = pathSegment.at(-1);
|
const folderName = pathSegment.at(-1);
|
||||||
console.log(folderName, parentPath);
|
const canCreateFolder = permission.rules.some((rule) =>
|
||||||
if (folderName && parentPath) {
|
(rule.subject as ProjectPermissionSub[]).includes(ProjectPermissionSub.SecretFolders)
|
||||||
|
)
|
||||||
|
? permission.can(
|
||||||
|
ProjectPermissionActions.Create,
|
||||||
|
subject(ProjectPermissionSub.SecretFolders, {
|
||||||
|
environment: slug,
|
||||||
|
secretPath: parentPath
|
||||||
|
})
|
||||||
|
)
|
||||||
|
: permission.can(
|
||||||
|
ProjectPermissionActions.Create,
|
||||||
|
subject(ProjectPermissionSub.Secrets, { environment: slug, secretPath: parentPath })
|
||||||
|
);
|
||||||
|
if (folderName && parentPath && canCreateFolder) {
|
||||||
await createFolder({
|
await createFolder({
|
||||||
projectId: workspaceId,
|
projectId: workspaceId,
|
||||||
environment: slug,
|
environment: slug,
|
||||||
@@ -584,22 +597,14 @@ export const SecretOverviewPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
{userAvailableEnvs.length > 0 && (
|
{userAvailableEnvs.length > 0 && (
|
||||||
<div>
|
<div>
|
||||||
<ProjectPermissionCan
|
<Button
|
||||||
I={ProjectPermissionActions.Create}
|
variant="outline_bg"
|
||||||
a={subject(ProjectPermissionSub.Secrets, { secretPath })}
|
leftIcon={<FontAwesomeIcon icon={faPlus} />}
|
||||||
|
onClick={() => handlePopUpOpen("addSecretsInAllEnvs")}
|
||||||
|
className="h-10 rounded-r-none"
|
||||||
>
|
>
|
||||||
{(isAllowed) => (
|
Add Secret
|
||||||
<Button
|
</Button>
|
||||||
variant="outline_bg"
|
|
||||||
leftIcon={<FontAwesomeIcon icon={faPlus} />}
|
|
||||||
onClick={() => handlePopUpOpen("addSecretsInAllEnvs")}
|
|
||||||
className="h-10 rounded-r-none"
|
|
||||||
isDisabled={!isAllowed}
|
|
||||||
>
|
|
||||||
Add Secret
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</ProjectPermissionCan>
|
|
||||||
<DropdownMenu
|
<DropdownMenu
|
||||||
open={popUp.misc.isOpen}
|
open={popUp.misc.isOpen}
|
||||||
onOpenChange={(isOpen) => handlePopUpToggle("misc", isOpen)}
|
onOpenChange={(isOpen) => handlePopUpToggle("misc", isOpen)}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ClipboardEvent } from "react";
|
import { ClipboardEvent } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
|
import { subject } from "@casl/ability";
|
||||||
import { faWarning } from "@fortawesome/free-solid-svg-icons";
|
import { faWarning } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
@@ -17,7 +18,12 @@ import {
|
|||||||
Tooltip
|
Tooltip
|
||||||
} from "@app/components/v2";
|
} from "@app/components/v2";
|
||||||
import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
|
import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
|
||||||
import { useWorkspace } from "@app/context";
|
import {
|
||||||
|
ProjectPermissionActions,
|
||||||
|
ProjectPermissionSub,
|
||||||
|
useProjectPermission,
|
||||||
|
useWorkspace
|
||||||
|
} from "@app/context";
|
||||||
import { getKeyValue } from "@app/helpers/parseEnvVar";
|
import { getKeyValue } from "@app/helpers/parseEnvVar";
|
||||||
import { useCreateFolder, useCreateSecretV3, useUpdateSecretV3 } from "@app/hooks/api";
|
import { useCreateFolder, useCreateSecretV3, useUpdateSecretV3 } from "@app/hooks/api";
|
||||||
import { SecretType, SecretV3RawSanitized } from "@app/hooks/api/types";
|
import { SecretType, SecretV3RawSanitized } from "@app/hooks/api/types";
|
||||||
@@ -62,6 +68,7 @@ export const CreateSecretForm = ({
|
|||||||
const newSecretKey = watch("key");
|
const newSecretKey = watch("key");
|
||||||
|
|
||||||
const { currentWorkspace } = useWorkspace();
|
const { currentWorkspace } = useWorkspace();
|
||||||
|
const { permission } = useProjectPermission();
|
||||||
const workspaceId = currentWorkspace?.id || "";
|
const workspaceId = currentWorkspace?.id || "";
|
||||||
const environments = currentWorkspace?.environments || [];
|
const environments = currentWorkspace?.environments || [];
|
||||||
|
|
||||||
@@ -86,7 +93,24 @@ export const CreateSecretForm = ({
|
|||||||
const pathSegment = secretPath.split("/").filter(Boolean);
|
const pathSegment = secretPath.split("/").filter(Boolean);
|
||||||
const parentPath = `/${pathSegment.slice(0, -1).join("/")}`;
|
const parentPath = `/${pathSegment.slice(0, -1).join("/")}`;
|
||||||
const folderName = pathSegment.at(-1);
|
const folderName = pathSegment.at(-1);
|
||||||
if (folderName && parentPath) {
|
const canCreateFolder = permission.rules.some((rule) =>
|
||||||
|
(rule.subject as ProjectPermissionSub[]).includes(ProjectPermissionSub.SecretFolders)
|
||||||
|
)
|
||||||
|
? permission.can(
|
||||||
|
ProjectPermissionActions.Create,
|
||||||
|
subject(ProjectPermissionSub.SecretFolders, {
|
||||||
|
environment: env.slug,
|
||||||
|
secretPath: parentPath
|
||||||
|
})
|
||||||
|
)
|
||||||
|
: permission.can(
|
||||||
|
ProjectPermissionActions.Create,
|
||||||
|
subject(ProjectPermissionSub.Secrets, {
|
||||||
|
environment: env.slug,
|
||||||
|
secretPath: parentPath
|
||||||
|
})
|
||||||
|
);
|
||||||
|
if (folderName && parentPath && canCreateFolder) {
|
||||||
await createFolder({
|
await createFolder({
|
||||||
projectId: workspaceId,
|
projectId: workspaceId,
|
||||||
path: parentPath,
|
path: parentPath,
|
||||||
@@ -186,39 +210,52 @@ export const CreateSecretForm = ({
|
|||||||
/>
|
/>
|
||||||
<FormLabel label="Environments" className="mb-2" />
|
<FormLabel label="Environments" className="mb-2" />
|
||||||
<div className="thin-scrollbar grid max-h-64 grid-cols-3 gap-4 overflow-auto py-2">
|
<div className="thin-scrollbar grid max-h-64 grid-cols-3 gap-4 overflow-auto py-2">
|
||||||
{environments.map((env) => {
|
{environments
|
||||||
return (
|
.filter((environmentSlug) =>
|
||||||
<Controller
|
permission.can(
|
||||||
name={`environments.${env.slug}`}
|
ProjectPermissionActions.Create,
|
||||||
key={`secret-input-${env.slug}`}
|
subject(ProjectPermissionSub.Secrets, {
|
||||||
control={control}
|
environment: environmentSlug.slug,
|
||||||
render={({ field }) => (
|
secretPath
|
||||||
<Checkbox
|
})
|
||||||
isChecked={field.value}
|
)
|
||||||
onCheckedChange={field.onChange}
|
)
|
||||||
id={`secret-input-${env.slug}`}
|
.map((env) => {
|
||||||
className="!justify-start"
|
return (
|
||||||
>
|
<Controller
|
||||||
<span className="flex w-full flex-row items-center justify-start whitespace-pre-wrap">
|
name={`environments.${env.slug}`}
|
||||||
<span title={env.name} className="truncate">
|
key={`secret-input-${env.slug}`}
|
||||||
{env.name}
|
control={control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<Checkbox
|
||||||
|
isChecked={field.value}
|
||||||
|
onCheckedChange={field.onChange}
|
||||||
|
id={`secret-input-${env.slug}`}
|
||||||
|
className="!justify-start"
|
||||||
|
>
|
||||||
|
<span className="flex w-full flex-row items-center justify-start whitespace-pre-wrap">
|
||||||
|
<span title={env.name} className="truncate">
|
||||||
|
{env.name}
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
{getSecretByKey(env.slug, newSecretKey) && (
|
||||||
|
<Tooltip
|
||||||
|
className="max-w-[150px]"
|
||||||
|
content="Secret already exists, and it will be overwritten"
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon
|
||||||
|
icon={faWarning}
|
||||||
|
className="ml-1 text-yellow-400"
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<span>
|
</Checkbox>
|
||||||
{getSecretByKey(env.slug, newSecretKey) && (
|
)}
|
||||||
<Tooltip
|
/>
|
||||||
className="max-w-[150px]"
|
);
|
||||||
content="Secret already exists, and it will be overwritten"
|
})}
|
||||||
>
|
|
||||||
<FontAwesomeIcon icon={faWarning} className="ml-1 text-yellow-400" />
|
|
||||||
</Tooltip>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</Checkbox>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-7 flex items-center">
|
<div className="mt-7 flex items-center">
|
||||||
<Button
|
<Button
|
||||||
|
|||||||