Example #1
0
def student_toggle_enabled():
    student_id = request.args(0)
    if student_id == None:
        if session.back:
            redirect(session.back)
        else:
            redirect(URL('faculty', 'manage_student'))

    current_user = Student.GetUsername(student_id)

    status_action = "Change Status"

    student = db(db.student_info.user_id == student_id).select().first()
    if (student == None):
        message = 'Invalid Student!'
    else:
        if (student.account_enabled == True):
            # Disable
            r = Student.DisableAccount(student_id)
            if r != "":
                r = " - ERROR trying to disable account - most likely couldn't find LDAP object. Make sure AD Student Cn is configured correctly in  Admin -> Configure App -> Student Settings  (missing cn=<program>)??" + r
            message = "Account disabled. " + r
            status_action = 'Disable Account'
        else:
            # Enable
            r = Student.EnableAccount(student_id)
            if r != "":
                r = " - ERROR trying to enable account - most likely couldn't find LDAP object. Make sure AD Student Cn is configured correctly in  Admin -> Configure App -> Student Settings  (missing cn=<program>)??" + r
            message = "Account enabled. " + r
            status_action = 'Enable Account'
    return dict(message=message,
                current_user=current_user,
                status_action=status_action)
Example #2
0
def student_canvas_quota():
    student_id = request.args(0)
    if (student_id == None):
        if (session.back):
            redirect(session.back)
        else:
            redirect(URL('faculty', 'manage_student'))

    current_user = Student.GetUsername(student_id)

    row = db(db.student_info.user_id == student_id).select().first()
    form = SQLFORM(db.student_info,
                   row,
                   showid=False,
                   fields=["student_canvas_quota"]).process()

    if (form.accepted):
        # Saved
        quota = request.vars.get('student_canvas_quota', '1')
        Canvas.SetQuota(current_user, quota)
        msg = "Settings Saved!"
        if (len(Canvas._errors) > 0):
            msg += Canvas.GetErrorString()
        response.flash = msg

    return dict(form=form, current_user=current_user)
Example #3
0
def student_toggle_upload_media():
    student_id = request.args(0)
    account_id = request.args(1)
    if (student_id == None or account_id == None):
        if (session.back):
            redirect(session.back)
        else:
            redirect(URL('faculty', 'manage_student'))

    current_user = Student.GetUsername(student_id)

    status_action = "Change Status"
    auth = current.auth  # Grab the current auth object

    # Add to the group
    if (auth.has_membership(role='Media Upload', user_id=account_id) == True):
        status_action = "Removing Media Upload Rights"
        auth.del_membership(auth.id_group(role='Media Upload'),
                            user_id=account_id)
    else:
        status_action = "Adding Media Upload Rights"
        auth.add_membership('Media Upload', user_id=account_id)
    message = status_action
    return dict(message=message,
                current_user=current_user,
                status_action=status_action)
Example #4
0
def refresh_all_ad_logins(run_from="UI"):
    # Go to the AD server and refresh all student and staff AD login times
    ret = ""

    # Might be longer running - make sure to commit so we don't leave databases locked
    db.commit()

    # Update the last login value for all users (students and faculty)
    if AD._ldap_enabled is not True:
        ret = "[AD Disabled]"
        return ret
    if AD.ConnectAD() is not True:
        ret = "[AD Connection Error]" + AD.GetErrorString()
        return ret

    # Grab list of students
    rows = db(db.student_info).select(db.student_info.user_id)
    for row in rows:
        # ret += "UID: " + row.user_id
        ll = Student.GetLastADLoginTime(row.user_id)
        # if (ll == None):
        #    ret += "None"
        # else:
        #    ret += str(ll)
        db(db.student_info.user_id == row.user_id).update(ad_last_login=ll)
        db.commit()

    # Grab a list of faculty
    rows = db(db.faculty_info).select(db.faculty_info.user_id)
    for row in rows:
        # ret += "UID: " + row.user_id
        ll = Faculty.GetLastADLoginTime(row.user_id)
        # if (ll == None):
        #    ret += "None"
        # else:
        #    ret += str(ll)
        db(db.faculty_info.user_id == row.user_id).update(ad_last_login=ll)
        db.commit()

    rows = None
    ad_errors = AD.GetErrorString()
    ret = "Done."

    # Have to call commit in tasks if changes made to the db
    db.commit()
    return ret
