def get_block_info(self, brl_block):
        '''Check if auth_user can publish a block version specified by parameter block_version
         Returns:
            BlockInfo
         '''

        try:
            self.security.check_read_block(brl_block)
        except NotInStoreException:
            # In this case, the block doesnt exist, but return information of -1 and permissions
            return self._get_new_block_info(brl_block)

        block_info = BlockInfo()
        try:
            self.security.check_write_block(brl_block)
            block_info.can_write = True
        except ForbiddenException:
            block_info.can_write = False

        try:
            block = self._store.read_block(brl_block)
            block_info.last_version = block.last_version()
            block_info.private = self.security.is_private(brl_block)
        except Exception as e:
            tb = traceback.format_exc()
            logger.debug(tb)
            logger.error("Something went wrong with %s" % e)
            raise BiiServiceException('Something went wrong')

        return block_info
Example #2
0
    def test_equals(self):
        bversion = BlockVersion("phil/phil/super_block/master", "0")
        bversion2 = BlockVersion("fenix/fenix/slight_block/master", "0")

        block_info = BlockInfo(True, bversion, False)
        block_info2 = BlockInfo(True, bversion, False)

        self.assertEquals(block_info, block_info2)

        block_info2.last_version = bversion2
        self.assertNotEquals(block_info, block_info2)

        block_info2.last_version = bversion
        block_info.can_write = False
        self.assertNotEquals(block_info, block_info2)

        block_info.can_write = True
        block_info.private = True
        self.assertNotEquals(block_info, block_info2)
    def _get_new_block_info(self, brl_block):
        '''
        Returns BlockInfo that new block would have if we publish it.
        Raises exception if block cannot be created for any reason
        '''
        last_version = BlockVersion(brl_block, -1)
        can_write = False
        try:
            self.security.check_create_block(brl_block.owner)
            can_write = True
        except ForbiddenException:
            can_write = False
        except NotInStoreException:
            raise NotFoundException("Block %s not found!" %
                                    brl_block.to_pretty())

        return BlockInfo(can_write=can_write, last_version=last_version)
Example #4
0
 def test_block_info(self):
     bversion = BlockVersion("phil/phil/super_block/master", "0")
     t = BlockInfo(True, bversion, False)
     s = t.serialize()
     t2 = BlockInfo.deserialize(s)
     self.assertEqual(t, t2)