Skip to content

Commit

Permalink
fix remove coowner and contact
Browse files Browse the repository at this point in the history
  • Loading branch information
kbecker42 committed Sep 15, 2022
1 parent 3fb42e5 commit ac88368
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pybossa/view/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3244,7 +3244,7 @@ def coowners(short_name):

# remove any contacts that were just removed from coowners.
for _id in delete:
if _id in project.info.get('contacts', []):
if _id in new_list:
new_list.remove(_id)

auditlogger.log_event(project, current_user, 'update', 'project.contacts',
Expand Down
67 changes: 66 additions & 1 deletion test/test_coowners.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def test_coowner_add_contact(self):
assert res_data['coowners_dict'][1]['id'] == user3.id

# Add user3 (coowner) as a contact.
data = {'contacts': [user2.id, user3.id]}
data = {'coowners': project.owners_ids, 'contacts': [user2.id, user3.id]}
res = self.app.post('/project/%s/coowners?api_key=%s' % (project.short_name, admin.api_key),
content_type='application/json',
data=json.dumps(data),
Expand All @@ -248,6 +248,71 @@ def test_coowner_add_contact(self):
assert res_data['contacts_dict'][0]['id'] == user2.id
assert res_data['contacts_dict'][1]['id'] == user3.id

@with_context
def test_coowner_remove_contact(self):
from pybossa.core import project_repo

admin, user2, user3, user4 = UserFactory.create_batch(4)

project = ProjectFactory.create(owner=user2, published=True, short_name='sampleapp')
project.owners_ids.append(user3.id)
project_repo.save(project)

csrf = self.get_csrf('/account/signin')
self.signin(email=admin.email_addr, csrf=csrf)

data = {'user': user3.name}
res = self.app.post('/project/%s/coowners?api_key=%s' % (project.short_name, admin.api_key),
content_type='application/json',
data=json.dumps(data),
follow_redirects=True,
headers={'X-CSRFToken': csrf})
res_data = json.loads(res.data)

# Verify project owner is only user included in contacts.
assert len(res_data['contacts_dict']) == 1
assert res_data['contacts_dict'][0]['id'] == user2.id

# Verify project coowner is included in coowners.
assert len(res_data['coowners_dict']) == 2
assert res_data['coowners_dict'][0]['id'] == user2.id
assert res_data['coowners_dict'][1]['id'] == user3.id

# Add user3 (coowner) as a contact.
data = {'coowners': project.owners_ids, 'contacts': [user2.id, user3.id]}
res = self.app.post('/project/%s/coowners?api_key=%s' % (project.short_name, admin.api_key),
content_type='application/json',
data=json.dumps(data),
follow_redirects=True,
headers={'X-CSRFToken': csrf})
res_data = json.loads(res.data)

# Verify project owner and coowner are included in contacts.
assert len(res_data['contacts_dict']) == 2
assert res_data['contacts_dict'][0]['id'] == user2.id
assert res_data['contacts_dict'][1]['id'] == user3.id

# Remove user3 as a coowner.
data = {'coowners': [user2.id], 'contacts': [user2.id, user3.id]}
res = self.app.post('/project/%s/coowners?api_key=%s' % (project.short_name, admin.api_key),
content_type='application/json',
data=json.dumps(data),
follow_redirects=True,
headers={'X-CSRFToken': csrf})
res_data = json.loads(res.data)

# Verify project owner is only user included in contacts.
assert len(res_data['contacts_dict']) == 1
assert res_data['contacts_dict'][0]['id'] == user2.id

# Verify coowner has been removed.
assert len(res_data['coowners_dict']) == 1
assert res_data['coowners_dict'][0]['id'] == user2.id

# Verify contact has been removed.
assert len(res_data['contacts_dict']) == 1
assert res_data['contacts_dict'][0]['id'] == user2.id

@with_context
def test_user_search_found(self):
from pybossa.core import project_repo
Expand Down

0 comments on commit ac88368

Please sign in to comment.