-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Remove user data from couch user model #34805
Changes from 3 commits
07d5a70
160d540
45137f3
8e813e2
983b087
d04391c
5081177
ca7845f
ab0ed8a
a181308
da40b4d
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 |
---|---|---|
|
@@ -41,17 +41,15 @@ def __init__(self, upload_domain, user_domain, user, is_new_user, changed_by_use | |
|
||
if not is_new_user: | ||
self.original_user_doc = self.user.to_json() | ||
self.original_user_data = self.user.get_user_data(user_domain).raw | ||
else: | ||
self.original_user_doc = None | ||
self.original_user_data = None | ||
|
||
self.fields_changed = {} | ||
self.change_messages = {} | ||
|
||
self._save = False # flag to check if log needs to be saved for updates | ||
|
||
def add_changes(self, changes): | ||
def add_changes(self, changes, skip_confirmation=False): | ||
""" | ||
Add changes to user properties. | ||
Ignored for new user since the whole user doc is logged for a new user | ||
|
@@ -60,7 +58,7 @@ def add_changes(self, changes): | |
if self.is_new_user: | ||
return | ||
for name, new_value in changes.items(): | ||
if self.original_user_doc[name] != new_value: | ||
if skip_confirmation or self.original_user_doc[name] != new_value: | ||
self.fields_changed[name] = new_value | ||
self._save = True | ||
|
||
|
@@ -157,6 +155,8 @@ def update_user_data(self, data, uncategorized_data, profile_name, profiles_by_n | |
from corehq.apps.users.user_data import UserDataError | ||
user_data = self.user.get_user_data(self.user_domain) | ||
old_profile_id = user_data.profile_id | ||
old_user_data = user_data.raw | ||
|
||
if PROFILE_SLUG in data: | ||
raise UserUploadError(_("You cannot set {} directly").format(PROFILE_SLUG)) | ||
if profile_name: | ||
|
@@ -174,20 +174,16 @@ def update_user_data(self, data, uncategorized_data, profile_name, profiles_by_n | |
if user_data.profile_id and user_data.profile_id != old_profile_id: | ||
self.logger.add_info(UserChangeMessage.profile_info(user_data.profile_id, profile_name)) | ||
|
||
if old_user_data != user_data.raw: | ||
self.logger.add_changes({'user_data': user_data.raw}, skip_confirmation=True) | ||
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. I understand we did that before too. But is logging the user data a good idea? 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. Can you elaborate? This code logs all changes made to a user for auditing purposes. 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. Maybe it is just the name of the field being 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. true - though 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. Fair |
||
|
||
def save_log(self): | ||
# Tracking for role is done post save to have role setup correctly on save | ||
if self.role_updated: | ||
new_role = self.user.get_role(domain=self.user_domain) | ||
self.logger.add_info(UserChangeMessage.role_change(new_role)) | ||
|
||
self._include_user_data_changes() | ||
return self.logger.save() | ||
|
||
def _include_user_data_changes(self): | ||
new_user_data = self.user.get_user_data(self.user_domain).raw | ||
if self.logger.original_user_data != new_user_data: | ||
self.logger.add_changes({'user_data': new_user_data}) | ||
|
||
|
||
class CommCareUserImporter(BaseUserImporter): | ||
|
||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't the API still be trying to update the
user_data
attribute on theCommCareUser
model? Or is that somehow otherwise accounted for?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, good question. That's handled here:
commcare-hq/corehq/apps/api/user_updates.py
Lines 112 to 122 in d3d0b80
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see,
obj_update
should manually override the update for this field.