コード例 #1
0
ファイル: action.py プロジェクト: Engerrs/ckanext-workflow
def _prepare_workflow_action(context, data_dict, auth_name):
    pkg_dict = tk.get_action('package_show')(context, data_dict)
    tk.check_access(auth_name, context, pkg_dict)

    wf, _ = workflow_helpers.get_workflow_from_package(context['package'])
    stage = wf.get_stage(pkg_dict[workflow_helpers._workflow_stage_field()])
    return pkg_dict, stage, wf
コード例 #2
0
def workflow_stage_validator(key, data, errors, context):
    stage = data[key]
    type = data.get((h._workflow_type_field(),), missing)

    if type is missing or not type:
        type = 'base'
    wf = Workflow.get_workflow(type)
    first_stage = str(wf.start)

    pkg = context.get('package')

    if stage is missing or not stage:
        if pkg:
            first_stage = pkg.extras.get(
                h._workflow_stage_field()) or first_stage
        data[key] = first_stage
        return
    if pkg is None and stage != first_stage:
        raise Invalid('You cannot skip fist stage')
    current_stage = pkg.extras.get(key[0]) if pkg else first_stage

    if current_stage == stage:
        return

    try:
        wf.get_stage(stage)
    except KeyError:
        raise Invalid('Unsupported workflow stage')
    user = context['auth_user_obj']
    if user and (user.sysadmin or h.is_site_admin(user)):
        return
    if stage == wf.finish:
        raise Invalid('Only site admin can set this stage')
    if not user or user.id != pkg.creator_user_id:
        raise Invalid('Only dataset creator can change stage')
コード例 #3
0
ファイル: action.py プロジェクト: Engerrs/ckanext-workflow
def reset_to_initial_stage(context, data_dict):
    pkg_dict, stage, wf = _prepare_workflow_action(context, data_dict,
                                                   'reset_to_initial_stage')
    next_stage = wf.start
    field_name = workflow_helpers._workflow_stage_field()
    _update_workflow_stage(field_name, str(next_stage), context)

    return {field_name: str(next_stage)}
コード例 #4
0
ファイル: auth.py プロジェクト: Engerrs/ckanext-workflow
def move_to_previous_stage(context, data_dict):
    pkg = context['package']
    wf, _ = workflow_helpers.get_workflow_from_package(pkg)
    stage = wf.get_stage(pkg[workflow_helpers._workflow_stage_field()])
    if roles.creator in stage.who_can_reject and stage.reject() is not None:
        user = model.User.get(context['user'])
        if user is not None and user.id == pkg['creator_user_id']:
            return _success()
    return _success(False)
コード例 #5
0
ファイル: action.py プロジェクト: Engerrs/ckanext-workflow
def move_to_previous_stage(context, data_dict):
    pkg_dict, stage, wf = _prepare_workflow_action(context, data_dict,
                                                   'move_to_previous_stage')
    next_stage = stage.reject()
    field_name = workflow_helpers._workflow_stage_field()
    _update_workflow_stage(field_name, str(next_stage), context)

    if callable(stage.rejection_effect):
        stage.rejection_effect(context, pkg_dict, data_dict)

    return {field_name: str(next_stage)}
コード例 #6
0
ファイル: plugin.py プロジェクト: mutantsan/ckanext-workflow
    def get_dataset_labels(self, dataset_obj):
        field = workflow_helpers._workflow_stage_field()
        stage = getattr(dataset_obj, field,
                        None) or dataset_obj.extras.get(field)

        if not stage or stage in Workflow.get_all_finish_stages():
            return DefaultPermissionLabels().get_dataset_labels(dataset_obj)

        return [
            u'stage_{}_{}'.format(
                stage, dataset_obj.owner_org or dataset_obj.creator_user_id)
        ]
コード例 #7
0
    def pending_list(self):
        context = {'model': model, 'user': c.user, 'auth_user_obj': c.userobj}
        try:
            tk.check_access('sysadmin', context, {})
        except tk.NotAuthorized:
            base.abort(401, _('Need to be system administrator to administer'))

        extra_vars = {
            'datasets':
            model.Session.query(model.Package).join(model.PackageExtra).filter(
                model.PackageExtra.key == wh._workflow_stage_field(),
                model.PackageExtra.value.in_(['pending']),
                model.Package.state == 'active')
        }

        return base.render('workflow/pending_list.html', extra_vars=extra_vars)
