コード例 #1
0
def update_sheet_status(google_id, event):

    if event == 'Request Public':
        permission_level = ue.check_user_role(session['au_id'])
        if permission_level == 'Super User':
            event = "Make Public"

    sheet_id = db_session.query(sheet.s_id).filter_by(s_google_id=google_id).scalar()
    action_type_id = db_session.query(sheet_action_type.sat_id).filter_by(sat_type_name=event).scalar()

    new_event = sheet_action(
        sa_au_id=session['au_id'],
        sa_s_id=sheet_id,
        sa_sat_id=action_type_id,
        sa_timestamp=datetime.utcnow()
    )
    db_session.add(new_event)
    db_session.commit()

    new_status = (db_session.query(sheet_status.ss_status_name)
                            .filter(sheet.s_ss_id == sheet_status.ss_id)
                            .filter(sheet.s_google_id == google_id)
                            .first())

    return new_status
コード例 #2
0
ファイル: views.py プロジェクト: vladimiriii/open-flashcards
def terms_and_conditions_page():
    try:
        if 'au_id' in session:
            permission_level = ue.check_user_role(session['au_id'])
        else:
            permission_level = 'Guest'
        return render_template('terms-conditions.html', value=permission_level)
    except:
        print(utils.generate_error_message(sys.exc_info()))
        return redirect(url_for('basic_page.general_error_page'))
コード例 #3
0
ファイル: views.py プロジェクト: vladimiriii/open-flashcards
def create_flashcards_page():
    try:
        if 'au_id' in session:
            permission_level = ue.check_user_role(session['au_id'])
            return render_template('create-flashcards.html', value=permission_level)
        else:
            return redirect(url_for('basic_page.landing_page'))
    except:
        print(utils.generate_error_message(sys.exc_info()))
        return redirect(url_for('basic_page.general_error_page'))
コード例 #4
0
ファイル: views.py プロジェクト: vladimiriii/open-flashcards
def oauth2callback():
    try:
        pl.handle_callback()
        uu.update_user_info()
        user_blocked = ue.check_user_role(session['au_id']) == 'Blocked'
        if user_blocked:
            session.clear()
            return redirect(url_for('basic_page.account_suspended_page'))
        else:
            return redirect(url_for('internal_page.dashboard_page'))
    except:
        print(utils.generate_error_message(sys.exc_info()))
        return redirect(url_for('basic_page.general_error_page'))
コード例 #5
0
ファイル: views.py プロジェクト: vladimiriii/open-flashcards
def get_user_list():
    if 'au_id' in session:
        permission_level = ue.check_user_role(session['au_id'])
        if permission_level == 'Super User':
            raw_data = ue.get_user_data()
        else:
            raw_data = None
    else:
        raw_data = None

    table_data = utils.process_table_data(raw_data)

    return jsonify(table_data)
コード例 #6
0
ファイル: views.py プロジェクト: vladimiriii/open-flashcards
def get_student_list():
    if 'au_id' in session:
        permission_level = ue.check_user_role(session['au_id'])
        if permission_level in ['Super User', 'Teacher']:
            raw_data = ue.get_student_data(session['au_id'])
        else:
            raw_data = None
    else:
        raw_data = None

    table_data = utils.process_table_data(raw_data)

    return jsonify(table_data)
コード例 #7
0
ファイル: views.py プロジェクト: vladimiriii/open-flashcards
def sheet_management_page():
    try:
        if 'au_id' in session:
            permission_level = ue.check_user_role(session['au_id'])
            if permission_level == 'Super User':
                return render_template('sheet-management.html')
            else:
                return redirect(url_for('internal_page.dashboard_page'))
        else:
            return redirect(url_for('basic_page.landing_page'))
    except:
        print(utils.generate_error_message(sys.exc_info()))
        return redirect(url_for('basic_page.general_error_page'))
