Skip to content

Commit

Permalink
Merge pull request #954 from ae-utbm/fix-subscription
Browse files Browse the repository at this point in the history
fix access to the subscription page
  • Loading branch information
imperosol authored Dec 18, 2024
2 parents 6416de2 + be6a077 commit c5646b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 2 additions & 4 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,8 @@ def can_read_subscription_history(self):

@cached_property
def can_create_subscription(self) -> bool:
from club.models import Membership

return (
Membership.objects.board()
return self.is_root or (
self.memberships.board()
.ongoing()
.filter(club_id__in=settings.SITH_CAN_CREATE_SUBSCRIPTIONS)
.exists()
Expand Down
15 changes: 11 additions & 4 deletions subscription/tests/test_new_susbcription.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,20 @@ def test_form_new_user(settings: SettingsWrapper):

@pytest.mark.django_db
@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]):
"""Just check the page doesn't crash."""
def test_page_access(
client: Client, user_factory: Callable[[], User], status_code: int
):
"""Check that only authorized users may access this page."""
client.force_login(user_factory())
res = client.get(reverse("subscription:subscription"))
assert res.status_code == 200
assert res.status_code == status_code


@pytest.mark.django_db
Expand Down

0 comments on commit c5646b1

Please sign in to comment.