Exemple #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
Exemple #2
0
def check_user_role_by_email(email):
    user_role = (db_session.query(
        app_user, app_user_role).filter(app_user.au_email == email).filter(
            app_user.au_aur_id == app_user_role.aur_id).first()
                 ).app_user_role.aur_role_name

    return user_role
Exemple #3
0
def check_user_role(au_id):
    user_role = (db_session.query(
        app_user, app_user_role).filter(app_user.au_id == au_id).filter(
            app_user.au_aur_id == app_user_role.aur_id).first()
                 ).app_user_role.aur_role_name

    return user_role
Exemple #4
0
def check_sheet_is_public(sheet_id):

    status = (db_session.query(sheet_status.ss_status_name).filter(
        sheet.s_ss_id == sheet_status.ss_id).filter(
            sheet.s_id == sheet_id).scalar())
    if status == 'Public':
        return True
    else:
        return False
def update_user_role(user_id, event):

    action_type_id = db_session.query(app_user_action_type.auat_id).filter_by(auat_type_name=event).scalar()

    new_event = app_user_action(
        aua_auat_id=action_type_id,
        aua_initiator_au_id=session['au_id'],
        aua_impacted_au_id=user_id,
        aua_timestamp=datetime.utcnow()
    )
    db_session.add(new_event)
    db_session.commit()

    return event
Exemple #6
0
def update_sheet_metadata(sheet_id):

    google_id = db_session.query(sheet.s_google_id).filter_by(s_id=sheet_id).scalar()
    metadata = se.get_sheet_metadata(google_id)

    # Update sheet record with latest metadata
    sheet_record = sheet.query.filter_by(s_id=sheet_id).first()
    sheet_record.s_sheet_name = metadata['sheet_name']
    sheet_record.s_owner_name = metadata['owner_name']
    sheet_record.s_owner_email = metadata['owner_email']
    sheet_record.s_row_count = metadata['row_count']
    sheet_record.s_sheet_last_modified = metadata['last_modified']
    sheet_record.s_last_modifed = datetime.utcnow()

    # Commit changes to the database
    db_session.commit()
Exemple #7
0
def add_new_sheet_entry(metadata):
    status_id = db_session.query(sheet_status.ss_id).filter_by(ss_status_name='Private').first()
    sheet_record = sheet(s_ss_id=status_id,
                         s_google_id=metadata['google_id'],
                         s_sheet_name=metadata['sheet_name'],
                         s_owner_name=metadata['owner_name'],
                         s_owner_email=metadata['owner_email'],
                         s_row_count=metadata['row_count'],
                         s_sheet_created=metadata['created_date'],
                         s_sheet_last_modified=metadata['last_modified'],
                         s_created=datetime.utcnow(),
                         s_last_modified=datetime.utcnow(),
                         )
    db_session.add(sheet_record)
    db_session.commit()

    return sheet_record.s_id
Exemple #8
0
def add_sheet_view(sheet_id):
    if 'au_id' in session:
        view_record = view(v_au_id=session['au_id'],
                           v_s_id=sheet_id,
                           v_timestamp=datetime.now())
    else:
        guest_user_id = (db_session.query(app_user.au_id)
                                   .filter(app_user.au_aur_id == app_user_role.aur_id)
                                   .filter(app_user_role.aur_role_name == "Guest")
                                   .scalar())
        view_record = view(v_au_id=guest_user_id,
                           v_s_id=sheet_id,
                           v_timestamp=datetime.now())

    # Save to Database
    db_session.add(view_record)
    db_session.commit()

    return view_record.v_id
def update_user_info():
    profile_info = get_profile_info()
    email = profile_info['email']
    first_name = profile_info['given_name']
    last_name = profile_info['family_name']
    current_user = app_user.query.filter_by(au_email=email).first()

    if current_user is None:
        role_id = db_session.query(app_user_role.aur_id).filter_by(aur_role_name='Undergraduate').first()
        current_user = app_user(
            au_aur_id=role_id,
            au_email=email,
            au_first_name=first_name,
            au_last_name=last_name,
            au_created=datetime.utcnow(),
            au_last_modified=datetime.utcnow(),
        )
        db_session.add(current_user)
        db_session.commit()
    else:
        current_user.au_last_modified = datetime.utcnow()
        db_session.commit()

    session['au_id'] = current_user.au_id
Exemple #10
0
def get_google_id(sheet_id):

    google_id = db_session.query(
        sheet.s_google_id).filter_by(s_id=sheet_id).scalar()

    return google_id