Beispiel #1
0
def request_permissions(ownername, projectname):
    copr = get_copr(ownername, projectname)
    roles = flask.request.get_json()
    if not isinstance(roles, dict):
        raise BadRequest("invalid 'roles' dict format, expected: "
                         "{'admin': True, 'builder': False}")
    if not roles:
        raise BadRequest("no permission requested")

    permission_dict = {}
    with db_session_scope():
        for permission, request_bool in roles.items():
            change = CoprPermissionsLogic.request_permission(
                copr, flask.g.user, permission, request_bool)
            if change:
                permission_dict['old_' + permission] = change[0]
                permission_dict['new_' + permission] = change[1]

    if permission_dict:
        msg = PermissionRequestMessage(copr, flask.g.user, permission_dict)
        for address in copr.admin_mails:
            if flask.current_app.config.get("SEND_EMAILS", False):
                send_mail([address], msg)

    return flask.jsonify({'updated': bool(permission_dict)})
Beispiel #2
0
def clean_old_builds():
    """
    This garbage collects all builds which are "obsoleted" per user
    configuration, per models.Package.max_builds configuration.
    """
    with db_session_scope():
        BuildsLogic.clean_old_builds()
Beispiel #3
0
def alter_chroot(chroot_names, action):
    """Activates or deactivates a chroot"""
    activate = (action == "activate")
    for chroot_name in chroot_names:
        try:
            with db_session_scope():
                mock_chroot = coprs_logic.MockChrootsLogic.edit_by_name(
                    chroot_name, activate)

                if action != "eol":
                    continue

                for copr_chroot in mock_chroot.copr_chroots:
                    delete_after_days = app.config[
                        "DELETE_EOL_CHROOTS_AFTER"] + 1
                    delete_after_timestamp = datetime.datetime.now(
                    ) + datetime.timedelta(delete_after_days)
                    # Workarounding an auth here
                    coprs_logic.CoprChrootsLogic.update_chroot(
                        copr_chroot.copr.user,
                        copr_chroot,
                        delete_after=delete_after_timestamp)
        except exceptions.MalformedArgumentException:
            print_invalid_format(chroot_name)
        except exceptions.NotFoundException:
            print_doesnt_exist(chroot_name)
def clean_expired_projects():
    """
    Clean all the expired temporary projects.  This command is meant to be
    executed by cron.
    """

    with db_session_scope():
        ComplexLogic.delete_expired_projects()
Beispiel #5
0
def set_permissions(copr):
    permissions = flask.request.get_json()
    if not isinstance(permissions, dict):
        raise BadRequest(
            "request is not a dictionary, expected format: "
            "{'username': {'admin': 'nothing', 'builder': 'request'} ...}")

    if not permissions:
        raise BadRequest("no permission change requested")

    updated = {}
    messages = []
    with db_session_scope():
        for username, perm_set in permissions.items():
            user = models.User.query.filter_by(username=username).first()
            if not user:
                raise BadRequest(
                    "user '{0}' doesn't exist in database".format(username))

            permission_dict = {}
            for perm, state in perm_set.items():
                change = CoprPermissionsLogic.set_permissions(
                    flask.g.user, copr, user, perm, state)
                if change:
                    updated[username] = True
                    permission_dict['old_' + perm] = change[0]
                    permission_dict['new_' + perm] = change[1]

            if permission_dict:
                msg = PermissionChangeMessage(copr, permission_dict)
                messages.append({'address': user.mail, 'message': msg})

    # send emails only if transaction succeeded
    for task in messages:
        if flask.current_app.config.get("SEND_EMAILS", False):
            send_mail([task['address']], task['message'])

    return flask.jsonify({'updated': list(updated.keys())})
Beispiel #6
0
 def run(self):
     with db_session_scope():
         BuildsLogic.clean_old_builds()
 def run(self):
     with db_session_scope():
         ComplexLogic.delete_expired_projects()