コード例 #8
0
ファイル: views.py プロジェクト: vladimiriii/open-flashcards
def dashboard_page():
    try:
        if 'au_id' in session:
            permission_level = ue.check_user_role(session['au_id'])
            if permission_level == 'Blocked':
                session.clear()
                return redirect(url_for('basic_page.account_suspended_page'))
            else:
                return render_template('dashboard.html', value=permission_level)
        else:
            return redirect(url_for('basic_page.landing_page'))
    except:
        print(utils.generate_error_message(sys.exc_info()))
        return redirect(url_for('basic_page.general_error_page'))
コード例 #9
0
ファイル: views.py プロジェクト: vladimiriii/open-flashcards
def show_blog(sheet_id):
    try:
        if 'au_id' in session:
            permission_level = ue.check_user_role(session['au_id'])
            if permission_level == 'Blocked':
                session.clear()
                return redirect(url_for('basic_page.account_suspended_page'))
        else:
            permission_level = 'Guest'

        return render_template('flashcards-template.html', sheet_id=sheet_id, permission_level=permission_level)
    except:
        print(utils.generate_error_message(sys.exc_info()))
        return redirect(url_for('basic_page.general_error_page'))
コード例 #10
0
ファイル: views.py プロジェクト: vladimiriii/open-flashcards
def process_update_user_role_request():
    input = json.loads(request.data)
    user_id = int(input['userId'])
    event = input['event']

    result = {}
    if 'au_id' in session:
        permission_level = ue.check_user_role(session['au_id'])
        if permission_level == 'Super User':
            result['event'] = uu.update_user_role(user_id=user_id, event=event)
        else:
            result['event'] = "Unauthorized Access"
    else:
        result['event'] = "Unauthorized Access"

    return jsonify(result)
コード例 #11
0
ファイル: views.py プロジェクト: vladimiriii/open-flashcards
def get_sheet_lists():
    data_type = request.args['table']
    if data_type == "publicSheets":
        raw_data = se.get_public_sheets()
    elif data_type == "userSheets" and 'au_id' in session:
        raw_data = se.get_user_sheets(session['au_id'])
    elif data_type == "requestSheets" and 'au_id' in session:
        permission_level = ue.check_user_role(session['au_id'])
        if permission_level == 'Super User':
            raw_data = se.get_request_sheets()
    else:
        raw_data = None

    table_data = utils.process_table_data(raw_data)

    return jsonify(table_data)
コード例 #12
0
def import_new_sheet(google_id):
    response = {}
    current_sheet = sheet.query.filter_by(s_google_id=google_id).first()
    user_role = ue.check_user_role(session['au_id'])

    try:
        metadata = se.get_sheet_metadata(google_id)
        owner_role = ue.check_user_role_by_email(metadata['owner_email'])

        paid_user = user_role in ['Graduate', 'Teacher', 'Super User']
        user_is_owner = metadata['is_owner']
        owner_is_teacher = owner_role in ['Teacher', 'Super User']
        if paid_user or user_is_owner or owner_is_teacher:
            if current_sheet is None:
                sheet_id = add_new_sheet_entry(metadata)
            else:
                sheet_id = current_sheet.s_id
                update_sheet_metadata(sheet_id)

            sheet_rel_user = app_user_rel_sheet.query.filter_by(aurs_s_id=sheet_id, aurs_au_id=session['au_id']).first()
            if sheet_rel_user is None:
                add_new_user_rel_sheet_entry(sheet_id, metadata['is_owner'])
                response['status'] = 'sheet_imported'
            else:
                response['status'] = 'sheet_already_imported'

            response['sheetId'] = str(sheet_id)
        else:
            response['status'] = 'upgrade_needed'

    except HttpError as e:
        if e.resp.status == 404:
            response['status'] = 'sheet_not_exist'
        elif e.resp.status == 400:
            response['status'] = 'invalid_url'

    return response
コード例 #13
0
ファイル: views.py プロジェクト: vladimiriii/open-flashcards
def process_check_user_role_request():
    if 'au_id' in session:
        permission_level = ue.check_user_role(session['au_id'])
    else:
        permission_level = "Guest"
    return jsonify({"role": permission_level})