Skip to content

Commit

Permalink
AB#1004 Make primary advisor and primary principal configurable throu…
Browse files Browse the repository at this point in the history
…gh the dictionary
  • Loading branch information
gjvoosten committed Dec 13, 2023
1 parent dc755f4 commit 12e777e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 37 deletions.
2 changes: 2 additions & 0 deletions anet-dictionary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ fields:
filter: [POINT_LOCATION, VIRTUAL_LOCATION]
reportPeople:
optionalAttendingAuthor: false
optionalPrimaryAdvisor: false
optionalPrimaryPrincipal: true
customFields:
relatedReport:
type: anet_object
Expand Down
72 changes: 40 additions & 32 deletions client/src/models/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,10 @@ export default class Report extends Model {
.array()
.nullable()
.when("cancelled", ([cancelled], schema) =>
// Only do validation warning when engagement not cancelled
cancelled
? schema.nullable()
: schema // Only do validation warning when engagement not cancelled
.test(
"primary-advisor",
"primary advisor error",
(reportPeople, testContext) => {
const message = Report.checkPrimaryAttendee(
reportPeople,
Person.ROLE.ADVISOR
)
return message ? testContext.createError({ message }) : true
}
)
? schema
: Report.testPrimaryAttendees(schema, false)
.test(
"no-author",
"no author error",
Expand Down Expand Up @@ -281,20 +271,8 @@ export default class Report extends Model {
.array()
.nullable()
.when("cancelled", ([cancelled], schema) =>
cancelled
? schema.nullable()
: schema // Only do validation warning when engagement not cancelled
.test(
"primary-principal",
"primary principal error",
(reportPeople, testContext) => {
const message = Report.checkPrimaryAttendee(
reportPeople,
Person.ROLE.PRINCIPAL
)
return message ? testContext.createError({ message }) : true
}
)
// Only do validation warning when engagement not cancelled
cancelled ? schema : Report.testPrimaryAttendees(schema, true)
),
reportSensitiveInformation: yup.object().nullable().default({}),
authorizationGroups: yup
Expand All @@ -317,6 +295,36 @@ export default class Report extends Model {
)
})

static testPrimaryAttendees(schema, asWarning) {
return schema
.test(
"primary-advisor",
"primary advisor error",
(reportPeople, testContext) => {
const message = Report.checkPrimaryAttendee(
reportPeople,
Person.ROLE.ADVISOR,
Settings.fields.report.reportPeople?.optionalPrimaryAdvisor,
asWarning
)
return message ? testContext.createError({ message }) : true
}
)
.test(
"primary-principal",
"primary principal error",
(reportPeople, testContext) => {
const message = Report.checkPrimaryAttendee(
reportPeople,
Person.ROLE.PRINCIPAL,
Settings.fields.report.reportPeople?.optionalPrimaryPrincipal,
asWarning
)
return message ? testContext.createError({ message }) : true
}
)
}

static autocompleteQuery = "uuid, intent, authors { uuid, name, rank, role }"

constructor(props) {
Expand Down Expand Up @@ -404,13 +412,13 @@ export default class Report extends Model {
return this.intent || "None"
}

static checkPrimaryAttendee(reportPeople, role) {
static checkPrimaryAttendee(reportPeople, role, optional, asWarning) {
const primaryAttendee = Report.getPrimaryAttendee(reportPeople, role)
const roleName = Person.humanNameOfRole(role)
if (!primaryAttendee && role === Person.ROLE.ADVISOR) {
return `You must provide the primary ${roleName} for the Engagement`
} else if (!primaryAttendee && role === Person.ROLE.PRINCIPAL) {
return `No primary ${roleName} has been provided for the Engagement`
if (!primaryAttendee) {
if ((optional && asWarning) || (!optional && !asWarning)) {
return `No primary ${roleName} has been provided for the Engagement`
}
} else if (primaryAttendee.status !== Model.STATUS.ACTIVE) {
return `The primary ${roleName} - ${primaryAttendee.name} - needs to have an active profile`
} else if (
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/mil/dds/anet/resources/ReportResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,26 @@ public int submitReport(@GraphQLRootContext Map<String, Object> context,

if (r.getAdvisorOrgUuid() == null) {
final ReportPerson advisor = r.loadPrimaryAdvisor(engine.getContext()).join();
final Boolean optionalPrimaryAdvisor =
(Boolean) config.getDictionaryEntry("fields.report.reportPeople.optionalPrimaryAdvisor");
if (advisor == null) {
throw new WebApplicationException("Report missing primary advisor", Status.BAD_REQUEST);
if (!Boolean.TRUE.equals(optionalPrimaryAdvisor)) {
throw new WebApplicationException("Report missing primary advisor", Status.BAD_REQUEST);
}
} else {
r.setAdvisorOrg(
engine.getOrganizationForPerson(engine.getContext(), advisor.getUuid()).join());
}
r.setAdvisorOrg(
engine.getOrganizationForPerson(engine.getContext(), advisor.getUuid()).join());
}
if (r.getPrincipalOrgUuid() == null) {
final ReportPerson principal = r.loadPrimaryPrincipal(engine.getContext()).join();
if (principal != null) {
final Boolean optionalPrimaryPrincipal = (Boolean) config
.getDictionaryEntry("fields.report.reportPeople.optionalPrimaryPrincipal");
if (principal == null) {
if (!Boolean.TRUE.equals(optionalPrimaryPrincipal)) {
throw new WebApplicationException("Report missing primary principal", Status.BAD_REQUEST);
}
} else {
r.setPrincipalOrg(
engine.getOrganizationForPerson(engine.getContext(), principal.getUuid()).join());
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/anet-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -641,12 +641,20 @@ properties:
enum:
[VIRTUAL_LOCATION, PHYSICAL_LOCATION, GEOGRAPHICAL_AREA, POINT_LOCATION, ADVISOR_LOCATION, PRINCIPAL_LOCATION]
reportPeople:
required: [optionalAttendingAuthor]
required: [optionalAttendingAuthor, optionalPrimaryAdvisor, optionalPrimaryPrincipal]
properties:
optionalAttendingAuthor:
type: boolean
default: false
description: Defines if having an attending author for a report is optional
optionalPrimaryAdvisor:
type: boolean
default: false
description: Defines if having a primary advisor for a report is optional
optionalPrimaryPrincipal:
type: boolean
default: false
description: Defines if having a primary principal for a report is optional
customFields:
type: object
additionalProperties:
Expand Down
2 changes: 2 additions & 0 deletions testDictionaries/no-custom-fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ fields:
filter: [POINT_LOCATION, VIRTUAL_LOCATION]
reportPeople:
optionalAttendingAuthor: false
optionalPrimaryAdvisor: false
optionalPrimaryPrincipal: true
attendeeGroups:
- label: Linguists
filter:
Expand Down

0 comments on commit 12e777e

Please sign in to comment.