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

Add Groundwork Pro upgrade workflow #5615

Merged
merged 7 commits into from
Aug 27, 2021

Conversation

jisantuc
Copy link
Contributor

@jisantuc jisantuc commented Aug 24, 2021

Overview

This (wip) PR updates scopes and the authentication flow to bump users' limits when a special key is present in their JWT.
It's wip because there's some cursed caching going on and I haven't figured out where yet.

Checklist

  • Description of PR is in an appropriate section of the changelog and grouped with similar changes if possible
  • Any new SQL strings have tests

Demo

forthcoming

Notes

There's still an Auth0 rule in the mix here, because adidng things to app_metadata doesn't automatically add them to the JWT, but fortunately the rule is just "copy what's in app_metadata" instead of anything involving inference about organization membership from emails.

Testing Instructions

  • assemble api server
  • update your local .env to have a GROUNDWORK_SAMPLE_PROJECT that's actually in your database (select id, name from annotation_projects to pick one, it doesn't matter which one you pick)
  • ./scripts/server
  • create a new user for yourself in Auth0 in the dev tenant in the Groundwork app
  • bring up Groundwork pointed to local RF
  • sign in as your new special user
  • click on the dropdown at your profile and look at your limits -- they should be non-pro user limits
  • set groundworkProUser: true in the app_metadata for your new user
  • wait a minute
  • refresh the page in GroundWork
  • you should see pro user limits 😎

Helps with azavea/raster-foundry-platform#1299

something's wrong right now though, because a mysterious force
is caching the user scope preventing the next call after auth
from recognizing that we've already upgraded the user to pro 🤔
handle empty scopes, add database-private method that skips cache
busting (since nothing puts the user in the cache), move scope
generation somewhere importable for db tests
@jisantuc jisantuc changed the title [wip] Add Groundwork Pro upgrade workflow Add Groundwork Pro upgrade workflow Aug 24, 2021
} else {
fr"""update users set scopes = to_jsonb(trim(both '"' from cast(scopes :: jsonb as text)) || ${";" ++ scope.asJson.noSpaces
.replace("\"", "")}) where id = $userId""".update.run <* (if (bust) {
Cache
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this formatting is awful but it's scalafmt's fault :(

@jisantuc jisantuc requested a review from pcaisse August 24, 2021 21:19
Copy link
Contributor

@pcaisse pcaisse left a comment

Choose a reason for hiding this comment

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

So initially when I went to test this by signing up with a brand new user I got this error from Auth0: http://localhost:3000/app/callback?error=access_denied&error_description=Cannot%20read%20property%20%27groundworkProUser%27%20of%20undefined&state=NjRBdHJNaHB2RHF2bnRiYVNxUWFFYXlGSDZMVlcwNH5zNlBEdkdvTV90Uw%3D%3D

If I then hit the 'Back' button and try to log in again, I get this:
oops

I then changed app_metadata for my user to:

{
  "groundworkProUser": false
}

and went all the way back to http://localhost:3000/app/login and logged in with the new user and it worked (can toggle between free and pro and user dropdown looks different).

@pcaisse
Copy link
Contributor

pcaisse commented Aug 27, 2021

@jisantuc Do we need to consider the case of pro users getting downgraded back to free? It looks like we don't remove the pro scope after modifying the app_metadata to set groundworkProUser to false which can result in a weird UI like this:
groundwork_free_pro

@jisantuc
Copy link
Contributor Author

Uhhhhh that's a good question. I don't really know how to do that right now 🤔 Scope subtraction makes a little less sense than scope addition. I will think about this. I think we don't need to solve the problem right now but it's important to figure out how it works.

@jisantuc
Copy link
Contributor Author

jisantuc commented Aug 27, 2021

I should also add -- the back button behavior (and some weird things that happen when you log out from the app -- i think that still spins forever?) has been a problem for a while, since it's impossible to codify** Auth0 config to get it to cooperate.

** not actually, since there's a terraform provider, but we've never used it

@jisantuc jisantuc merged commit ba25b44 into develop Aug 27, 2021
@jisantuc jisantuc deleted the feature/js/add-pro-upgrade-workflow branch August 27, 2021 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants