Skip to content

Commit

Permalink
fix: allow admins to delete opps under review
Browse files Browse the repository at this point in the history
(cherry picked from commit 13dc4e1)
  • Loading branch information
IanFonzie authored and bdolor committed Feb 14, 2024
1 parent 303ffb8 commit c9f1ad4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
10 changes: 8 additions & 2 deletions src/back-end/lib/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { Affiliation } from "shared/lib/resources/affiliation";
import {
CWUOpportunity,
CWUOpportunityStatus,
doesCWUOpportunityStatusAllowGovToViewProposals
} from "shared/lib/resources/opportunity/code-with-us";
import {
Expand Down Expand Up @@ -351,12 +352,17 @@ export async function editCWUOpportunity(
export async function deleteCWUOpportunity(
connection: Connection,
session: Session,
opportunityId: string
opportunityId: string,
status: CWUOpportunityStatus
): Promise<boolean> {
return (
isAdmin(session) ||
(isAdmin(session) &&
[CWUOpportunityStatus.Draft, CWUOpportunityStatus.UnderReview].includes(
status
)) ||
(session &&
isGovernment(session) &&
status === CWUOpportunityStatus.Draft &&
(await isCWUOpportunityAuthor(
connection,
session.user,
Expand Down
22 changes: 10 additions & 12 deletions src/back-end/lib/resources/opportunity/code-with-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1089,28 +1089,26 @@ const delete_: crud.Delete<
> = (connection: db.Connection) => {
return {
async validateRequestBody(request) {
const validatedCWUOpportunity = await validateCWUOpportunityId(
connection,
request.params.id,
request.session
);
if (isInvalid(validatedCWUOpportunity)) {
return invalid({ notFound: ["Opportunity not found."] });
}
if (
!(await permissions.deleteCWUOpportunity(
connection,
request.session,
request.params.id
request.params.id,
validatedCWUOpportunity.value.status
))
) {
return invalid({
permissions: [permissions.ERROR_MESSAGE]
});
}
const validatedCWUOpportunity = await validateCWUOpportunityId(
connection,
request.params.id,
request.session
);
if (isInvalid(validatedCWUOpportunity)) {
return invalid({ notFound: ["Opportunity not found."] });
}
if (validatedCWUOpportunity.value.status !== CWUOpportunityStatus.Draft) {
return invalid({ permissions: [permissions.ERROR_MESSAGE] });
}
return valid(validatedCWUOpportunity.value.id);
},
respond: wrapRespond({
Expand Down

0 comments on commit c9f1ad4

Please sign in to comment.