Skip to content

Commit

Permalink
Review requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Oct 13, 2023
1 parent 1858470 commit 0c77966
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Creating a new Booking Folder
If the product is correctly installed the **Booking Folder** entry is available on the `add new` action menu.

You can configure:

- hidden booking types for the internal usage
- more then one gate
- booking vacations
- custom duration for booking types
Expand Down
5 changes: 5 additions & 0 deletions src/redturtle/prenotazioni/permissions.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
title="redturtle.prenotazioni: Manage Prenotazioni"
/>

<permission
id="redturtle.prenotazioni.ViewHiddenTypes"
title="redturtle.prenotazioni: View Hidden Types"
/>


</configure>

Expand Down
6 changes: 6 additions & 0 deletions src/redturtle/prenotazioni/profiles/default/rolemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,11 @@
<role name="Bookings Manager" />
</permission>

<permission name="redturtle.prenotazioni: View Hidden Types" acquire="True">
<role name="Manager"/>
<role name="Site Administrator"/>
<role name="Bookings Manager" />
</permission>

</permissions>
</rolemap>
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
from plone.restapi.serializer.dxcontent import SerializeFolderToJson
from zope.component import adapter
from zope.interface import implementer
from plone import api

from redturtle.prenotazioni.content.prenotazioni_folder import IPrenotazioniFolder
from redturtle.prenotazioni.content.prenotazioni_folder import (
IPrenotazioniFolder,
)
from redturtle.prenotazioni.interfaces import IRedturtlePrenotazioniLayer


Expand All @@ -15,6 +18,11 @@ def __call__(self, *args, **kwargs):
res = super().__call__()

if res.get("booking_types"):
if api.user.has_permission(
"redturtle.prenotazioni.ViewHiddenTypes"
):
return res

res["booking_types"] = [
t for t in res["booking_types"] if not t.get("hidden")
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
from plone.restapi.testing import RelativeSession

from redturtle.prenotazioni.adapters.booker import IBooker
from redturtle.prenotazioni.testing import REDTURTLE_PRENOTAZIONI_INTEGRATION_TESTING
from redturtle.prenotazioni.testing import (
REDTURTLE_PRENOTAZIONI_INTEGRATION_TESTING,
)
from redturtle.prenotazioni.tests.helpers import WEEK_TABLE_SCHEMA


Expand Down Expand Up @@ -43,6 +45,7 @@ def setUp(self):
],
gates=["Gate A"],
week_table=WEEK_TABLE_SCHEMA,
max_bookings_allowed=100,
)

def test_get_free_slots_skip_bookigs_inside_pause_range(self):
Expand Down Expand Up @@ -81,10 +84,18 @@ def test_get_free_slots_skip_bookigs_inside_pause_range(self):
res = view.get_free_slots(today)
# available slots are only arount the pause and not inside it
self.assertEqual(len(res["Gate A"]), 2)
self.assertEqual(view.get_free_slots(today)["Gate A"][0].start(), "07:00")
self.assertEqual(view.get_free_slots(today)["Gate A"][0].stop(), "08:00")
self.assertEqual(view.get_free_slots(today)["Gate A"][1].start(), "11:00")
self.assertEqual(view.get_free_slots(today)["Gate A"][1].stop(), "13:00")
self.assertEqual(
view.get_free_slots(today)["Gate A"][0].start(), "07:00"
)
self.assertEqual(
view.get_free_slots(today)["Gate A"][0].stop(), "08:00"
)
self.assertEqual(
view.get_free_slots(today)["Gate A"][1].start(), "11:00"
)
self.assertEqual(
view.get_free_slots(today)["Gate A"][1].stop(), "13:00"
)

def test_get_free_slots_handle_pauses_correctly(self):
booker = IBooker(self.folder_prenotazioni)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
from zope.interface import implementer
from zope.interface.interfaces import IObjectEvent

from redturtle.prenotazioni.testing import REDTURTLE_PRENOTAZIONI_FUNCTIONAL_TESTING
from redturtle.prenotazioni.tests.helpers import WEEK_TABLE_SCHEMA
from redturtle.prenotazioni.testing import (
REDTURTLE_PRENOTAZIONI_FUNCTIONAL_TESTING,
)


@implementer(IObjectEvent)
Expand All @@ -19,7 +22,7 @@ def __init__(self, object):
self.object = object


class TestEmailToManagers(unittest.TestCase):
class TestPrenotazioniFolderSerializer(unittest.TestCase):
layer = REDTURTLE_PRENOTAZIONI_FUNCTIONAL_TESTING

def setUp(self):
Expand Down Expand Up @@ -51,13 +54,11 @@ def setUp(self):
],
gates=["Gate A"],
)
week_table = self.folder_prenotazioni.week_table
for data in week_table:
data["morning_start"] = "0700"
data["morning_end"] = "1000"
self.folder_prenotazioni.week_table = week_table
self.folder_prenotazioni.week_table = WEEK_TABLE_SCHEMA

def test_hidden_type_is_not_shown(self):
setRoles(self.portal, TEST_USER_ID, ["User"])

def test_hidden_type_is_not_shown_if_no_premission(self):
self.assertNotIn(
self.hidden_type_name,
[
Expand All @@ -69,12 +70,14 @@ def test_hidden_type_is_not_shown(self):
)

def test_not_hidden_type_is_being_shown(self):
self.assertIn(
self.not_hidden_type_name,
[
i["name"]
for i in getMultiAdapter(
(self.folder_prenotazioni, getRequest()), ISerializeToJson
)()["booking_types"]
],
)
with api.env.adopt_roles(roles="Bookings Manager"):
self.assertIn(
self.not_hidden_type_name,
[
i["name"]
for i in getMultiAdapter(
(self.folder_prenotazioni, getRequest()),
ISerializeToJson,
)()["booking_types"]
],
)

0 comments on commit 0c77966

Please sign in to comment.