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

feat!: country configurable user scopes & roles #7301

Open
wants to merge 334 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
334 commits
Select commit Hold shift + click to select a range
7c14348
Add missing scope
tumbledwyer Oct 14, 2024
8dded26
(User roles) fix: update registration list type (#7766)
Nil20 Oct 14, 2024
4519746
Merge remote-tracking branch 'origin/configurable-roles' into scoped-…
tumbledwyer Oct 14, 2024
a4369d8
Remove unused scopes
tumbledwyer Oct 14, 2024
8c4ce55
Fix linting
tumbledwyer Oct 14, 2024
2abd7d9
(User roles) fix: update previour version of user details in indexdb …
Nil20 Oct 14, 2024
d3d052e
Add explicit lambda variable name
tumbledwyer Oct 15, 2024
2f6ea10
Add missing scopes
tumbledwyer Oct 16, 2024
82de107
Replace all scope strings with constants
tumbledwyer Oct 16, 2024
7369a07
Merge branch 'develop' into configurable-roles
Zangetsu101 Oct 16, 2024
7cf5a4e
Merge remote-tracking branch 'origin/configurable-roles' into scoped-…
tumbledwyer Oct 16, 2024
b1e3a32
Fix merge issues
tumbledwyer Oct 16, 2024
24416c1
fix: import COUNTRY_CONFIG_URL from env
Zangetsu101 Oct 17, 2024
bfb4cb6
Add scopes to routes - first pass
tumbledwyer Oct 17, 2024
4837e3a
Change protected route to accept any scope rather than all scopes
tumbledwyer Oct 17, 2024
cc73931
feat: add scope protection to event creation
tumbledwyer Oct 17, 2024
8aa8b20
feat: conditionally render new event button based on scopes
tumbledwyer Oct 17, 2024
1633658
Merge pull request #7741 from opencrvs/scoped-components
tumbledwyer Oct 18, 2024
ae11108
Merge remote-tracking branch 'origin/configurable-roles' into ocrvs-7…
tumbledwyer Oct 18, 2024
a2b915a
fix: Update route scopes as per PR feedback
tumbledwyer Oct 21, 2024
6953fb1
fix: Remove redundant check for empty array
tumbledwyer Oct 21, 2024
443a27d
fix: scope breakages in tests
tumbledwyer Oct 23, 2024
dcb4d37
fix: Update login "vite" to be the same version as client
tumbledwyer Oct 23, 2024
d4838b9
Merge pull request #7794 from opencrvs/ocrvs-7419-add-scopes-to-event…
tumbledwyer Oct 23, 2024
c81ce5d
fix: amend scope for collector route
tumbledwyer Oct 23, 2024
231e680
Merge remote-tracking branch 'origin/configurable-roles' into scoped-…
tumbledwyer Oct 23, 2024
a3d9a91
feat: Change action component buttons to use scopes
tumbledwyer Oct 25, 2024
f2ebde0
fix: Update tests to use new scopes
tumbledwyer Oct 25, 2024
1f3a551
chore: Change requires update permission to scopes
tumbledwyer Oct 29, 2024
faf1eaf
chore: Updated scopes for Sent for review
tumbledwyer Oct 29, 2024
2998fd8
Merge pull request #7791 from opencrvs/scoped-routes
tumbledwyer Oct 29, 2024
6c39f7c
Merge develop in user roles (#7861)
Nil20 Oct 29, 2024
26a2a22
chore: update roles as per notion
tumbledwyer Oct 29, 2024
b6578df
chore: Change all instances of 'validate' to scopes
tumbledwyer Oct 29, 2024
2eaee42
chore: remove additional validate instances
tumbledwyer Oct 29, 2024
1b8ab36
chore: Remove 'register' legacy scope
tumbledwyer Oct 30, 2024
47226ab
chore: remove 'certify' scopes
tumbledwyer Oct 30, 2024
047de75
chore: Remove legacy admin scopes
tumbledwyer Oct 31, 2024
644d123
chore: Remove legacy scopes from tests
tumbledwyer Oct 31, 2024
9046aad
Merge remote-tracking branch 'origin/develop' into configurable-roles
tumbledwyer Nov 1, 2024
0cd4934
Merge fixes
tumbledwyer Nov 1, 2024
b2815af
Merge branch 'configurable-roles' into remove-legacy-scopes-frontend
tumbledwyer Nov 1, 2024
91e48b8
chore: Updated ActionMenu with new scopes
tumbledwyer Nov 4, 2024
5c654c9
feat: Protect reject action with scopes
tumbledwyer Nov 4, 2024
fa46a62
chore: Add 'register' as a validate scope
tumbledwyer Nov 4, 2024
e991ef6
fic: Re-order nav items to be closer to existing implementation
tumbledwyer Nov 4, 2024
17350e1
fix: lint
tumbledwyer Nov 4, 2024
4666389
fix: test
tumbledwyer Nov 4, 2024
f7a9711
fix: Conditionally render buttons based on completed status
tumbledwyer Nov 5, 2024
ad2769a
fix: Remove erroneously left in '.only' in test
tumbledwyer Nov 5, 2024
91645a4
Merge branch 'develop' into configurable-roles
Zangetsu101 Nov 6, 2024
9841784
test: check for signature scope in tests
Zangetsu101 Nov 6, 2024
5238009
Merge remote-tracking branch 'origin/configurable-roles' into remove-…
tumbledwyer Nov 6, 2024
36dd812
Merge pull request #7865 from opencrvs/remove-legacy-scopes-frontend
tumbledwyer Nov 6, 2024
395912c
chore: amend data seeder with scopes (#7898)
Nil20 Nov 6, 2024
811d81d
deps: add dependency on commons from data-seeder
Zangetsu101 Nov 6, 2024
2b22744
test: remove .only & fix signature test
Zangetsu101 Nov 6, 2024
337ece8
test: add missing request handler
Zangetsu101 Nov 6, 2024
cae49fb
chore: amend commons scopes (#7895)
Nil20 Nov 6, 2024
889381b
fix: amend auth scopes (#7894)
Nil20 Nov 6, 2024
95ffacd
feat: validate scopes returned from country config
Zangetsu101 Nov 7, 2024
8c6d26a
chore: improve error logs
Zangetsu101 Nov 7, 2024
7c74daa
chore: amend legacy scopes of config (#7897)
Nil20 Nov 7, 2024
81be7d7
chore: amend metrics changes with scopes (#7900)
Nil20 Nov 7, 2024
56519da
chore: amend user-mgnt changes with scopes (#7903)
Nil20 Nov 7, 2024
5dbf04f
chore: amend search changes with scopes (#7902)
Nil20 Nov 7, 2024
a597f9f
Merge branch 'configurable-roles' into validate-scopes-before-seeding
Zangetsu101 Nov 7, 2024
d615498
fix: sync all scopes with notion scopes
Nil20 Nov 8, 2024
0f6f7f5
chore: remove unused imports
Nil20 Nov 8, 2024
938649d
chore: amend role validation message format
Nil20 Nov 8, 2024
b2f1627
chore!: update data seeding user with new scope
Nil20 Nov 8, 2024
757df8f
fix: remove redundant client queries (#7893)
Nil20 Nov 8, 2024
b27226f
chore: amend notification changes with scopes (#7901)
Nil20 Nov 8, 2024
fc1b3d2
Merge pull request #7923 from opencrvs/validate-scopes-before-seeding
Zangetsu101 Nov 11, 2024
5619401
chore: amend gateway changes with scopes (#7899)
Nil20 Nov 11, 2024
c6d5a0d
Merge branch 'develop' into configurable-roles
Zangetsu101 Nov 11, 2024
47b90f3
test(login): run tsc check first
Zangetsu101 Nov 11, 2024
019765d
test(gateway): update error messages
Zangetsu101 Nov 11, 2024
6fa5ccd
chore: amend workflow changes with scopes (#7905)
Nil20 Nov 11, 2024
a8235cb
chore: update services with user scopes (#7949)
Nil20 Nov 12, 2024
8ef3f92
Merge branch 'develop' into configurable-roles
Nil20 Nov 12, 2024
347ecfc
Merge branch 'develop' into configurable-roles
Nil20 Nov 12, 2024
c4f381d
fix: add reject registration scope in scope list
Nil20 Nov 12, 2024
75d9964
fix: incorrect usage of deprecated GQL type
tumbledwyer Nov 13, 2024
cb82b38
fix: changeaction menu and download button to take use assignment
tumbledwyer Nov 13, 2024
6cee925
fix: lint
tumbledwyer Nov 13, 2024
fe05e0f
Merge branch 'develop' into configurable-roles
Nil20 Nov 13, 2024
610831f
Merge branch 'develop' into configurable-roles
Nil20 Nov 13, 2024
acfb43b
fix: update get user query and user-mgnt route configuration
Nil20 Nov 13, 2024
bbb207e
chore: add request correction scope to action menu correct record com…
Nil20 Nov 13, 2024
4e220c7
chore: update confirm registration scope to workflow confirm reg route
Nil20 Nov 13, 2024
9d5c393
Remove usage of future scopes (#7981)
Zangetsu101 Nov 13, 2024
41e36b4
Merge branch 'develop' into configurable-roles
Nil20 Nov 14, 2024
ec83109
fix: update workflow unit test with confirm reg scope (#7984)
Nil20 Nov 14, 2024
b679c99
fix: extract role from new format
Zangetsu101 Nov 14, 2024
a5ca6a1
fix: logic around disabling review button (#7973)
tumbledwyer Nov 14, 2024
ebc5d69
fix: render only one review button
Zangetsu101 Nov 14, 2024
ca0b360
fix: sync gateway types with client
Nil20 Nov 14, 2024
1dee340
chore: refactor: add COUNTRY_CONFIG_URL_INTERNAL to auth service
Nil20 Nov 14, 2024
050d147
Merge branch 'configurable-roles' into ocrvs-7431-unassign-user
Zangetsu101 Nov 15, 2024
17eb435
chore: remove unassign out of download button
Zangetsu101 Nov 15, 2024
06c1a63
chore: remove deprecated action buttons
Zangetsu101 Nov 15, 2024
87596f7
feat: create isRecordActionable utility
Zangetsu101 Nov 15, 2024
d4f1291
fix: require any scope instead of all
Zangetsu101 Nov 18, 2024
3c017c8
feat: enable download button only when actionable
Zangetsu101 Nov 18, 2024
a602baa
chore: remove unnecessary check
Zangetsu101 Nov 18, 2024
1f7ac53
test: include mock values
Zangetsu101 Nov 18, 2024
005c5f0
test: provide mock for COUNTRY_CONFIG_URL_INTERNAL
Zangetsu101 Nov 19, 2024
99b6739
refactor: move record scopes to a single place
Zangetsu101 Nov 19, 2024
13462b0
chore: remove retrieve action from workflow
Zangetsu101 Nov 19, 2024
f23165a
fix: add missing correction approval action check
Zangetsu101 Nov 19, 2024
dfe9868
feat: decouple review correction from review
Zangetsu101 Nov 19, 2024
062eb10
test: decouple review/correction/duplicates tests
Zangetsu101 Nov 19, 2024
fdb6282
fix: allow assigned user to download the record
Zangetsu101 Nov 20, 2024
d23b0da
chore: remove show assignment modal
Zangetsu101 Nov 21, 2024
98c1fdc
test: add tests for disabled & assigned but not downloaded
Zangetsu101 Nov 21, 2024
2963983
chore: add vs export scope in query (#8050)
Nil20 Nov 22, 2024
536e0af
test: fixes e2e (#7993)
Nil20 Nov 25, 2024
55efc59
fix: update action menu options for draft declarations (#8057)
Nil20 Nov 25, 2024
dd8e3c8
Merge branch 'develop' into configurable-roles
Zangetsu101 Nov 25, 2024
b292b29
Merge branch 'configurable-roles' of github.com:opencrvs/opencrvs-cor…
Zangetsu101 Nov 25, 2024
5dea4d4
test: set module resolution to node16
Zangetsu101 Nov 25, 2024
73ad0b2
chore: fix client imports
Zangetsu101 Nov 25, 2024
ab43c09
Merge branch 'develop' into configurable-roles
Zangetsu101 Nov 25, 2024
cfb783c
test: mock fetchJSON imported from commons/http
Zangetsu101 Nov 25, 2024
699cec5
chore: use the new constant instead of the old one
Zangetsu101 Nov 25, 2024
e2cabcc
Merge branch 'develop' into configurable-roles
Zangetsu101 Nov 25, 2024
5d00064
Merge branch 'develop' into configurable-roles
Zangetsu101 Nov 25, 2024
cca9b68
fix: set module resolution to node16
Zangetsu101 Nov 25, 2024
b35bc38
test: remove .only modifier
Zangetsu101 Nov 26, 2024
01db4a7
Merge branch 'configurable-roles' into ocrvs-7431-unassign-user
Zangetsu101 Nov 26, 2024
95f061d
Merge pull request #7970 from opencrvs/ocrvs-7431-unassign-user
Zangetsu101 Nov 26, 2024
1b229d9
fix: update client tests for after merging scopes (#8066)
Nil20 Nov 26, 2024
fb58069
chore!: introduce new parameter to query for checking workqueue data
Nil20 Nov 26, 2024
2ab4e6e
chore: amend search query error message
Nil20 Nov 26, 2024
5c2b01e
Revert "chore!: introduce new parameter to query for checking workque…
Nil20 Nov 26, 2024
2697f0a
chore: modify search query for no search scope
Nil20 Nov 26, 2024
ab7919a
chore: update advanced search tabs based on search scopes
Nil20 Nov 26, 2024
330ed06
fix: update advanced search url name
Nil20 Nov 26, 2024
e33bbcc
refactor: update event search scopes of client
Nil20 Nov 26, 2024
9891ff1
fix: update header component to use custom hook for search scope perm…
Nil20 Nov 26, 2024
4da60be
fix: add comment for new release scope
Nil20 Nov 27, 2024
d98fb16
Merge develop into configurable-roles
Zangetsu101 Nov 27, 2024
eabcfb2
Merge branch 'develop' into configurable-roles
Zangetsu101 Nov 27, 2024
8788699
fix: merge issues
Zangetsu101 Nov 27, 2024
2cf5a35
fix: amend advance search tab
Nil20 Nov 27, 2024
cc8c550
fix: add comment for new release scope (#8090)
Nil20 Nov 28, 2024
ee061c6
fix: update in progress tab
Nil20 Nov 29, 2024
70610aa
chore: update event search param of advance search based on scopes
Nil20 Nov 29, 2024
c0a9976
Merge branch 'develop' into configurable-roles
Zangetsu101 Dec 2, 2024
5ace925
fix: update user activation route with proper scopes (#8117)
Nil20 Dec 2, 2024
222db41
Merge branch 'configurable-roles' into ocrvs-6909
Nil20 Dec 2, 2024
7172a94
Merge branch 'develop' into configurable-roles
Zangetsu101 Dec 3, 2024
d94227d
chore!: update searching with jurisdiction scopes
Nil20 Dec 3, 2024
34b1ba0
feat: use commons as source of truth for scopes (#8147)
Zangetsu101 Dec 4, 2024
babf055
chore: revert client changes to pass declarationLocationId
Nil20 Dec 4, 2024
f0d3696
fix: amend searching using jurisdiction params
Nil20 Dec 4, 2024
1ce2dc1
Merge branch 'develop' into configurable-roles
Zangetsu101 Dec 5, 2024
6a8d99f
feat(user-scopes): control who can see organisation views (#8012)
Zangetsu101 Dec 9, 2024
4b461f3
feat(user-scopes): control read/create/update user using scopes (#8105)
Zangetsu101 Dec 9, 2024
2db4f53
chore: amend form tab extra props
Nil20 Dec 10, 2024
35937ac
chore: amend gateway search communication payload
Nil20 Dec 10, 2024
1303c28
feat(user-scopes): address to-do items (#8150)
Zangetsu101 Dec 10, 2024
b44bdfd
fix: protect archive button behind scope
Zangetsu101 Dec 11, 2024
0759725
Merge branch 'develop' into configurable-roles
Zangetsu101 Dec 11, 2024
0c064f3
Merge pull request #8189 from opencrvs/ocrvs-7427
Zangetsu101 Dec 11, 2024
0f5760d
fix: protect add event button behind declare scopes
Zangetsu101 Dec 11, 2024
72023c6
Merge pull request #8190 from opencrvs/ocrvs-7419
Zangetsu101 Dec 11, 2024
d7e00f9
Merge branch 'configurable-roles' into ocrvs-6909
Zangetsu101 Dec 12, 2024
400c571
chore: add comment to add additional params to search
Nil20 Dec 12, 2024
5fca572
Merge branch 'chore/upgrade-react-router-dom' into configurable-route…
makelicious Dec 12, 2024
6bc6a5c
fix: bring back wrongly removed items from merge
makelicious Dec 12, 2024
788106b
fix: remove unused variables and imports
makelicious Dec 13, 2024
867be47
Merge branch 'chore/upgrade-react-router-dom' into configurable-route…
makelicious Dec 13, 2024
0223916
fix: update App.test to match target branch
makelicious Dec 13, 2024
0f6ae9c
fix: move files around to prevent circular dependencies
makelicious Dec 13, 2024
50ff945
fix: remove unneeded useParams mocks
makelicious Dec 13, 2024
36b8444
fix: fix remaining tests either
makelicious Dec 13, 2024
b0f4b1b
fix: drop --coverage from login tests until they are brought back
makelicious Dec 13, 2024
fc5387f
Merge pull request #8206 from opencrvs/configurable-routes-merge-routes
Zangetsu101 Dec 17, 2024
9dc7c3f
Merge branch 'develop' into configurable-roles
Zangetsu101 Dec 17, 2024
f5b1f0d
Merge branch 'develop' into configurable-roles
Zangetsu101 Dec 17, 2024
c83e452
feat: export scopes via toolkit (#8192)
Zangetsu101 Dec 23, 2024
4319447
Merge branch 'configurable-roles' into ocrvs-6909
Zangetsu101 Dec 23, 2024
8c29231
style: remove unnecessary changes
Zangetsu101 Dec 23, 2024
c0ff6f1
feat: transform search params depending on scopes
Zangetsu101 Dec 24, 2024
51d16c2
feat: respect search scope when searching
Zangetsu101 Dec 24, 2024
c57c4d1
feat: tighten elasticsearch search param types
Zangetsu101 Dec 24, 2024
5031b38
test: add mocks for data sources
Zangetsu101 Dec 24, 2024
d8ce995
test: change event search params
Zangetsu101 Dec 24, 2024
10cab5e
test: update search result mock & set search scope
Zangetsu101 Dec 24, 2024
25ade2f
Merge pull request #8084 from opencrvs/ocrvs-6909
Zangetsu101 Dec 24, 2024
d8fb219
Merge branch 'develop' into configurable-roles
Zangetsu101 Dec 27, 2024
ae31682
chore: remove unused param
Zangetsu101 Dec 27, 2024
4c845b1
feat: separate page for my drafts
Zangetsu101 Dec 26, 2024
6344c30
feat: home page redirection
Zangetsu101 Dec 26, 2024
62d3106
feat: use pageId as current page for drafts
Zangetsu101 Dec 27, 2024
de52fad
test: separate myDrafts tests from inProgress ones
Zangetsu101 Dec 27, 2024
ef2aa55
chore: remove todo comment
Zangetsu101 Dec 27, 2024
d97e382
chore: update my drafts label
Zangetsu101 Dec 27, 2024
855dacc
fix: do not throw error on empty nav
Zangetsu101 Dec 27, 2024
47f96f0
fix: update home page routes
Zangetsu101 Dec 27, 2024
f7785d0
Merge pull request #8264 from opencrvs/my-drafts
Zangetsu101 Dec 30, 2024
64a4b6e
feat: separate query for sent for review tab
Zangetsu101 Dec 30, 2024
8672895
fix: remove createdBy filter from approval tab
Zangetsu101 Dec 30, 2024
935d5de
fix: include role resources for view record
Zangetsu101 Dec 31, 2024
0c945ce
test: update assertion
Zangetsu101 Dec 31, 2024
fbb2b54
test: mock PractitionerRole history resources
Zangetsu101 Dec 31, 2024
aeba0a9
fix: show field agent tab by default
Zangetsu101 Dec 31, 2024
f13a825
fix: use first nav item as landing page
Zangetsu101 Dec 31, 2024
d22980c
fix: add disable logic to profile image
Zangetsu101 Jan 1, 2025
d1de9c3
fix: give update scopes access to user data
Zangetsu101 Jan 1, 2025
81ce315
Merge pull request #8271 from opencrvs/ocrvs-7436
Zangetsu101 Jan 1, 2025
fadf552
fix: provide primary office to history user
Zangetsu101 Jan 1, 2025
899bdb1
fix: show update action for declare scopes
Zangetsu101 Jan 1, 2025
1ea2991
fix: hide outbox for only declare scopes
Zangetsu101 Jan 1, 2025
72864b5
fix: show ready for review tab for register scope
Zangetsu101 Jan 1, 2025
d287bcf
fix: hide send incomplete btn without req scope
Zangetsu101 Jan 1, 2025
eef358e
Merge pull request #8272 from opencrvs/ocrvs-7419
Zangetsu101 Jan 1, 2025
d8d0627
test: add required scope for ready for review tab
Zangetsu101 Jan 1, 2025
16fa42c
Merge pull request #8273 from opencrvs/ocrvs-7421
Zangetsu101 Jan 1, 2025
ad687d0
Merge pull request #8265 from opencrvs/configurable-roles-e2e
Zangetsu101 Jan 1, 2025
694d661
fix: Scopes: correction related scopes (#8268)
jamil314 Jan 2, 2025
8ac2d29
ocrvs-8194: print & issue bugs (#8275)
Zangetsu101 Jan 3, 2025
28fdc9d
fix: misc bugs (#8281)
Zangetsu101 Jan 3, 2025
60401e0
Revert "fix: include role resources for view record" (#8283)
Zangetsu101 Jan 3, 2025
bf6b219
Merge branch 'develop' into configurable-roles
Zangetsu101 Jan 3, 2025
a533093
(User roles) fix search scope bugs (#8267)
Nil20 Jan 9, 2025
6d3b7ac
fix: add prop to protected component to show update action (#8307)
Nil20 Jan 9, 2025
5ae2637
Merge branch 'develop' into configurable-roles
Nil20 Jan 9, 2025
a87ba79
(Configurable roles) Unassign scope fix (#8305)
Nil20 Jan 10, 2025
f68d20d
Merge branch 'develop' into configurable-roles
Nil20 Jan 10, 2025
ab88d0f
fix: update new sys admin scope in events middleware (#8315)
Nil20 Jan 10, 2025
39a3530
Merge branch 'develop' into configurable-roles
Nil20 Jan 10, 2025
c946959
fix: amend data seeding user scope (#8323)
Nil20 Jan 13, 2025
5c44f51
fix: update scope of event tests of seeding users (#8324)
Nil20 Jan 13, 2025
5d06701
Merge branch 'develop' into configurable-roles
Nil20 Jan 13, 2025
502a2bc
fix: amend death and marriage fetch query
Nil20 Jan 13, 2025
33fbd04
fix: save additional practitioner role entry in bundle during view ac…
Nil20 Jan 15, 2025
6be87b6
fix: add comment for clarity for saving practitioner role information…
Nil20 Jan 15, 2025
888cf50
fix: add primary office info in query in user history
Nil20 Jan 16, 2025
f4eebcb
fix: add practitioner role entry in download bundle (#8338)
Nil20 Jan 16, 2025
980f37d
fix: delete redundant props of protected component (#8351)
Nil20 Jan 20, 2025
6b6d689
fix: update resolver parameter of certTemplateId (#8349)
Nil20 Jan 21, 2025
3096dd3
Merge branch 'develop' into configurable-roles
Zangetsu101 Jan 21, 2025
b85d411
fix: use data seeding user in middleware
Zangetsu101 Jan 21, 2025
6e30787
(User roles) Assignment update (#8348)
Nil20 Jan 21, 2025
2dfa94a
fix: update draft button conditional in action menu (#8366)
Nil20 Jan 21, 2025
5bdbc45
fix: create patient resource for practitioners
Zangetsu101 Jan 22, 2025
2cc8278
Merge branch 'develop' into configurable-roles
Zangetsu101 Jan 22, 2025
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
5 changes: 3 additions & 2 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
Copy link
Member Author

@rikukissa rikukissa Jul 5, 2024

Choose a reason for hiding this comment

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

Auth service

The auth service's new responsibility is to, as part of authentication, connect scopes coming from CC to user's role field. This is done every time a user needs a JWT token

"start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --exec ts-node -r tsconfig-paths/register src/index.ts",
"start:prod": "TS_NODE_BASEURL=./build/dist/src node -r tsconfig-paths/register build/dist/src/index.js",
"test": "jest --coverage --silent --noStackTrace && yarn test:compilation",
"test": "yarn test:compilation && jest --coverage --silent --noStackTrace",
naftis marked this conversation as resolved.
Show resolved Hide resolved
"test:watch": "jest --watch",
"open:cov": "yarn test && opener coverage/index.html",
"lint": "eslint -c .eslintrc.js --fix ./src",
Expand Down Expand Up @@ -84,7 +84,8 @@
"<rootDir>"
],
"moduleNameMapper": {
"@auth/(.*)": "<rootDir>/src/$1"
"@auth/(.*)": "<rootDir>/src/$1",
"@opencrvs/commons/(.*)": "@opencrvs/commons/build/dist/$1"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
"setupFiles": [
Expand Down
25 changes: 18 additions & 7 deletions packages/auth/src/features/authenticate/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import * as fetchAny from 'jest-fetch-mock'
import { createServerWithEnvironment } from '@auth/tests/util'
import { createServer } from '@auth/server'
import { DEFAULT_ROLES_DEFINITION } from '@opencrvs/commons/authentication'

const fetch = fetchAny as fetchAny.FetchMock
describe('authenticate handler receives a request', () => {
Expand Down Expand Up @@ -54,7 +55,7 @@ describe('authenticate handler receives a request', () => {
it('returns 403', async () => {
fetch.mockResponse(
JSON.stringify({
userId: '1',
id: '1',
naftis marked this conversation as resolved.
Show resolved Hide resolved
status: 'deactivated',
scope: ['admin']
})
Expand All @@ -78,14 +79,18 @@ describe('authenticate handler receives a request', () => {

jest.spyOn(reloadedCodeService, 'generateNonce').mockReturnValue('12345')

fetch.mockResponse(
fetch.mockResponseOnce(
JSON.stringify({
userId: '1',
id: '1',
status: 'active',
scope: ['admin'],
role: 'NATIONAL_SYSTEM_ADMIN',
Copy link
Member Author

Choose a reason for hiding this comment

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

user-mgnt doesn't return scopes anymore as it doesn't know what scopes are. Scopes are now controlled by CC's /roles endpoint in combination with the auth service which creates JWT tokens.

mobile: `+345345343`
})
)

fetch.mockResponse(JSON.stringify(DEFAULT_ROLES_DEFINITION), {
status: 200
})
const spy = jest.spyOn(reloadedCodeService, 'sendVerificationCode')

await server.server.inject({
Expand All @@ -109,14 +114,20 @@ describe('authenticate handler receives a request', () => {

jest.spyOn(reloadedCodeService, 'generateNonce').mockReturnValue('12345')

fetch.mockResponse(
fetch.mockResponseOnce(
JSON.stringify({
userId: '1',
id: '1',
status: 'pending',
scope: ['admin'],
role: 'NATIONAL_SYSTEM_ADMIN',
systemRole: 'NATIONAL_SYSTEM_ADMIN',
mobile: `+345345343`
})
)

fetch.mockResponse(JSON.stringify(DEFAULT_ROLES_DEFINITION), {
status: 200
})

const spy = jest.spyOn(reloadedCodeService, 'sendVerificationCode')

await server.server.inject({
Expand Down
38 changes: 29 additions & 9 deletions packages/auth/src/features/authenticate/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import * as Hapi from '@hapi/hapi'
import * as Joi from 'joi'
import { JWT_ISSUER, WEB_USER_JWT_AUDIENCES } from '@auth/constants'
import {
IAuthentication,
authenticate,
storeUserInformation,
createToken,
generateAndSendVerificationCode,
IAuthentication
storeUserInformation
} from '@auth/features/authenticate/service'
import {
NotificationEvent,
generateNonce
} from '@auth/features/verifyCode/service'
import { unauthorized, forbidden } from '@hapi/boom'
import { WEB_USER_JWT_AUDIENCES, JWT_ISSUER } from '@auth/constants'
import { forbidden, unauthorized } from '@hapi/boom'
import * as Hapi from '@hapi/hapi'
import { CoreUserRole } from '@opencrvs/commons/authentication'
import * as Joi from 'joi'
import { getUserRoleScopeMapping } from '@auth/features/scopes/service'

interface IAuthPayload {
username: string
Expand All @@ -34,6 +36,7 @@ interface IAuthResponse {
mobile?: string
email?: string
status: string
systemRole: CoreUserRole
naftis marked this conversation as resolved.
Show resolved Hide resolved
token?: string
}

Expand All @@ -43,6 +46,7 @@ export default async function authenticateHandler(
): Promise<IAuthResponse> {
const payload = request.payload as IAuthPayload
let result: IAuthentication

const { username, password } = payload
try {
result = await authenticate(username.trim(), password)
Expand All @@ -58,15 +62,28 @@ export default async function authenticateHandler(
mobile: result.mobile,
email: result.email,
status: result.status,
systemRole: result.systemRole,
nonce
}

const isPendingUser = response.status && response.status === 'pending'

const roleScopeMappings = await getUserRoleScopeMapping()
naftis marked this conversation as resolved.
Show resolved Hide resolved

let scopes = []

const role = result.role as keyof typeof roleScopeMappings

if (roleScopeMappings[role]) {
scopes = roleScopeMappings[role]
} else {
scopes = roleScopeMappings[response.systemRole]
}

if (isPendingUser) {
response.token = await createToken(
result.userId,
result.scope,
scopes,
WEB_USER_JWT_AUDIENCES,
JWT_ISSUER
)
Expand All @@ -75,7 +92,7 @@ export default async function authenticateHandler(
nonce,
result.name,
result.userId,
result.scope,
scopes,
result.mobile,
result.email
)
Expand All @@ -84,13 +101,14 @@ export default async function authenticateHandler(

await generateAndSendVerificationCode(
nonce,
result.scope,
scopes,
notificationEvent,
result.name,
result.mobile,
result.email
)
}

return response
}

Expand All @@ -104,5 +122,7 @@ export const responseSchema = Joi.object({
mobile: Joi.string().optional(),
email: Joi.string().optional(),
status: Joi.string(),
role: Joi.string(),
systemRole: Joi.string(),
token: Joi.string().optional()
})
25 changes: 12 additions & 13 deletions packages/auth/src/features/authenticate/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ import {
storeVerificationCode
} from '@auth/features/verifyCode/service'
import { logger } from '@opencrvs/commons'
import { CoreUserRole } from '@opencrvs/commons/authentication'
import { unauthorized } from '@hapi/boom'
import { chainW, tryCatch } from 'fp-ts/Either'
import { pipe } from 'fp-ts/function'

import * as F from 'fp-ts'
const { chainW, tryCatch } = F.either
const { pipe } = F.function

const cert = readFileSync(CERT_PRIVATE_KEY_PATH)
const publicCert = readFileSync(CERT_PUBLIC_KEY_PATH)
Expand All @@ -55,8 +58,9 @@ export interface IAuthentication {
mobile?: string
userId: string
status: string
scope: string[]
email?: string
systemRole: CoreUserRole
role: string
}

export interface ISystemAuthentication {
Expand Down Expand Up @@ -86,11 +90,14 @@ export async function authenticate(
if (res.status !== 200) {
throw Error(res.statusText)
}

const body = await res.json()

return {
name: body.name,
userId: body.id,
scope: body.scope,
role: body.role,
systemRole: body.systemRole,
status: body.status,
mobile: body.mobile,
email: body.email
Expand Down Expand Up @@ -128,9 +135,6 @@ export async function createToken(
issuer: string,
temporary?: boolean
): Promise<string> {
if (typeof userId === undefined) {
throw new Error('Invalid userId found for token creation')
}
return sign({ scope }, cert, {
subject: userId,
algorithm: 'RS256',
Expand Down Expand Up @@ -174,12 +178,7 @@ export async function generateAndSendVerificationCode(
email?: string
) {
const isDemoUser = scope.indexOf('demo') > -1 || QA_ENV
logger.info(
`isDemoUser,
${JSON.stringify({
isDemoUser: isDemoUser
})}`
)
logger.info(`Is demo user: ${isDemoUser}. Scopes: ${scope.join(', ')}`)
let verificationCode
if (isDemoUser) {
verificationCode = '000000'
Expand Down
11 changes: 10 additions & 1 deletion packages/auth/src/features/authenticateSuperUser/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
} from '@auth/features/authenticate/service'
import { unauthorized } from '@hapi/boom'
import { WEB_USER_JWT_AUDIENCES, JWT_ISSUER } from '@auth/constants'
import { DEFAULT_CORE_ROLE_SCOPES } from '@opencrvs/commons/authentication'
import { logger } from '@opencrvs/commons'

interface IAuthPayload {
username: string
Expand All @@ -36,9 +38,16 @@ export default async function authenticateSuperUserHandler(
throw unauthorized()
}

if (result.status === 'deactivated') {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is just to improve error messaging when you try to seed again after seeding once

logger.info('Login attempt with a deactivated super user account detected')
throw unauthorized()
}

const scope = DEFAULT_CORE_ROLE_SCOPES.SUPER_ADMIN

const token = await createToken(
result.userId,
result.scope,
scope,
WEB_USER_JWT_AUDIENCES,
JWT_ISSUER
)
Expand Down
21 changes: 16 additions & 5 deletions packages/auth/src/features/refresh/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,36 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import { createServerWithEnvironment } from '@auth/tests/util'
import { DEFAULT_ROLES_DEFINITION } from '@opencrvs/commons/authentication'
import * as fetchAny from 'jest-fetch-mock'
const fetch = fetchAny as fetchAny.FetchMock

describe('authenticate handler receives a request', () => {
let server: any

beforeEach(async () => {
server = await createServerWithEnvironment({ NODE_ENV: 'production' })
server = await createServerWithEnvironment({
NODE_ENV: 'production'
})
})

describe('refresh expiring token', () => {
it('verifies a token and generates a new token', async () => {
it.only('verifies a token and generates a new token', async () => {
fetch.mockResponseOnce(JSON.stringify(DEFAULT_ROLES_DEFINITION), {
status: 200
})
// eslint-disable-next-line @typescript-eslint/no-var-requires
const codeService = require('../verifyCode/service')

// eslint-disable-next-line @typescript-eslint/no-var-requires
const authService = require('../authenticate/service')
const codeSpy = jest.spyOn(codeService, 'sendVerificationCode')
fetch.mockResponseOnce(JSON.stringify(DEFAULT_ROLES_DEFINITION), {
status: 200
})
jest.spyOn(authService, 'authenticate').mockReturnValue({
userId: '1',
scope: ['admin'],
role: 'NATIONAL_SYSTEM_ADMIN',
mobile: '+345345343'
})

Expand Down Expand Up @@ -63,7 +74,7 @@ describe('authenticate handler receives a request', () => {

const [, payload] = refreshResponse.result.token.split('.')
const body = JSON.parse(Buffer.from(payload, 'base64').toString())
expect(body.scope).toEqual(['admin'])
expect(body.scope).toEqual(['sysadmin', 'natlsysadmin'])
expect(body.sub).toBe('1')
})
it('refreshError returns a 401 to the client if the token is bad', async () => {
Expand All @@ -73,7 +84,7 @@ describe('authenticate handler receives a request', () => {
const authService = require('../authenticate/service')
const codeSpy = jest.spyOn(codeService, 'sendVerificationCode')
jest.spyOn(authService, 'authenticate').mockReturnValue({
userId: '1',
id: '1',
scope: ['admin'],
username: '+345345343'
})
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/features/resend/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('resend handler receives a request', () => {
// eslint-disable-next-line
const authService = require('../authenticate/service')
jest.spyOn(authService, 'getStoredUserInformation').mockReturnValue({
userId: '1',
id: '1',
scope: ['admin'],
mobile: '+345345343'
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('verifyNumber handler receives a request', () => {
jest.spyOn(codeService, 'generateNonce').mockReturnValue('12345')
fetch.mockResponse(
JSON.stringify({
userId: '1',
id: '1',
username: 'fake_user_name',
status: 'active',
scope: ['demo'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('verifyUser handler receives a request', () => {
jest.spyOn(codeService, 'generateNonce').mockReturnValue('12345')
fetch.mockResponse(
JSON.stringify({
userId: '1',
id: '1',
username: 'fake_user_name',
status: 'active',
scope: ['demo'],
Expand All @@ -75,7 +75,7 @@ describe('verifyUser handler receives a request', () => {

fetch.mockResponse(
JSON.stringify({
userId: '1',
id: '1',
username: 'fake_user_name',
status: 'active',
scope: ['admin'],
Expand Down
Loading
Loading