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

#953 - Part 2 Generate review assignments action not auto assign final decision #955

Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e0059c4
Stop creating FinalDecision assignments differently, they should also…
Nov 7, 2022
545628d
Merge remote-tracking branch 'origin/54T-prevent-overlapping-assignme…
Nov 7, 2022
520d7fc
Fix AssignmentStatus update for selfAssignment reviews setting others…
Nov 7, 2022
203d601
Delete action not used - after decision to not lock other self-assign…
Nov 7, 2022
bbb0491
Update docs to remove action and generate new Assignment isLocked = true
Nov 7, 2022
a1db36b
Remove type ASSIGN_LOCKED, remove duplicated declartion of applicatio…
Nov 8, 2022
9d106bc
use plural name for variable
Nov 8, 2022
f570ea6
Revert wrong removal of file
Nov 8, 2022
a5aff90
Delete table from separated file to keep in 43_view_functions_trigger…
Nov 8, 2022
22623a1
Delete table from separated file to keep in 43_view_functions_trigger…
Nov 8, 2022
3fa2d71
Revert change to remove table for view. Just update on migration code
Nov 8, 2022
94f06b6
Merge branch 'feature/final-decision-fixes' into #953-generateReviewA…
CarlosNZ Nov 8, 2022
52ce0d8
Fix functions and migration script
CarlosNZ Nov 9, 2022
4469444
Set isLocked to be false in generateReviewAssignment for existing ass…
Nov 9, 2022
ec05384
Have to also lock the ReviewAssignment linked to the Review sending a…
Nov 9, 2022
33d8b60
Revert accidental change
Nov 10, 2022
6f187f3
Set ReviewAssignment to locked for Review submitted as Changes requir…
Nov 10, 2022
20a80b4
Improve documentation about action to Generate Review Assignments
Nov 10, 2022
5131912
Reverting changed for isLocked in generateReviewAssignments and updat…
Nov 10, 2022
eb76dcb
Add log of reviews to be updated
Nov 10, 2022
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
1 change: 0 additions & 1 deletion database/buildSchema/36_action_list_types.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ DROP TYPE IF EXISTS public.assigner_action;

CREATE TYPE public.assigner_action AS ENUM (
'ASSIGN',
'ASSIGN_LOCKED',
'RE_ASSIGN'
);

Expand Down
68 changes: 63 additions & 5 deletions database/buildSchema/43_views_functions_triggers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,46 @@ DROP TRIGGER IF EXISTS review_assignment_validate_section_trigger ON public.revi
CREATE TRIGGER review_assignment_validate_section_trigger
BEFORE UPDATE ON public.review_assignment
FOR EACH ROW
WHEN (NEW.trigger IS NULL AND OLD.trigger IS NULL)
WHEN (NEW.trigger IS NOT NULL AND OLD.trigger IS NULL)
EXECUTE FUNCTION public.enforce_asssigned_section_validity ();

-- FUNCTION to return `available_sections` for a given review_assignment based
-- on other assignments and allowed sections
CREATE OR REPLACE FUNCTION public.review_assignment_available_sections (assignment public.review_assignment)
RETURNS varchar[]
AS $$
SELECT
ARRAY ( WITH my_array AS (
SELECT DISTINCT
(ts.code) available_sections
FROM
template_section ts
JOIN TEMPLATE t ON t.id = ts.template_id
JOIN application a ON a.template_id = t.id
WHERE
a.id = $1.application_id
)
SELECT
available_sections
FROM
my_array
WHERE
available_sections NOT IN (
SELECT
unnest(assigned_sections)
FROM
review_assignment
WHERE
status = 'ASSIGNED'
AND stage_id = $1.stage_id
AND level_number = $1.level_number
AND application_id = $1.application_id)
AND (available_sections = ANY ($1.allowed_sections)
OR $1.allowed_sections IS NULL))
$$
LANGUAGE sql
STABLE;

-- TRIGGER (Listener) on review_assignment table: To update trigger
DROP TRIGGER IF EXISTS review_assignment_trigger ON public.review_assignment;

