def setUp(self):
        super().setUp()

        self.mitch = AppUser(phone_number=self.inviter_number,
                             username='******',
                             timezone=US_TIMEZONES['b'])
        self.db.session.add(self.mitch)

        self.billy = AppUser(phone_number=self.secondary_number,
                             username='******',
                             timezone=US_TIMEZONES['b'])
        self.db.session.add(self.billy)

        self.team = Team(founder=self.mitch, name='The Cherrys')
        self.db.session.add(self.team)

        self.mitch_member = TeamMember(user=self.mitch,
                                       team=self.team,
                                       inviter=self.mitch,
                                       status=Statuses.ACTIVE)
        self.db.session.add(self.mitch_member)

        self.billy_member = TeamMember(user=self.billy,
                                       team=self.team,
                                       inviter=self.mitch,
                                       status=Statuses.PENDING)
        self.db.session.add(self.billy_member)

        self.db.session.commit()

        self.mitch = self.mitch.to_dict()
        self.billy = self.billy.to_dict()
        self.team = self.team.to_dict()
Exemple #2
0
def team_members(app):
    with app.app_context():
        db.session.add(TeamMember(team_id=1, user_id=4, is_team_lead=True))

        db.session.add(TeamMember(team_id=1, user_id=5, is_team_lead=False))

        db.session.commit()

        yield db.session.query(TeamMember).all()
Exemple #3
0
    def setUp(self):
        super().setUp()
        # add a user
        self.mitch = AppUser(phone_number=self.inviter_number,
                             username='******',
                             timezone=US_TIMEZONES['b'])

        self.db.session.add(self.mitch)
        # self.db.session.add(self.blair)

        # add a notif
        self.notif = Notification(router=RouterNames.DID_YOU_DO_IT,
                                  hour=21,
                                  minute=0,
                                  active=True,
                                  user=self.mitch)

        self.db.session.add(self.notif)

        # add exchange
        self.exchange = Exchange(router=RouterNames.DID_YOU_DO_IT,
                                 outbound='Did you do it?',
                                 user=self.mitch,
                                 created=dt.datetime.now() -
                                 dt.timedelta(days=10))

        self.db.session.add(self.exchange)

        # add point
        self.point = Point(value=10, user=self.mitch)

        # add task
        self.task = Task(description='Win today',
                         due_date=dt.datetime.now(),
                         active=True,
                         exchange=self.exchange,
                         user=self.mitch)

        self.db.session.add(self.task)

        self.inteam = Team(id=TEST_TEAM_ID, founder=self.mitch, name='inteam')
        self.db.session.add(self.inteam)

        self.pendingteam = Team(founder=self.mitch, name='pendingteam')
        self.db.session.add(self.pendingteam)

        self.mitch_member = TeamMember(user=self.mitch,
                                       team=self.inteam,
                                       inviter=self.mitch,
                                       status=Statuses.ACTIVE)
        self.db.session.add(self.mitch_member)

        self.mitch_member2 = TeamMember(user=self.mitch,
                                        team=self.pendingteam,
                                        inviter=self.mitch,
                                        status=Statuses.PENDING)
        self.db.session.add(self.mitch_member2)
def team_members(client, app, buyer_user, teams):
    with app.app_context():
        db.session.add(TeamMember(id=1, team_id=1, user_id=buyer_user.id))

        db.session.commit()

        yield db.session.query(TeamMember).all()
def create_team():
    user = users.get(current_user.id)
    created_teams = team_service.get_teams_for_user(user.id, 'created')
    completed_teams = team_service.get_teams_for_user(user.id)

    if len(completed_teams) == 0:
        if len(created_teams) == 0:
            team = team_service.save(
                Team(name='',
                     status='created',
                     team_members=[
                         TeamMember(user_id=user.id, is_team_lead=True)
                     ]))

            audit_service.log_audit_event(audit_type=audit_types.create_team,
                                          data={},
                                          db_object=team,
                                          user=current_user.email_address)

            publish_tasks.team.delay(publish_tasks.compress_team(team),
                                     'created')

            return get_team(team.id)

        created_team = created_teams.pop()
        return get_team(created_team.id)
    else:
        team = completed_teams[0]
        raise TeamError(
            'You can only be in one team. You\'re already a member of {}.'.
            format(team.name))
    def test_team_fails_validation_when_member_is_in_another_team(
            self, users, user, teams, team, team_members):
        db.session.add(TeamMember(team_id=2, user_id=5, is_team_lead=True))

        errors = TeamValidator(team, user).validate_team_members()

        assert len(errors) == 1
        assert all(error['id'] in ['TM004'] for error in errors)
def team_members(client, app, team):
    with app.app_context():
        db.session.add(
            TeamMember(id=1, is_team_lead=True, team_id=1, user_id=3))

        db.session.commit()

        yield db.session.query(Team).all()
