예제 #1
0
def setup_user_make_sysadmin():
    """ Make them a sysadmin"""
    user_id = session['user_id']

    if not check_perm(user_id, 0, 1):
        flash("You do not have User Administration access.")
        return redirect(url_for('setup_top'))

    new_user = request.form.get('userid', None)
    if not new_user:
        abort(400)
    user = Users2.get_user(new_user)
    add_perm(new_user, 0, 1)
    flash("%s is now a system admin on OASIS" % user['uname'])
    return redirect(url_for("setup_usersearch"))
예제 #2
0
def setup_user_make_sysadmin():
    """ Make them a sysadmin"""
    user_id = session['user_id']

    if not check_perm(user_id, 0, 1):
        flash("You do not have User Administration access.")
        return redirect(url_for('setup_top'))

    new_user = request.form.get('userid', None)
    if not new_user:
        abort(400)
    user = Users2.get_user(new_user)
    add_perm(new_user, 0, 1)
    flash("%s is now a system admin on OASIS" % user['uname'])
    return redirect(url_for("setup_usersearch"))
예제 #3
0
def save_perms(request, cid, user_id):
    """ Save permission changes
    """

    permlist = get_course_perms(cid)
    perms = {}
    users = {}
    for perm in permlist:
        u = Users2.get_user(perm[0])
        uname = u['uname']
        if not uname in users:
            users[uname] = {}
        users[uname]['fullname'] = u['fullname']

        if not uname in perms:
            perms[uname] = []
        perms[uname].append(int(perm[1]))

    form = request.form
    if form:    # we received a form submission, work out changes and save them
        fields = [field for field in form.keys() if field[:5] == "perm_"]
        newperms = {}

        for field in fields:
            uname = field.split('_')[1]
            perm = int(field.split('_')[2])

            if not uname in newperms:
                newperms[uname] = []
            newperms[uname].append(perm)

        for uname in users:
            uid = Users2.uid_by_uname(uname)
            for perm in [2, 5, 10, 14, 11, 8, 9, 15]:
                if uname in newperms and perm in newperms[uname]:
                    if not perm in perms[uname]:
                        add_perm(uid, cid, perm)
                        audit(
                            1,
                            user_id,
                            uid,
                            "CourseAdmin",
                            "%s given %s permission by %s" % (uname, get_perm_short(perm), user_id,)
                        )
                else:
                    if uname in perms and perm in perms[uname]:
                        delete_perm(uid, cid, perm)
                        audit(
                            1,
                            user_id,
                            uid,
                            "CourseAdmin",
                            "%s had %s permission revoked by %s" % (uname, get_perm_short(perm), user_id,)
                        )

        for uname in newperms:
            uid = Users2.uid_by_uname(uname)
            if not uname in perms:
                # We've added a user
                for perm in [2, 5, 10, 14, 11, 8, 9, 15]:
                    if perm in newperms[uname]:
                        add_perm(uid, cid, perm)
                        audit(
                            1,
                            user_id,
                            uid,
                            "CourseAdmin",
                            "%s given %s permission by %s" % (uname, get_perm_short(perm), user_id,)
                        )
        if "adduser" in form:
            newuname = form['adduser']
            newuid = Users2.uid_by_uname(newuname)
            if newuid:
                add_perm(newuid, cid, 10)
                audit(
                    1,
                    user_id,
                    newuid,
                    "CourseAdmin",
                    "%s given '%s' permission by %s" % (newuname, get_perm_short(10), user_id,)
                )
    return
예제 #4
0
def save_perms(request, cid, user_id):
    """ Save permission changes
    """

    permlist = get_course_perms(cid)
    perms = {}
    users = {}
    for perm in permlist:
        u = Users2.get_user(perm[0])
        uname = u['uname']
        if uname not in users:
            users[uname] = {}
        users[uname]['fullname'] = u['fullname']

        if uname not in perms:
            perms[uname] = []
        perms[uname].append(int(perm[1]))

    form = request.form
    if form:  # we received a form submission, work out changes and save them
        fields = [field for field in form.keys() if field[:5] == "perm_"]
        newperms = {}

        for field in fields:
            uname = field.split('_')[1]
            perm = int(field.split('_')[2])

            if uname not in newperms:
                newperms[uname] = []
            newperms[uname].append(perm)

        for uname in users:
            uid = Users2.uid_by_uname(uname)
            for perm in [2, 5, 10, 14, 11, 8, 9, 15]:
                if uname in newperms and perm in newperms[uname]:
                    if perm not in perms[uname]:
                        add_perm(uid, cid, perm)
                        audit(
                            1, user_id, uid, "CourseAdmin",
                            "%s given %s permission by %s" % (
                                uname,
                                get_perm_short(perm),
                                user_id,
                            ))
                else:
                    if uname in perms and perm in perms[uname]:
                        delete_perm(uid, cid, perm)
                        audit(
                            1, user_id, uid, "CourseAdmin",
                            "%s had %s permission revoked by %s" % (
                                uname,
                                get_perm_short(perm),
                                user_id,
                            ))

        for uname in newperms:
            uid = Users2.uid_by_uname(uname)
            if uname not in perms:
                # We've added a user
                for perm in [2, 5, 10, 14, 11, 8, 9, 15]:
                    if perm in newperms[uname]:
                        add_perm(uid, cid, perm)
                        audit(
                            1, user_id, uid, "CourseAdmin",
                            "%s given %s permission by %s" % (
                                uname,
                                get_perm_short(perm),
                                user_id,
                            ))
        if "adduser" in form:
            newuname = form['adduser']
            newuid = Users2.uid_by_uname(newuname)
            if newuid:
                add_perm(newuid, cid, 10)
                audit(
                    1, user_id, newuid, "CourseAdmin",
                    "%s given '%s' permission by %s" % (
                        newuname,
                        get_perm_short(10),
                        user_id,
                    ))
    return