示例#1
0
def admin_action_edit_status(action_id):
    """ Edit Admin Action status update
    """

    admin_action = pkgdblib.get_admin_action(SESSION, action_id)
    if not admin_action:
        flask.flash("No action found with this identifier.", "errors")
        return flask.render_template("msg.html")

    action_status = pkgdblib.get_status(SESSION, "admin_status")["admin_status"]

    form = pkgdb2.forms.EditActionStatusForm(status=action_status, obj=admin_action)
    form.id.data = action_id

    if form.validate_on_submit():

        try:
            message = pkgdblib.edit_action_status(
                SESSION, admin_action, action_status=form.status.data, user=flask.g.fas_user, message=form.message.data
            )
            SESSION.commit()
            flask.flash(message)
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            # We can only reach here in two cases:
            # 1) the user is not an admin, but that's taken care of
            #    by the decorator
            # 2) we have a SQLAlchemy problem when storing the info
            #    in the DB which we cannot test
            SESSION.rollback()
            flask.flash(err, "errors")
            return flask.render_template("msg.html")

        return flask.redirect(flask.url_for(".admin_actions"))
示例#2
0
文件: admin.py 项目: voxik/pkgdb2
def admin_action_edit_status(action_id):
    """ Edit Admin Action status update
    """

    admin_action = pkgdblib.get_admin_action(SESSION, action_id)
    if not admin_action:
        flask.flash('No action found with this identifier.', 'errors')
        return flask.render_template('msg.html')

    action_status = pkgdblib.get_status(
        SESSION, 'admin_status')['admin_status']

    form = pkgdb2.forms.EditActionStatusForm(
        status=action_status,
        obj=admin_action
    )
    form.id.data = action_id

    if form.validate_on_submit():

        try:
            message = pkgdblib.edit_action_status(
                SESSION,
                admin_action,
                action_status=form.status.data,
                user=flask.g.fas_user,
                message=form.message.data,
            )
            SESSION.commit()
            flask.flash(message)
        except PkgdbException as err:  # pragma: no cover
            # We can only reach here in two cases:
            # 1) the user is not an admin, but that's taken care of
            #    by the decorator
            # 2) we have a SQLAlchemy problem when storing the info
            #    in the DB which we cannot test
            SESSION.rollback()
            flask.flash(err, 'errors')
            return flask.render_template('msg.html')

        return flask.redirect(
            flask.url_for('.admin_actions')
        )

    return flask.render_template(
        'actions_update.html',
        admin_action=admin_action,
        action_id=action_id,
        form=form,
    )
示例#3
0
def package_request_edit(action_id):
    """ Edit an Admin Action status
    """

    admin_action = pkgdblib.get_admin_action(SESSION, action_id)
    if not admin_action:
        flask.flash('No action found with this identifier.', 'errors')
        return flask.render_template('msg.html')

    package = None
    if admin_action.package:
        package = admin_action.package.name

    if admin_action.status in ['Accepted', 'Blocked', 'Denied']:
        return flask.render_template(
            'actions_update_ro.html',
            admin_action=admin_action,
            action_id=action_id,
        )

    if not is_authenticated() or not 'packager' in flask.g.fas_user.groups:
        return flask.render_template(
            'actions_update_ro.html',
            admin_action=admin_action,
            action_id=action_id,
        )

    # Check user is the pkg/pkgdb admin
    pkg_admin = pkgdblib.has_acls(SESSION, flask.g.fas_user.username, package,
                                  'approveacls')
    if not is_pkgdb_admin(flask.g.fas_user) \
            and not pkg_admin \
            and not admin_action.user == flask.g.fas_user.username:
        flask.flash(
            'Only package adminitrators (`approveacls`) and the requester '
            'can review pending branch requests', 'errors')
        if package:
            return flask.redirect(
                flask.url_for('.package_info', package=package))
        else:
            return flask.redirect(
                flask.url_for('.packager_requests',
                              packager=flask.g.fas_user.username))

    action_status = ['Pending', 'Awaiting Review', 'Blocked']
    if admin_action.user == flask.g.fas_user.username:
        action_status = ['Pending', 'Obsolete']
        if pkg_admin or admin_action.action == 'request.package':
            action_status.append('Awaiting Review')

    form = pkgdb2.forms.EditActionStatusForm(status=action_status,
                                             obj=admin_action)
    form.id.data = action_id

    if form.validate_on_submit():

        try:
            message = pkgdblib.edit_action_status(
                SESSION,
                admin_action,
                action_status=form.status.data,
                user=flask.g.fas_user,
                message=form.message.data,
            )
            SESSION.commit()
            flask.flash(message)
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            # We can only reach here in two cases:
            # 1) the user is not an admin, but that's taken care of
            #    by the decorator
            # 2) we have a SQLAlchemy problem when storing the info
            #    in the DB which we cannot test
            SESSION.rollback()
            flask.flash(err, 'errors')
            return flask.render_template('msg.html')

        if package:
            return flask.redirect(
                flask.url_for('.package_info', package=package))
        else:
            return flask.redirect(
                flask.url_for('.packager_requests',
                              packager=flask.g.fas_user.username))
