mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 07:41:14 +00:00
fix access to the subscription page
This commit is contained in:
parent
6416de237f
commit
be6a077c8e
@ -530,10 +530,8 @@ class User(AbstractBaseUser):
|
|||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def can_create_subscription(self) -> bool:
|
def can_create_subscription(self) -> bool:
|
||||||
from club.models import Membership
|
return self.is_root or (
|
||||||
|
self.memberships.board()
|
||||||
return (
|
|
||||||
Membership.objects.board()
|
|
||||||
.ongoing()
|
.ongoing()
|
||||||
.filter(club_id__in=settings.SITH_CAN_CREATE_SUBSCRIPTIONS)
|
.filter(club_id__in=settings.SITH_CAN_CREATE_SUBSCRIPTIONS)
|
||||||
.exists()
|
.exists()
|
||||||
|
@ -90,13 +90,20 @@ def test_form_new_user(settings: SettingsWrapper):
|
|||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"user_factory", [lambda: baker.make(User, is_superuser=True), board_user.make]
|
("user_factory", "status_code"),
|
||||||
|
[
|
||||||
|
(lambda: baker.make(User, is_superuser=True), 200),
|
||||||
|
(board_user.make, 200),
|
||||||
|
(subscriber_user.make, 403),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
def test_load_page(client: Client, user_factory: Callable[[], User]):
|
def test_page_access(
|
||||||
"""Just check the page doesn't crash."""
|
client: Client, user_factory: Callable[[], User], status_code: int
|
||||||
|
):
|
||||||
|
"""Check that only authorized users may access this page."""
|
||||||
client.force_login(user_factory())
|
client.force_login(user_factory())
|
||||||
res = client.get(reverse("subscription:subscription"))
|
res = client.get(reverse("subscription:subscription"))
|
||||||
assert res.status_code == 200
|
assert res.status_code == status_code
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
|
Loading…
Reference in New Issue
Block a user