Verified Commit a5d5c41d authored by Sli's avatar Sli

pedagogy: fix a bug when updating an UV from a different author

parent 824ea37f
Pipeline #1981 passed with stage
in 22 minutes and 17 seconds
......@@ -252,61 +252,64 @@ class UVUpdateTest(TestCase):
call_command("populate")
self.bibou = User.objects.filter(username="root").first()
self.tutu = User.objects.filter(username="tutu").first()
self.sli = User.objects.filter(username="sli").first()
self.guy = User.objects.filter(username="guy").first()
self.uv = UV.objects.get(code="PA00")
def test_uv_update_root_success(self):
self.client.login(username="root", password="plop")
self.client.post(
reverse(
"pedagogy:uv_update", kwargs={"uv_id": UV.objects.get(code="PA00").id}
),
reverse("pedagogy:uv_update", kwargs={"uv_id": self.uv.id}),
create_uv_template(self.bibou.id, code="PA00"),
)
self.assertEquals(UV.objects.get(code="PA00").credit_type, "TM")
self.uv.refresh_from_db()
self.assertEquals(self.uv.credit_type, "TM")
def test_uv_update_pedagogy_admin_success(self):
self.client.login(username="tutu", password="plop")
self.client.post(
reverse(
"pedagogy:uv_update", kwargs={"uv_id": UV.objects.get(code="PA00").id}
),
reverse("pedagogy:uv_update", kwargs={"uv_id": self.uv.id}),
create_uv_template(self.bibou.id, code="PA00"),
)
self.uv.refresh_from_db()
self.assertEquals(self.uv.credit_type, "TM")
def test_uv_update_original_author_does_not_change(self):
self.client.login(username="tutu", password="plop")
response = self.client.post(
reverse("pedagogy:uv_update", kwargs={"uv_id": self.uv.id}),
create_uv_template(self.tutu.id, code="PA00"),
)
self.assertEquals(UV.objects.get(code="PA00").credit_type, "TM")
self.uv.refresh_from_db()
self.assertEquals(response.status_code, 200)
self.assertEquals(self.uv.author, self.bibou)
def test_uv_update_pedagogy_unauthorized_fail(self):
# Anonymous user
response = self.client.post(
reverse(
"pedagogy:uv_update", kwargs={"uv_id": UV.objects.get(code="PA00").id}
),
create_uv_template(0, code="PA00"),
reverse("pedagogy:uv_update", kwargs={"uv_id": self.uv.id}),
create_uv_template(self.bibou.id, code="PA00"),
)
self.assertEquals(response.status_code, 403)
# Not subscribed user
self.client.login(username="guy", password="plop")
response = self.client.post(
reverse(
"pedagogy:uv_update", kwargs={"uv_id": UV.objects.get(code="PA00").id}
),
create_uv_template(self.guy.id, code="PA00"),
reverse("pedagogy:uv_update", kwargs={"uv_id": self.uv.id}),
create_uv_template(self.bibou.id, code="PA00"),
)
self.assertEquals(response.status_code, 403)
# Simply subscribed user
self.client.login(username="sli", password="plop")
response = self.client.post(
reverse(
"pedagogy:uv_update", kwargs={"uv_id": UV.objects.get(code="PA00").id}
),
create_uv_template(self.sli.id, code="PA00"),
reverse("pedagogy:uv_update", kwargs={"uv_id": self.uv.id}),
create_uv_template(self.bibou.id, code="PA00"),
)
self.assertEquals(response.status_code, 403)
# Check that the UV has not changed
self.assertEquals(UV.objects.get(code="PA00").credit_type, "OM")
self.uv.refresh_from_db()
self.assertEquals(self.uv.credit_type, "OM")
# UVComment class tests
......
......@@ -328,7 +328,8 @@ class UVUpdateView(CanEditPropMixin, UpdateView):
def get_form_kwargs(self):
kwargs = super(UVUpdateView, self).get_form_kwargs()
kwargs["author_id"] = self.request.user.id
obj = self.get_object()
kwargs["author_id"] = obj.author.id
return kwargs
def get_success_url(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment