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

Save collaborators to report #272

Merged
merged 24 commits into from
Jan 29, 2021
Merged

Save collaborators to report #272

merged 24 commits into from
Jan 29, 2021

Conversation

jasalisbury
Copy link
Contributor

@jasalisbury jasalisbury commented Jan 28, 2021

Description of change

Includes a few additional improvements, got bigger because I refactored some tests to hopefully make them easier to deal with in the future.

  • Collaborators join table added.
  • Collaborators hooked up on the frontend. Available collaborators depends on the report's region (hardcoded to 1 for now)
  • Activity report checks permissions
  • Added the first "policies" which can be used for authorization. Should be easier to test separated from controllers
  • Route tests that hit the DB moved to the services folder, only deal with the DB interactions
  • Route tests mock out DB and authorization calls focusing on constructing correct responses based on (mocked) calls to the DB/policies
  • Multiselect sets null values to an empty array, allowing collaborators/recipients to be "zeroed" in the report
  • Approvers are scoped to region
  • The activity report now makes all API calls up front in parallel. Should keep other components simpler and cuts down on calls to the API (they can be made once instead on every form page load)
  • Added Krys and I to seeders as Admins so we should be admins in sandbox/dev until HSES resets again. (can add others to the seeders but we were the only two who currently have accounts on sandbox, so the only two I know HSES ids)
  • Updated swagger/API docs

