How to use the ckan.plugins.toolkit.abort function in ckan

To help you get started, we’ve selected a few ckan examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ckan / ckanext-issues / ckanext / issues / controller / moderation.py View on Github external
def all_reported_issues(self, organization_id):
        '''show all issues over max_strikes and are not moderated'''
        try:
            issues, organization = all_reported_issues(organization_id)
            extra_vars = {
                'issues': issues.get('results', []),
                'organization': organization,
            }
            return toolkit.render("issues/moderation.html",
                                  extra_vars=extra_vars)
        except toolkit.ObjectNotFound:
            toolkit.abort(404, toolkit._('Organization not found'))
github ckan / ckanext-issues / ckanext / issues / controller / controller.py View on Github external
if notifications:
                    subject = get_issue_subject(issue)
                    body = toolkit._('Assigned to {user}'.format(
                        user=assignee['display_name']))

                    user_obj = model.User.get(assignee_id)
                    try:
                        mailer.mail_user(user_obj, subject, body)
                    except mailer.MailerException, e:
                        log.debug(e.message)

            except toolkit.NotAuthorized:
                msg = _('Unauthorized to assign users to issue'.format(
                    issue_number))
                toolkit.abort(401, msg)
            except toolkit.ValidationError, e:
                toolkit.abort(404)

        return p.toolkit.redirect_to('issues_show',
                                     issue_number=issue_number,
                                     dataset_id=dataset_id)
github NaturalHistoryMuseum / ckanext-nhm / ckanext / nhm / controllers / object.py View on Github external
:param _format: the format requested
        :param version: the version of the record to retrieve, or None if the current version is
                        desired
        :return: the data to display
        """
        data_dict = {
            'uuid': uuid,
            'format': _format,
            'version': version,
        }

        p.toolkit.response.headers.update({'Content-type': CONTENT_TYPES[_format]})
        try:
            return p.toolkit.get_action('object_rdf')(self.context, data_dict)
        except p.toolkit.ValidationError, e:
            p.toolkit.abort(409, str(e))
github ckan / ckanext-pages / ckanext / pages / actions.py View on Github external
def group_pages_list(context, data_dict):
    try:
        p.toolkit.check_access('ckanext_group_pages_list', context, data_dict)
    except p.toolkit.NotAuthorized:
        p.toolkit.abort(401, p.toolkit._('Not authorized to see this page'))
    return _pages_list(context, data_dict)
github ckan / ckanext-issues / ckanext / issues / controller / controller.py View on Github external
def _before_org(self, org_id):
        '''Returns the organization dict and checks issues are enabled for it.'''
        self.context = {'for_view': True}
        try:
            org = logic.get_action('organization_show')(self.context,
                                                        {'id': org_id})

            # we should pass org to the template as an extra_var
            # directly that's returned from this function
            if not issues_helpers.issues_enabled_for_organization(org):
                abort(404, _('Issues have not been enabled for this organization'))
            return org
        except logic.NotFound:
            abort(404, _('Dataset not found'))
        except p.toolkit.NotAuthorized:
            p.toolkit.abort(401,
                            _('Unauthorized to view issues for this organization'))
github ckan / ckanext-issues / ckanext / issues / controller / moderation.py View on Github external
'id': organization_id,
            })
            comments = toolkit.get_action('issue_comment_search')(data_dict={
                'organization_id': organization['id'],
                'only_hidden': True,
            })

            return toolkit.render(
                'issues/comment_moderation.html',
                extra_vars={
                    'comments': comments,
                    'organization': organization,
                }
            )
        except toolkit.ObjectNotFound:
            toolkit.abort(404, toolkit._('Organization not found'))
github ckan / ckanext-pages / ckanext / pages / actions.py View on Github external
def group_pages_show(context, data_dict):
    try:
        p.toolkit.check_access('ckanext_group_pages_show', context, data_dict)
    except p.toolkit.NotAuthorized:
        p.toolkit.abort(401, p.toolkit._('Not authorized to see this page'))
    return _pages_show(context, data_dict)
github frictionlessdata / ckanext-datapackager / ckanext / datapackager / controllers / datapackage.py View on Github external
def _authorize_or_abort(self, context):
        try:
            toolkit.check_access('package_create', context)
        except toolkit.NotAuthorized:
            toolkit.abort(401, toolkit._('Unauthorized to create a dataset'))