Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix report approval by admins and when automatic #4936

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions client/src/components/ReportWorkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const ACTION_TYPE_DETAILS = {
UNPUBLISH: { text: "Unpublished", cssClass: "btn-danger unpublished" },
null: { text: "Pending", cssClass: "btn-pending default" }
}
const SYSTEM_USER = "system"

const ApprovalStepModalStatus = ({ action }) => {
if (action.type) {
Expand All @@ -27,7 +28,7 @@ const ApprovalStepModalStatus = ({ action }) => {
<LinkTo
modelType="Person"
model={action.person}
whenUnspecified="system"
whenUnspecified={SYSTEM_USER}
isLink={false}
/>{" "}
on
Expand Down Expand Up @@ -109,7 +110,12 @@ export const ActionButton = ({ action }) => {
disabled
>
<span>
<LinkTo modelType="Person" model={action.person} isLink={false} />
<LinkTo
modelType="Person"
model={action.person}
whenUnspecified={SYSTEM_USER}
isLink={false}
/>
</span>
</Button>
)
Expand All @@ -127,7 +133,7 @@ const ActionDetails = ({ action }) => {
<LinkTo
modelType="Person"
model={action.person}
whenUnspecified="system"
whenUnspecified={SYSTEM_USER}
/>
</span>
<br />
Expand Down
8 changes: 4 additions & 4 deletions client/src/pages/reports/Show.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,11 @@ const ReportShow = ({ setSearchQuery, pageDispatchers }) => {
)
const tasksLabel = pluralize(Settings.fields.task.shortLabel)

// User can approve when admin,
// or if report is pending approval and user is one of the approvers in the current approval step
// User can approve when report is pending approval,
// and user is admin or user is one of the approvers in the current approval step
const canApprove =
isAdmin ||
(report.isPending() &&
report.isPending() &&
(isAdmin ||
report.approvalStep?.approvers?.some(member =>
Position.isEqual(member, currentUser?.position)
))
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mil/dds/anet/resources/ReportResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public int approveReport(@GraphQLRootContext Map<String, Object> context,
}

// Verify that this user can approve for this step.
final boolean canApprove = engine
final boolean canApprove = AuthUtils.isAdmin(approver) || engine
.canUserApproveStep(engine.getContext(), approver.getUuid(), step, r.getAdvisorOrgUuid())
.join();
if (!canApprove) {
Expand Down
41 changes: 20 additions & 21 deletions src/main/java/mil/dds/anet/threads/ReportApprovalWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,29 @@ protected void runInternal(Instant now, JobHistory jobHistory, Map<String, Objec
logger.error("Couldn't process report approval for report {}, it has no workflow",
r.getUuid());
} else {
for (int i = workflow.size() - 1; i >= 0; i--) {
for (int i = workflow.size() - 1; i >= 1; i--) {
final ReportAction reportAction = workflow.get(i);
if (reportAction.getCreatedAt() == null && i > 1) {
// Check previous action
final ReportAction previousAction = workflow.get(i - 1);
if (previousAction.getCreatedAt() != null
&& previousAction.getCreatedAt().isBefore(approvalTimeout)) {
// Approve the report
try {
final ApprovalStep approvalStep = reportAction.getStep();
final int numRows = dao.approve(r, null, approvalStep);
if (numRows == 0) {
logger.error("Couldn't process report approval for report {} step {}",
r.getUuid(), DaoUtils.getUuid(approvalStep));
} else {
AnetAuditLogger.log(
"report {} step {} automatically approved by the ReportApprovalWorker",
r.getUuid(), DaoUtils.getUuid(approvalStep));
}
} catch (Exception e) {
logger.error("Exception when approving report", e);
final ReportAction previousAction = workflow.get(i - 1);
if (reportAction.getCreatedAt() == null
// Check previous action
&& previousAction.getCreatedAt() != null
&& previousAction.getCreatedAt().isBefore(approvalTimeout)) {
// Approve the report
try {
final ApprovalStep approvalStep = reportAction.getStep();
final int numRows = dao.approve(r, null, approvalStep);
if (numRows == 0) {
logger.error("Couldn't process report approval for report {} step {}",
r.getUuid(), DaoUtils.getUuid(approvalStep));
} else {
AnetAuditLogger.log(
"report {} step {} automatically approved by the ReportApprovalWorker",
r.getUuid(), DaoUtils.getUuid(approvalStep));
}
break;
} catch (Exception e) {
logger.error("Exception when approving report", e);
}
break;
}
}
}
Expand Down
Loading