Ejemplo n.º 1
0
def update_group(id, user=None):
    """Update a group"""
    try:
        data = json.loads(request.body.read())
        login = user.to_json().get('login')
        if data.get('invitation'):
            invitation_type = data.get('invitation')
            return GroupView().handle_invitation(id, login, invitation_type)
        if data.get('beer_call'):
            return GroupView().new_beer_call(id)
        if data.get('location_permission'):
            permission = bool(data.get('location_permission'))
            return GroupView().update_permission_location(id, login, permission)
        if data.get('location_sent'):
            try:
                location = Location(data.get('location_sent'))
            except Error as e:
                return Error('Wrong location attribute', 400)
            if GroupView().user_allow_location(id, user.to_json().get('login')):
                return GroupView().update_location(user.to_json().get('login'), location, id)
            else:
                return Error('User do not allow location', 403)

    except Exception as e:
        return e
Ejemplo n.º 2
0
def delete_group(id, user=None):
    """deletes a group if owner"""
    try:
        data = json.loads(request.body.read())
        login = user.to_json().get('login')
        if data.get('invitation'):
            invitation_type = data.get('invitation')
            return GroupView().handle_invitation(id, login, invitation_type)
        if data.get('delete'):
            return GroupView().delete(id, login)

    except Exception as e:
        return e
Ejemplo n.º 3
0
def get_group_infos(id, user=None):
    """get group and list users from id group"""
    try:
        return GroupView().get(id)

    except Exception as e:
        return e
Ejemplo n.º 4
0
def get_groups(user=None):
    """get groups from login"""
    try:
        return GroupView().list(user.to_json().get('login'))

    except Exception as e:
        return e
Ejemplo n.º 5
0
def get_group_infos(id, user=None):
    """get group and list users from id group"""
    try:
        login = user.to_json().get('login')
        return GroupView(login).get(id)

    except Exception as e:
        return e
Ejemplo n.º 6
0
def update_group(id, user=None):
    """Update group and retrieve one group"""
    try:
        data = json.loads(request.body.read())
        login = user.to_json().get('login')
        if data.get('invitation'):
            invitation_type = data.get('invitation')
            return GroupView(login).handle_invitation(id, login,
                                                      invitation_type)
        if data.get('beer_call'):
            return GroupView(login).new_beer_call(id, data)
        if 'location_permission' in data:
            print('oui')
            permission = bool(data.get('location_permission'))
            return GroupView(login).update_permission_location(
                id, login, permission)
        if data.get('list_login'):
            #send invitations
            login_list = data.get('list_login')
            GroupView(login).add_to_group(id, login_list=login_list)
            return GroupView(login).get(id)
        if data.get('to_remove'):
            GroupView(login).remove_from_group(id,
                                               data.get('to_remove'),
                                               owner=login)
            return GroupView(login).get(id)
    except Exception as e:
        return e
Ejemplo n.º 7
0
def send_invitation(id, user=None):
    """send invitation to user/s for a group"""
    try:
        data = json.loads(request.body.read())
        if not data.get('list_login'):
            return Error('No login provided - invitation is cancelled', 400)
        login_list = data.get('list_login')
        return GroupView().add_to_group(id, login_list=login_list)

    except Exception as e:
        return e
Ejemplo n.º 8
0
def create_group(user=None):
    """création d'un groupe"""
    try:
        data = json.loads(request.body.read())
        if not data.get('name'):
            return Error('Please provide a name', 400)
        name = data.get('name')
        owner = user.to_json().get('login')
        list_login = data.get('list_login')
        return GroupView(owner).create(name, owner, list_login)

    except Exception as e:
        return e