Exemple #8
0
def flumride_add_member(id):
    team = Team.get(id)
    assert team

    if request.method == 'POST':
        member = TeamMember()
        form = MemberForm(request.form)
        form.populate_obj(member)
        member.team = team
        db.session.add(member)
        db.session.commit()
        return redirect(url_for('flumride_teams', _anchor=member.team.id))
    else:
        form = MemberForm()
        return render_template("flumride/edit_member.html",
                               form=form,
                               title='Lägg till medlem')
Exemple #9
0
def flumride_teams():
    teams = db.session.query(Team)
    has_payed_arg = request.args.get('has_payed')
    if has_payed_arg is not None:
        has_payed = has_payed_arg == 'True'
        teams = teams.filter_by(has_payed=has_payed)
    ticket_info = [{
        'type': ticket_type['name'],
        'count': TeamMember.ticket_count_by_type(index)
    } for index, ticket_type in enumerate(app.config['FLUMRIDE']
                                          ['ticket_types'])]
    total = {
        'teams': teams.count(),
        'members': db.session.query(TeamMember).count(),
        'ticket_info': ticket_info,
        'non_members_sfs': TeamMember.not_sfs_count()
    }
    return render_template("flumride/teams.html",
                           teams=teams,
                           total=total,
                           has_payed=has_payed_arg)
Exemple #10
0
    def setUp(self):
        super().setUp()

        # the scenario is Mitch has received an invitation to a team
        # He has never used Bricks before
        self.inviter = AppUser(
            phone_number=self.inviter_number,
            username='******',
            timezone=US_TIMEZONES['b'])

        self.mitch = AppUser(
            phone_number=self.invitee_number,
            username='******',
            timezone=US_TIMEZONES['b'])

        self.team = Team(
            founder=self.inviter,
            name='The Cherrys')
        
        self.inviter_member = TeamMember(
            user=self.inviter,
            team=self.team,
            inviter=self.inviter,
            status=Statuses.ACTIVE)
        
        self.invitee_member = TeamMember(
            user=self.mitch,
            team=self.team,
            inviter=self.inviter,
            status=Statuses.PENDING)
        
        self.exchange = Exchange(
            user=self.mitch,
            router=InitOnboardingInvited.__name__)
        
        self.db.session.add(self.inviter)
        self.db.session.add(self.mitch)
        self.db.session.add(self.team)
        self.db.session.add(self.inviter_member)
        self.db.session.add(self.invitee_member)
Exemple #11
0
def insert_team(user, inbound, **kwargs):
    '''Create a new team with the user as the founder, and the inbound as the team name. 
     add this user to this team in TeamMember'''
    team = Team(founder_id=user['id'], name=inbound)

    member = TeamMember(user_id=user['id'],
                        team=team,
                        inviter_id=user['id'],
                        status=Statuses.ACTIVE)

    db.session.add(team)
    db.session.add(member)
    db.session.commit()

    print(f"USER {user['username']} CREATED TEAM {team.name}")
Exemple #12
0
def flumride_edit_member(id):
    member = TeamMember.get(id)
    assert member

    if request.method == 'POST':
        form = MemberForm(request.form)
        form.populate_obj(member)
        db.session.add(member)
        db.session.commit()
        return redirect(url_for('flumride_teams', _anchor=member.team.id))
    else:
        form = MemberForm(obj=member)
        return render_template("flumride/edit_member.html",
                               form=form,
                               title='Editera medlem')
Exemple #13
0
def insert_member(user, inbound, init_onboarding_invited, you_were_invited,
                  **kwargs):
    '''Add member to the given team as PENDING. 
    Inbound should already be parsed as tuple(team_id, phone_number_str)'''

    team_id, phone_number = inbound

    # confirm that user is part of team
    team = db.session.query(Team).join(TeamMember).filter(
        Team.id == team_id, TeamMember.user_id == user['id'],
        TeamMember.status == Statuses.ACTIVE).one()

    # confirm that this team is open
    open_team_ids = get_open_teams(user, id_only=True)
    assert team.id in open_team_ids

    # lookup the phone-number, add if not already a user
    invited_user = tools.query_user_with_number(phone_number)

    # insert invitee into db
    invited_member = TeamMember(user_id=invited_user['id'],
                                team_id=team_id,
                                inviter_id=user['id'],
                                status=Statuses.PENDING)

    db.session.add(invited_member)
    db.session.commit()

    # send invitation to invitee
    # you need to get the right router
    # you should trigger a new router, but does that

    exchange = tools.query_last_exchange(invited_user)
    if exchange is None or invited_user['username'] == Reserved.NEW_USER:
        router = init_onboarding_invited()
    else:
        router = you_were_invited()

    results = router.run_pre_actions(user=invited_user,
                                     exchange=exchange,
                                     inviter=user)

    router.outbound = router.outbound.format(**results)

    tools.send_message(invited_user, router.outbound)

    # record the fact that this invitation was sent to a user
    tools.insert_exchange(router, invited_user)
