Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Finalization message to use team name instead of 'Blank' #142

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/backend/app/models/slack_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class SlackOrganization(db.Model):
__tablename__ = "slack_organizations"
team_id = sa.Column(sa.String, primary_key=True)
team_name = sa.Column(sa.String, nullable=True)
team_name = sa.Column(sa.String, nullable=False)
enterprise_id = sa.Column(sa.String, nullable=True)
enterprise_name = sa.Column(sa.String, nullable=True)
app_id = sa.Column(sa.String, nullable=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ class FinalizationEventEventSchema(Schema):
restaurant_name = fields.Str(required=True)
slack_ids = fields.List(fields.Str(), required=True)
team_id = fields.Str(required=True)
team_name = fields.Str(required=True)
bot_token = fields.Str(required=True)
channel_id = fields.Str(required=True)
2 changes: 2 additions & 0 deletions application/backend/app/services/invitation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def _withdraw_invitation(self, rsvp, invitation, event):
'restaurant_name': restaurant.name,
'slack_ids': attending_users,
'team_id': event.slack_organization.team_id,
'team_name': event.slack_organization.team_name,
'bot_token': event.slack_organization.access_token,
'channel_id': event.slack_organization.channel_id
})
Expand Down Expand Up @@ -191,6 +192,7 @@ def _accept_invitation(self, invitation, event):
'restaurant_name': restaurant.name,
'slack_ids': [user[0] for user in InvitationRepository.get_attending_users(event.id)],
'team_id': event.slack_organization.team_id,
'team_name': event.slack_organization.team_name,
'bot_token': event.slack_organization.access_token,
'channel_id': event.slack_organization.channel_id
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""team name not nullable

Revision ID: ea2b97c97b55
Revises: 8c1b0067412f
Create Date: 2023-05-21 11:36:07.850828

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'ea2b97c97b55'
down_revision = '8c1b0067412f'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('slack_organizations', 'team_name',
existing_type=sa.VARCHAR(),
nullable=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('slack_organizations', 'team_name',
existing_type=sa.VARCHAR(),
nullable=True)
# ### end Alembic commands ###
2 changes: 2 additions & 0 deletions application/backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ def migrate(app, db):
def slack_organizations(app, db, migrate):
slack_organization1 = SlackOrganization(
team_id="testSlackOrganizationId1",
team_name="testSlackOrganization1",
access_token="dontCareBotToken",
channel_id="dontCareChannelId",
app_id="dontCareAppId",
bot_user_id="dontCareBotUserId"
)
slack_organization2 = SlackOrganization(
team_id="testSlackOrganizationId2",
team_name="testSlackOrganization2",
access_token="dontCareBotToken",
channel_id="dontCareChannelId",
app_id="dontCareAppId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def test_get_slack_installation(self, mock_broker, slack_organizations, rpc_queu
assert len(mock_broker.sync_send.call_args_list) == 1
assert mock_broker.sync_send.call_args_list[0].kwargs['body'] == {
'team_id': slack_organization.team_id,
'team_name': slack_organization.team_name,
'app_id': slack_organization.app_id,
'bot_user_id': slack_organization.bot_user_id,
'access_token': slack_organization.access_token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test_upsert(self, db, slack_organization_service):

new_slack_organization = SlackOrganization(
team_id="dontCareNewTeamId",
team_name="dontCareNewTeamName",
app_id="dontCareAppId",
bot_user_id="dontCareBotUserId",
access_token="dontCareAccessToken"
Expand Down
4 changes: 2 additions & 2 deletions application/bot/src/api/bot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def send_reminders(self):
else:
self.logger.warning("failed to update invitation")

def send_event_finalized(self, timestamp, restaurant_name, slack_ids, channel_id, slack_client):
def send_event_finalized(self, timestamp, restaurant_name, team_name, slack_ids, channel_id, slack_client):
self.logger.info("Finalizing event %s %s", timestamp, restaurant_name)
# Convert timestamp to Norwegian timestamp
timestamp = pytz.utc.localize(timestamp.replace(tzinfo=None), is_dst=None).astimezone(self.timezone)
Expand All @@ -158,7 +158,7 @@ def send_event_finalized(self, timestamp, restaurant_name, slack_ids, channel_id
# Send the finalization Slack message
slack_client.send_slack_message(
channel_id=channel_id,
text="Halloi! %s! Dere skal spise 🍕 på %s, %s. %s booker bord, og %s legger ut for maten. Blank betaler!" % (ids_string, restaurant_name, timestamp.strftime("%A %d. %B kl %H:%M"), booker, payer)
text="Halloi! %s! Dere skal spise 🍕 på %s, %s. %s booker bord, og %s legger ut for maten. %s betaler!" % (ids_string, restaurant_name, timestamp.strftime("%A %d. %B kl %H:%M"), booker, payer, team_name)
)

def send_event_unfinalized(self, timestamp, restaurant_name, slack_ids, channel_id, slack_client):
Expand Down
2 changes: 2 additions & 0 deletions application/bot/src/broker/handlers/finalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def withdraw_invitation(event: dict):
ba.send_event_finalized(
timestamp=event['timestamp'],
restaurant_name=event['restaurant_name'],
team_name=event["team_name"],
slack_ids=event['slack_ids'],
channel_id=event["channel_id"],
slack_client=slack_client
Expand All @@ -20,6 +21,7 @@ def withdraw_invitation(event: dict):
ba.send_event_unfinalized(
timestamp=event['timestamp'],
restaurant_name=event['restaurant_name'],
team_name=event["team_name"],
slack_ids=event['slack_ids'],
channel_id=event["channel_id"],
slack_client=slack_client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ class FinalizationEventEventSchema(Schema):
restaurant_name = fields.Str(required=True)
slack_ids = fields.List(fields.Str(), required=True)
team_id = fields.Str(required=True)
team_name = fields.Str(required=True)
bot_token = fields.Str(required=True)
channel_id = fields.Str(required=True)