def test_signals(self):
        logger = Logger()
        superdesk.connect('read:items', logger.callme)

        with self.app.test_request_context():
            getattr(self.app, 'on_fetched_resource')('items', ({}, ))

        self.assertTrue(logger.called)
        self.assertIn('docs', logger.kwargs)
Exemplo n.º 2
0
        except UnicodeEncodeError as error:
            traceback.print_exc()
            raise error

    def get_url(self, endpoint):
        """Get API url for given endpoint."""
        return '/'.join([self.URL, endpoint])

    def format_date(self, date):
        """Format date for API usage."""
        return date.strftime(self.DATE_FORMAT)

    def prepare_href(self, href):
        (scheme, netloc, path, params, query, fragment) = urlparse(href)
        new_href = urlunparse((scheme, netloc, path, '', '', ''))
        return '%s?auth_token=%s' % (new_href, self.get_token())


def on_read_ingest(data, docs):
    provider = data.find_one('ingest_providers', type=PROVIDER, req=None)
    if not provider:
        return
    for doc in docs:
        if str(doc.get('ingest_provider')) == str(provider['_id']):
            for i, rendition in doc.get('renditions', {}).items():
                rendition['href'] = '%s?auth_token=%s' % (rendition['href'], get_token(provider))


superdesk.connect('read:ingest', on_read_ingest)
superdesk.provider(PROVIDER, ReutersUpdateService())
Exemplo n.º 3
0

class HashUserPasswordsCommand(superdesk.Command):
    def run(self):
        users = superdesk.app.data.find_all('auth_users')
        for user in users:
            pwd = user.get('password')
            if not pwd.startswith('$2a$'):
                updates = {}
                hashed = hash_password(user['password'])
                user_id = user.get('_id')
                updates['password'] = hashed
                superdesk.apps['users'].update(id=user_id, updates=updates, trigger_events=False)


superdesk.connect('read:users', on_read_users)
superdesk.connect('created:users', on_read_users)
superdesk.command('users:create', CreateUserCommand())
superdesk.command('users:hash_passwords', HashUserPasswordsCommand())


class RolesModel(BaseModel):

    endpoint_name = 'roles'
    schema = {
        'name': {
            'type': 'string',
            'unique': True,
            'required': True,
        },
        'extends': {
Exemplo n.º 4
0
            traceback.print_exc()
            raise error

    def get_url(self, endpoint):
        """Get API url for given endpoint."""
        return '/'.join([self.URL, endpoint])

    def format_date(self, date):
        """Format date for API usage."""
        return date.strftime(self.DATE_FORMAT)

    def prepare_href(self, href):
        (scheme, netloc, path, params, query, fragment) = urlparse(href)
        new_href = urlunparse((scheme, netloc, path, '', '', ''))
        return '%s?auth_token=%s' % (new_href, self.get_token())


def on_read_ingest(data, docs):
    provider = data.find_one('ingest_providers', type=PROVIDER, req=None)
    if not provider:
        return
    for doc in docs:
        if str(doc.get('ingest_provider')) == str(provider['_id']):
            for i, rendition in doc.get('renditions', {}).items():
                rendition['href'] = '%s?auth_token=%s' % (rendition['href'],
                                                          get_token(provider))


superdesk.connect('read:ingest', on_read_ingest)
register_provider(PROVIDER, ReutersIngestService())
Exemplo n.º 5
0

class HashUserPasswordsCommand(superdesk.Command):
    def run(self):
        users = superdesk.app.data.find_all("auth_users")
        for user in users:
            pwd = user.get("password")
            if not pwd.startswith("$2a$"):
                updates = {}
                hashed = hash_password(user["password"])
                user_id = user.get("_id")
                updates["password"] = hashed
                superdesk.apps["users"].update(id=user_id, updates=updates, trigger_events=False)


superdesk.connect("read:users", on_read_users)
superdesk.connect("created:users", on_read_users)
superdesk.command("users:create", CreateUserCommand())
superdesk.command("users:hash_passwords", HashUserPasswordsCommand())


class RolesModel(BaseModel):

    endpoint_name = "roles"
    schema = {
        "name": {"type": "string", "unique": True, "required": True},
        "extends": {"type": "objectid"},
        "permissions": {"type": "dict"},
    }
    datasource = {"default_sort": [("_created", -1)]}
Exemplo n.º 6
0

class HashUserPasswordsCommand(superdesk.Command):
    def run(self):
        users = superdesk.app.data.find_all('auth_users')
        for user in users:
            pwd = user.get('password')
            if not pwd.startswith('$2a$'):
                updates = {}
                hashed = hash_password(user['password'])
                user_id = user.get('_id')
                updates['password'] = hashed
                superdesk.apps['users'].update(id=user_id, updates=updates, trigger_events=False)


superdesk.connect('read:users', on_read_users)
superdesk.connect('created:users', on_read_users)
superdesk.command('users:create', CreateUserCommand())
superdesk.command('users:hash_passwords', HashUserPasswordsCommand())


class UserRolesModel(BaseModel):

    endpoint_name = 'user_roles'
    schema = {
        'name': {
            'type': 'string',
            'unique': True,
            'required': True,
        },
        'extends': {