Example #5
0
def student_enrollment():
    student_id = request.args(0)
    if (student_id == None):
        if (session.back):
            redirect(session.back)
        else:
            redirect(URL('faculty', 'manage_student'))

    current_user = Student.GetUsername(student_id)

    user = db(db.student_info.user_id == student_id).select().first()
    query = None
    if (user != None):
        query = (db.student_enrollment.parent_id == user['id'])

    fields = (
        db.student_enrollment.course_code,
        db.student_enrollment.enrollment_status,
        db.student_enrollment.enrolled_on,
    )

    #links = [dict(header=T('Enrollment'),body=lambda row: A(Student.GetEnrolledClassesString(row.user_id), _href=URL('faculty', 'student_enrollment', args=[row.user_id], user_signature=True)) ),
    #         ]

    form = SQLFORM.grid(query,
                        fields=fields,
                        orderby=db.student_enrollment.course_code,
                        searchable=False,
                        create=False,
                        deletable=False,
                        paginate=50,
                        csv=False,
                        details=False,
                        editable=False,
                        links=None,
                        links_placement='right',
                        links_in_grid=True)

    return dict(form=form, current_user=current_user)
Example #6
0
def UpdateLastADLogin():
    ret = ""
    # Update the last login value for all users (students and faculty)
    if (AD.ConnectAD() != True):
        ret = "[AD Disabled]" + AD.GetErrorString()
        return ret

    # Grab list of students
    rows = db(db.student_info).select(db.student_info.user_id)
    for row in rows:
        #ret += "UID: " + row.user_id
        ll = Student.GetLastADLoginTime(row.user_id)
        #if (ll == None):
        #    ret += "None"
        #else:
        #    ret += str(ll)
        db(db.student_info.user_id == row.user_id).update(ad_last_login=ll)
        pass
    db.commit()

    # Grab a list of faculty
    rows = db(db.faculty_info).select(db.faculty_info.user_id)
    for row in rows:
        #ret += "UID: " + row.user_id
        ll = Faculty.GetLastADLoginTime(row.user_id)
        #if (ll == None):
        #    ret += "None"
        #else:
        #    ret += str(ll)
        db(db.faculty_info.user_id == row.user_id).update(ad_last_login=ll)
        pass
    db.commit()

    rows = None
    ad_errors = AD.GetErrorString()
    ret = "Done."
    return locals()