示例#4
0
def api_admin_action_edit_status():
    '''
Edit Admin Action status update
-------------------------------
    Edit the status of an Admin Action.

    ::

        /admin/action/status

    Accept POST queries only.

    :arg id: An integer representing the identifier of the admin
        action to update in the database. The identifier is returned in the
        API, see ``List admin actions``.
    :arg status: The status to which the action should be updated.
        Can be any of: ``Approved``, ``Awaiting Review``, ``Blocked``,
        ``Denied``, ``Pending`` and ``Obsolete``.

    ..note:: The ``Obsolete`` status can only be set by the person who made
             the request.

    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["Admin action status updated to: Approved"]
        }

        {
          "output": "notok",
          "error": ["You are not an admin"]
        }

    '''
    httpcode = 200
    output = {}

    action_status = pkgdblib.get_status(
        SESSION, 'admin_status')['admin_status']

    form = pkgdb2.forms.EditActionStatusForm(
        csrf_enabled=False,
        status=action_status,
    )
    if form.validate_on_submit():
        action_id = form.id.data

        admin_action = pkgdblib.get_admin_action(SESSION, action_id)
        if not admin_action:
            output['output'] = 'notok'
            output['error'] = 'No Admin action with this identifier found'
            httpcode = 500
        else:

            try:
                message = pkgdblib.edit_action_status(
                    SESSION,
                    admin_action,
                    action_status=form.status.data,
                    user=flask.g.fas_user,
                    message=form.message.data,
                )
                SESSION.commit()
                output['output'] = 'ok'
                output['messages'] = [message]
            except PkgdbException as err:  # pragma: no cover
                # We can only reach here in two cases:
                # 1) the user is not an admin, but that's taken care of
                #    by the decorator
                # 2) we have a SQLAlchemy problem when storing the info
                #    in the DB which we cannot test
                SESSION.rollback()
                output['output'] = 'notok'
                output['error'] = str(err)
                httpcode = 500
    else:
        output['output'] = 'notok'
        output['error'] = 'Invalid input submitted'
        if form.errors:
            detail = []
            for error in form.errors:
                detail.append('%s: %s' % (error,
                              '; '.join(form.errors[error])))
            output['error_detail'] = detail
        httpcode = 500

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
示例#5
0
def api_admin_action(actionid=None):
    '''
Get a specific Admin Action
---------------------------
    Return the desired Admin Action using its identifier.

    ::

        /admin/action/<actionid>
        /admin/action/?actionid=<actionid>

    Accept GET queries only.

    :arg actionid: An integer representing the identifier of the admin
        action in the database. The identifier is returned in the
        API, see ``List admin actions``.

    Sample response:

    ::

        {
          "action": "request.branch",
          "collection": {
            "branchname": "epel7",
            "dist_tag": ".el7",
            "koji_name": "epel7",
            "name": "Fedora EPEL",
            "status": "Active",
            "version": "7"
          },
          "date_created": 1410161489.0,
          "date_updated": 1410168952.0,
          "from_collection": {
            "branchname": "master",
            "dist_tag": ".fc21",
            "koji_name": "rawhide",
            "name": "Fedora",
            "status": "Under Development",
            "version": "devel"
          },
          "id": 1,
          "info": {},
          "package": {
            "acls": [],
            "creation_date": 1397204290.0,
            "description": null,
            "name": "R-BiocGenerics",
            "review_url": null,
            "status": "Approved",
            "summary": "Generic functions for Bioconductor",
            "upstream_url": null
          },
          "status": "Approved",
          "user": "******"
        }

    '''
    httpcode = 200
    output = {}

    actionid = flask.request.args.get('actionid', actionid)

    try:
        int(actionid)
    except:
        output['output'] = 'notok'
        output['error'] = 'No Admin action with this identifier found'
        httpcode = 500
    else:
        admin_action = pkgdblib.get_admin_action(SESSION, actionid)
        if not admin_action:
            output['output'] = 'notok'
            output['error'] = 'No Admin action with this identifier found'
            httpcode = 500
        else:
            output = admin_action.to_json()
            output['output'] = 'ok'

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
示例#6
0
def package_request_edit(action_id):
    """ Edit an Admin Action status
    """

    admin_action = pkgdblib.get_admin_action(SESSION, action_id)
    if not admin_action:
        flask.flash('No action found with this identifier.', 'errors')
        return flask.render_template('msg.html')

    package = None
    namespace = None
    if admin_action.package:
        package = admin_action.package.name
        namespace = admin_action.package.namespace

    if admin_action.status in ['Accepted', 'Blocked', 'Denied']:
        return flask.render_template(
            'actions_update_ro.html',
            admin_action=admin_action,
            action_id=action_id,
        )

    pkger_grp = APP.config.get('PKGER_GROUP', 'packager')
    if not is_authenticated() or not pkger_grp in flask.g.fas_user.groups:
        return flask.render_template(
            'actions_update_ro.html',
            admin_action=admin_action,
            action_id=action_id,
        )

    # Check user is the pkg/pkgdb admin
    pkg_admin = pkgdblib.has_acls(
        SESSION, flask.g.fas_user.username,
        namespace, package, 'approveacls')

    if not is_pkgdb_admin(flask.g.fas_user) \
            and not pkg_admin \
            and not admin_action.user == flask.g.fas_user.username:
        flask.flash(
            'Only package adminitrators (`approveacls`) and the requester '
            'can review pending branch requests', 'errors')
        if package:
            return flask.redirect(flask.url_for(
                '.package_info', namespace=namespace, package=package)
            )
        else:
            return flask.redirect(
                flask.url_for(
                    '.packager_requests',
                    packager=flask.g.fas_user.username)
            )

    action_status = ['Pending', 'Awaiting Review', 'Blocked']
    if admin_action.user == flask.g.fas_user.username:
        action_status = ['Pending', 'Obsolete']
        if pkg_admin or admin_action.action in [
                'request.package', 'request.unretire']:
            action_status.append('Awaiting Review')

    form = pkgdb2.forms.EditActionStatusForm(
        status=action_status,
        obj=admin_action
    )
    form.id.data = action_id

    if form.validate_on_submit():

        try:
            message = pkgdblib.edit_action_status(
                SESSION,
                admin_action,
                action_status=form.status.data,
                user=flask.g.fas_user,
                message=form.message.data,
            )
            SESSION.commit()
            flask.flash(message)
        except PkgdbException as err:  # pragma: no cover
            # We can only reach here in two cases:
            # 1) the user is not an admin, but that's taken care of
            #    by the decorator
            # 2) we have a SQLAlchemy problem when storing the info
            #    in the DB which we cannot test
            SESSION.rollback()
            flask.flash(err, 'errors')
            return flask.render_template('msg.html')

        if package:
            return flask.redirect(flask.url_for(
                '.package_info', namespace=namespace, package=package)
            )
        else:
            return flask.redirect(
                flask.url_for(
                    '.packager_requests',
                    packager=flask.g.fas_user.username)
            )

    return flask.render_template(
        'actions_update.html',
        admin_action=admin_action,
        action_id=action_id,
        form=form,
        package=package,
        tag='packages',
    )
