From ef3e21d32d68fe21e72422b9026603b81cf30c5f Mon Sep 17 00:00:00 2001 From: Jose Benito Date: Thu, 7 Feb 2013 18:33:22 +0100 Subject: [PATCH] [REF] Wording, Naming and Style on Protection --- bin/migration/migrate.py | 20 ++--- indico/MaKaC/accessControl.py | 32 ++++---- indico/MaKaC/conference.py | 85 ++++++++++------------ indico/MaKaC/fossils/conference.py | 9 ++- indico/MaKaC/fossils/contribution.py | 4 +- indico/MaKaC/services/implementation/conference.py | 8 +- .../MaKaC/services/implementation/contribution.py | 8 +- indico/MaKaC/services/implementation/session.py | 8 +- .../webinterface/tpls/AccessControlStatusFrame.tpl | 70 ++++++++++-------- indico/htdocs/css/Default.css | 24 +++++- indico/htdocs/js/indico/Core/Dialogs/Popup.js | 11 ++- .../python/unit/MaKaC_tests/protection_test.py | 32 ++++---- 12 files changed, 166 insertions(+), 145 deletions(-) diff --git a/bin/migration/migrate.py b/bin/migration/migrate.py index 6332514fd..8a0dce54a 100644 --- a/bin/migration/migrate.py +++ b/bin/migration/migrate.py @@ -657,36 +657,36 @@ def removeOldCSSTemplates(dbi, withRBDB, prevVersion): dbi.commit() @since('1.0') -def updateNonInheritedChildren(dbi, withRBDB, prevVersion): +def updateNonInheritingChildren(dbi, withRBDB, prevVersion): """ Update non inherited children list """ def _updateMaterial(obj): for material in obj.getAllMaterialList(): - material.getAccessController().setNonInheritedChildren(set()) - material.updateInheritedParent(material) + material.getAccessController().setNonInheritingChildren(set()) + material.notify_protection_to_owner(material) for resource in material.getResourceList(): - resource.updateInheritedParent() + resource.notify_protection_to_owner() ch = ConferenceHolder() i = 0 for (__, conf) in console.conferenceHolderIterator(ch, deepness='event'): - conf.getAccessController().setNonInheritedChildren(set()) + conf.getAccessController().setNonInheritingChildren(set()) _updateMaterial(conf) for session in conf.getSessionList(): - session.getAccessController().setNonInheritedChildren(set()) - session.updateInheritedParent(session) + session.getAccessController().setNonInheritingChildren(set()) + session.notify_protection_to_owner(session) _updateMaterial(session) for contrib in conf.getContributionList(): - contrib.getAccessController().setNonInheritedChildren(set()) - contrib.updateInheritedParent(contrib) + contrib.getAccessController().setNonInheritingChildren(set()) + contrib.notify_protection_to_owner(contrib) _updateMaterial(contrib) for subContrib in contrib.getSubContributionList(): _updateMaterial(subContrib) - if i % 1000 == 999: + if i % 10000 == 9999: dbi.commit() i += 1 dbi.commit() diff --git a/indico/MaKaC/accessControl.py b/indico/MaKaC/accessControl.py index 867c5cbcc..3701ac517 100644 --- a/indico/MaKaC/accessControl.py +++ b/indico/MaKaC/accessControl.py @@ -32,7 +32,7 @@ def isFullyAccess(level): def wrap(func): @wraps(func) def decorator(*args): - for child in args[0].getNonInheritedChildren(): + for child in args[0].getNonInheritingChildren(): if child.getAccessController().getAccessProtectionLevel() == level: return False return True @@ -43,7 +43,7 @@ def getChildren(level): def wrap(func): @wraps(func) def decorator(*args): - return [child for child in args[0].getNonInheritedChildren() if child.getAccessController().getAccessProtectionLevel() == level] + return [child for child in args[0].getNonInheritingChildren() if child.getAccessController().getAccessProtectionLevel() == level] return decorator return wrap @@ -80,7 +80,7 @@ class AccessController( Persistent, Observable ): self.accessKey = "" self.owner = owner self.contactInfo = "" - self.nonInheritedChildren = set() + self.nonInheritingChildren = set() def getOwner(self): return self.owner @@ -370,25 +370,25 @@ class AccessController( Persistent, Observable ): def setContactInfo(self, info): self.contactInfo = info - def addNonInheritedChild(self, obj): - self.nonInheritedChildren.add(obj) + def addNonInheritingChildren(self, obj): + self.nonInheritingChildren.add(obj) self._p_changed = 1 - def removeNonInheritedChild(self, obj): - self.nonInheritedChildren.discard(obj) + def removeNonInheritingChildren(self, obj): + self.nonInheritingChildren.discard(obj) self._p_changed = 1 - def getNonInheritedChildren(self): - return self.nonInheritedChildren + def getNonInheritingChildren(self): + return self.nonInheritingChildren - def setNonInheritedChildren(self, nonInheritedChildren): - self.nonInheritedChildren = nonInheritedChildren + def setNonInheritingChildren(self, nonInheritingChildren): + self.nonInheritingChildren = nonInheritingChildren - def updateNonInheritedChildren(self, elem, delete=False): + def updateNonInheritingChildren(self, elem, delete=False): if delete or elem.getAccessController().getAccessProtectionLevel() == 0: - self.removeNonInheritedChild(elem) + self.removeNonInheritingChildren(elem) else: - self.addNonInheritedChild(elem) + self.addNonInheritingChildren(elem) self._p_changed = 1 @@ -401,11 +401,11 @@ class AccessController( Persistent, Observable ): pass @getChildren(1) - def getChildrenProtected(self): + def getProtectedChildren(self): pass @getChildren(-1) - def getChildrenPublic(self): + def getPublicChildren(self): pass diff --git a/indico/MaKaC/conference.py b/indico/MaKaC/conference.py index 5ae3f3349..eab9d5e24 100644 --- a/indico/MaKaC/conference.py +++ b/indico/MaKaC/conference.py @@ -2205,8 +2205,8 @@ class Conference(CommonObjectBase, Locatable): if len(self.getOwnerList()) > 0: self.getOwnerList()[0].cleanCache() - def updateInheritedChild(self, elem, delete=False): - self.getAccessController().updateNonInheritedChildren(elem, delete) + def updateNonInheritingChildren(self, elem, delete=False): + self.getAccessController().updateNonInheritingChildren(elem, delete) def getKeywords(self): try: @@ -5395,13 +5395,15 @@ class Session(CommonObjectBase, Locatable): def getTimezone( self ): return self.getConference().getTimezone() - def updateInheritedChild(self, elem, delete=False, propagate=True): - self.getAccessController().updateNonInheritedChildren(elem, delete) + def updateNonInheritingChildren(self, elem, delete=False, propagate=True): + self.getAccessController().updateNonInheritingChildren(elem, delete) if propagate == True: - self.updateInheritedParent(elem, delete) + self.notify_protection_to_owner(elem, delete) - def updateInheritedParent(self, elem, delete=False): - self.getOwner().updateInheritedChild(elem, delete) + def notify_protection_to_owner(self, elem, delete=False): + """ This methods notifies the owner that the protection has been changed, + so it can update its list of non inheriting children """ + self.getOwner().updateNonInheritingChildren(elem, delete) def getKeywords(self): try: @@ -5530,7 +5532,7 @@ class Session(CommonObjectBase, Locatable): self.getRegistrationSession().setRegistrationForm(None) TrashCanManager().add(self.getRegistrationSession()) self.conference=None - self.updateInheritedParent(self, delete=True) + self.notify_protection_to_owner(self, delete=True) TrashCanManager().add(self) def recover(self, isCancelled): @@ -6212,9 +6214,9 @@ class Session(CommonObjectBase, Locatable): self.contributions[newContrib.getId()]=newContrib newContrib.setSession(self) - self.updateInheritedChild(newContrib) - for child in newContrib.getAccessController().getNonInheritedChildren(): - self.updateInheritedChild(child) + self.updateNonInheritingChildren(newContrib) + for child in newContrib.getAccessController().getNonInheritingChildren(): + self.updateNonInheritingChildren(child) self.notifyModification() @@ -6234,9 +6236,9 @@ class Session(CommonObjectBase, Locatable): sch.removeEntry(contrib.getSchEntry()) del self.contributions[contrib.getId()] - self.updateInheritedChild(contrib, delete=True, propagate=False) - for child in contrib.getAccessController().getNonInheritedChildren(): - self.updateInheritedChild(child, delete=True, propagate=False) + self.updateNonInheritingChildren(contrib, delete=True, propagate=False) + for child in contrib.getAccessController().getNonInheritingChildren(): + self.updateNonInheritingChildren(child, delete=True, propagate=False) contrib.setSession(None) @@ -6301,7 +6303,7 @@ class Session(CommonObjectBase, Locatable): def setProtection( self, private ): self.__ac.setProtection( private ) - self.updateInheritedParent(self) + self.notify_protection_to_owner(self) def grantAccess( self, prin ): self.__ac.grantAccess( prin ) @@ -6395,9 +6397,6 @@ class Session(CommonObjectBase, Locatable): def getAllowedToAccessList( self ): return self.__ac.getAccessList() - def getProtectionURL(self): - return str(urlHandlers.UHSessionModifAC.getURL(self)) - def addMaterial( self, newMat ): newMat.setId( str(self.__materialGenerator.newCount()) ) newMat.setOwner( self ) @@ -7790,12 +7789,12 @@ class Contribution(CommonObjectBase, Locatable): self._reviewManager = ReviewManager(self) return self._reviewManager - def updateInheritedChild(self, elem, delete=False): - self.getAccessController().updateNonInheritedChildren(elem, delete) - self.updateInheritedParent(elem, delete) + def updateNonInheritingChildren(self, elem, delete=False): + self.getAccessController().updateNonInheritingChildren(elem, delete) + self.notify_protection_to_owner(elem, delete) - def updateInheritedParent(self, elem, delete=False): - self.getOwner().updateInheritedChild(elem, delete) + def notify_protection_to_owner(self, elem, delete=False): + self.getOwner().updateNonInheritingChildren(elem, delete) def getKeywords(self): try: @@ -8162,7 +8161,7 @@ class Contribution(CommonObjectBase, Locatable): self.removeMinutes() self.removeReviewing() - self.updateInheritedParent(self, delete=True) + self.notify_protection_to_owner(self, delete=True) self.setSession(None) @@ -9000,7 +8999,7 @@ class Contribution(CommonObjectBase, Locatable): oldValue = 1 if self.isProtected() else -1 self.__ac.setProtection( private ) - self.updateInheritedParent(self) + self.notify_protection_to_owner(self) if oldValue != private: # notify listeners @@ -9088,9 +9087,6 @@ class Contribution(CommonObjectBase, Locatable): def getAllowedToAccessList( self ): return self.__ac.getAccessList() - def getProtectionURL(self): - return str(urlHandlers.UHContribModifAC.getURL(self)) - def addMaterial( self, newMat ): newMat.setId( str(self.__materialGenerator.newCount()) ) newMat.setOwner( self ) @@ -10115,8 +10111,8 @@ class SubContribution(CommonObjectBase, Locatable): grandpaId = None return "" % (grandpaId, parentId, self.getId(), hex(id(self))) - def updateInheritedChild(self, elem, delete=False): - self.getOwner().updateInheritedChild(elem, delete) + def updateNonInheritingChildren(self, elem, delete=False): + self.getOwner().updateNonInheritingChildren(elem, delete) def getAccessController(self): return self.getOwner().getAccessController() @@ -10696,12 +10692,12 @@ class Material(CommonObjectBase): self.__ac = AccessController(self) self._mainResource = None - def updateInheritedChild(self, elem, delete=False): - self.getAccessController().updateNonInheritedChildren(elem, delete) - self.updateInheritedParent(elem, delete) + def updateNonInheritingChildren(self, elem, delete=False): + self.getAccessController().updateNonInheritingChildren(elem, delete) + self.notify_protection_to_owner(elem, delete) - def updateInheritedParent(self, elem, delete=False): - self.getOwner().updateInheritedChild(elem, delete) + def notify_protection_to_owner(self, elem, delete=False): + self.getOwner().updateNonInheritingChildren(elem, delete) def setValues( self, params ): """Sets all the values of the current material object from a diccionary @@ -10938,7 +10934,7 @@ class Material(CommonObjectBase): def delete( self ): for res in self.getResourceList(): self.removeResource( res ) - self.updateInheritedParent(self, delete=True) + self.notify_protection_to_owner(self, delete=True) TrashCanManager().add(self) def recover(self): @@ -10978,7 +10974,7 @@ class Material(CommonObjectBase): def setProtection( self, private ): self.__ac.setProtection( private ) - self.updateInheritedParent(self) + self.notify_protection_to_owner(self) self._p_changed = 1 def isHidden( self ): @@ -11117,9 +11113,6 @@ class Material(CommonObjectBase): def isBuiltin(self): return False - def getProtectionURL(self): - return str(urlHandlers.UHMaterialModification.getURL(self)) - class BuiltinMaterial(Material): """ Non-customizable material types @@ -11420,7 +11413,7 @@ class Resource(CommonObjectBase): def delete( self ): if self._owner != None: - self.updateInheritedParent(delete=True) + self.notify_protection_to_owner(delete=True) self._owner.removeResource( self ) self._owner = None TrashCanManager().add(self) @@ -11450,15 +11443,15 @@ class Resource(CommonObjectBase): return self.getOwner().isProtected() return False - def updateInheritedParent(self, delete=False): - self.getOwner().updateInheritedChild(self, delete) + def notify_protection_to_owner(self, delete=False): + self.getOwner().updateNonInheritingChildren(self, delete) @Updates (['MaKaC.conference.Link', 'MaKaC.conference.LocalFile'],'protection', lambda(x): int(x)) def setProtection( self, private ): self.__ac.setProtection( private ) - self.updateInheritedParent() + self.notify_protection_to_owner() def grantAccess( self, prin ): self.__ac.grantAccess( prin ) @@ -11585,10 +11578,6 @@ class Resource(CommonObjectBase): return 'converting' return None - def getProtectionURL(self): - return str(urlHandlers.UHMaterialModification.getURL(self.getOwner())) - - class Link(Resource): """Specialises Resource class in order to represent web links. Objects of this class will contain necessary information to include in a conference diff --git a/indico/MaKaC/fossils/conference.py b/indico/MaKaC/fossils/conference.py index 26e87c70e..8e36c82e1 100644 --- a/indico/MaKaC/fossils/conference.py +++ b/indico/MaKaC/fossils/conference.py @@ -132,7 +132,7 @@ class IResourceMinimalFossil(IFossil): def getProtectionURL(self): """ Resource protection URL """ - getProtectionURL.produce = lambda s: s.getOwner().getProtectionURL() + getProtectionURL.produce = lambda s: str(urlHandlers.UHMaterialModification.getURL(s.getOwner())) class ILinkMinimalFossil(IResourceMinimalFossil): @@ -226,7 +226,9 @@ class IMaterialMinimalFossil(IFossil): """ The type of material""" def getProtectionURL(self): - pass + """ Material protection URL """ + getProtectionURL.produce = lambda s: str(urlHandlers.UHMaterialModification.getURL(s)) + class IMaterialFossil(IMaterialMinimalFossil): @@ -328,7 +330,8 @@ class ISessionFossil(IFossil): getLocator.name = 'url' def getProtectionURL(self): - pass + """Session protection URL""" + getProtectionURL.produce = lambda s: str(urlHandlers.UHSessionModifAC.getURL(s)) class ISessionSlotFossil(IFossil): diff --git a/indico/MaKaC/fossils/contribution.py b/indico/MaKaC/fossils/contribution.py index a48776d0d..b668446a2 100644 --- a/indico/MaKaC/fossils/contribution.py +++ b/indico/MaKaC/fossils/contribution.py @@ -21,6 +21,7 @@ from MaKaC.common.fossilize import IFossil from MaKaC.common.Conversion import Conversion from MaKaC.fossils.subcontribution import ISubContributionFossil from MaKaC.fossils.reviewing import IReviewManagerFossil +from MaKaC.webinterface import urlHandlers class IContributionFossil(IFossil): @@ -78,7 +79,8 @@ class IContributionFossil(IFossil): getType.convert = lambda t: t and t.getName() def getProtectionURL(self): - pass + """Contribution protection URL""" + getProtectionURL.produce = lambda s: str(urlHandlers.UHContribModifAC.getURL(s)) class IContributionParticipationTTDisplayFossil(IFossil): """ diff --git a/indico/MaKaC/services/implementation/conference.py b/indico/MaKaC/services/implementation/conference.py index d840c679a..1bddcb2d0 100644 --- a/indico/MaKaC/services/implementation/conference.py +++ b/indico/MaKaC/services/implementation/conference.py @@ -1571,12 +1571,12 @@ class ConferenceProtectionRemoveRegistrar(ConferenceManagerListBase): class ConferenceGetChildrenProtected(ConferenceModifBase): def _getAnswer(self): - return fossilize(self._conf.getAccessController().getChildrenProtected()) + return fossilize(self._conf.getAccessController().getProtectedChildren()) class ConferenceGetChildrenPublic(ConferenceModifBase): def _getAnswer(self): - return fossilize(self._conf.getAccessController().getChildrenPublic()) + return fossilize(self._conf.getAccessController().getPublicChildren()) class ConferenceExportURLs(ConferenceDisplayBase, ExportToICalBase): @@ -1660,7 +1660,7 @@ methodMap = { "protection.removeManager": ConferenceProtectionRemoveManager, "protection.addExistingRegistrar": ConferenceProtectionAddExistingRegistrar, "protection.removeRegistrar": ConferenceProtectionRemoveRegistrar, - "protection.getChildrenProtected": ConferenceGetChildrenProtected, - "protection.getChildrenPublic": ConferenceGetChildrenPublic, + "protection.getProtectedChildren": ConferenceGetChildrenProtected, + "protection.getPublicChildren": ConferenceGetChildrenPublic, "api.getExportURLs": ConferenceExportURLs } diff --git a/indico/MaKaC/services/implementation/contribution.py b/indico/MaKaC/services/implementation/contribution.py index afa742ac4..12397a4b1 100644 --- a/indico/MaKaC/services/implementation/contribution.py +++ b/indico/MaKaC/services/implementation/contribution.py @@ -229,12 +229,12 @@ class ContributionProtectionRemoveUser(ContributionModifBase): class ContributionGetChildrenProtected(ContributionModifBase): def _getAnswer(self): - return fossilize(self._contribution.getAccessController().getChildrenProtected()) + return fossilize(self._contribution.getAccessController().getProtectedChildren()) class ContributionGetChildrenPublic(ContributionModifBase): def _getAnswer(self): - return fossilize(self._contribution.getAccessController().getChildrenPublic()) + return fossilize(self._contribution.getAccessController().getPublicChildren()) class ContributionParticipantsBase(ContributionModifBase): @@ -902,8 +902,8 @@ methodMap = { "protection.getAllowedUsersList": ContributionProtectionUserList, "protection.addAllowedUsers": ContributionProtectionAddUsers, "protection.removeAllowedUser": ContributionProtectionRemoveUser, - "protection.getChildrenProtected": ContributionGetChildrenProtected, - "protection.getChildrenPublic": ContributionGetChildrenPublic, + "protection.getProtectedChildren": ContributionGetChildrenProtected, + "protection.getPublicChildren": ContributionGetChildrenPublic, "participants.addNewParticipant": ContributionAddNewParticipant, "participants.addExistingParticipant": ContributionAddExistingParticipant, diff --git a/indico/MaKaC/services/implementation/session.py b/indico/MaKaC/services/implementation/session.py index 2711968db..f4259f02c 100644 --- a/indico/MaKaC/services/implementation/session.py +++ b/indico/MaKaC/services/implementation/session.py @@ -358,12 +358,12 @@ class SessionProtectionToggleDomains(SessionModifBase): class SessionGetChildrenProtected(SessionModifBase): def _getAnswer(self): - return fossilize(self._session.getAccessController().getChildrenProtected()) + return fossilize(self._session.getAccessController().getProtectedChildren()) class SessionGetChildrenPublic(SessionModifBase): def _getAnswer(self): - return fossilize(self._session.getAccessController().getChildrenPublic()) + return fossilize(self._session.getAccessController().getPublicChildren()) methodMap = { "getBooking": SessionGetBooking, @@ -377,6 +377,6 @@ methodMap = { "protection.addExistingCoordinator": SessionAddExistingChair, "protection.removeCoordinator": SessionRemoveChair, "protection.toggleDomains": SessionProtectionToggleDomains, - "protection.getChildrenProtected": SessionGetChildrenProtected, - "protection.getChildrenPublic": SessionGetChildrenPublic + "protection.getProtectedChildren": SessionGetChildrenProtected, + "protection.getPublicChildren": SessionGetChildrenPublic } diff --git a/indico/MaKaC/webinterface/tpls/AccessControlStatusFrame.tpl b/indico/MaKaC/webinterface/tpls/AccessControlStatusFrame.tpl index 061c0758a..a8aa5cd11 100644 --- a/indico/MaKaC/webinterface/tpls/AccessControlStatusFrame.tpl +++ b/indico/MaKaC/webinterface/tpls/AccessControlStatusFrame.tpl @@ -7,6 +7,7 @@ termsDict={ 'Category': {'name':'category', 'paramsKey': 'categId', 'parentName' 'InSessionContribution': {'name':'contribution', 'paramsKey': 'contribId', 'parentName':'session'}, 'SubContribution': {'name':'contribution', 'paramsKey': 'contribId', 'parentName':'contribution'} } +from MaKaC.conference import Category %> ${ _("Current status")} @@ -34,36 +35,41 @@ termsDict={ 'Category': {'name':'category', 'paramsKey': 'categId', 'parentName' % endif - % if not target.getAccessController().isFullyPublic() and (privacy == 'PUBLIC' or (privacy == 'INHERITING' and parentPrivacy == 'PUBLIC')): -
- - - ${_('Some parts of it are accesible only for authorized people. Which ones?').format(termsDict[type]['name'])} - -
- % elif not target.getAccessController().isFullyPrivate() and (privacy == 'PRIVATE' or (privacy == 'INHERITING' and parentPrivacy == 'PRIVATE')): -
- - - ${_('Some parts of it are accesible for everybody. Which ones?').format(termsDict[type]['name'])} - -
- % if len(target.getAccessController().getChildrenProtected()) > 0: -
- - - ${_('Some other parts are still protected but their protection has been redefined. Which ones?').format(termsDict[type]['name'])} - -
- %endif + % if not isinstance(target, Category): + % if (privacy == 'PUBLIC' or (privacy == 'INHERITING' and parentPrivacy == 'PUBLIC')) and not target.getAccessController().isFullyPublic(): +
+ +
+ ${_('Some parts of the event are accessible only by authorized people. Which ones?').format(termsDict[type]['name'])} +
+
+ % elif (privacy == 'PRIVATE' or (privacy == 'INHERITING' and parentPrivacy == 'PRIVATE')): + % if len(target.getAccessController().getPublicChildren()) > 0: +
+ +
+ ${_('Some parts of the event are accessible by everybody. Which ones?').format(termsDict[type]['name'])} +
+
+ %endif + % if len(target.getAccessController().getProtectedChildren()) > 0: +
+ +
+ ${_('Some parts of the event are still protected but their protection has been redefined. Which ones?').format(termsDict[type]['name'])} +
+
+ %endif + % endif % endif - % if privacy == 'PRIVATE' or (privacy == 'INHERITING' and parentPrivacy == 'PRIVATE') : -
-
-
-
- % endif + % if privacy == 'PRIVATE' or (privacy == 'INHERITING' and parentPrivacy == 'PRIVATE') : +

${_('Access control List')}

+
+
+
+
+ % endif % if privacy == 'PRIVATE' or (privacy == 'INHERITING' and parentPrivacy == 'PRIVATE') : @@ -103,11 +109,11 @@ termsDict={ 'Category': {'name':'category', 'paramsKey': 'categId', 'parentName'