def user_role_edit(): """ Purpose: From this page system admin users can edit other user roles. Permission: This page is available to SYSTEM_ADMIN users only. Working: a. On request user is first asked to enter the mail address b. If provided mail address is not registered in the system then an error message is displayed. Otherwise user details are displayed with an option to change the user role. c. A success message is displayed to user on change of given user role. """ # check if current user is with system admin role if not current_user.is_system_admin(): return redirect(url_for('main.home')) if request.method == 'POST': if request.form['btn'] == 'search': user = User.query.filter_by(email=request.form['email']).first() if user: role_list = UserRole.query.all() return render_template('pages/edit_user_role.html', user=user, role_list=role_list) else: flash('Entered email address is not registered in the system', 'error') elif request.form['btn'] == 'edit': user_email = request.form['user_email'] user_role = request.form['user_role'] user = User.query.filter_by(email=user_email).first() user.role_id = int(user_role) db.session.commit() flash("User '" + user_email + "' role has been updated", 'success') return render_template('pages/edit_user_role.html')
def home(): if current_user.is_survey_taker(): # get survey groups in which user is added survey_groups = SurveyGroupMember.query.filter(SurveyGroupMember.email == current_user.email).subquery() # get surveys user has already taken surveys_taken = SurveyData.query.filter(SurveyData.user_id == current_user.id).all() # surveys id list taken by current user surveys_taken_list = [] for survey in surveys_taken: surveys_taken_list.append(survey.survey_id) # get surveys associated with survey groups # filter surveys that are expired # filter surveys user has already taken surveys = Survey.query.filter(Survey.survey_group_id == survey_groups.c.survey_group_id) \ .filter(Survey.expiry_date >= datetime.date.today()) \ .filter(Survey.id.notin_(surveys_taken_list)).all() return render_template('pages/home_survey_taker.html', surveys=surveys) elif current_user.is_survey_admin(): return render_template('pages/home_survey_admin.html') elif current_user.is_system_admin(): return render_template('pages/home_system_admin.html') return render_template('errors/404.html')