示例#7
0
def api_admin_action_edit_status():
    '''
Edit Admin Action status update
-------------------------------
    Edit the status of an Admin Action.

    ::

        /admin/action/status

    Accept POST queries only.

    :arg id: An integer representing the identifier of the admin
        action to update in the database. The identifier is returned in the
        API, see ``List admin actions``.
    :arg status: The status to which the action should be updated.
        Can be any of: ``Approved``, ``Awaiting Review``, ``Blocked``,
        ``Denied``, ``Pending`` and ``Obsolete``.

    ..note:: The ``Obsolete`` status can only be set by the person who made
             the request.

    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["Admin action status updated to: Approved"]
        }

        {
          "output": "notok",
          "error": ["You are not an admin"]
        }

    '''
    httpcode = 200
    output = {}

    action_status = pkgdblib.get_status(SESSION,
                                        'admin_status')['admin_status']

    form = pkgdb2.forms.EditActionStatusForm(
        csrf_enabled=False,
        status=action_status,
    )
    if form.validate_on_submit():
        action_id = form.id.data

        admin_action = pkgdblib.get_admin_action(SESSION, action_id)
        if not admin_action:
            output['output'] = 'notok'
            output['error'] = 'No Admin action with this identifier found'
            httpcode = 500
        else:

            try:
                message = pkgdblib.edit_action_status(
                    SESSION,
                    admin_action,
                    action_status=form.status.data,
                    user=flask.g.fas_user,
                    message=form.message.data,
                )
                SESSION.commit()
                output['output'] = 'ok'
                output['messages'] = [message]
            except pkgdblib.PkgdbException, err:  # pragma: no cover
                # We can only reach here in two cases:
                # 1) the user is not an admin, but that's taken care of
                #    by the decorator
                # 2) we have a SQLAlchemy problem when storing the info
                #    in the DB which we cannot test
                SESSION.rollback()
                output['output'] = 'notok'
                output['error'] = str(err)
                httpcode = 500
