Skip to content

Commit

Permalink
Added more improvements about roles, roles mapping and it's testing #33
Browse files Browse the repository at this point in the history
  • Loading branch information
alfadestroyer committed Jul 26, 2023
1 parent dfdef96 commit c941298
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
4 changes: 4 additions & 0 deletions backend/src/slc_web/src/slc_web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

PACKAGE_NAME = "slc_web"

# Permissions Roles
ADD_SPONSOR_ROLES = ["Manager", "Site Administrator", "Sponsorship Committee"]
MANAGE_SPONSOR_ROLES = ["Manager", "Sponsorship Committee"]

_ = MessageFactory("slc_web")

logger = logging.getLogger("slc_web")
8 changes: 4 additions & 4 deletions backend/src/slc_web/src/slc_web/profiles/default/rolemap.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<rolemap>
<roles>
<role name="Community Sponsorship Committee" />
<role name="Sponsorship Committee" />
<role name="Community Membership Committee" />
</roles>
<permissions>
<permission acquire="True"
name="Community Sponsor: Add Community Sponsor"
>
<role name="Community Sponsorship Committee" />
<role name="Sponsorship Committee" />
<role name="Manager" />
<role name="Site Administrator" />
</permission>
<permission acquire="True"
name="Community Sponsor: View Detail"
>
<role name="Community Sponsorship Committee" />
<role name="Sponsorship Committee" />
<role name="Manager" />
</permission>
<permission acquire="True"
name="Community Sponsor: Manage Sponsors"
>
<role name="Community Sponsorship Committee" />
<role name="Sponsorship Committee" />
<role name="Manager" />
</permission>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.dexterity.interfaces import IDexterityFTI

from slc_web import ADD_SPONSOR_ROLES
from slc_web import MANAGE_SPONSOR_ROLES
from slc_web.testing import SLC_WEB_INTEGRATION_TESTING

from zope.component import queryUtility

import unittest
Expand All @@ -22,7 +26,47 @@ def setUp(self):
self.portal = self.layer["portal"]
setRoles(self.portal, TEST_USER_ID, ["Manager"])

def test_fti_community_sponsor(self):
def test_ct_community_sponsor_fti(self):
"""Test If CommunitySponsor exits on Dexterity FTI."""
fti = queryUtility(IDexterityFTI, name="CommunitySponsor")
self.assertTrue(fti)
# self.assertNotEqual(None, fti)

def test_ct_community_sponsor_globally_addable(self):
"""Test If CommunitySponsor is globally addable."""

setRoles(self.portal, TEST_USER_ID, ["Contributor"])
fti = queryUtility(IDexterityFTI, name="CommunitySponsor")
self.assertTrue(
fti.global_allow,
"{0} is not globally addable!".format(fti.id),
)

def test_ct_community_sponsor_roles(self):
"""Test correct assigning of permissions from rolemap.xml file."""

# Test permission mapping for adding an Community Sponsor
sponsor_roles = [
r["name"]
for r in self.portal.rolesOfPermission(
"Community Sponsor: Add Community Sponsor"
)
if r["selected"]
]
self.assertEqual(sponsor_roles, ADD_SPONSOR_ROLES)

# Test permission mapping for View Detail
sponsor_roles = [
r["name"]
for r in self.portal.rolesOfPermission("Community Sponsor: View Detail")
if r["selected"]
]
self.assertEqual(sponsor_roles, MANAGE_SPONSOR_ROLES)

# Test permission mapping for managing Manage Sponsors
sponsor_roles = [
r["name"]
for r in self.portal.rolesOfPermission("Community Sponsor: Manage Sponsors")
if r["selected"]
]
self.assertEqual(sponsor_roles, MANAGE_SPONSOR_ROLES)

0 comments on commit c941298

Please sign in to comment.