Skip to content

Commit 7757bf3

Browse files
committed
Notify on setting up one on ones
1 parent 85d07f0 commit 7757bf3

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

snowflake/controllers/notifications.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def build_redirect(notification: Notification):
1414
elif notification.type == TYPE_COMMENT_ON_APPRECIATION_RECEIVED \
1515
or notification.type == TYPE_COMMENT_ON_APPRECIATION_GIVEN:
1616
return url_for('index.index') + f"#appreciation-{notification.object.appreciation.id}"
17+
elif notification.type == TYPE_ONE_ON_ONE_SETUP or TYPE_ONE_ON_ONE_ACTION_ITEM_ADDED:
18+
return url_for('one_on_one.one_on_one', _id=notification.object.id)
1719

1820

1921
@login_required

snowflake/controllers/one_on_one.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from snowflake.forms import OneOnOneForm, OneOnOneActionItemForm, OneOnOneActionItemStateChange
55
from snowflake.models import User, OneOnOne, OneOnOneActionItem
6+
from snowflake.services import notification
67

78
blueprint = Blueprint('one_on_one', __name__)
89

@@ -21,6 +22,9 @@ def one_on_one(_id):
2122
if user is not None:
2223
o = OneOnOne(user=user, created_by=current_user)
2324
OneOnOne.create(o)
25+
26+
notification.notify_one_on_one_setup(o)
27+
2428
return redirect(url_for("one_on_one.one_on_one"))
2529
else:
2630
form.user.errors.append("User not found")
@@ -47,6 +51,8 @@ def one_on_one_action_item():
4751

4852
OneOnOneActionItem.create(action_item)
4953

54+
notification.notify_one_on_one_action_item_added(action_item)
55+
5056
return redirect(f'/1-on-1s/{form.one_on_one.data}')
5157

5258

snowflake/models/notification.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from . import Comment
22
from .appreciation import Appreciation
3+
from .one_on_one import OneOnOne
34
from .user import User
45
from ..db import db
56

67
TYPE_APPRECIATION = "appreciation"
8+
TYPE_ONE_ON_ONE_SETUP = "one_on_one_setup"
9+
TYPE_ONE_ON_ONE_ACTION_ITEM_ADDED = "one_on_one_action_item_added"
710
TYPE_COMMENT_ON_APPRECIATION_RECEIVED = "comment_on_appreciation_received"
811
TYPE_COMMENT_ON_APPRECIATION_GIVEN = "comment_on_appreciation_given"
912
TYPE_COMMENT_ON_APPRECIATION_COMMENTED = "comment_on_appreciation_commented"
@@ -47,5 +50,7 @@ def object(self):
4750
return Appreciation.get(int(self.object_id))
4851
elif self.type == TYPE_COMMENT_ON_APPRECIATION_GIVEN or self.type == TYPE_COMMENT_ON_APPRECIATION_RECEIVED:
4952
return Comment.get(int(self.object_id))
53+
elif self.type == TYPE_ONE_ON_ONE_SETUP or self.type == TYPE_ONE_ON_ONE_ACTION_ITEM_ADDED:
54+
return OneOnOne.get(self.object_id)
5055

5156
return None

snowflake/services/notification.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from flask_login import current_user
55

66
from ..db import transaction
7+
from ..models import OneOnOneActionItem
78
from ..models.notification import *
89

910

@@ -39,3 +40,23 @@ def notify_comment(c: Comment):
3940
if user_id != current_user.id:
4041
db.session.add(Notification(created_at=now, user_id=user_id, type=notification_type,
4142
object_id=str(c.id)))
43+
44+
45+
def notify_one_on_one_setup(o: OneOnOne):
46+
with transaction():
47+
db.session.add(Notification(created_at=datetime.now(),
48+
user_id=o.user_id,
49+
type=TYPE_ONE_ON_ONE_SETUP,
50+
object_id=str(o.id)))
51+
52+
53+
def notify_one_on_one_action_item_added(action_item: OneOnOneActionItem):
54+
with transaction():
55+
user_id = action_item.one_on_one.user_id \
56+
if action_item.one_on_one.created_by_id == current_user.id else \
57+
action_item.one_on_one.created_by_id
58+
59+
db.session.add(Notification(created_at=datetime.now(),
60+
user_id=user_id,
61+
type=TYPE_ONE_ON_ONE_ACTION_ITEM_ADDED,
62+
object_id=str(action_item.one_on_one.id)))

snowflake/templates/notifications.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ <h2 class="is-size-2 is-bold">Your notifications</h2>
2222
<span>{{ notification.object.user.name }} commented on an appreciation you have given</span>
2323
{% elif notification.type == "comment_on_appreciation_commented" %}
2424
<span>{{ notification.object.user.name }} also commented on an appreciation you commented</span>
25+
{% elif notification.type == "one_on_one_setup" %}
26+
<span>{{ notification.object.created_by.name }} setup an one on one with you</span>
27+
{% elif notification.type == "one_on_one_action_item_added" %}
28+
{% if notification.object.created_by_id == current_user.id %}
29+
<span>{{ notification.object.user.name }} added an action item to your one on one</span>
30+
{% else %}
31+
<span>{{ notification.object.created_by.name }} added an action item to your one on one</span>
32+
{% endif %}
2533
{% endif %}
2634
<span class="help">
2735
<time datetime="{{ notification.created_at | iso_time }}">{{ notification.created_at | humanize_time }}</time>

0 commit comments

Comments
 (0)