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

RDISCROWD-7561 Sorting users #969

Merged
merged 13 commits into from
Sep 19, 2024
2 changes: 1 addition & 1 deletion pybossa/themes/default
4 changes: 3 additions & 1 deletion pybossa/view/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3865,7 +3865,9 @@ def assign_users(short_name):

# Update users with last_name for sorting.
for user in users:
full_name_parts = user.get('fullname', '').split(' ')
# Remove content within parentheses and digits in name: Jane Doe (ai)
cleaned_name = re.sub(r'\s*\(.*?\)|\d+', '', user.get('fullname', ''))
full_name_parts = cleaned_name.split(' ')
user['last_name'] = full_name_parts[-1] if len(full_name_parts) > 1 else user.get('fullname')

form = DataAccessForm(request.body)
Expand Down
12 changes: 7 additions & 5 deletions test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -9928,14 +9928,16 @@ def test_get_assign_users_to_project(self):
user1.info['data_access'] = ["L1", "L2", "L3", "L4"]
user_repo.save(user1)

user2 = UserFactory.create(id=998, subadmin=False, admin=False, name="workeruser1")
user2 = UserFactory.create(id=998, subadmin=False, admin=False, name="workeruser_one")
user2.set_password('1234')
user2.info['data_access'] = ["L1", "L2", "L3", "L4"]
user2.fullname = 'workeruser one'
user_repo.save(user2)

user3 = UserFactory.create(id=997, subadmin=False, admin=False, name="workeruser2", enabled=False)
user3 = UserFactory.create(id=997, subadmin=False, admin=False, name="workeruser_two", enabled=False)
user3.set_password('1234')
user3.info['data_access'] = ["L1", "L2", "L3", "L4"]
user3.fullname = 'workeruser two'
user_repo.save(user3)

project = ProjectFactory.create(info={
Expand All @@ -9954,9 +9956,9 @@ def test_get_assign_users_to_project(self):
res = self.app.get('/project/{}/assign-users'.format(project.short_name))

# Confirm users exist in the page and disables users do not.
assert user1.fullname in str(res.data), 'User 1 not found on assign-users page.'
assert user2.fullname in str(res.data), 'User 2 not found on assign-users page.'
assert user3.fullname not in str(res.data), 'User 3 is disabled and should not be found on assign-users page.'
assert user1.fullname in str(res.data), user1.fullname + ' not found on assign-users page.'
assert user2.fullname in str(res.data), user2.fullname + ' not found on assign-users page.'
assert user3.fullname not in str(res.data), user3.fullname + ' is disabled and should not be found on assign-users page.'

@with_context
@patch('pybossa.view.account.send_mail', autospec=True)
Expand Down
Loading