示例#1
0
 def deserialize(doc):
     '''Deserializes the object from a list of 4 elements'''
     permi = ElementPermissions(doc[ElementPermissions.SERIAL_ID],
                                doc[ElementPermissions.SERIAL_IS_PRIVATE])
     permi.read = Permissions.deserialize(doc[ElementPermissions.SERIAL_READ])
     permi.write = Permissions.deserialize(doc[ElementPermissions.SERIAL_WRITE])
     return permi
 def deserialize(doc):
     '''Deserializes the object from a list of 4 elements'''
     permi = ElementPermissions(doc[ElementPermissions.SERIAL_ID],
                                doc[ElementPermissions.SERIAL_IS_PRIVATE])
     permi.read = Permissions.deserialize(
         doc[ElementPermissions.SERIAL_READ])
     permi.write = Permissions.deserialize(
         doc[ElementPermissions.SERIAL_WRITE])
     return permi
示例#3
0
    def deserialize(doc):
        brl = BRLUser(doc[User.SERIAL_ID_KEY])
        user = User(brl)
        user._encrypted_password = doc[User.SERIAL_ENCRYPTED_PASSWORD]
        user.password_timestamp = doc.get(User.SERIAL_PASSWORD_TIMESTAMP, None)

        if User.SERIAL_NUMERIC_ID in doc:
            user.numeric_id = ID.deserialize(doc[User.SERIAL_NUMERIC_ID])

        # Profile fields
        user.firstname = doc.get(User.SERIAL_FIRSTNAME, None)
        user.lastname = doc.get(User.SERIAL_LASTNAME, None)
        user.country = doc.get(User.SERIAL_COUNTRY, None)
        user.description = doc.get(User.SERIAL_DESCRIPTION, None)
        user.email = doc.get(User.SERIAL_EMAIL, None)
        user.visible_email = doc.get(User.SERIAL_VISIBLE_EMAIL, 0) == 1
        user.allow_mailing = doc.get(User.SERIAL_ALLOW_MAILING, 0) == 1
        user.active = doc.get(User.SERIAL_ACTIVE, 0) == 1
        user.staff = doc.get(User.SERIAL_STAFF, 0) == 1
        user.joined_date = UtcDatetime.deserialize(
            doc.get(User.SERIAL_JOINED_DATE, None))
        user.confirmation_date = UtcDatetime.deserialize(
            doc.get(User.SERIAL_CONFIRMATION_DATE, None))
        user.confirmation_token = doc.get(User.SERIAL_CONFIRMATION_TOKEN, None)
        # Old workspace methods
        user.block_counter = doc.get(User.SERIAL_MOD_COUNTER, 0)
        blocks_data = doc.get(User.SERIAL_BLOCKS, {})
        user.blocks = DictDeserializer(
            BRLBlock, BlockMetaInfoDeserializer).deserialize(blocks_data)
        user.administrators = Permissions.deserialize(
            doc.get(User.SERIAL_ADMINISTRATORS, {}))
        social_accounts_doc = doc.get(User.SERIAL_SOCIAL_ACCOUNTS)
        user.social_accounts = DictDeserializer(
            str, SocialAccount).deserialize(social_accounts_doc)

        # Achievements
        user.read_api_counter = doc.get(User.SERIAL_READ_API_COUNTER, 0)
        user.publish_counter = doc.get(User.SERIAL_PUBLISH_COUNTER, 0)
        user.reuse_counter = doc.get(User.SERIAL_REUSE_COUNTER, 0)

        # Additional profile fields
        user.street_1 = doc.get(User.SERIAL_STREET1, "")
        user.street_2 = doc.get(User.SERIAL_STREET2, "")
        user.city = doc.get(User.SERIAL_CITY, "")
        user.postal_code = doc.get(User.SERIAL_POSTAL_CODE, "")
        user.region = doc.get(User.SERIAL_REGION, "")
        user.tax_id = doc.get(User.SERIAL_TAX_ID, "")
        user.vat = doc.get(User.SERIAL_VAT, "")

        # OAuth
        user.oauth_github_token = doc.get(User.SERIAL_OAUTH_GITHUB_TOKEN, None)
        user.oauth_google_token = doc.get(User.SERIAL_OAUTH_GOOGLE_TOKEN, None)

        # Max workspace size, default BII_MAX_USER_WORKSPACE_SIZE
        user.max_workspace_size = doc.get(User.SERIAL_MAX_WORKSPACE_SIZE,
                                          BII_MAX_USER_WORKSPACE_SIZE)

        # Invited by
        user.invited_by = doc.get(User.SERIAL_INVITED_BY, None)
        return user
    def get_version_info_test(self):
        store = Mock(GenericServerStore)

        # Block doesn't exist and user is other
        p = PublishService(store, 'any_user')
        block_brl = BRLBlock("user/user/theblock/master")
        store.read_block_permissions = Mock(side_effect=NotInStoreException())
        block_info = p.get_block_info(block_brl)
        self.assertFalse(block_info.can_write)

        # Now block exists
        store.read_block_permissions = Mock(
            return_value=ElementPermissions(block_brl))

        # Block exists and user is the authorized one
        p = PublishService(store, 'theuser')
        block_brl = BRLBlock("theuser/theuser/theblock/master")
        block_info = p.get_block_info(block_brl)
        self.assertTrue(block_info.can_write)

        # No authorized write to an existing block
        p = PublishService(store, 'wronguser')
        user = Mock(User)
        user.administrators = Permissions()
        store.read_user = Mock(return_value=user)
        block_info = p.get_block_info(block_brl)
        self.assertFalse(block_info.can_write)

        # Authorized user with an existing block
        p = PublishService(store, 'theuser')
        block_brl = BRLBlock("theuser/theuser/theblock/master")
        block_info = p.get_block_info(block_brl)
        self.assertTrue(block_info.can_write)
