mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 09:26:47 +00:00
feat(access-request): code improvements
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import { Knex } from "knex";
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
import { ApprovalStatus } from "@app/ee/services/secret-approval-request/secret-approval-request-types";
|
||||||
|
|
||||||
import { TableName } from "../schemas";
|
import { TableName } from "../schemas";
|
||||||
|
|
||||||
export async function up(knex: Knex): Promise<void> {
|
export async function up(knex: Knex): Promise<void> {
|
||||||
@@ -17,12 +19,12 @@ export async function up(knex: Knex): Promise<void> {
|
|||||||
|
|
||||||
if (!hasStatusColumn) {
|
if (!hasStatusColumn) {
|
||||||
await knex.schema.alterTable(TableName.AccessApprovalRequest, (t) => {
|
await knex.schema.alterTable(TableName.AccessApprovalRequest, (t) => {
|
||||||
t.string("status").defaultTo("pending").notNullable();
|
t.string("status").defaultTo(ApprovalStatus.PENDING).notNullable();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update existing rows based on business logic
|
// Update existing rows based on business logic
|
||||||
// If privilegeId is not null, set status to "approved"
|
// If privilegeId is not null, set status to "approved"
|
||||||
await knex(TableName.AccessApprovalRequest).whereNotNull("privilegeId").update({ status: "approved" });
|
await knex(TableName.AccessApprovalRequest).whereNotNull("privilegeId").update({ status: ApprovalStatus.APPROVED });
|
||||||
|
|
||||||
// If privilegeId is null and there's a rejected reviewer, set to "rejected"
|
// If privilegeId is null and there's a rejected reviewer, set to "rejected"
|
||||||
const rejectedRequestIds = await knex(TableName.AccessApprovalRequestReviewer)
|
const rejectedRequestIds = await knex(TableName.AccessApprovalRequestReviewer)
|
||||||
@@ -35,7 +37,7 @@ export async function up(knex: Knex): Promise<void> {
|
|||||||
await knex(TableName.AccessApprovalRequest)
|
await knex(TableName.AccessApprovalRequest)
|
||||||
.whereNull("privilegeId")
|
.whereNull("privilegeId")
|
||||||
.whereIn("id", rejectedRequestIds)
|
.whereIn("id", rejectedRequestIds)
|
||||||
.update({ status: "rejected" });
|
.update({ status: ApprovalStatus.REJECTED });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -392,7 +392,7 @@ export const accessApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
// an approval is pending if there is no reviewer rejections, no privilege ID is set and the number of approvals is less than the number of approvals required
|
// an approval is pending if there is no reviewer rejections, no privilege ID is set and the status is pending
|
||||||
const pendingApprovals = formattedRequests.filter(
|
const pendingApprovals = formattedRequests.filter(
|
||||||
(req) =>
|
(req) =>
|
||||||
!req.privilegeId &&
|
!req.privilegeId &&
|
||||||
|
|||||||
Reference in New Issue
Block a user