コード例 #8
0
ファイル: action.py プロジェクト: smotornyuk/ckanext-workflow
def workflow_rescind_dataset(context, data_dict):
    """Move package to initial stage in its workflow.

    :param id: id or name of package
    :returns:  dict with name of new stage
    :rtype: dict

    """

    pkg_dict, stage, wf = _prepare_workflow_action(context, data_dict,
                                                   'workflow_rescind_dataset')
    next_stage = wf.start
    field_name = workflow_helpers._workflow_stage_field()
    _update_workflow_stage(field_name, str(next_stage), context['package'])

    return {field_name: str(next_stage)}
コード例 #9
0
ファイル: action.py プロジェクト: smotornyuk/ckanext-workflow
def _prepare_workflow_action(context, data_dict, auth_name):
    """Check access and get workflow info from package.

    :param context: api context
    :param data_dict: data for `package_show`
    :param auth_name: name of auth function for performing action

    :returns: tuple with pkg_dict, stage and workflow objects
    :rtype: typle(dict, Stage, Workflow)

    """
    pkg_dict = tk.get_action('package_show')(context, data_dict)
    tk.check_access(auth_name, context, pkg_dict)

    wf, _ = workflow_helpers.get_workflow_from_package(pkg_dict)
    stage = wf.get_stage(pkg_dict[workflow_helpers._workflow_stage_field()])
    return pkg_dict, stage, wf
コード例 #10
0
    def before_search(self, search_params):
        fq = search_params.get('fq', '')
        q = search_params.get('q', '')
        is_member = False
        match = org_re.search(fq) or org_re.search(q)
        if match is not None:
            id = match.group('id').strip('\'"')
            is_member = helpers.user_in_org_or_group(id)

        if c.userobj and '+creator_user_id:{0}'.format(
                c.userobj.id) in fq or is_member:
            pass
        else:
            fq += ' +{0}:({1})'.format(
                workflow_helpers._workflow_stage_field(),
                ' OR '.join(Workflow.get_all_finish_stages()))
        search_params['fq'] = fq
        return search_params
コード例 #11
0
ファイル: action.py プロジェクト: smotornyuk/ckanext-workflow
def move_to_previous_stage(context, data_dict):
    """Move package to previous stage in its workflow.

    :param id: id or name of package
    :returns:  dict with name of new stage
    :rtype: dict

    """

    pkg_dict, stage, wf = _prepare_workflow_action(context, data_dict,
                                                   'move_to_previous_stage')
    next_stage = stage.reject()
    field_name = workflow_helpers._workflow_stage_field()
    _update_workflow_stage(field_name, str(next_stage), context['package'])

    if callable(stage.rejection_effect):
        stage.rejection_effect(context, pkg_dict, data_dict)

    return {field_name: str(next_stage)}
コード例 #12
0
ファイル: command.py プロジェクト: mutantsan/ckanext-workflow
from ckan.lib.cli import CkanCommand
import paste.script
import logging
import ckan.model as model
from ckanext.workflow.helpers import (_workflow_stage_field,
                                      _workflow_type_field)

wf_field = _workflow_type_field()
stage_field = _workflow_stage_field()
WORKFLOW = 'base'
PUBLISHED = 'published'
UNPUBLISHED = 'unpublished'

log = logging.getLogger('ckanext.workflow')


def migrate_one(id):
    pkg = model.Package.get(id)
    if pkg is None:
        print('Package {0} not found'.format(id))
        return False
    wf = pkg.extras.get(wf_field)
    stage = pkg.extras.get(stage_field)
    if None not in (wf, stage):
        print('Package {0} currently in state({1}, {2})'.format(id, wf, stage))
        return False
    else:
        model.repo.new_revision()
        extras = pkg.extras
        extras.update({wf_field: WORKFLOW})
        if pkg.state == model.State.ACTIVE and not pkg.private:
コード例 #13
0
ファイル: action.py プロジェクト: smotornyuk/ckanext-workflow
import ckan.plugins as plugins
from ckan.plugins.interfaces import IDomainObjectModification

import ckan.plugins.toolkit as tk
import ckan.model as model
import ckanext.workflow.helpers as workflow_helpers

ignored_fields = ('id', workflow_helpers._workflow_stage_field(), 'resources',
                  'creator_user_id')


def get_actions():
    return dict(move_to_next_stage=move_to_next_stage,
                move_to_previous_stage=move_to_previous_stage,
                create_dataset_revision=create_dataset_revision,
                merge_dataset_revision=merge_dataset_revision,
                workflow_rescind_dataset=workflow_rescind_dataset)


def _prepare_workflow_action(context, data_dict, auth_name):
    """Check access and get workflow info from package.

    :param context: api context
    :param data_dict: data for `package_show`
    :param auth_name: name of auth function for performing action

    :returns: tuple with pkg_dict, stage and workflow objects
    :rtype: typle(dict, Stage, Workflow)

    """
    pkg_dict = tk.get_action('package_show')(context, data_dict)