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

19698 Added Account-Id to auth api call + check for null auth info + small cleanup #650

Merged
merged 2 commits into from
Feb 13, 2024

Conversation

severinbeauvais
Copy link
Collaborator

@severinbeauvais severinbeauvais commented Feb 8, 2024

Issue #: bcgov/entity#19698

Description of changes:
- app version = 5.8.15
- added get after set to update store
- added check for empty auth info when re-fetching ting business info
- added some safety checks when updating prepopulated data (ie, new holding/primary business)
- moved accountId computed to store
- added Account-Id header to fetchAuthInfo()
- deleted some unused getters/local code
- cleaned up some App unit tests

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the bcrs-entities-create-ui license (Apache 2.0).

@@ -875,6 +873,8 @@ export default class App extends Mixins(CommonMixin, DateMixin, FilingTemplateMi
// set the resources
if (!resources) throw new Error(`Invalid ${this.getEntityType} resources`)
this.setResources(resources)
// NB - for some reason, need to call this here so the store updates this getter
const dummy = this.getFilingData // eslint-disable-line
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is very strange. Without this here, getFilingData (which returns one of the resource properties) always returned null. I tried a few things, including awaiting next tick, refactoring getFilingData, refactoring a failing App unit test, etc, and this is the only thing that worked consistently.

In any case, this code is safe (won't hurt anything), but I am a tad concerned about other getters that might not work after just setting a value/object in the store. 🤷‍♂️

name: item.name,
legalType: item.legalType
} as AmalgamatingBusinessIF
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This item will appear as "not affiliated".

It should never happen that the user was able to add the business but now it doesn't exist at all.

import { useStore } from '@/store/store'

setActivePinia(createPinia())
const store = useStore()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is how to access the store in a non-Vue class where you can't use the @Getter or @Action decorations/declarations.

PS This is actually type-safe!

image


return axios.get(url).then(response => {
return axios.get(url, config).then(response => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We pass in the account id and the API checks it against the business we're asking about. We'll get a HTTP 403 (Forbidden) back if the business isn't affiliated to this account id.

NB - The API continues to accept "missing account id" and just returns the data if the business is affiliated with any account for the current login (Keycloak token). Ultimately the API should require the account id but if we did that now it might break other things.

- added get after set to update store
- added check for empty auth info when re-fetching ting business info
- added some safety checks when updating prepopulated data (ie, new holding/primary business)
- moved accountId computed to store
- added Account-Id header to fetchAuthInfo()
- deleted some unused getters/local code
- cleaned up some App unit tests
@severinbeauvais
Copy link
Collaborator Author

/gcbrun

@bcregistry-sre
Copy link
Collaborator

bcregistry-sre commented Feb 13, 2024

// safety checks
if (!business || business.type !== AmlTypes.LEAR) throw new Error('Invalid business')
if (!business.addresses) throw new Error('Missing business addresses')
if (!business.authInfo) throw new Error('Missing share classes')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to display a console error (and however the caller wants to handle the exception) in case there is any error with the data (eg, Riyaz's testing in 19750).

Copy link
Collaborator

@PaulGarewal PaulGarewal left a comment

Choose a reason for hiding this comment

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

LGTM 👍 lots of interesting things going on here that I will look at again for learning/investigating

Copy link
Collaborator

@ketaki-deodhar ketaki-deodhar left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@JazzarKarim JazzarKarim left a comment

Choose a reason for hiding this comment

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

LGTM Sev!

@bcgov bcgov deleted a comment from bcregistry-sre Feb 13, 2024
@severinbeauvais
Copy link
Collaborator Author

Test results

As BCREG0020/Severin Dev Account:

image

Note the 3 businesses that display as "affiliate to view". Those businesses are either affiliated to a different account under BCREG0020 or to a different login altogether.

As a staff user:

image

Note that all businesses display as affiliated (even though they aren't) because this is a staff (IDIR) login.

@severinbeauvais severinbeauvais merged commit 41efbd8 into bcgov:main Feb 13, 2024
4 of 5 checks passed
JazzarKarim pushed a commit to JazzarKarim/business-create-ui that referenced this pull request Feb 23, 2024
…small cleanup (bcgov#650)

* - app version = 5.8.15
- added get after set to update store
- added check for empty auth info when re-fetching ting business info
- added some safety checks when updating prepopulated data (ie, new holding/primary business)
- moved accountId computed to store
- added Account-Id header to fetchAuthInfo()
- deleted some unused getters/local code
- cleaned up some App unit tests

* - added some line breaks between code blocks in legal services

---------

Co-authored-by: Severin Beauvais <severin.beauvais@gov.bc.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants