Exemplo n.º 1
0
def delete_view(id):
    if 'cancel' in tk.request.params:
        tk.redirect_to('showcase_blueprint.edit' if tk.check_ckan_version(
            min_version='2.9.0') else 'showcase_edit',
                       id=id)

    context = {
        'model': model,
        'session': model.Session,
        'user': c.user or c.author,
        'auth_user_obj': c.userobj
    }

    try:
        tk.check_access('ckanext_showcase_delete', context, {'id': id})
    except tk.NotAuthorized:
        return tk.abort(401, _('Unauthorized to delete showcase'))

    if tk.check_ckan_version(min_version='2.9.0'):
        index_route = 'showcase_blueprint.index'
    else:
        index_route = 'showcase_index'

    try:
        if tk.request.method == 'POST':
            tk.get_action('ckanext_showcase_delete')(context, {'id': id})
            h.flash_notice(_('Showcase has been deleted.'))
            return tk.redirect_to(index_route)
        c.pkg_dict = tk.get_action('package_show')(context, {'id': id})
    except tk.NotAuthorized:
        tk.abort(401, _('Unauthorized to delete showcase'))
    except tk.ObjectNotFound:
        tk.abort(404, _('Showcase not found'))
    return tk.render('showcase/confirm_delete.html',
                     extra_vars={'dataset_type': DATASET_TYPE_NAME})
Exemplo n.º 2
0
def open_datarequest(id):
    data_dict = {'id': id}
    context = _get_context()

    # Basic initialization
    c.datarequest = {}
    try:
        check_access(OPEN_DATAREQUEST, context, data_dict)
        c.datarequest = get_action(SHOW_DATAREQUEST)(context, data_dict)

        if c.datarequest.get('closed', False) is False:
            return abort(403, _('This data request is already open'))
        else:
            data_dict = {}
            data_dict['id'] = id
            data_dict['organization_id'] = c.datarequest.get('organization_id')

            get_action(OPEN_DATAREQUEST)(context, data_dict)
            return redirect_to(url_for('datarequest.show', id=data_dict['id']))
    except ValidationError as e:
        log.warn(e)
        errors_summary = _get_errors_summary(e.error_dict)
        return abort(403, errors_summary)
    except ObjectNotFound as e:
        log.warn(e)
        return abort(404, _('Data Request %s not found') % id)
    except NotAuthorized as e:
        log.warn(e)
        return abort(
            403, _('You are not authorized to open the Data Request %s' % id))
Exemplo n.º 3
0
def remove_showcase_admin():
    '''
    Remove a user from the Showcase Admin list.
    '''
    context = {
        'model': model,
        'session': model.Session,
        'user': c.user or c.author
    }

    try:
        tk.check_access('sysadmin', context, {})
    except tk.NotAuthorized:
        return tk.abort(401, _('User not authorized to view page'))

    form_data = tk.request.form if tk.check_ckan_version(
        '2.9') else tk.request.params

    if tk.check_ckan_version(min_version='2.9.0'):
        admins_route = 'showcase_blueprint.admins'
    else:
        admins_route = 'showcase_admins'

    if 'cancel' in form_data:
        return tk.redirect_to(admins_route)

    user_id = tk.request.params['user']
    if tk.request.method == 'POST' and user_id:
        user_id = tk.request.params['user']
        try:
            tk.get_action('ckanext_showcase_admin_remove')(data_dict={
                'username': user_id
            })
        except tk.NotAuthorized:
            return tk.abort(401, _('Unauthorized to perform that action'))
        except tk.ObjectNotFound:
            h.flash_error(_('The user is not a Showcase Admin'))
        else:
            h.flash_success(_('The user is no longer a Showcase Admin'))

        return tk.redirect_to(h.url_for(admins_route))

    c.user_dict = tk.get_action('user_show')(data_dict={'id': user_id})
    c.user_id = user_id
    return tk.render('admin/confirm_remove_showcase_admin.html')
