示例#1
0
 def test_fields(self):
     node_settings = BoxNodeSettings(user_settings=self.user_settings)
     node_settings.save()
     assert_true(node_settings.user_settings)
     assert_equal(node_settings.user_settings.owner, self.user)
     assert_true(hasattr(node_settings, 'folder_id'))
     assert_true(hasattr(node_settings, 'user_settings'))
示例#2
0
 def test_fields(self):
     node_settings = BoxNodeSettings(user_settings=self.user_settings)
     node_settings.save()
     assert_true(node_settings.user_settings)
     assert_equal(node_settings.user_settings.owner, self.user)
     assert_true(hasattr(node_settings, 'folder_id'))
     assert_true(hasattr(node_settings, 'user_settings'))
示例#3
0
    def test_has_auth(self):
        settings = BoxNodeSettings(user_settings=self.user_settings, )
        settings.save()
        assert_false(settings.has_auth)

        settings.user_settings.access_token = '123abc'
        settings.user_settings.save()
        assert_true(settings.has_auth)
示例#4
0
    def test_has_auth(self):
        self.user_settings.access_token = None
        settings = BoxNodeSettings(user_settings=self.user_settings)
        settings.save()
        assert_false(settings.has_auth)

        settings.user_settings.access_token = '123abc'
        settings.user_settings.save()
        assert_true(settings.has_auth)
示例#5
0
    def test_has_auth(self):
        self.user.external_accounts = []
        self.user_settings.reload()
        settings = BoxNodeSettings(user_settings=self.user_settings)
        settings.save()
        assert_false(settings.has_auth)

        self.user.external_accounts.append(self.external_account)
        settings.reload()
        assert_true(settings.has_auth)
示例#6
0
    def test_has_auth(self):
        self.user.external_accounts = []
        self.user_settings.reload()
        settings = BoxNodeSettings(user_settings=self.user_settings)
        settings.save()
        assert_false(settings.has_auth)

        self.user.external_accounts.append(self.external_account)
        settings.reload()
        assert_true(settings.has_auth)
def do_migration(records):
    database['boxnodesettings'].update({'user_settings': {'$type': 2}}, {'$rename': { 'user_settings': 'foreign_user_settings'}}, multi=True)

    for user_addon in records:
        user = user_addon.owner
        old_account = user_addon.oauth_settings

        logger.info('Record found for user {}'.format(user._id))

        # Create/load external account and append to user
        try:
            account = ExternalAccount(
                provider='box',
                provider_name='Box',
                display_name=old_account.username,
                oauth_key=old_account.access_token,
                refresh_token=old_account.refresh_token,
                provider_id=old_account.user_id,
                expires_at=old_account.expires_at,
            )
            account.save()
        except KeyExistsException:
            # ... or get the old one
            account = ExternalAccount.find_one(
                Q('provider', 'eq', 'box') &
                Q('provider_id', 'eq', old_account.user_id)
            )
            assert account is not None
        user.external_accounts.append(account)
        user.save()

        # Remove oauth_settings from user settings object
        user_addon.oauth_settings = None
        user_addon.save()

        logger.info('Added external account {0} to user {1}'.format(
            account._id, user._id,
        ))

    for node in BoxNodeSettings.find():
        if node.foreign_user_settings is None:
            continue
        logger.info('Migrating user_settings for box {}'.format(node._id))
        node.user_settings = node.foreign_user_settings
        node.save()
示例#8
0
def do_migration():
    for node_addon in BoxNodeSettings.find(Q('foreign_user_settings', 'ne', None)):
        user_addon = node_addon.foreign_user_settings
        user = user_addon.owner
        if not user_addon.external_accounts:
            logger.warning('User {0} has no box external account'.format(user._id))
            continue
        account = user_addon.external_accounts[0]
        node_addon.set_auth(account, user_addon.owner)

        user_addon.grant_oauth_access(
            node=node_addon.owner,
            external_account=account,
            metadata={'folder': node_addon.folder_id}
        )

        logger.info('Added external account {0} to node {1}'.format(
            account._id, node_addon.owner._id,
        ))
示例#9
0
 def test_folder_defaults_to_none(self):
     node_settings = BoxNodeSettings(user_settings=self.user_settings)
     node_settings.save()
     assert_is_none(node_settings.folder_id)
示例#10
0
 def test_folder_defaults_to_none(self):
     node_settings = BoxNodeSettings(user_settings=self.user_settings)
     node_settings.save()
     assert_is_none(node_settings.folder_id)