コード例 #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
ファイル: auth.py プロジェクト: smotornyuk/ckanext-workflow
def package_update(context, data_dict):
    package = logic_auth.get_package_object(context, data_dict)
    workflow, _ = workflow_helpers.get_workflow_from_package(package)
    stage = workflow_helpers.get_stage_from_package(package)

    if stage != workflow.finish:
        return auth_update.package_update(context, data_dict)
    return _success(False, 'Cannot edit published dataset')
コード例 #3
0
ファイル: auth.py プロジェクト: smotornyuk/ckanext-workflow
def move_to_previous_stage(context, data_dict):
    wf, _ = workflow_helpers.get_workflow_from_package(data_dict)
    stage = workflow_helpers.get_stage_from_package(data_dict)
    if stage and 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 == data_dict['creator_user_id']:
            return _success()
    return _success(False)
コード例 #4
0
ファイル: auth.py プロジェクト: Engerrs/ckanext-workflow
def move_to_next_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_approve and stage.approve() 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
ファイル: auth.py プロジェクト: smotornyuk/ckanext-workflow
def create_dataset_revision(context, data_dict):
    workflow, _ = workflow_helpers.get_workflow_from_package(data_dict)
    stage = workflow_helpers.get_stage_from_package(data_dict)

    if stage != workflow.finish:
        return _success(False, 'Dataset must be published')
    if workflow_helpers.get_original_dataset_id_from_package(data_dict):
        return _success(False, 'Cannot create revision of revision')
    if workflow_helpers.get_dataset_revision_query(data_dict['id']).count():
        return _success(False, 'Dataset already has revision')
    return authz.is_authorized('package_create', context, data_dict)
コード例 #6
0
ファイル: auth.py プロジェクト: smotornyuk/ckanext-workflow
def workflow_rescind_dataset(context, data_dict):
    wf, _ = workflow_helpers.get_workflow_from_package(data_dict)
    stage = workflow_helpers.get_stage_from_package(data_dict)
    if stage == wf.start:
        return _success(False, 'Already on initial stage')
    if stage == wf.finish:
        return _success(False, 'Already on published stage')

    user = model.User.get(context['user'])
    if user is not None and user.id == data_dict['creator_user_id']:
        return _success()
    return _success(False)
コード例 #7
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
コード例 #8
0
    def approve(self, id):
        """Approve common dataset.

        If package just've got its last stage and it looks like
        revision - redirects to merge_revision route
        """
        context = {
            'user': c.user,
            'model': model
        }
        endpoint = request.referrer or '/'

        pkg = tk.get_action('package_show')(context, {'id': id})
        wf, _ = wh.get_workflow_from_package(pkg)

        next = str(wh.get_stage_from_package(pkg).approve())
        if next == str(wf.finish) and wh.is_revision(pkg):
            endpoint = h.url_for('merge_dataset_revision', id=id)
        tk.get_action('move_to_next_stage')(context, {'id': id})

        return base.redirect(endpoint)