def populateRights(): ''' Synchronize the active acl rights with the database rights. ''' rightTypeService = support.entityFor(IRightTypeService) assert isinstance(rightTypeService, IRightTypeService) rightService = support.entityFor(IRightService) assert isinstance(rightService, IRightService) for aclType in acl().activeTypes(resourcesRoot()): assert isinstance(aclType, TypeAcl), 'Invalid acl type %s' % aclType try: rightType = rightTypeService.getByName(aclType.name) except InputError: rightType = RightType() rightType.Name = aclType.name rightType.Description = aclType.description rightTypeId = rightTypeService.insert(rightType) else: # Update the description if is the case assert isinstance(rightType, RightType) if rightType.Description != aclType.description: rightType.Description = aclType.description rightTypeService.update(rightType) rightTypeId = rightType.Id aclRights = {right.name: right for right in aclType.activeRights(resourcesRoot())} for right in rightService.getAll(rightTypeId): assert isinstance(right, Right), 'Invalid right %s' % right aclRight = aclRights.pop(right.Name, None) if aclRight: assert isinstance(aclRight, RightBase) # Update the description if is the case if right.Description != aclRight.description: right.Description = aclRight.description rightService.update(right) for aclRight in aclRights.values(): right = Right() right.Type = rightTypeId right.Name = aclRight.name right.Description = aclRight.description rightService.insert(right)
def processRightType(self, aclType): ''' Process the security right type for ACL type. @param aclType: TypeAcl The ACL type to process. ''' assert isinstance(aclType, TypeAcl), 'Invalid acl type %s' % aclType try: rightType = self.rightTypeService.getByName(aclType.name) except InputError: rightType = RightType() rightType.Name = aclType.name rightType.Description = aclType.description typeId = self.rightTypeService.insert(rightType) self.processRights(typeId, True, aclType) else: # Update the description if is the case assert isinstance(rightType, RightType) if rightType.Description != aclType.description: rightType.Description = aclType.description self.rightTypeService.update(rightType) self.processRights(rightType.Id, False, aclType)