Exemplo n.º 4
0
def pages_delete(page, page_type='pages'):
    if page.startswith('/'):
        page = page[1:]
    if 'cancel' in tk.request.params:
        if ckan_29_or_higher:
            return tk.redirect_to('pages.%s_edit' % page_type, page=page)
        else:
            tk.redirect_to('%s_edit' % page_type, page='/' + page)

    try:
        if tk.request.method == 'POST':
            tk.get_action('ckanext_pages_delete')({}, {'page': page})
            if ckan_29_or_higher:
                endpoint = 'index' if page_type in (
                    'pages', 'page') else '%s_index' % page_type
                return tk.redirect_to('pages.%s' % endpoint)
            else:
                tk.redirect_to('%s_index' % page_type)
        else:
            return tk.abort(404, _('Page Not Found'))
    except tk.NotAuthorized:
        return tk.abort(401, _('Unauthorized to delete page'))
    except tk.ObjectNotFound:
        return tk.abort(404, _('Group not found'))
    return tk.render('ckanext_pages/confirm_delete.html', {'page': page})
Exemplo n.º 5
0
def manage_showcase_admins():
    context = {
        'model': model,
        'session': model.Session,
        'user': c.user or c.author
    }

    try:
        tk.check_access('sysadmin', context, {})
    except tk.NotAuthorized:
        return tk.abort(401, _('User not authorized to view page'))

    form_data = tk.request.form if tk.check_ckan_version(
        '2.9') else tk.request.params

    if tk.check_ckan_version(min_version='2.9.0'):
        admins_route = 'showcase_blueprint.admins'
    else:
        admins_route = 'showcase_admins'

    # We're trying to add a user to the showcase admins list.
    if tk.request.method == 'POST' and form_data['username']:
        username = form_data['username']
        try:
            tk.get_action('ckanext_showcase_admin_add')(data_dict={
                'username': username
            })
        except tk.NotAuthorized:
            abort(401, _('Unauthorized to perform that action'))
        except tk.ObjectNotFound:
            h.flash_error(
                _("User '{user_name}' not found.").format(user_name=username))
        except tk.ValidationError as e:
            h.flash_notice(e.error_summary)
        else:
            h.flash_success(_("The user is now a Showcase Admin"))

        return tk.redirect_to(h.url_for(admins_route))

    c.showcase_admins = tk.get_action('ckanext_showcase_admin_list')()

    return tk.render('admin/manage_showcase_admins.html')
Exemplo n.º 6
0
def group_delete(id, group_type, page):

    _template_setup_group(id, group_type)

    if page.startswith('/'):
        page = page[1:]

    if 'cancel' in tk.request.params:
        if ckan_29_or_higher:
            return tk.redirect_to('pages.%s_edit' % group_type,
                                  id=tk.c.group_dict['name'],
                                  page=page)
        else:
            tk.redirect_to('%s_edit' % group_type,
                           id=tk.c.group_dict['name'],
                           page='/' + page)

    try:
        if tk.request.method == 'POST':
            action = 'ckanext_org_pages_delete' if group_type == 'organization' else 'ckanext_group_pages_delete'
            action = tk.get_action(action)
            action({}, {'org_id': tk.c.group_dict['id'], 'page': page})
            if ckan_29_or_higher:
                endpoint = 'pages.{}_pages_index'.format(group_type)
                return tk.redirect_to(endpoint, id=id)
            else:
                tk.redirect_to('{}_pages_index'.format(group_type), id=id)
        else:
            tk.abort(404, _('Page Not Found'))
    except tk.NotAuthorized:
        tk.abort(401, _('Unauthorized to delete page'))
    except tk.ObjectNotFound:
        tk.abort(404, _('{} not found'.format(group_type.title())))

    context = {'for_view': True}

    action = 'organization_show' if group_type == 'organization' else 'group_show'
    group_dict = tk.get_action(action)(context, {'id': id})

    return tk.render('ckanext_pages/confirm_delete.html', {
        'page': page,
        'group_type': group_type,
        'group_dict': group_dict
    })
