Ejemplo n.º 1
0
def add_trusted_contact(current_user):
    contact = User.get_by_username(request.get_json()['username'])
    if contact is not None:
        current_user.add_contact(contact)
        current_user.save()
        return ResponseCreator.response(
            'success',
            f'Added {contact.username} to trusted contacts',
            200
        )
    return ResponseCreator.response(
        'error',
        f'user: {contact.username} was not found',
        201
    )
Ejemplo n.º 2
0
def create_new_tab(current_user):
    tab_data = request.get_json()
    other_user = User.get_by_username(tab_data['otheruser'])
    if not other_user.id == current_user.id:
        new_tab = Tab(name=tab_data['name'], created_by_id=current_user.id)
        new_tab.save()

        current_user_tab_status = TabUserStatus(
            tab_id=new_tab.id,
            user_id=current_user.id,
            status=UserTabStatus.APPROVED,
        )
        other_user_tab_status = TabUserStatus(
            tab_id=new_tab.id, user_id=other_user.id
        )
        current_user_tab_status.save()
        other_user_tab_status.save()
        tab_view_data = create_tab_view_dictionary(new_tab, current_user_tab_status)
        return jsonify({'status': 'ok', 'created_tab': tab_view_data})
    else:
        return jsonify({'error': 'Currently, you cannot create a tab with yourself'})
Ejemplo n.º 3
0
def create_new_group_tab(current_user):
    tab_data = request.get_json()

    new_tab = Tab(name=tab_data['name'], created_by_id=current_user.id, is_group_tab=True)
    new_tab.save()
    #
    current_user_tab_status = TabUserStatus(
        tab_id=new_tab.id,
        user_id=current_user.id,
        status=UserTabStatus.APPROVED,
    )
    current_user_tab_status.save()
    users_in_group_tab = tab_data['otheruser'].split(',')

    for user in users_in_group_tab:
        other_user = User.get_by_username(user)
        other_user_tab_status = TabUserStatus(
            tab_id=new_tab.id, user_id=other_user.id
        )
        other_user_tab_status.save()

    tab_view_data = create_tab_view_dictionary(new_tab, current_user_tab_status)
    return jsonify({'status': 'ok', 'created_tab': tab_view_data})