How to test

  1. Browse to dev
  2. Fill out a report, add Chuck or Josh as a collaborator (If you aren't on the list I can add you, just ping me. Permissions should be setup correctly on Dev unless another deploy happens)
  3. Verify collaborators persist across reloads
  4. Send the ID of the report to someone who isn't a collaborator and verify they can't access the report

Note
I still need to update API docs/DB docs

Issue(s)

Checklist

  • Meets issue criteria
  • Code tested
  • Meets accessibility standards (WCAG 2.1 Levels A, AA)
  • Documentation updated

jasalisbury and others added 17 commits January 22, 2021 16:54
Includes a few additional imporvements

 * Collaborators join table added.
 * Collaborators hooked up on the frontend. Avaliable collaborators
depends on the report's region (hardcoded to 1 for now)
 * Activity report checks permissions
 * Added the first "policies" which can be used for authorization.
Should be easier to test separated from controllers
 * Route tests that hit the DB moved to the services folder, only deal
with the DB ineractions
 * Route tests mock out DB and authorization calls focusing on
constructing correct responses based on (mocked) calls to the DB/policies
 * Multiselect sets null values to an empty array, allowing
collaborators/recipients to be "zeroed" in the report
 * Approvers are scoped to region
 * The activity report now makes all API calls up front in parallel.
Should keep other components simpler and cuts down on calls to the API
(they can be made once instead on every form page load)
 * Added Krys and I to seeders as Admins so we should be admins in
sandbox/dev until HSES resets again. (can add others to the seeders but
we were the only two who currently have accounts on sandbox, so the only
two I know HSES ids)
Conflicts:
	.circleci/config.yml
	frontend/src/pages/ActivityReport/Pages/ReviewSubmit.js
	frontend/src/pages/ActivityReport/Pages/__tests__/ReviewSubmit.js
	frontend/src/pages/ActivityReport/Pages/index.js
	frontend/src/pages/ActivityReport/index.js
	src/services/activityReports.js
Conflicts:
	src/models/activityReport.js
	src/routes/apiDirectory.js
 * Add unique indexes to Activity Recipient and collaborators join
   tables
 * Replace lodash functions in two places
 * collaborators and recipients are "upsert"ed instead of all removed
   and recreated
 * Add FIXME to comment
Conflicts:
	src/routes/files/handlers.test.js
Copy link
Contributor

@rahearn rahearn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work. I really like the policies classes.

@@ -107,7 +107,7 @@ components:
description: The type of the activity, Training or Technical Assistance (or both)
items:
type: string
approvingUser:
selectableUser:
type: object
description: Users with permission to approve reports
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description should be updated as well, now that this could be a user being selected for any purpose

@@ -3,8 +3,8 @@ import { get, put, post } from './index';

const activityReportUrl = join('/', 'api', 'activity-reports');

export const fetchApprovers = async () => {
const res = await get(join(activityReportUrl, 'approvers'));
export const fetchApprovers = async (region) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency's sake, it looks like we have a couple of getXXX methods in this file, and then one fetchApprovers. Can we standardize on getThing?

@@ -12,7 +12,6 @@ import {
nonGranteeParticipants,
granteeParticipants,
reasons,
otherUsers,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// The key in the join table that points to the model defined in this file
foreignKey: 'activityReportId',
// The key in the join table that points to the "target" of the belongs to many (Users in
// this case)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A+ comment to keep the two keys straight.

src/routes/activityReports/handlers.js Show resolved Hide resolved
],

it('returns the report', async () => {
ActivityReport.prototype.canUpdate = jest.fn().mockReturnValue(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some of my javascript ignorance showing, but, how does this implementation impact the rest of the tests? Does this pollute everything? Or is it somehow scoped to this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good question, I'll look into it.

@jasalisbury
Copy link
Contributor Author

Awesome work. I really like the policies classes.

Stole the pattern from a great ruby library https://github.com/varvet/pundit

@rahearn
Copy link
Contributor

rahearn commented Jan 29, 2021

Stole the pattern from a great ruby library https://github.com/varvet/pundit

Probably why I like it, I use pundit on all of my ruby apps.

 * Properly mock classes in activity report tests
 * Update description of API doc "selectableUser"
 * Rename 'fetchApprovers' to 'getApprovers'
 * Remove 'otherUsers' from constants
@rahearn rahearn merged commit 541640a into HHS:main Jan 29, 2021
dcmcand referenced this pull request in adhocteam/Head-Start-TTADP Feb 10, 2021
commit d1c5786
Merge: 44eeeb8 059425c
Author: Ryan Ahearn <[email protected]>
Date:   Tue Feb 9 17:10:20 2021 -0500

    Merge pull request #157 from HHS/user-last-login

    Allow filtering users by last login and access permissions

commit 059425c
Author: Ryan Ahearn <[email protected]>
Date:   Tue Feb 9 15:25:09 2021 -0500

    Make eslint happy

commit 09e906f
Author: Ryan Ahearn <[email protected]>
Date:   Tue Feb 9 14:46:50 2021 -0500

    Refactor user filtering to match access control SOP rules directly

commit facfee4
Author: Ryan Ahearn <[email protected]>
Date:   Tue Feb 9 14:03:29 2021 -0500

    Allow filtering by only showing users who do have SITE_ACCESS

commit b5b93f0
Author: Ryan Ahearn <[email protected]>
Date:   Tue Feb 9 13:40:44 2021 -0500

    Allow filtering by last login > 60 or 180 days ago

    Options to match process here: https://github.com/HHS/Head-Start-TTADP/wiki/Access-Control-&-Account-Management-SOP#account-review-frequency-and-process

commit 1d08788
Author: Ryan Ahearn <[email protected]>
Date:   Tue Feb 9 12:18:39 2021 -0500

    Display lastLogin on admin user details

commit 31883dd
Author: Ryan Ahearn <[email protected]>
Date:   Tue Feb 9 11:12:00 2021 -0500

    Add lastLogin to user api response

commit 60bbefd
Author: Ryan Ahearn <[email protected]>
Date:   Tue Feb 9 10:20:03 2021 -0500

    Add lastLogin value to user model & update on login

commit 1a2dd2c
Author: Ryan Ahearn <[email protected]>
Date:   Tue Feb 9 09:36:09 2021 -0500

    Prevent validation issues if HSES email updates

commit 7554928
Merge: 875f5e2 44eeeb8
Author: Ryan Ahearn <[email protected]>
Date:   Tue Feb 9 14:15:51 2021 -0500

    Merge pull request #286 from adhocteam/main

    Fix cucumber test on CI

commit 875f5e2
Merge: 4bd8566 9f5bb95
Author: Ryan Ahearn <[email protected]>
Date:   Fri Feb 5 16:31:48 2021 -0500

    Merge pull request #284 from adhocteam/main

    Filter locked users from admin list

commit 4bd8566
Merge: 17f9d7f f327246
Author: Ryan Ahearn <[email protected]>
Date:   Fri Feb 5 16:05:29 2021 -0500

    Merge pull request #281 from adhocteam/main

    Case insensitive admin search, testing updates and manager setting of notes and report status

commit 17f9d7f
Merge: 16d54e2 8e5d3ef
Author: Ryan Ahearn <[email protected]>
Date:   Wed Feb 3 16:09:21 2021 -0500

    Merge pull request #279 from adhocteam/main

    add frontend for file upload

commit 16d54e2
Merge: 541640a e27e7df
Author: Ryan Ahearn <[email protected]>
Date:   Tue Feb 2 15:33:25 2021 -0500

    Merge pull request #275 from adhocteam/main

    Add goal component to frontend

commit 541640a
Merge: 790ca05 4c3a436
Author: Ryan Ahearn <[email protected]>
Date:   Fri Jan 29 15:47:13 2021 -0500

    Merge pull request #272 from adhocteam/main

    Save collaborators to report

commit 790ca05
Merge: 4948bd3 3cff2f4
Author: Ryan Ahearn <[email protected]>
Date:   Wed Jan 27 12:04:04 2021 -0500

    Merge pull request #267 from adhocteam/main

    Add file upload api
rahearn pushed a commit that referenced this pull request Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants