@wraps(f)
def decorated_function(*args, **kwargs):
    '\n        Decorator to check if the user is allowed access to the app.\n        If user is allowed, return the decorated function.\n        Otherwise, return an error page with corresponding message.\n        '
    canvas_user_id = session.get('canvas_user_id')
    lti_logged_in = session.get('lti_logged_in', False)
    if ((not lti_logged_in) or (not canvas_user_id)):
        return render_template('error.html', message='Not allowed!')
    if ('course_id' not in kwargs.keys()):
        return render_template('error.html', message='No course_id provided.')
    course_id = int(kwargs.get('course_id'))
    if (not session.get('is_admin', False)):
        enrollments_url = '{}courses/{}/enrollments'.format(config.API_URL, course_id)
        payload = {'user_id': canvas_user_id, 'type': ['TeacherEnrollment', 'TaEnrollment', 'DesignerEnrollment']}
        user_enrollments_response = requests.get(enrollments_url, data=json.dumps(payload), headers=json_headers)
        user_enrollments = user_enrollments_response.json()
        if ((not user_enrollments) or ('errors' in user_enrollments)):
            message = 'You are not enrolled in this course as a Teacher, TA, or Designer.'
            return render_template('error.html', message=message)
    return f(*args, **kwargs)
Decorator to check if the user is allowed access to the app.
If user is allowed, return the decorated function.
Otherwise, return an error page with corresponding message.
@wraps(f)
def decorated_function(*args, **kwargs):
    '\n        Decorator to check if the user is allowed access to the app.\n        If user is allowed, return the decorated function.\n        Otherwise, return an error page with corresponding message.\n        '
    canvas_user_id = session.get('canvas_user_id')
    lti_logged_in = session.get('lti_logged_in', False)
    if ((not lti_logged_in) or (not canvas_user_id)):
        return render_template('error.html', message='Not allowed!')
    if ('course_id' not in kwargs.keys()):
        return render_template('error.html', message='No course_id provided.')
    course_id = int(kwargs.get('course_id'))
    if (not session.get('is_admin', False)):
        enrollments_url = '{}courses/{}/enrollments'.format(config.API_URL, course_id)
        payload = {'user_id': canvas_user_id, 'type': ['TeacherEnrollment', 'TaEnrollment', 'DesignerEnrollment']}
        user_enrollments_response = requests.get(enrollments_url, data=json.dumps(payload), headers=json_headers)
        user_enrollments = user_enrollments_response.json()
        if ((not user_enrollments) or ('errors' in user_enrollments)):
            message = 'You are not enrolled in this course as a Teacher, TA, or Designer.'
            return render_template('error.html', message=message)
    return f(*args, **kwargs)