Expand Down Expand Up @@ -1288,10 +1325,6 @@ CREATE OR REPLACE FUNCTION assigner_list (stage_id int, assigner_id int)
AND assigned_questions_count (application_id, $1, level_number) >= reviewable_questions_count (application_id)
AND submitted_assigned_questions_count (application_id, $1, level_number) < assigned_questions_count (application_id, $1, level_number) THEN
'RE_ASSIGN'
WHEN COUNT(DISTINCT (review_assignment.id)) != 0
AND assigned_questions_count (application_id, $1, level_number) >= reviewable_questions_count (application_id)
AND submitted_assigned_questions_count (application_id, $1, level_number) >= assigned_questions_count (application_id, $1, level_number) THEN
'ASSIGN_LOCKED'
WHEN COUNT(DISTINCT (review_assignment.id)) != 0
AND assigned_questions_count (application_id, $1, level_number) < reviewable_questions_count (application_id) THEN
'ASSIGN'
Expand Down Expand Up @@ -1383,6 +1416,31 @@ LANGUAGE sql
STABLE;

-- APPLICATION_LIST_VIEW
-- Aggregated VIEW method of all data required for application list page
-- Requires an empty table as setof return and smart comment to make orderBy work (https://github.com/graphile/graphile-engine/pull/378)
DROP TABLE IF EXISTS application_list_shape CASCADE;

CREATE TABLE IF NOT EXISTS application_list_shape (
id int,
"serial" varchar,
"name" varchar,
template_code varchar,
template_name varchar,
applicant varchar,
org_name varchar,
stage varchar,
stage_colour varchar,
"status" public.application_status,
outcome public.application_outcome,
last_active_date timestamptz,
applicant_deadline timestamptz,
-- TO-DO: reviewer_deadline
assigners varchar[],
reviewers varchar[],
reviewer_action public.reviewer_action,
assigner_action public.assigner_action
);

CREATE OR REPLACE FUNCTION application_list (userid int DEFAULT 0)
RETURNS SETOF application_list_shape
AS $$
Expand Down
11 changes: 11 additions & 0 deletions database/migration/migrateData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,17 @@ const migrateData = async () => {
ALTER TABLE data_table
ADD COLUMN data_view_code varchar;
`)

console.log(' - Remove type ASSIGN_LOCKED from assign_action ENUM')
await DB.changeSchema(`
DROP TYPE IF EXISTS public.assigner_action CASCADE;

CREATE TYPE public.assigner_action AS ENUM
(
'ASSIGN',
'RE_ASSIGN'
);
`)
}
// Other version migrations continue here...

Expand Down
22 changes: 5 additions & 17 deletions documentation/List-of-Action-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
- [Grant Permissions](#grant-permissions)
- [Revoke Permissions](#revoke-permissions)
- [Generate Review Assignments](#generate-review-assignments)
- [Update Review Assignments](#update-review-assignments)
- [Refresh Review Assignments](#refresh-review-assignments)
- [Trim Responses](#trim-responses)
- [Update Review Visibility](#update-review-visibility)
Expand Down Expand Up @@ -461,7 +460,11 @@ See [Grant Permissions](#grant-permissions) above regarding acting on user-only

### Generate Review Assignments

Generates records in the `review_assignment` table -- i.e. which users (reviewers) are allowed to do a review for the current stage/level (and for which Sections). The records are set with `status` "Available" or "Assigned" and flags for `isSelfAssignable` and `isLocked` to help define when is allowed self-assignment.
Generates records in the `review_assignment` table -- i.e. which users (reviewers) are allowed to do a review for the current stage/level (and for which Sections).
- Records are set with `status` "Available" or "Assigned".
- Each record has properties to specify the type of assignment:
- `isSelfAssignable` if it should show for self-assignment when not assigned by another user
- `isLocked` defining that the review can start but not be submitted (Used for applications which has been sent back to Applicant for ammendments)

It also creates records in the `review_assignment_assigner_join` table -- basically a list of users who have permission to make the _assignments_ in the review_assignment table.

Expand All @@ -487,21 +490,6 @@ Should be run whenever an application or review is submitted or re-submitted, an

---

### Update Review Assignments

When a reviewer self-assigns themselves to a review_assignment (i.e. its status changes from "Available" to "Assigned") the other review assignment records pertaining to that review/stage/level are marked as "is_locked = true" so that no other reviewer can start a review for the same thing.

- _Action Code:_ **`updateReviewAssignmentsStatus`**

| Input parameters<br />(\*required) <br/> | Output properties |
| ---------------------------------------------------- | ----------------------------------------------------- |
| `reviewAssignmentId`\* | `reviewAssignmentUpdates` (`array` of `{id, status}`) |
| `trigger` (only executes on `ON_REVIEW_SELF_ASSIGN`) | |

**Note:** If `trigger` is not supplied, the plugin will try to infer it from `applicationData`

---

### Refresh Review Assignments

A "super-action", which regenerates all `review_assignment` and `review_assignment_assigner_join` records associated with a specific user, or group of users (or all users). It does this by figuring out which active applications are associated with the input user(s), and then running [`generateReviewAssignments`](#generate-review-assignments) on each of them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,7 @@ const generateNextReviewAssignments: RegerenateReviewAssignments = (
// Get assignmentState with: status, isLocked and isSelfAssigned (to create new or update)
const assignment = getNewOrExistingAssignmentStatus(
existingReviewsAssigned,
reviewer.canMakeFinalDecision,
reviewer.canSelfAssign || nextReviewLevel > 1,
sectionCodes,
existingAssignment
)

Expand Down Expand Up @@ -456,41 +454,24 @@ const constructReviewAssignmentObject = (
// Checks if existing assignment, should keep status and update if isLocked
const getNewOrExistingAssignmentStatus = (
existingReviewsAssigned: ExistingReviewAssignment[],
canMakeFinalDecision: boolean,
isSelfAssignable: boolean,
sectionCodes: string[],
existingAssignment?: ExistingReviewAssignment
): AssignmentState => {
const isReviewAssigned = existingReviewsAssigned.length > 0
const isAssigned = existingReviewsAssigned.some(
({ userId }) => userId === existingAssignment?.userId
)
// temporarily final decision shouldn't be locked if there are other reviewAssignment assigned
// Note: This logic will be updated during implementation of ISSUE #836 (front-end) to allow
// locking other reviewAssignments for finalDecision once one has been submitted.
if (canMakeFinalDecision)
return {
status: ReviewAssignmentStatus.Assigned,
isSelfAssignable: true,
isLocked: false,
assignedSections: sectionCodes,
}

// Create new OR update ReviewAssignment:
// Create NEW or update EXISTING ReviewAssignment:
// 1. If existing
// - keep same status, isSelfAssignable
// - just update isLocked = true (if already assigned to another)
// - set isLocked = false
// 2. If new reviewAssignment:
// - status = Available (always)
// - if review canSelfAssign set isSelfAssignable = true (Default: false)
// - if isReviewAssigned then isLocked = true (only when is self-assignable)
// - isLocked = false (unless is existing, assigned and locked)
// - isSelfAssignable = true if canSelfAssign (Default: false)
return {
status: existingAssignment?.status ?? ReviewAssignmentStatus.Available,
isSelfAssignable: existingAssignment?.isSelfAssignable ?? isSelfAssignable,
isLocked:
existingAssignment && isAssigned
? existingAssignment.isLocked
: isReviewAssigned && isSelfAssignable,
isLocked: existingAssignment && isAssigned ? existingAssignment.isLocked : false,
}
}

Expand Down
13 changes: 0 additions & 13 deletions plugins/action_update_review_assignments_status/package.json

This file was deleted.

24 changes: 0 additions & 24 deletions plugins/action_update_review_assignments_status/plugin.json

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions plugins/action_update_review_assignments_status/src/index.ts

This file was deleted.

Loading