Exemplo n.º 7
0
def pages_edit(page=None,
               data=None,
               errors=None,
               error_summary=None,
               page_type='pages'):

    page_dict = None
    if page:
        if page.startswith('/'):
            page = page[1:]
        page_dict = tk.get_action('ckanext_pages_show')(data_dict={
            'org_id': None,
            'page': page
        })
    if page_dict is None:
        page_dict = {}
    if tk.request.method == 'POST' and not data:
        data = _parse_form_data(tk.request)

        page_dict.update(data)

        page_dict['org_id'] = None
        page_dict['page'] = page
        page_dict['page_type'] = 'page' if page_type == 'pages' else page_type

        try:
            tk.get_action('ckanext_pages_update')(data_dict=page_dict)
        except tk.ValidationError as e:
            errors = e.error_dict
            error_summary = e.error_summary
            tk.h.flash_error(error_summary)
            return pages_edit(page,
                              data,
                              errors,
                              error_summary,
                              page_type=page_type)
        if ckan_29_or_higher:
            endpoint = 'show' if page_type in (
                'pages', 'page') else '%s_show' % page_type
            return tk.redirect_to('pages.%s' % endpoint,
                                  page=page_dict['name'])
        else:
            endpoint = 'pages_show' if page_type == 'page' else '%s_show' % page_type
            tk.redirect_to(endpoint, page='/' + page_dict['name'])

    try:
        tk.check_access('ckanext_pages_update',
                        {'user': tk.c.user or tk.c.author})
    except tk.NotAuthorized:
        return tk.abort(401, _('Unauthorized to create or edit a page'))

    if not data:
        data = page_dict

    errors = errors or {}
    error_summary = error_summary or {}

    form_snippet = config.get('ckanext.pages.form',
                              'ckanext_pages/base_form.html')

    vars = {
        'data': data,
        'errors': errors,
        'error_summary': error_summary,
        'page': page or '',
        'form_snippet': form_snippet
    }

    return tk.render('ckanext_pages/%s_edit.html' % page_type, extra_vars=vars)
Exemplo n.º 8
0
def group_edit(id,
               group_type,
               page=None,
               data=None,
               errors=None,
               error_summary=None):

    _template_setup_group(id, group_type)

    page_dict = None
    if page:
        if page.startswith('/'):
            page = page[1:]
        page_dict = tk.get_action('ckanext_pages_show')(
            data_dict={
                'org_id': tk.c.group_dict['id'],
                'page': page
            })
    if page_dict is None:
        page_dict = {}

    if tk.request.method == 'POST' and not data:

        data = _parse_form_data(tk.request)

        page_dict.update(data)

        data = _parse_form_data(tk.request)
        page_dict['org_id'] = tk.c.group_dict['id']
        page_dict['page'] = page
        try:
            tk.get_action('ckanext_org_pages_update')(data_dict=page_dict)
        except tk.ValidationError as e:
            errors = e.error_dict
            error_summary = e.error_summary
            return group_edit(id, group_type, page, data, errors,
                              error_summary)
        if ckan_29_or_higher:
            endpoint = 'pages.{}_pages_show'.format(group_type)
            return tk.redirect_to(endpoint, id=id, page=page_dict['name'])
        else:
            endpoint = '{}_pages'.format(group_type)
            tk.redirect_to(endpoint, id=id, page='/' + page_dict['name'])

    if not data:
        data = page_dict

    errors = errors or {}
    error_summary = error_summary or {}

    context = {'for_view': True}

    action = 'organization_show' if group_type == 'organization' else 'group_show'
    group_dict = tk.get_action(action)(context, {'id': id})

    vars = {
        'data': data,
        'errors': errors,
        'error_summary': error_summary,
        'page': page,
        'group_type': group_type,
        'group_dict': group_dict
    }

    return tk.render('ckanext_pages/{}_page_edit.html'.format(group_type),
                     extra_vars=vars)
 def post(self):
     type_ = tk.request.form["type"]
     return tk.redirect_to(type_ + ".new")