示例#5
0
    def __init__(self, brl_id):
        self.ID = brl_id
        self.password_timestamp = None
        self._encrypted_password = None
        # TODO: Confirmed email accounts? <= Only one at the moment, migrate active account
        # Basic fields
        self._email = None
        self.firstname = None
        self.lastname = None
        self.country = None
        self.description = None
        self.visible_email = False

        # Admin fields
        self.staff = False
        self.allow_mailing = True

        # Activation fields
        self.active = False
        self.confirmation_token = None
        self.joined_date = None
        self.confirmation_date = None

        # Workspace fields
        self.block_counter = 0
        self.blocks = {
        }  # {BRLBlock => (set(TAGS), "description", bytes_size)}
        self.administrators = Permissions()

        # Dict of brl_user => Num grants (block, hive or administrators)
        self.numeric_id = None
        self.social_accounts = {}

        # Achievements
        self.read_api_counter = 0
        self.publish_counter = 0
        self.reuse_counter = 0

        # Profile fields
        self.street_1 = ""
        self.street_2 = ""
        self.city = ""
        self.postal_code = ""
        self.region = ""
        self.tax_id = ""
        self.vat = ""

        # OAuth credentials
        self.oauth_google_token = None
        self.oauth_github_token = None

        # Max workspace size
        self.max_workspace_size = BII_MAX_USER_WORKSPACE_SIZE

        # Invited by
        self.invited_by = None
示例#6
0
    def deserialize(doc):
        brl = BRLUser(doc[User.SERIAL_ID_KEY])
        user = User(brl)
        user._encrypted_password = doc[User.SERIAL_ENCRYPTED_PASSWORD]
        user.password_timestamp = doc.get(User.SERIAL_PASSWORD_TIMESTAMP, None)

        if User.SERIAL_NUMERIC_ID in doc:
            user.numeric_id = ID.deserialize(doc[User.SERIAL_NUMERIC_ID])

        # Profile fields
        user.firstname = doc.get(User.SERIAL_FIRSTNAME, None)
        user.lastname = doc.get(User.SERIAL_LASTNAME, None)
        user.country = doc.get(User.SERIAL_COUNTRY, None)
        user.description = doc.get(User.SERIAL_DESCRIPTION, None)
        user.email = doc.get(User.SERIAL_EMAIL, None)
        user.visible_email = doc.get(User.SERIAL_VISIBLE_EMAIL, 0) == 1
        user.allow_mailing = doc.get(User.SERIAL_ALLOW_MAILING, 0) == 1
        user.active = doc.get(User.SERIAL_ACTIVE, 0) == 1
        user.staff = doc.get(User.SERIAL_STAFF, 0) == 1
        user.joined_date = UtcDatetime.deserialize(doc.get(User.SERIAL_JOINED_DATE, None))
        user.confirmation_date = UtcDatetime.deserialize(doc.get(User.SERIAL_CONFIRMATION_DATE,
                                                                 None))
        user.confirmation_token = doc.get(User.SERIAL_CONFIRMATION_TOKEN, None)
        # Old workspace methods
        user.block_counter = doc.get(User.SERIAL_MOD_COUNTER, 0)
        blocks_data = doc.get(User.SERIAL_BLOCKS, {})
        user.blocks = DictDeserializer(BRLBlock, BlockMetaInfoDeserializer).deserialize(blocks_data)
        user.administrators = Permissions.deserialize(doc.get(User.SERIAL_ADMINISTRATORS, {}))
        social_accounts_doc = doc.get(User.SERIAL_SOCIAL_ACCOUNTS)
        user.social_accounts = DictDeserializer(str, SocialAccount).deserialize(social_accounts_doc)

        # Achievements
        user.read_api_counter = doc.get(User.SERIAL_READ_API_COUNTER, 0)
        user.publish_counter = doc.get(User.SERIAL_PUBLISH_COUNTER, 0)
        user.reuse_counter = doc.get(User.SERIAL_REUSE_COUNTER, 0)

        # Additional profile fields
        user.street_1 = doc.get(User.SERIAL_STREET1, "")
        user.street_2 = doc.get(User.SERIAL_STREET2, "")
        user.city = doc.get(User.SERIAL_CITY, "")
        user.postal_code = doc.get(User.SERIAL_POSTAL_CODE, "")
        user.region = doc.get(User.SERIAL_REGION, "")
        user.tax_id = doc.get(User.SERIAL_TAX_ID, "")
        user.vat = doc.get(User.SERIAL_VAT, "")

        # OAuth
        user.oauth_github_token = doc.get(User.SERIAL_OAUTH_GITHUB_TOKEN, None)
        user.oauth_google_token = doc.get(User.SERIAL_OAUTH_GOOGLE_TOKEN, None)

        # Max workspace size, default BII_MAX_USER_WORKSPACE_SIZE
        user.max_workspace_size = doc.get(User.SERIAL_MAX_WORKSPACE_SIZE,
                                          BII_MAX_USER_WORKSPACE_SIZE)

        # Invited by
        user.invited_by = doc.get(User.SERIAL_INVITED_BY, None)
        return user
 def __init__(self, ID, private=False):
     self.ID = ID
     self.is_private = private
     self.read = Permissions()
     self.write = Permissions()