feat: only show instruments and calls on tags for proposal reader role#1465
feat: only show instruments and calls on tags for proposal reader role#1465ellen-wright wants to merge 11 commits intodevelopfrom
Conversation
mutambaraf
left a comment
There was a problem hiding this comment.
Just some comments looks good.
| callsByRole(@Ctx() context: ResolverContext) { | ||
| const t = context.queries.call.getTagCallsByRoleId(context.user); | ||
|
|
||
| return t; |
There was a problem hiding this comment.
We can remove the variable declaration here.
| isRootRole: false, | ||
| } as Role; | ||
| } | ||
| async getCallsbyRoleId(agent: number): Promise<Call[]> { |
There was a problem hiding this comment.
We can use camelCase here : getCallsByRoleId
| } | ||
| } | ||
|
|
||
| async getCallsbyRoleId(agent: number): Promise<Call[]> { |
There was a problem hiding this comment.
We can improve naming here to getCallsByRoleId
| } | ||
| } | ||
|
|
||
| async getInstrumentsbyRoleId(agent: number): Promise<Instrument[]> { |
There was a problem hiding this comment.
We can improve naming to : getInstrumentsbyRoleId
| const tagIds = tags.map((tag) => tag.id); | ||
| if (tagIds.length != 0) { | ||
| const instruments = await database<InstrumentRecord>( | ||
| 'tag_instrument as fi' |
There was a problem hiding this comment.
Maybe we can name it to ti here.
| if (currentRole === UserRole.PROPOSAL_READER) { | ||
| getCallsByRole({}).then((data) => { | ||
| if (unmounted) { | ||
| return; | ||
| } | ||
| if (data.callsByRole) { | ||
| setCalls(data.callsByRole as Call[]); | ||
| setLoadingCalls(false); | ||
| } | ||
| }); | ||
| } else { | ||
| getCalls({ filter: callsFilter, ...callsQueryParams }).then((data) => { | ||
| if (unmounted) { | ||
| return; | ||
| } | ||
|
|
||
| getCalls({ filter: callsFilter, ...callsQueryParams }).then((data) => { | ||
| if (unmounted) { | ||
| return; | ||
| } | ||
|
|
||
| if (data.calls) { | ||
| setCalls(data.calls as Call[]); | ||
| } | ||
| setLoadingCalls(false); | ||
| }); | ||
| if (data.calls) { | ||
| setCalls(data.calls as Call[]); | ||
| } | ||
| setLoadingCalls(false); | ||
| }); | ||
| } |
There was a problem hiding this comment.
I think in the backend we technically do not care if a user has UserRole.PROPOSAL_READER so do not know if we need the if switch here. Lets just add the filters callsFilter, ...callsQueryParams to getCallsByRole endpoint and use it for all calls.
There was a problem hiding this comment.
This is because the get calls and instruments by tag isn't needed for User Officers and other roles so it's not necessary to alter how the filters are populated for them
| if (currentRole === UserRole.PROPOSAL_READER) { | ||
| getCallsByRole({}).then((data) => { | ||
| if (unmounted) { | ||
| return; | ||
| } | ||
| if (data.callsByRole) { | ||
| setCalls(data.callsByRole as Call[]); | ||
| setLoadingCalls(false); | ||
| } | ||
| }); | ||
| } else { | ||
| getCalls({ filter: callsFilter, ...callsQueryParams }).then((data) => { |
There was a problem hiding this comment.
If we are getting the calls by roles do we still need the if statement here we may just need to pass in the filters.
There was a problem hiding this comment.
This separation is because currently the proposal reader is the role that changes depending on what tags are assigned
| } else if (currentRole === UserRole.PROPOSAL_READER) { | ||
| api() | ||
| .getInstrumentsByRole() | ||
| .then((data) => { | ||
| if (unmounted) { | ||
| return; | ||
| } | ||
|
|
||
| if (data.instrumentByRole) { | ||
| setInstruments(data.instrumentByRole); | ||
| } | ||
| setLoadingInstruments(false); | ||
| }); | ||
| } else { | ||
| api() | ||
| .getMyInstrumentsMinimal() |
There was a problem hiding this comment.
I have added a comment above.
| const tags = await this.getTagsByRoleId(agent); | ||
| const tagIds = tags.map((tag) => tag.id); |
There was a problem hiding this comment.
The tags variable can be handled this way, If getTagsByRoleId(agent) returns null or undefined, the subsequent .map() call will throw a runtime error. Consider defaulting to an empty array to ensure safety: const tags = (await this.getTagsByRoleId(agent)) ?? [];."
…com/UserOfficeProject/user-office-core into 1562-fix-filters-for-read-only-role
jekabs-karklins
left a comment
There was a problem hiding this comment.
question: will the proposal reader role will be able to get all calls by calling the previous call getCalls, say buy crafting the GraphQL request? If yes, I'm therefore thinking if it isn't better to simply modify the existing getCalls and getCallsMinimal and filter out calls that proposal reader is not part of in the backend query. Or was it what @mutambaraf already asked?
…com/UserOfficeProject/user-office-core into 1562-fix-filters-for-read-only-role
Yeah I agree, I have removed the new queries and added them to the original call and instrument queries |
Description
refs: UserOfficeProject/issue-tracker#1562
This PR makes it so that only calls and instruments on tags attached to the specific proposal reader role are shown in the proposal filters.
Motivation and Context
Currently all calls and instruments are shown even if a user does not have access to them through the tags attached tot eh proposal reader role.
Changes
Adds two new graphQL queries
These are called from the instrument and call hooks when logged in on the proposal reader role and returns only the calls and instruments that are assigned to any tag attached to the role.
If there are no tags on a role or you are using the root proposal reader role then all calls and instruments are returned, similarly to user officer.
Depends on
Tests included/Docs Updated?