Skip to content

Commit

Permalink
Merge pull request #327 from ucb-rit/issue_323
Browse files Browse the repository at this point in the history
Issue 323
  • Loading branch information
matthew-li authored Jan 19, 2022
2 parents 38b0877 + 0b96d0a commit c7caa42
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
4 changes: 1 addition & 3 deletions coldfront/core/project/templates/project/project_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ <h2 class="d-inline">
<a class="btn btn-success" href="{% url 'project-add-users-search' project.pk %}" role="button"><i class="fas fa-user-plus" aria-hidden="true"></i> Add Users</a>
<a class="btn btn-danger" href="{% url 'project-remove-users' project.pk %}" role="button"><i class="fas fa-user-times" aria-hidden="true"></i> Remove Users</a>
{% endif %}
</div>
<div class="float-right">
{% if project.status.name != 'Archived' and can_leave_project %}
<div class="modal fade" id="denial{{ user.pk }}Modal" tabindex="-1" role="dialog" aria-labelledby="denial{{ user.pk }}ModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
Expand Down Expand Up @@ -259,7 +257,7 @@ <h2 class="d-inline">
</form>
</div>
</div>
<button class="btn btn-danger mr-1" data-toggle="modal" data-target="#denial{{ user.pk }}Modal">
<button class="btn btn-danger" data-toggle="modal" data-target="#denial{{ user.pk }}Modal">
Leave Project
</button>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,34 @@ def test_remove_self(self):

self.client.logout()

def test_remove_self_superuser(self):
"""Test that ProjectRemoveSelf POST performs the correct actions when
requester is a superuser."""
self.user1.is_superuser = True
self.user1.save()
self.assertTrue(self.user1.is_superuser)
self.client.login(username=self.user1.username, password=self.password)

url = reverse('project-detail', kwargs={'pk': self.project1.pk})
response = self.client.get(url)
self.assertContains(response, 'Leave Project')

url = reverse(
'project-remove-self', kwargs={'pk': self.project1.pk})
pre_time = utc_now_offset_aware()
response = self.client.post(url, {})

self.assertRedirects(response, reverse('home'))
self.assertTrue(ProjectUserRemovalRequest.objects.filter(
requester=self.user1).exists())

removal_request = \
ProjectUserRemovalRequest.objects.filter(requester=self.user1).first()
self.assertTrue(pre_time <= removal_request.request_time <=
utc_now_offset_aware())

self.client.logout()


class TestProjectRemoveUsersView(TestBase):
"""A class for testing ProjectRemoveUsersView."""
Expand Down
2 changes: 1 addition & 1 deletion coldfront/core/project/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def get_context_data(self, **kwargs):
if self.request.user.is_superuser:
context['is_allowed_to_update_project'] = True

elif self.object.projectuser_set.filter(user=self.request.user).exists():
if self.object.projectuser_set.filter(user=self.request.user).exists():
project_user = self.object.projectuser_set.get(user=self.request.user)

if project_user.role.name in ['Principal Investigator', 'Manager']:
Expand Down

0 comments on commit c7caa42

Please sign in to comment.