Example #7
0
def manage_students():

    # Set back link
    session.back = URL(args=request.args, vars=request.get_vars, host=True)

    #SQLFORM.factory(Field('item_cat'),widget=SQLFORM.widget.autocomplete(request, db.cat.name))
    #SQLFORM.factory(Field('item_cat',db.cat),widget=SQLFORM.widget.autocomplete(request, db.cat.name, id_field=db.cat.id) )
    #id_field=db.student_info.user_id
    choose_student_form = SQLFORM.factory(Field(
        'student_name',
        'string',
        widget=SQLFORM.widgets.autocomplete(request,
                                            db.student_info.student_name,
                                            limitby=(0, 10),
                                            min_length=1)),
                                          submit_button="Find")

    query = db.student_info

    db.student_info.import_classes.readable = False
    db.student_info.student_ad_quota.readable = False
    db.student_info.student_canvas_quota.readable = False
    db.student_info.account_enabled.readable = False
    db.student_info.student_password.readable = False
    db.student_info.student_guid.readable = False
    db.student_info.sheet_name.readable = False
    db.student_info.id.readable = False
    #db.student_info.account_id.readable=False
    db.student_info.user_id.label = "ID"
    db.student_info.account_id.label = "User Name"
    db.student_info.additional_fields.readable = False

    fields = (
        db.student_info.user_id,
        db.student_info.account_id,
        db.student_info.student_name,
        db.student_info.import_classes,
        db.student_info.student_ad_quota,
        #db.student_info.student_canvas_quota,
        db.student_info.account_enabled,
        db.student_info.account_added_on,
        db.student_info.account_updated_on,
        #db.student_info.account_id,
        db.student_info.ad_last_login,
    )
    maxtextlengths = {
        'student_info.account_added_on': 24,
        'student_info.account_updated_on': 24,
        'student_info.ad_last_login': 24
    }

    links = [
        #dict(header=T('Last AD Logon'),body=lambda row: Student.GetLastADLoginTime(row.user_id ) ),
        dict(header=T('Enrollment'),
             body=lambda row: A(Student.GetEnrolledClassesString(row.user_id),
                                _href=URL('faculty',
                                          'student_enrollment',
                                          args=[row.user_id],
                                          user_signature=True))),
        #dict(header=T('Canvas Quota'),body=lambda row: A(GetDisplaySize(row.student_canvas_quota), _href=URL('faculty', 'student_canvas_quota', args=[row.user_id])) ),
        dict(header=T('AD Quota'),
             body=lambda row:
             A(GetDisplaySize(row.student_ad_quota),
               _href=URL('faculty', 'student_ad_quota', args=[row.user_id]))),
        dict(header=T('Account Enabled'),
             body=lambda row: A(row.account_enabled,
                                _href=URL('faculty',
                                          'student_toggle_enabled',
                                          args=[row.user_id]))),
        dict(header=T('Change Password'),
             body=lambda row: A('Change Password',
                                _href=URL('faculty',
                                          'student_change_password',
                                          args=[row.user_id]))),
        dict(
            header=T('Upload Media***'),
            body=lambda row: A(GetUploadMediaStatus(row.account_id),
                               _href=URL('faculty',
                                         'student_toggle_upload_media',
                                         args=[row.user_id, row.account_id]))),
    ]

    user_grid = SQLFORM.grid(query,
                             fields=fields,
                             orderby=db.student_info.student_name,
                             searchable=True,
                             create=False,
                             deletable=False,
                             paginate=50,
                             csv=False,
                             details=False,
                             editable=False,
                             links=links,
                             links_placement='right',
                             links_in_grid=True,
                             maxtextlengths=maxtextlengths)

    return dict(choose_student_form=choose_student_form, user_grid=user_grid)
Example #8
0
def student_change_password():
    student_id = request.args(0)
    if (student_id == None):
        if (session.back):
            redirect(session.back)
        else:
            redirect(URL('faculty', 'manage_student'))

    current_user = Student.GetUsername(student_id)

    default_pw_form = SQLFORM.factory(
        submit_button="Set Default Password",
        _name="default_pw_form").process(formname="default_pw_form")

    custom_pw_form = SQLFORM.factory(Field(
        'new_password',
        'password',
        requires=[
            IS_NOT_EMPTY(),
            IS_STRONG(
                min=6,
                special=1,
                upper=1,
                error_message=
                'minimum 6 characters, and at least 1 uppercase character, 1 lower case character, and 1 special character'
            )
        ]),
                                     Field('confirm_new_password',
                                           'password',
                                           requires=IS_EXPR(
                                               'value==%s' % repr(
                                                   request.vars.get(
                                                       'new_password', None)),
                                               error_message=
                                               "Password fields don't match")),
                                     submit_button="Set New Password",
                                     _name="custom_pw_form").process(
                                         formname="custom_pw_form")

    if (default_pw_form.accepted):
        new_pw = AppSettings.GetValue('student_password_pattern',
                                      'SID<user_id>!')
        # Replace the possible values in this string with real info
        new_pw = Student.process_config_params(student_id,
                                               new_pw,
                                               is_username=False,
                                               row=None)
        #new_pw = new_pw.replace('<user_id>', student_id)
        msg = Student.SetPassword(student_id, new_pw)
        if msg == "":
            response.flash = "Default Password Set!"
        else:
            response.flash = msg

    if (custom_pw_form.accepted):
        pw = request.vars.get('new_password', '')
        if (pw != ""):
            ret = Student.SetPassword(student_id, pw)
            if (ret != ""):
                response.flash = ret
            else:
                response.flash = "Password Changed."
    elif (custom_pw_form.errors):
        response.flash = "Unable to set new password"

    return dict(default_pw_form=default_pw_form,
                custom_pw_form=custom_pw_form,
                current_user=current_user)