-
Notifications
You must be signed in to change notification settings - Fork 0
Delete files associated with anonymous msgs #258
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
Changes from all commits
f12c432
6b65f5c
099af16
02d404a
0de2cf9
b3fac3f
ba429a7
da585d9
3a59576
e45b572
1781e34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |||||||
| from src.api_interface import APIInterface | ||||||||
| from src.dao.user import User | ||||||||
| from src.hubspot_service import create_contact | ||||||||
| from src.message.GoogleCloudStorage import GoogleCloudStorage | ||||||||
|
|
||||||||
|
|
||||||||
| class UpsertUserRequest(APIInterface): | ||||||||
|
|
@@ -60,7 +61,7 @@ class MigrateFromAnonymousUserResponse(APIInterface): | |||||||
| messages_updated_count: int = Field() | ||||||||
|
|
||||||||
|
|
||||||||
| def migrate_user_from_anonymous_user(dbc: db.Client, anonymous_user_id: str, new_user_id: str): | ||||||||
| def migrate_user_from_anonymous_user(dbc: db.Client, storage_client: GoogleCloudStorage, anonymous_user_id: str, new_user_id: str): | ||||||||
| # migrate tos | ||||||||
| previous_user = dbc.user.get_by_client(anonymous_user_id) | ||||||||
| new_user = dbc.user.get_by_client(new_user_id) | ||||||||
|
|
@@ -84,6 +85,17 @@ def migrate_user_from_anonymous_user(dbc: db.Client, anonymous_user_id: str, new | |||||||
| elif previous_user is None and new_user is not None: | ||||||||
| updated_user = new_user | ||||||||
|
|
||||||||
|
|
||||||||
| msgs_to_be_migrated = dbc.message.get_by_creator(creator=anonymous_user_id) | ||||||||
|
|
||||||||
| for index, msg in enumerate(msgs_to_be_migrated): | ||||||||
| # 1. migrate anonyous files on Google Cloud | ||||||||
| for url in msg.file_urls or []: | ||||||||
| filename = url.split('/')[-1] | ||||||||
| whole_name = f"{msg.root}/{filename}" | ||||||||
|
Comment on lines
+94
to
+95
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably use Python's URL parsing here. We can also get the full path from the URL! Maybe something like this?
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The url includes the bucket name. I don't think we want it here..
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, right, because we're doing this within the context of a bucket. This is fine then! |
||||||||
| storage_client.migrate_anonymous_file(whole_name) | ||||||||
|
|
||||||||
| # 2. Remove expiration time, set private to false, update messages and labels with new user id | ||||||||
| updated_messages_count = dbc.message.migrate_messages_to_new_user( | ||||||||
| previous_user_id=anonymous_user_id, new_user_id=new_user_id | ||||||||
| ) | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.