Exemple #14
0
def insert_team_beta(user, name, **kwargs):
    '''Create a new team with the user as the founder. 
     add this user to this team in TeamMember'''
    team = Team(founder_id=user.id, name=name)

    member = TeamMember(user_id=user.id,
                        team=team,
                        inviter_id=user.id,
                        status=Statuses.ACTIVE)

    db.session.add(team)
    db.session.add(member)
    db.session.commit()
    db.session.close()

    return team
Exemple #15
0
def post(user):
    """check if code matches a team. if yes, join the team, and return team"""

    data = request.get_json()

    try:
        team = decode(data["code"])
    except Exception:
        message = f"The code {data['code']} was not accepted. Please try again."
        print(message)
        return make_response(jsonify({"message": message}), 400)

    # ensure user is not already on team
    already_team_member = db.session.query(TeamMember).filter(
        TeamMember.user == user, TeamMember.team == team).all()

    if len(already_team_member) > 0:
        message = f"You are already a team member of {team.name}."
        print(message)
        return make_response(jsonify({"message": message}), 400)

    # add user to team
    team_member = TeamMember(
        user=user,
        team=team,
        inviter=
        user,  # TODO you can only correct this if you make codes specific
        status=Statuses.ACTIVE)

    db.session.add(team_member)
    db.session.commit()

    # return team
    team_dict = {
        "name": team.name,
        "team_id": team.id,
        "founder_id": team.founder_id
    }
    db.session.close()

    return make_response(jsonify(team_dict), 200)
Exemple #16
0
def get_number_of_tickets_for_this_type_left(ticket_type):
    max_number_of_tickets = app.config['FLUMRIDE']['ticket_types'][
        ticket_type]['max_nr']
    return max_number_of_tickets - TeamMember.ticket_count_by_type(ticket_type)
def update_team_leads_and_members(team, data):
    incoming_team_leads = data.get('teamLeads', {})
    incoming_team_members = data.get('teamMembers', {})

    incoming_team_lead_ids = []
    if incoming_team_leads:
        incoming_team_lead_ids = [
            int(team_lead_id) for team_lead_id in incoming_team_leads
        ]

    incoming_team_member_ids = []
    if incoming_team_members:
        incoming_team_member_ids = [
            int(team_member_id) for team_member_id in incoming_team_members
        ]

    # set any active join requests for the incoming users to this team as approved and done
    incoming_user_emails = []
    for user_id in incoming_team_lead_ids + incoming_team_member_ids:
        user = users.get_by_id(user_id)
        if user:
            incoming_user_emails.append(user.email_address)
    for email_address in incoming_user_emails:
        clear_all_join_requests(email_address, team.id)

    current_team_members = [tm.user_id for tm in team.team_members]
    new_team_leads = []
    new_team_members = []
    removed_team_members = []

    for tm in team.team_members:
        if tm.user_id in incoming_team_lead_ids:
            if tm.is_team_lead is False:
                tm.is_team_lead = True
                new_team_leads.append(tm.user_id)

        if tm.user_id in incoming_team_member_ids:
            if tm.is_team_lead is True:
                tm.is_team_lead = False

        if tm.user_id not in incoming_team_lead_ids + incoming_team_member_ids:
            removed_team_members.append(tm.user_id)

    for user_id in removed_team_members:
        team_member = team_member_service.find(team_id=team.id,
                                               user_id=user_id).one_or_none()

        if team_member:
            team.team_members.remove(team_member)

    for user_id in incoming_team_lead_ids:
        if user_id not in current_team_members:
            team.team_members.append(
                TeamMember(team_id=team.id, user_id=user_id,
                           is_team_lead=True))
            new_team_leads.append(user_id)

    for user_id in incoming_team_member_ids:
        if user_id not in current_team_members:
            team.team_members.append(
                TeamMember(team_id=team.id,
                           user_id=user_id,
                           is_team_lead=False))
            new_team_members.append(user_id)

    return {
        'new_team_leads': new_team_leads,
        'new_team_members': new_team_members,
        'removed_team_members': removed_team_members
    }
