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

Is677/trial account #3352

Merged
merged 35 commits into from
Sep 21, 2022
Merged

Conversation

pcrespov
Copy link
Member

@pcrespov pcrespov commented Sep 12, 2022

What do these changes do?

A user account can have an expiration date. Expired users access is blocked with 401.

image

packages/postgres-database

  • users.expires_at column used for account expiration.
  • 📝 updates doc of users table
  • ✨ periodic task checks for expired users
  • 🐛 fixes wrong openapi specs

services/web/server

  • ✨ Requests from users marked as EXPIRED are errored with 401 and MSG_USER_EXPIRED
  • ✨ pydantic models to validate openapi schemas for users entrypoint
    • `users_models``: mainly Profile-like models
    • `groups_models`` currently only used in Profile. groups API entrypoints are still not using these models. Will follow up with Use new models in groups plugin #3361
  • ✨ periodic task (launched in the garbage-collector plugin) updates the users table looking for expired accounts.

⚠️ devops

  • new environment variable to update trial accounts: GARBAGE_COLLECTOR_EXPIRED_USERS_CHECK_INTERVAL_S (defaults to 6h interval)

Related issue/s

How to test

pytest -v tests/**/test_users*.py

Checklist

  • Openapi changes? make openapi-specs, git commit ... and then make version-*)
  • Database migration script? cd packages/postgres-database, make setup-commit, sc-pg review -m "my changes"
  • Unit tests for the changes exist
  • Runs in the swarm
  • Documentation reflects the changes
  • New module? Add your github username to .github/CODEOWNERS

@pcrespov pcrespov self-assigned this Sep 12, 2022
@codecov
Copy link

codecov bot commented Sep 12, 2022

Codecov Report

Merging #3352 (1bf7818) into master (ecb8b35) will increase coverage by 0.0%.
The diff coverage is 97.0%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #3352    +/-   ##
=======================================
  Coverage    83.0%   83.0%            
=======================================
  Files         808     811     +3     
  Lines       34261   34410   +149     
  Branches     1358    1358            
=======================================
+ Hits        28437   28593   +156     
+ Misses       5643    5636     -7     
  Partials      181     181            
Flag Coverage Δ
integrationtests 68.7% <83.0%> (+0.3%) ⬆️
unittests 79.8% <97.0%> (+<0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...erver/src/simcore_service_webserver/users_utils.py 90.0% <80.0%> (-10.0%) ⬇️
.../server/src/simcore_service_webserver/users_api.py 95.1% <88.8%> (-1.2%) ⬇️
...service_webserver/users_garbage_collector_tasks.py 95.5% <95.5%> (ø)
...rver/src/simcore_service_webserver/users_models.py 97.6% <97.6%> (ø)
...s/models-library/src/models_library/basic_types.py 96.5% <100.0%> (+0.1%) ⬆️
...base/src/simcore_postgres_database/models/users.py 93.3% <100.0%> (+0.2%) ⬆️
...src/simcore_service_webserver/garbage_collector.py 100.0% <100.0%> (ø)
...re_service_webserver/garbage_collector_settings.py 100.0% <100.0%> (ø)
...ver/src/simcore_service_webserver/groups_models.py 100.0% <100.0%> (ø)
...er/src/simcore_service_webserver/login/handlers.py 87.1% <100.0%> (+0.1%) ⬆️
... and 15 more

@pcrespov pcrespov added this to the vaporwave milestone Sep 13, 2022
@pcrespov pcrespov force-pushed the is677/trial-account branch 6 times, most recently from a9482c3 to 3b1270a Compare September 15, 2022 18:05
@pcrespov pcrespov mentioned this pull request Sep 16, 2022
3 tasks
@pcrespov pcrespov force-pushed the is677/trial-account branch 4 times, most recently from 54bd382 to 9fcbd01 Compare September 20, 2022 09:59
@pcrespov pcrespov changed the title WIP: Is677/trial account Is677/trial account Sep 20, 2022
@pcrespov pcrespov added the a:webserver issue related to the webserver service label Sep 20, 2022
@pcrespov pcrespov marked this pull request as ready for review September 20, 2022 10:00
@pcrespov pcrespov requested a review from odeimaiz September 20, 2022 10:00
Copy link
Member

@sanderegg sanderegg left a comment

Choose a reason for hiding this comment

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

great!, some minor comments, thanks !

services/web/server/src/simcore_service_webserver/users.py Outdated Show resolved Hide resolved
@@ -102,11 +103,11 @@ async def get_user_profile(app: web.Application, user_id: UserID) -> Dict[str, A
"organizations": user_standard_groups,
"all": all_group,
}
return user_profile
return ProfileGet.parse_obj(user_profile)
Copy link
Member

Choose a reason for hiding this comment

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

minor: does it make sense to create first the dictionary and then right away the pydantic model?

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 are composing a dict and then using the model to validate the entire structure.
If we would have the user_profile in one go I would definitively use the model constructor but it is not the case.

body = await request.json()
updates = ProfileUpdate.parse_obj(body)
Copy link
Member

Choose a reason for hiding this comment

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

minor: why not using the parse_body_as method? it works beautifully.

Copy link
Member Author

Choose a reason for hiding this comment

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

parse_body_as will create a tmp model and include the model class as __root__ and the it calls model.parse_obj. That is handy when you have classes not derived from BaseModel. If your class is derived from BaseModel calling the free function is a unnecessary overhead.

If you do not understand what I mean, just check the implementation
https://github.com/pydantic/pydantic/blob/main/pydantic/tools.py#L38

Copy link
Contributor

@GitHK GitHK left a comment

Choose a reason for hiding this comment

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

👍 Please have look at my questions below

@sonarcloud
Copy link

sonarcloud bot commented Sep 21, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@pcrespov pcrespov requested review from GitHK and sanderegg September 21, 2022 13:47
@pcrespov pcrespov merged commit 4fc72ac into ITISFoundation:master Sep 21, 2022
@pcrespov pcrespov deleted the is677/trial-account branch September 21, 2022 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:webserver issue related to the webserver service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants