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

Rewrite StartPrefs #1072

Merged

Conversation

Abby-Wheelis
Copy link
Member

This PR will rewrite the service in splash/startprefs.js, as noted in this comment. It might also be time to re-consider exactly how consent is handled, as discussed in this issue. After the patch in #1071, I anticipate some merge conflicts, since the files overlap, but since I've worked on both changes I'm hopeful to be able to resolve them quickly.

Abby Wheelis added 6 commits October 17, 2023 16:18
first attempt at converting to a ts file, not fully functional, but did find several functions that were no longer used and so have been removed
we are now not using the angular service anymore, so should access everything from the new ts file
we had a bug related to this call, so adding a note to future development to make sure we're aware of the ramifications that this can cause.
was breaking because I spelled cordova wrong
@Abby-Wheelis Abby-Wheelis changed the base branch from master to service_rewrite_2023 October 18, 2023 23:57
@Abby-Wheelis
Copy link
Member Author

The tests are currently failing because of a timeout issue with the React test (for LoadMoreButton) sometimes locally, and it looks like that's the case here as well. There is a way to expand the time limit, which I've done for one or two other tests.

@Abby-Wheelis
Copy link
Member Author

One small problem that I'm running into here is that one of the functions relies on $emit which I have not run into in the rewrite quite yet. I haven't figured out what this particular emit was desiged to do yet, but I can see where different emit events are received with $on so I think my next step is to try and find the corresponding on for this emit.

@Abby-Wheelis
Copy link
Member Author

so I think my next step is to try and find the corresponding on for this emit.

Looking through the code base here, I can't really find where this event is received. What's emitted is "data_collection_consented" which I have been unable to find outside of this file on either master or service_rewrite_2023. I didn't find too many hints in the blame either.

Ah! But when I look for CONSENTED_EVENT I find two .on listeners for it, one in splash/storedevicesettings.js and one in splash/pushnotify.js. We haven't rewritten either of these services yet, but it seems that this event is the catalyst to register push notifications and store device settings in a re-consent situation. I'm wondering if there would be a way to leverage our onboarding routes / states to set these processes off at the right times in the migrated code? There are a few other places where emit and on are used for similar purposes, so it would be good to figure out our migration strategy.

@Abby-Wheelis
Copy link
Member Author

I was just able to talk through this a bit with @sebastianbarry, and what we settled on was extracting the functionality from the .on receivers into functions, exporting them, and then calling them (in this case) when we mark consent. That way, the functions are called at the right time, and don't rely on the angular emit and on. Even though some of the "receiving" files are still in angular, we can leverage getAngularService to access those functions from our React contexts.

I haven't quite implemented this yet, but it seems like a good migration strategy.

Abby Wheelis added 5 commits October 19, 2023 14:39
remove unused key, update to single source of truth for INTRO_DONE_KEY
Pre-migration, there was a "consent done" event broadcasted from startprefs whenever the user marked consent. However, Reach and typescript does not handle events like this. Instead, we are extracting the code into a function, retrieving it from the plugin (for now), and then calling those functions when consent is marked.

As a part of this, unify the reading of "isIntroDone" to the method in onboardingHelper, rather than storing a variable in startPrefs
we actually need to wait until fully consented, and the user registered before we can take the actions in the plugins

I noticed this because of an error message that appeared when logging in, indicating that the user was not registered, so the device settings could not be stored

moving these calls to after the user has FULLY consented, resolved that issue
adding descriptions to the functions, and removed some unused imports
@Abby-Wheelis
Copy link
Member Author

This approach seems to be working based on logging in and out of the emulator and watching the log statements. The next step will be to write tests. This will not be very direct, since the file involves a lot of reading and writing from storage, but hopefully I can leverage existing mocks to help with that.

Abby Wheelis added 8 commits October 20, 2023 10:16
after adding more mocked functions, the startprefs now have one test, for getting the consent doc from storage
this test needed a mock of markConsented in the BEMDataCollection plugin, I have added _storage so that when the document is written in, it can also be retrieved -- even though that happens in two different plugins
since testing separately affects the local storage, testing in sequence allows for easier testing.

return json from fetch rather than string to make it parseable

in storage, had to check for the string undefined, since that was returned in one of the tests
…into startprefs-rewrite

also resolved merge conflicts
for consistency, since this is also a function that is async
since we no longer work with the IRB protocol within the app, we don't need to present it to the user
@Abby-Wheelis
Copy link
Member Author

After resolving merge conflicts and removing some of the old process, now I'm waiting until we make a final decision on how to handle the "check consent" from profile settings this comment before I think this is ready for merge.

@Abby-Wheelis
Copy link
Member Author

As decided in #1016:

  1. keep "check consent" and if no consent found, have a message to log out and log back in with the same code

But until we do that, the app may not be collecting any data because it can't find the consent. So we should go with (ii) until we implement the principled fix.

This is currently implemented:

If Consented If NOT Consented
Simulator Screenshot - iPhone 13 Pro - 2023-10-25 at 12 09 41 Simulator Screenshot - iPhone 13 Pro - 2023-10-25 at 12 11 03

@Abby-Wheelis Abby-Wheelis marked this pull request as ready for review October 25, 2023 18:19
Copy link
Collaborator

@JGreenlee JGreenlee left a comment

Choose a reason for hiding this comment

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

I have some suggestions for getting rid of the Angular emit events

www/js/splash/pushnotify.js Outdated Show resolved Hide resolved
www/js/splash/startprefs.ts Outdated Show resolved Hide resolved
Comment on lines 58 to 61
$rootScope.$on(startPrefs.INTRO_DONE_EVENT, function(event, data) {
console.log("intro is done -> original consent situation, we should have a token by now -> register");
storedevicesettings.storeDeviceSettings();
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like INTRO_DONE_EVENT is no longer emitted from anywhere. So I don't think you need to listen for it anymore, but I do think you need to find a suitable replacement.

From analyzing these 2 events (CONSENTED_EVENT and INTRO_DONE_EVENT) and seeing how the old StartPrefs worked, here's the high-level takeaway I'm getting.
When either:

  • a) the intro gets done
  • b) the user reconsents (consent gets done and intro was already done)

We call storedevicesettings.storeDeviceSettings() and pushnotify.registerPush.

So I think the afterConsent mechanism you made should be something more like afterIntroOrReconsent, and I think SaveQrPage is the wrong place to do it.
I'm not sure if reconsent is still a thing or will be a thing in the future (I saw there was recent discussion on this). If not, I suppose you'll only need to consider (a) and not (b)

Copy link
Member Author

Choose a reason for hiding this comment

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

We're taking out reconsent for now, as decided in this comment. Combining the mechanism makes sense, I'll work on combining things and finding a better place for it.

Copy link
Member Author

Choose a reason for hiding this comment

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

a) the intro gets done

One place to catch this would be to add the functionality to the markIntroDone method in onboarding helper

b) the user reconsents (consent gets done and intro was already done)

I could add the after consent part to markConsented in startPrefs - (if Intro is done) this would be a very similar place functionally, but maybe better organizationally?

@JGreenlee do those places sound better?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, those 2 places seem appropriate to me

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! I tested by logging in and out of the emulator and seeing the log statement for the "after intro events" and not the log statement for the "reconsent events". This is expected behavior since reconsent is not what's happening on login, and we don't currently have a reconsent scenario. I'll add some git comments to the new code to flag the changes.

www/js/onboarding/SaveQrPage.tsx Outdated Show resolved Hide resolved
www/js/splash/startprefs.ts Outdated Show resolved Hide resolved
Abby Wheelis added 4 commits October 25, 2023 15:42
saveQR was a bad place to handle this, moving to markConsented

As Jack pointed out, on a reconsent (mark consent after intro done) we want to call registerPush and storeDeviceSettings - that is what is done here

centralizing the logic to markConsented eliminated the need for the functions in the other files, since we check for consent done just once
We no longer emit this event, but still need to handle the logic

On marking intro done, we will registerPush and storeDeviceSettings

e-mission#1072 (comment)
Copy link
Member Author

@Abby-Wheelis Abby-Wheelis left a comment

Choose a reason for hiding this comment

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

calling out the changes I just made wrt "intro done" and "reconsent"

I also ran the tests and verified that they still pass after my recent changes

www/js/splash/startprefs.ts Outdated Show resolved Hide resolved
www/js/onboarding/onboardingHelper.ts Show resolved Hide resolved
www/js/splash/startprefs.ts Show resolved Hide resolved
www/js/splash/startprefs.ts Outdated Show resolved Hide resolved
www/js/splash/startprefs.ts Outdated Show resolved Hide resolved
www/js/splash/startprefs.ts Outdated Show resolved Hide resolved
www/js/control/ProfileSettings.jsx Outdated Show resolved Hide resolved
www/js/onboarding/onboardingHelper.ts Outdated Show resolved Hide resolved
www/js/plugin/storage.ts Outdated Show resolved Hide resolved
www/js/splash/startprefs.ts Outdated Show resolved Hide resolved
Abby Wheelis added 4 commits October 27, 2023 08:51
There were several places where I had other log statements, but logDebug was more appropriate, see review for details

e-mission#1072 (comment)
Copy link
Collaborator

@JGreenlee JGreenlee left a comment

Choose a reason for hiding this comment

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

Great!

Copy link
Contributor

@shankari shankari left a comment

Choose a reason for hiding this comment

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

Great start, just a few comments...

www/js/App.tsx Outdated Show resolved Hide resolved
www/js/control/ProfileSettings.jsx Show resolved Hide resolved
www/js/onboarding/OnboardingStack.tsx Outdated Show resolved Hide resolved
www/js/onboarding/ProtocolPage.tsx Outdated Show resolved Hide resolved
www/js/onboarding/SaveQrPage.tsx Show resolved Hide resolved
www/js/onboarding/onboardingHelper.ts Show resolved Hide resolved
www/js/onboarding/onboardingHelper.ts Show resolved Hide resolved
www/js/plugin/storage.ts Show resolved Hide resolved
www/js/splash/pushnotify.js Outdated Show resolved Hide resolved
www/js/splash/pushnotify.js Show resolved Hide resolved
@Abby-Wheelis Abby-Wheelis changed the base branch from service_rewrite_2023 to onboarding_routing_sept_2023 October 29, 2023 04:04
@Abby-Wheelis Abby-Wheelis changed the base branch from onboarding_routing_sept_2023 to service_rewrite_2023 October 29, 2023 04:04
@Abby-Wheelis Abby-Wheelis changed the base branch from service_rewrite_2023 to master October 30, 2023 15:12
@Abby-Wheelis Abby-Wheelis changed the base branch from master to service_rewrite_2023 October 30, 2023 15:13
@shankari shankari merged commit e8075b0 into e-mission:service_rewrite_2023 Nov 2, 2023
1 check passed
@Abby-Wheelis Abby-Wheelis deleted the startprefs-rewrite branch November 2, 2023 14:44
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.

3 participants