def update_team_leads_and_members(team, data):
    incoming_team_leads = data.get('teamLeads', {})
    incoming_team_members = data.get('teamMembers', {})

    incoming_team_lead_ids = []
    if incoming_team_leads:
        incoming_team_lead_ids = [int(team_lead_id) for team_lead_id in incoming_team_leads]

    incoming_team_member_ids = []
    if incoming_team_members:
        incoming_team_member_ids = [int(team_member_id) for team_member_id in incoming_team_members]

    current_team_members = [tm.user_id for tm in team.team_members]
    new_team_leads = []
    new_team_members = []
    removed_team_members = []

    for tm in team.team_members:
        if tm.user_id in incoming_team_lead_ids:
            if tm.is_team_lead is False:
                tm.is_team_lead = True
                new_team_leads.append(tm.user_id)

        if tm.user_id in incoming_team_member_ids:
            if tm.is_team_lead is True:
                tm.is_team_lead = False

        if tm.user_id not in incoming_team_lead_ids + incoming_team_member_ids:
            removed_team_members.append(tm.user_id)

    for user_id in removed_team_members:
        team_member = team_member_service.find(
            team_id=team.id,
            user_id=user_id
        ).one_or_none()

        if team_member:
            team.team_members.remove(team_member)

    for user_id in incoming_team_lead_ids:
        if user_id not in current_team_members:
            team.team_members.append(
                TeamMember(
                    team_id=team.id,
                    user_id=user_id,
                    is_team_lead=True
                )
            )
            new_team_leads.append(user_id)

    for user_id in incoming_team_member_ids:
        if user_id not in current_team_members:
            team.team_members.append(
                TeamMember(
                    team_id=team.id,
                    user_id=user_id,
                    is_team_lead=False
                )
            )
            new_team_members.append(user_id)

    return {
        'new_team_leads': new_team_leads,
        'new_team_members': new_team_members,
        'removed_team_members': removed_team_members
    }
    def setUp(self):
        super().setUp()

        self.mitch = AppUser(
            phone_number=self.inviter_number, 
            username='******',
            timezone=US_TIMEZONES['b'])
        self.db.session.add(self.mitch)

        self.billy = AppUser(
            phone_number=self.secondary_number, 
            username='******',
            timezone=US_TIMEZONES['b'])
        self.db.session.add(self.billy)

        self.jonah = AppUser(
            phone_number=self.third_number, 
            username='******',
            timezone=US_TIMEZONES['b'])
        self.db.session.add(self.jonah)

        self.allie = AppUser(
            phone_number=self.fourth_number, 
            username='******',
            timezone=US_TIMEZONES['b'])
        self.db.session.add(self.allie)

        self.winnie = AppUser(
            phone_number=self.fifth_number, 
            username='******',
            timezone=US_TIMEZONES['b'])
        self.db.session.add(self.winnie)

        self.full_team = Team(
            founder = self.mitch,
            name = 'The Fulls')
        self.db.session.add(self.full_team)

        self.open_team = Team(
            founder = self.mitch,
            name = 'The Opens')
        self.db.session.add(self.open_team)

        self.mitch_member = TeamMember(
            user = self.mitch,
            team = self.full_team,
            inviter = self.mitch,
            status = Statuses.ACTIVE)       
        self.db.session.add(self.mitch_member)

        self.mitch_member_2 = TeamMember(
            user = self.mitch,
            team = self.open_team,
            inviter = self.mitch,
            status = Statuses.ACTIVE)       
        self.db.session.add(self.mitch_member_2)

        self.billy_member = TeamMember(
            user = self.billy,
            team = self.full_team,
            inviter = self.mitch,
            status = Statuses.ACTIVE)       
        self.db.session.add(self.billy_member)

        self.jonah_member = TeamMember(
            user = self.jonah,
            team = self.full_team,
            inviter = self.mitch,
            status = Statuses.ACTIVE)       
        self.db.session.add(self.jonah_member)

        self.allie_member = TeamMember(
            user = self.allie,
            team = self.full_team,
            inviter = self.mitch,
            status = Statuses.ACTIVE)       
        self.db.session.add(self.allie_member)

        self.winnie_member = TeamMember(
            user = self.winnie,
            team = self.full_team,
            inviter = self.mitch,
            status = Statuses.ACTIVE)       
        self.db.session.add(self.winnie_member)

        self.db.session.commit()

        self.mitch = self.mitch.to_dict()
        self.billy = self.billy.to_dict()
Exemple #20
0
def get_number_of_non_sfs_left():
    max_nr_of_not_sfs = app.config['FLUMRIDE']['MAX_NR_OF_NOT_SFS']
    nr_of_not_sfs = TeamMember.not_sfs_count()
    return max_nr_of_not_sfs - nr_of_not_sfs
Exemple #21
0
#!/usr/bin/env python

from app.models import Mod, TeamMember, TEAM_OWNER

print('Starting...')

for mod in Mod.objects:
    if len(mod.team) == 0 and len(mod.members) > 0:
        print(mod.title)

        for mem in mod.members:
            mod.team.append(TeamMember(user=mem, role=TEAM_OWNER))

        mod.members = []
        mod.save()

print('Done')