Let the auth handler manage user merge

This commit is contained in:
Lance Edgar 2022-11-15 13:37:37 -06:00
parent 3b64950a38
commit fec259629e

View file

@ -52,6 +52,7 @@ class UserView(PrincipalMasterView):
model_row_class = UserEvent
has_versions = True
touchable = True
mergeable = True
grid_columns = [
'username',
@ -78,23 +79,13 @@ class UserView(PrincipalMasterView):
'occurred',
]
mergeable = True
merge_additive_fields = [
'sent_message_count',
'received_message_count',
]
merge_coalesce_fields = [
'person_uuid',
'person_name',
'active',
]
merge_fields = merge_additive_fields + [
'uuid',
'username',
'person_uuid',
'person_name',
'role_count',
]
def __init__(self, request):
super(UserView, self).__init__(request)
app = self.get_rattail_app()
# always get a reference to the auth/merge handler
self.auth_handler = app.get_auth_handler()
self.merge_handler = self.auth_handler
def query(self, session):
query = super(UserView, self).query(session)
@ -441,31 +432,6 @@ class UserView(PrincipalMasterView):
users.append(user)
return users
def get_merge_data(self, user):
return {
'uuid': user.uuid,
'username': user.username,
'person_uuid': user.person_uuid,
'person_name': user.person.display_name if user.person else None,
'_roles': user.roles,
'role_count': len(user.roles),
'active': user.active,
'sent_message_count': len(user.sent_messages),
'received_message_count': len(user._messages),
}
def get_merge_resulting_data(self, remove, keep):
result = super(UserView, self).get_merge_resulting_data(remove, keep)
result['role_count'] = len(set(remove['_roles'] + keep['_roles']))
return result
def merge_objects(self, removing, keeping):
# TODO: merge roles, messages
assert not removing.sent_messages
assert not removing._messages
assert not removing._roles
self.Session.delete(removing)
def preferences(self, user=None):
"""
View to modify preferences for a particular user.