Browse Source

Check membership before removing project member.

pull/217/head
Pēteris Caune 6 years ago
parent
commit
08810d1fca
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 18 additions and 3 deletions
  1. +11
    -0
      hc/accounts/tests/test_project.py
  2. +7
    -3
      hc/accounts/views.py

+ 11
- 0
hc/accounts/tests/test_project.py View File

@ -93,6 +93,17 @@ class ProfileTestCase(BaseTestCase):
self.bobs_profile.refresh_from_db() self.bobs_profile.refresh_from_db()
self.assertEqual(self.bobs_profile.current_project, None) self.assertEqual(self.bobs_profile.current_project, None)
def test_it_checks_membership_when_removing_team_member(self):
self.client.login(username="[email protected]", password="password")
url = "/projects/%s/settings/" % self.charlies_project.code
form = {"remove_team_member": "1", "email": "[email protected]"}
r = self.client.post(url, form)
self.assertEqual(r.status_code, 400)
self.profile.refresh_from_db()
self.assertIsNotNone(self.profile.current_project)
def test_it_sets_project_name(self): def test_it_sets_project_name(self):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")


+ 7
- 3
hc/accounts/views.py View File

@ -283,16 +283,20 @@ def project(request, code):
elif "remove_team_member" in request.POST: elif "remove_team_member" in request.POST:
form = RemoveTeamMemberForm(request.POST) form = RemoveTeamMemberForm(request.POST)
if form.is_valid(): if form.is_valid():
q = User.objects
q = q.filter(email=form.cleaned_data["email"])
q = q.filter(memberships__project=project)
farewell_user = q.first()
if farewell_user is None:
return HttpResponseBadRequest()
email = form.cleaned_data["email"]
farewell_user = User.objects.get(email=email)
farewell_user.profile.current_project = None farewell_user.profile.current_project = None
farewell_user.profile.save() farewell_user.profile.save()
Member.objects.filter(project=project, Member.objects.filter(project=project,
user=farewell_user).delete() user=farewell_user).delete()
ctx["team_member_removed"] = email
ctx["team_member_removed"] = form.cleaned_data["email"]
ctx["team_status"] = "info" ctx["team_status"] = "info"
elif "set_project_name" in request.POST: elif "set_project_name" in request.POST:
form = ProjectNameForm(request.POST) form = ProjectNameForm(request.POST)


Loading…
Cancel
Save