Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
[PC-10215] routes.pro.booking: allow access to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
rlecellier authored and asagot-ansa committed Aug 11, 2021
1 parent 0b32751 commit cbf9ba7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 52 deletions.
8 changes: 0 additions & 8 deletions src/pcapi/domain/users.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
from pcapi.core.users.models import User


def check_is_authorized_to_access_bookings_recap(user: User):
if user.isAdmin:
raise UnauthorizedForAdminUser()


class ClientError(Exception):
def __init__(self, field: str, error: str):
super().__init__()
Expand Down
3 changes: 0 additions & 3 deletions src/pcapi/routes/pro/bookings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pcapi.core.bookings.repository as booking_repository
import pcapi.core.bookings.validation as bookings_validation
from pcapi.domain.users import UnauthorizedForAdminUser
from pcapi.domain.users import check_is_authorized_to_access_bookings_recap
from pcapi.flask_app import private_api
from pcapi.flask_app import public_api
from pcapi.models import EventType
Expand Down Expand Up @@ -77,8 +76,6 @@ def get_all_bookings(query: ListBookingsQueryModel) -> ListBookingsResponseModel
event_date = query.event_date
booking_period = (query.booking_period_beginning_date, query.booking_period_ending_date)

check_is_authorized_to_access_bookings_recap(current_user)

# FIXME: due to generalisation, the performance issue has led to DDOS many
# users checking the many bookings of these offerers
temporarily_banned_sirens = ["334473352", "434001954", "343282380"]
Expand Down
30 changes: 0 additions & 30 deletions tests/domain/users_test.py

This file was deleted.

19 changes: 8 additions & 11 deletions tests/routes/pro/get_all_bookings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ def test_call_repository_with_venue_id(self, find_by_pro_user_id, app):

@pytest.mark.usefixtures("db_session")
class Returns200Test:
def when_user_is_admin(self, app):
admin = users_factories.AdminFactory()

client = TestClient(app.test_client()).with_auth(admin.email)
response = client.get(f"/bookings/pro?{BOOKING_PERIOD_PARAMS}")

assert response.status_code == 200

def when_user_is_linked_to_a_valid_offerer(self, app):
booking = bookings_factories.BookingFactory(
dateCreated=datetime(2020, 8, 11, 12, 0, 0),
Expand Down Expand Up @@ -218,17 +226,6 @@ def when_booking_period_is_not_given(self, app):

@pytest.mark.usefixtures("db_session")
class Returns401Test:
def when_user_is_admin(self, app):
admin = users_factories.AdminFactory()

client = TestClient(app.test_client()).with_auth(admin.email)
response = client.get(f"/bookings/pro?{BOOKING_PERIOD_PARAMS}")

assert response.status_code == 401
assert response.json == {
"global": ["Le statut d'administrateur ne permet pas d'accéder au suivi des réservations"]
}

@override_features(DISABLE_BOOKINGS_RECAP_FOR_SOME_PROS=True)
def when_user_is_blacklisted(self, app):
pro = users_factories.ProFactory(offerers=[offers_factories.OffererFactory(siren="334473352")])
Expand Down

0 comments on commit cbf9ba7

Please sign in to comment.