Skip to content

Commit 60d4135

Browse files
committed
Add command to manifest and fix bugs
1 parent 9f79456 commit 60d4135

File tree

7 files changed

+62
-20
lines changed

7 files changed

+62
-20
lines changed

backend/apps/nest/controllers/calendar_events.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ def schedule_reminder(
1616
reminder: Reminder,
1717
scheduled_time: timezone.datetime,
1818
recurrence=ReminderSchedule.Recurrence.ONCE,
19-
):
19+
) -> ReminderSchedule:
2020
"""Schedule a reminder."""
2121
if scheduled_time < timezone.now():
2222
message = "Scheduled time must be in the future."
2323
raise ValidationError(message)
2424
if recurrence not in ReminderSchedule.Recurrence.values:
2525
message = "Invalid recurrence value."
2626
raise ValidationError(message)
27-
ReminderSchedule.objects.create(
27+
return ReminderSchedule.objects.create(
2828
reminder=reminder,
2929
scheduled_time=scheduled_time,
3030
recurrence=recurrence,
@@ -38,7 +38,7 @@ def set_reminder(
3838
minutes_before: int,
3939
recurrence: str | None = None,
4040
message: str = "",
41-
) -> Reminder:
41+
) -> ReminderSchedule:
4242
"""Set a reminder for a user."""
4343
auth = GoogleAccountAuthorization.authorize(slack_user_id)
4444
if not isinstance(auth, GoogleAccountAuthorization):
@@ -62,16 +62,16 @@ def set_reminder(
6262
if recurrence and recurrence not in ReminderSchedule.Recurrence.values:
6363
message = "Invalid recurrence value."
6464
raise ValidationError(message)
65+
event.save()
6566
member = Member.objects.get(slack_user_id=slack_user_id)
6667
reminder = Reminder.objects.create(
6768
channel_id=channel,
6869
event=event,
6970
member=member,
7071
message=f"{event.name} - {message}" if message else event.name,
7172
)
72-
schedule_reminder(
73+
return schedule_reminder(
7374
reminder=reminder,
7475
scheduled_time=reminder_time,
7576
recurrence=recurrence or ReminderSchedule.Recurrence.ONCE,
7677
)
77-
return reminder
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 5.2.4 on 2025-09-07 16:11
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("owasp", "0052_remove_event_calendar_id_event_google_calendar_id"),
9+
]
10+
11+
operations = [
12+
migrations.AlterField(
13+
model_name="event",
14+
name="key",
15+
field=models.CharField(max_length=100, null=True, unique=True, verbose_name="Key"),
16+
),
17+
]

backend/apps/owasp/models/event.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Status(models.TextChoices):
6060
start_date = models.DateField(verbose_name="Start Date")
6161
end_date = models.DateField(verbose_name="End Date", null=True, blank=True)
6262
description = models.TextField(verbose_name="Description", default="", blank=True)
63-
key = models.CharField(verbose_name="Key", max_length=100, unique=True)
63+
key = models.CharField(verbose_name="Key", max_length=100, unique=True, null=True)
6464
status = models.CharField(
6565
verbose_name="Status",
6666
max_length=11,
@@ -360,10 +360,11 @@ def save(self, *args, **kwargs):
360360
**kwargs: Arbitrary keyword arguments.
361361
362362
"""
363-
if not self.suggested_location:
364-
self.generate_suggested_location()
363+
if self.category != Event.Category.COMMUNITY:
364+
if not self.suggested_location:
365+
self.generate_suggested_location()
365366

366-
if not self.latitude or not self.longitude:
367-
self.generate_geo_location()
367+
if not self.latitude or not self.longitude:
368+
self.generate_geo_location()
368369

369370
super().save(*args, **kwargs)

backend/apps/slack/MANIFEST.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ features:
6161
url: https://nest.owasp.org/integrations/slack/commands/
6262
description: Check out available job opportunities
6363
should_escape: false
64+
- command: /set-reminder
65+
url: https://nest.owasp.org/integrations/slack/commands/
66+
description: Set a reminder for a specific channel
67+
usage_hint: --channel <#channel_name> --event_number <event_number> --minutes_before <minutes_before_event> --message <optional_message>
68+
should_escape: false
6469
- command: /sponsor
6570
url: https://nest.owasp.org/integrations/slack/commands/
6671
description: Coming soon

backend/apps/slack/commands/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
owasp,
1919
policies,
2020
projects,
21+
set_reminder,
2122
sponsor,
2223
sponsors,
2324
staff,

backend/apps/slack/common/handlers/calendar_events.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from django.core.cache import cache
44
from django.core.exceptions import ValidationError
55
from django.utils import timezone
6+
from googleapiclient.errors import Error
7+
from httplib2.error import ServerNotFoundError
68

79
from apps.common.constants import NL
810
from apps.slack.blocks import get_pagination_buttons, markdown
@@ -60,7 +62,7 @@ def get_reminder_blocks(args, slack_user_id: str) -> list[dict]:
6062
from apps.nest.controllers.calendar_events import set_reminder
6163

6264
try:
63-
reminder = set_reminder(
65+
reminder_schedule = set_reminder(
6466
channel=args.channel,
6567
event_number=args.event_number,
6668
slack_user_id=slack_user_id,
@@ -70,7 +72,16 @@ def get_reminder_blocks(args, slack_user_id: str) -> list[dict]:
7072
)
7173
except ValidationError as e:
7274
return [markdown(f"*{e.message}*")]
73-
75+
except (ServerNotFoundError, Error):
76+
return [markdown("*An unexpected error occurred. Please try again later.*")]
7477
return [
75-
markdown(f"*{args.minutes_before}-minutes Reminder set for event '{reminder.event.name}'*")
78+
markdown(
79+
f"*{args.minutes_before}-minutes Reminder set for event"
80+
f" '{reminder_schedule.reminder.event.name}'*"
81+
f" in {args.channel}"
82+
f"{NL} Scheduled Time: "
83+
f"{reminder_schedule.scheduled_time.strftime('%Y-%m-%d %H:%M %Z')}"
84+
f"{NL} Recurrence: {reminder_schedule.recurrence}"
85+
f"{f'{NL} Message: {args.message}' if args.message else ''}"
86+
)
7687
]

backend/apps/slack/utils.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,24 +228,31 @@ def parse_slack_reminder_args(text: str):
228228
229229
"""
230230
parser = ArgumentParser(prog="/set-reminder", description="Set a reminder for a Slack event.")
231-
parser.add_argument("channel", type=str, help="The channel to send the reminder to.")
232-
parser.add_argument("event_number", type=int, help="The event number to set the reminder for.")
233231
parser.add_argument(
234-
"minutes_before", type=int, help="Minutes before the event to send the reminder."
232+
"--channel", type=str, help="The channel to send the reminder to.", required=True
235233
)
236234
parser.add_argument(
237-
"message",
235+
"--event_number", type=int, help="The event number to set the reminder for.", required=True
236+
)
237+
parser.add_argument(
238+
"--minutes_before",
239+
type=int,
240+
help="Minutes before the event to send the reminder.",
241+
default=10,
242+
)
243+
parser.add_argument(
244+
"--message",
238245
type=str,
239246
nargs="?",
240247
default="",
241248
help="Optional message to include in the reminder.",
242249
)
243250
parser.add_argument(
244-
"recurrence",
251+
"--recurrence",
245252
type=str,
246253
nargs="?",
247-
choices=["once", "daily", "weekly"],
248-
default=None,
254+
choices=["once", "daily", "weekly", "monthly"],
255+
default="once",
249256
help="Optional recurrence pattern for the reminder.",
250257
)
251258

0 commit comments

Comments
 (0)