Skip to content

Commit

Permalink
fix: update no submission user list when they do submit
Browse files Browse the repository at this point in the history
If users submit standup after all the submissions are published, the
list of users who didn't submit the standup gets updated in the Slack
message when they do after the scheduled time. Without this, the list of
users would be stale if they do submit after the scheduled post of
submissions on the channel.

Fixes #25
  • Loading branch information
vipul-sharma20 committed Aug 16, 2021
1 parent 5ba8a75 commit 61ba186
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
5 changes: 2 additions & 3 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
ACTIVE,
INACTIVE,
NO_USER_ERROR_MESSAGE,
POST_PUBLISH_STATS,
NO_USER_SUBMIT_MESSAGE,
BUTTON_TRIGGER,
SLASH_COMMAND_TRIGGER,
BLOCK_SIZE,
Expand Down Expand Up @@ -162,10 +160,11 @@ def publish_standup(team_name):
)
)

no_submission_users = utils.post_publish_stat(users)
message_response = client.chat_postMessage(
channel=team.standup.publish_channel,
text="Standup complete",
blocks=[STANDUP_INFO_SECTION],
blocks=[STANDUP_INFO_SECTION] + utils.users_left_section(no_submission_users),
)

standup_thread = StandupThread(standup=standup,
Expand Down
37 changes: 35 additions & 2 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from sqlalchemy import and_

from app import app_cache, client
from app.models import Submission, PostSubmitActionEnum, User, Standup, StandupThread
from app.models import Submission, PostSubmitActionEnum, User, Standup, \
StandupThread, Team, db
from app.constants import (
STANDUP_INFO_SECTION,
STANDUP_SECTION_DIVIDER,
Expand Down Expand Up @@ -118,11 +119,15 @@ def after_submission(submission: Submission, is_edit: bool = False) -> None:
StandupThread.standup == submission.standup,
StandupThread.created_at >= todays_datetime,
)).first()

channel = submission.user.team[0].standup.publish_channel
client.chat_postMessage(
channel=submission.user.team[0].standup.publish_channel,
channel=channel,
thread_ts=thread.thread_id,
blocks=blocks,
)
update_users_left_info(channel, thread.thread_id,
submission.standup.team.id)

if not is_edit:
client.chat_postMessage(
Expand Down Expand Up @@ -423,3 +428,31 @@ def get_standup_view(standup: Standup) -> str:
standup_blocks["callback_id"] = standup.trigger

return json.dumps(standup_blocks)


# Get section to show users left for submission
def users_left_section(users: List[str]) -> List[Dict[str, Any]]:
return [{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": f"Didn't hear from: {', '.join(users)}"
}
]
}]


# Update users left message
def update_users_left_info(channel: str, thread_id: str, team_id: int) -> None:
# Get all active users for this team
users = (
db.session.query(User)
.join(Team.user)
.filter(Team.id == team_id, User.is_active)
)

no_submission_users = post_publish_stat(users)
client.chat_update(channel=channel,
ts=thread_id,
blocks=[STANDUP_INFO_SECTION] + users_left_section(no_submission_users))

0 comments on commit 61ba186

Please sign in to comment.