Skip to content

Commit

Permalink
add is_contributor to rest api and admin
Browse files Browse the repository at this point in the history
  • Loading branch information
lukavdplas committed Oct 2, 2024
1 parent 34d2119 commit a1e6429
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions backend/core/tests/test_contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def setUpTestData(cls) -> None:
cls.episode = Episode.objects.create(
name="Death Star destroyed", source_id=source.pk
)
cls.user_1 = User.objects.create(username="Yoda")
cls.user_2 = User.objects.create(username="Obi-Wan")
cls.user_1 = User.objects.create(username="Yoda", is_contributor=True)
cls.user_2 = User.objects.create(username="Obi-Wan", is_contributor=True)

def test_single_contributor_one_contribution(self):
self.client.force_login(self.user_1)
Expand Down
3 changes: 2 additions & 1 deletion backend/user/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

@admin.register(models.User)
class UserAdmin(auth_admin.UserAdmin):
pass
fieldsets = auth_admin.UserAdmin.fieldsets
fieldsets[2][1]["fields"] = list(fieldsets[2][1]["fields"]) + ["is_contributor"]
3 changes: 2 additions & 1 deletion backend/user/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class Meta(UserDetailsSerializer.Meta):
"first_name",
"last_name",
"is_staff",
"is_contributor",
)
read_only_fields = ["is_staff", "id", "email"]
read_only_fields = ["is_staff", "id", "email", "is_contributor"]
6 changes: 4 additions & 2 deletions backend/user/tests/test_user_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def test_user_details(user_client, user_data):
"first_name": user_data["first_name"],
"last_name": user_data["last_name"],
"is_staff": False,
"is_contributor": False,
}


Expand All @@ -28,10 +29,11 @@ def test_user_updates(user_client, user_data):
assert response.status_code == 200
assert details()["username"] == "NewName"

# is_staff is readonly, so nothing should happen
# is_staff and is_contributor are readonly, so nothing should happen
response = user_client.patch(
route,
{"is_staff": True},
{"is_staff": True, "is_contributor": True},
content_type="application/json",
)
assert not details()["is_staff"]
assert not details()["is_contributor"]

0 comments on commit a1e6429

Please sign in to comment.