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 model_row_class = UserEvent
has_versions = True has_versions = True
touchable = True touchable = True
mergeable = True
grid_columns = [ grid_columns = [
'username', 'username',
@ -78,23 +79,13 @@ class UserView(PrincipalMasterView):
'occurred', 'occurred',
] ]
mergeable = True def __init__(self, request):
merge_additive_fields = [ super(UserView, self).__init__(request)
'sent_message_count', app = self.get_rattail_app()
'received_message_count',
] # always get a reference to the auth/merge handler
merge_coalesce_fields = [ self.auth_handler = app.get_auth_handler()
'person_uuid', self.merge_handler = self.auth_handler
'person_name',
'active',
]
merge_fields = merge_additive_fields + [
'uuid',
'username',
'person_uuid',
'person_name',
'role_count',
]
def query(self, session): def query(self, session):
query = super(UserView, self).query(session) query = super(UserView, self).query(session)
@ -441,31 +432,6 @@ class UserView(PrincipalMasterView):
users.append(user) users.append(user)
return users 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): def preferences(self, user=None):
""" """
View to modify preferences for a particular user. View to modify preferences for a particular user.