Skip to content

Commit 23bf251

Browse files
committed
some work
1 parent d70c155 commit 23bf251

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

src/slack.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ class SlackManager:
1717

1818
def __init__(self) -> None:
1919
self.webhooks: List[WebhookClient] = []
20-
self.webhooks.append(WebhookClient(Environment.get("SLACK_ENDPOINT")))
2120
self.warnings = []
2221
self.silent = False
2322

23+
if Environment.contains("SLACK_ENDPOINT"):
24+
self.webhooks.append(WebhookClient(Environment.get("SLACK_ENDPOINT")))
2425
if Environment.contains("SLACK_ENDPOINT_DEBUG"):
2526
if Environment.get("SLACK_ENDPOINT_DEBUG") != Environment.get("SLACK_ENDPOINT"):
2627
self.webhooks.append(WebhookClient(Environment.get("SLACK_ENDPOINT_DEBUG")))
28+
# after Slack configuration if there is no webhook then suppress any Slack action
29+
if not self.webhooks:
30+
# TODO: send warning that no slack endpoint is set up, printing log to GCP instead
31+
self.silent = True
2732

2833
def suppress(self):
2934
self.silent = True
@@ -65,6 +70,7 @@ def get_warnings(self) -> str:
6570

6671
def send_message(self, message: str) -> None:
6772
if self.silent:
73+
# TODO: configure gcp log instead
6874
print("\n" + ("#" * 30) + "\n" + message.strip() + "\n" + "#" * 30)
6975
return
7076

@@ -108,6 +114,7 @@ def send_student_update(self, message: str, autoapprove: bool = False) -> None:
108114
message += self.get_warnings()
109115

110116
if self.silent:
117+
# TODO: configure gcp log instead
111118
print("\n" + ("#" * 30) + "\n" + message.strip() + "\n" + "#" * 30)
112119
return
113120

src/utils.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def cast_list_int(cell: str) -> List[int]:
5151
return items
5252

5353

54-
PREFIX = "cs161extensions_"
54+
PREFIX = "FLEXTENSIONS_"
5555

5656

5757
class Environment:
@@ -79,6 +79,22 @@ def get(key: str) -> Any:
7979
if not os.getenv(PREFIX + key):
8080
raise ConfigurationError("Environment variable not set: " + key)
8181
return os.getenv(PREFIX + key)
82+
83+
@staticmethod
84+
def get_email_from() -> str:
85+
return str(Environment.get("EMAIL_FROM"))
86+
87+
@staticmethod
88+
def get_email_signature() -> str:
89+
return str(Environment.safe_get("EMAIL_SIGNATURE", "Data 000 Staff"))
90+
91+
@staticmethod
92+
def get_email_subject() -> str:
93+
return str(Environment.safe_get("EMAIL_SUBJECT", "[DATA 000] Extension Request Update"))
94+
95+
@staticmethod
96+
def get_email_reply_to() -> str:
97+
return str(Environment.get("EMAIL_REPLY_TO"))
8298

8399
@staticmethod
84100
def get_auto_approve_threshold() -> int:
@@ -87,6 +103,10 @@ def get_auto_approve_threshold() -> int:
87103
@staticmethod
88104
def get_auto_approve_threshold_dsp() -> int:
89105
return int(Environment.get("AUTO_APPROVE_THRESHOLD_DSP"))
106+
107+
@staticmethod
108+
def get_auto_approve_assignment_threshold() -> int:
109+
return int(Environment.get("AUTO_APPROVE_ASSIGNMENT_THRESHOLD"))
90110

91111
@staticmethod
92112
def get_max_total_requested_extensions_threshold() -> int:
@@ -96,8 +116,8 @@ def get_max_total_requested_extensions_threshold() -> int:
96116
return int(Environment.safe_get("MAX_TOTAL_REQUESTED_EXTENSIONS_THRESHOLD", default=-1))
97117

98118
@staticmethod
99-
def get_auto_approve_assignment_threshold() -> int:
100-
return int(Environment.get("AUTO_APPROVE_ASSIGNMENT_THRESHOLD"))
119+
def get_extend_gradescope_assignments() -> bool:
120+
return cast_bool(Environment.safe_get("EXTEND_GRADESCOPE_ASSIGNMENTS", "No"))
101121

102122
@staticmethod
103123
def get_course_name() -> str:
@@ -120,6 +140,7 @@ def configure_env_vars(sheet: Sheet):
120140
# Load local environment variables now from .env, which override remote provided variables for debugging
121141
if os.path.exists(".env-pytest"):
122142
for key, value in dotenv_values(".env-pytest").items():
143+
# TODO: is this still needed?
123144
if key == "APP_MASTER_SECRET":
124145
os.environ[key] = value
125146
else:

0 commit comments

Comments
 (0)