Exemplo n.º 1
0
 def processRights(self, typeId, isNew, aclType):
     '''
     Process the security rights from the provided ACL type.
     
     @param typeId: integer
         The security type id.
     @param isNew: boolean
         Flag indicating that the security type is new or not.
     @param aclType: TypeAcl
         The ACL type to have the rights processed.
     '''
     assert isinstance(typeId, int), 'Invalid security type id %s' % typeId
     assert isinstance(isNew, bool), 'Invalid is new flag %s' % isNew
     assert isinstance(aclType, TypeAcl), 'Invalid acl type %s' % aclType
     
     aclRights = {right.name: right for right in aclType.rights}
     if not isNew:
         for right in self.rightService.getAll(typeId):
             assert isinstance(right, Right), 'Invalid right %s' % right
         
             aclRight = aclRights.pop(right.Name, None)
             if aclRight:
                 assert isinstance(aclRight, RightAcl)
                 # Update the description if is the case
                 if right.Description != aclRight.description:
                     right.Description = aclRight.description
                     self.rightService.update(right)
     
     for aclRight in aclRights.values():
         right = Right()
         right.Type = typeId
         right.Name = aclRight.name
         right.Description = aclRight.description
         self.rightService.insert(right)
Exemplo n.º 2
0
    def processRights(self, typeId, isNew, aclType):
        '''
        Process the security rights from the provided ACL type.
        
        @param typeId: integer
            The security type id.
        @param isNew: boolean
            Flag indicating that the security type is new or not.
        @param aclType: TypeAcl
            The ACL type to have the rights processed.
        '''
        assert isinstance(typeId, int), 'Invalid security type id %s' % typeId
        assert isinstance(isNew, bool), 'Invalid is new flag %s' % isNew
        assert isinstance(aclType, TypeAcl), 'Invalid acl type %s' % aclType

        aclRights = {right.name: right for right in aclType.rights}
        if not isNew:
            for right in self.rightService.getAll(typeId):
                assert isinstance(right, Right), 'Invalid right %s' % right

                aclRight = aclRights.pop(right.Name, None)
                if aclRight:
                    assert isinstance(aclRight, RightAcl)
                    # Update the description if is the case
                    if right.Description != aclRight.description:
                        right.Description = aclRight.description
                        self.rightService.update(right)

        for aclRight in aclRights.values():
            right = Right()
            right.Type = typeId
            right.Name = aclRight.name
            right.Description = aclRight.description
            self.rightService.insert(right)
Exemplo n.º 3
0
 def createEntity(self, rightRepository, rightName):
     assert isinstance(rightRepository, RepositoryRight), 'Invalid repository %s' % rightRepository
     right = Right()
     right.Name = rightName
     right.Type = self.type_name
     right.Description = rightRepository.description
     return right
Exemplo n.º 4
0
 def createEntity(self, rightRepository, rightName):
     assert isinstance(
         rightRepository,
         RepositoryRight), 'Invalid repository %s' % rightRepository
     right = Right()
     right.Name = rightName
     right.Type = self.type_name
     right.Description = rightRepository.description
     return right
Exemplo n.º 5
0
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)