示例#8
0
def api_admin_action(actionid=None):
    '''
Get a specific Admin Action
---------------------------
    Return the desired Admin Action using its identifier.

    ::

        /admin/action/<actionid>
        /admin/action/?actionid=<actionid>

    Accept GET queries only.

    :arg actionid: An integer representing the identifier of the admin
        action in the database. The identifier is returned in the
        API, see ``List admin actions``.

    Sample response:

    ::

        {
          "action": "request.branch",
          "collection": {
            "branchname": "epel7",
            "dist_tag": ".el7",
            "koji_name": "epel7",
            "name": "Fedora EPEL",
            "status": "Active",
            "version": "7"
          },
          "date_created": 1410161489.0,
          "date_updated": 1410168952.0,
          "from_collection": {
            "branchname": "master",
            "dist_tag": ".fc21",
            "koji_name": "rawhide",
            "name": "Fedora",
            "status": "Under Development",
            "version": "devel"
          },
          "id": 1,
          "info": {},
          "package": {
            "acls": [],
            "creation_date": 1397204290.0,
            "description": null,
            "name": "R-BiocGenerics",
            "review_url": null,
            "status": "Approved",
            "summary": "Generic functions for Bioconductor",
            "upstream_url": null
          },
          "status": "Approved",
          "user": "******"
        }

    '''
    httpcode = 200
    output = {}

    actionid = flask.request.args.get('actionid', actionid)

    admin_action = pkgdblib.get_admin_action(SESSION, actionid)
    if not admin_action:
        output['output'] = 'notok'
        output['error'] = 'No Admin action with this identifier found'
        httpcode = 500
    else:
        output = admin_action.to_json()
        output['output'] = 'ok'

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout