From b2ace0759bb704ba1eb15db012ad4f1b1b61b002 Mon Sep 17 00:00:00 2001
From: amanshah2711 <36978283+amanshah2711@users.noreply.github.com>
Date: Tue, 14 Jul 2020 22:53:39 -0400
Subject: [PATCH 1/4] updating oh appts so pending appoints can be restricted
by time (#219)
---
.../components/admin_appointments_manager.js | 5 +++-
oh_queue/views.py | 23 +++++++++++++++----
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/oh_queue/static/js/components/admin_appointments_manager.js b/oh_queue/static/js/components/admin_appointments_manager.js
index cd3001f..382cc3b 100644
--- a/oh_queue/static/js/components/admin_appointments_manager.js
+++ b/oh_queue/static/js/components/admin_appointments_manager.js
@@ -61,8 +61,11 @@ function AdminAppointmentsManager({ state }) {
|
- How many appointments should a student have be pending simultaneously?
+ How many appointments should a student have be pending simultaneously?
+ (by
+
+ )
|
= daily_threshold:
return socket_error("You have already signed up for {} OH slots for the same day".format(daily_threshold))
-
num_pending = AppointmentSignup.query.join(AppointmentSignup.appointment).filter(
Appointment.status == AppointmentStatus.pending,
AppointmentSignup.user_id == current_user.id,
- ).count()
- if num_pending >= pending_threshold:
- return socket_error("You have already signed up for {} OH slots that have not yet occurred.".format(pending_threshold))
+ )
+ if pending_metric != 'false':
+ start = appointment.duration
+ num_pend = [appt.appointment.duration for appt in list(num_pending)]
+ threshold = datetime.timedelta(minutes=pending_threshold)
+ for item in num_pend:
+ start += item
+ if start > threshold:
+ return socket_error("You cannot sign up for more than {} minutes of OH that have not yet occurred.".format(pending_threshold))
+ else:
+ if num_pending.count() >= pending_threshold:
+ return socket_error("You have already signed up for {} OH slots that have not yet occurred.".format(pending_threshold))
old_signup = AppointmentSignup.query.filter_by(
appointment_id=data["appointment_id"],
From 954d8c9b4c00fc62e36f3170640389a6eceaf49e Mon Sep 17 00:00:00 2001
From: Laryn Qi
Date: Sat, 1 Aug 2020 04:14:43 -0700
Subject: [PATCH 2/4] require appointment fields
---
.../js/components/appointment_overlay.js | 24 +++++++++++--------
oh_queue/static/js/components/slots_form.js | 2 ++
2 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/oh_queue/static/js/components/appointment_overlay.js b/oh_queue/static/js/components/appointment_overlay.js
index 5347869..adb24be 100644
--- a/oh_queue/static/js/components/appointment_overlay.js
+++ b/oh_queue/static/js/components/appointment_overlay.js
@@ -38,15 +38,19 @@ function AppointmentOverlay({ staffMode, appointment, assignments, signup, onSub
};
const handleSubmit = () => {
- app.makeRequest(
- 'assign_appointment', {
- appointment_id: appointment,
- assignment_id: parseInt(assignment),
- question: question,
- description: description,
- email: signup ? signup.user.email : email,
- });
- onSubmit();
+ if (assignment && question && description) {
+ app.makeRequest(
+ 'assign_appointment', {
+ appointment_id: appointment,
+ assignment_id: parseInt(assignment),
+ question: question,
+ description: description,
+ email: signup ? signup.user.email : email,
+ });
+ onSubmit();
+ } else {
+ alert("Please fill out all fields.")
+ }
};
return ReactDOM.createPortal(
@@ -64,7 +68,7 @@ function AppointmentOverlay({ staffMode, appointment, assignments, signup, onSub
{!staffMode && (
- Leave fields blank if you aren't yet sure what you want to ask about.
+ Please fill out all fields to the best of your ability. You can always come back and edit them later.
)}
+
)
From 3be7f13afd11c2e2639d108fc540ab0d08f17d68 Mon Sep 17 00:00:00 2001
From: Laryn Qi
Date: Sat, 1 Aug 2020 04:16:51 -0700
Subject: [PATCH 3/4] clean
---
oh_queue/static/js/components/slots_form.js | 2 --
1 file changed, 2 deletions(-)
diff --git a/oh_queue/static/js/components/slots_form.js b/oh_queue/static/js/components/slots_form.js
index 4ec6202..f454471 100644
--- a/oh_queue/static/js/components/slots_form.js
+++ b/oh_queue/static/js/components/slots_form.js
@@ -31,7 +31,6 @@ function SlotsForm({
required/>
-
)
From e75c6e3aa9a2ab230dfa3b378cb5f2af9c9701c8 Mon Sep 17 00:00:00 2001
From: Laryn Qi
Date: Sat, 1 Aug 2020 05:03:19 -0700
Subject: [PATCH 4/4] config and migrate
---
migrations/alembic.ini => alembic.ini | 0
...046d24dc80b6_require_appointment_fields.py | 29 +++++++++++++++++++
.../ee50ab5f3371_added_appointments_tables.py | 2 ++
.../components/admin_appointments_manager.js | 11 +++++++
oh_queue/static/js/components/app.js | 1 +
.../js/components/appointment_overlay.js | 4 +--
.../components/confirmed_appointment_card.js | 3 +-
oh_queue/static/js/components/future_slots.js | 1 +
.../static/js/components/my_appointments.js | 1 +
oh_queue/views.py | 6 ++++
10 files changed, 55 insertions(+), 3 deletions(-)
rename migrations/alembic.ini => alembic.ini (100%)
create mode 100644 migrations/versions/046d24dc80b6_require_appointment_fields.py
diff --git a/migrations/alembic.ini b/alembic.ini
similarity index 100%
rename from migrations/alembic.ini
rename to alembic.ini
diff --git a/migrations/versions/046d24dc80b6_require_appointment_fields.py b/migrations/versions/046d24dc80b6_require_appointment_fields.py
new file mode 100644
index 0000000..598e5b6
--- /dev/null
+++ b/migrations/versions/046d24dc80b6_require_appointment_fields.py
@@ -0,0 +1,29 @@
+"""require appointment fields
+
+Revision ID: 046d24dc80b6
+Revises: 4c81c3744bc4
+Create Date: 2020-08-01 04:40:56.908992
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '046d24dc80b6'
+down_revision = '4c81c3744bc4'
+
+from alembic import op
+import sqlalchemy as sa
+import oh_queue.models
+from oh_queue.models import *
+
+
+def upgrade():
+ connection = op.get_bind()
+ session = orm.Session(bind=connection)
+
+ for course in session.query(ConfigEntry.course).distinct():
+ session.add(ConfigEntry(key='appointment_fields_required', value='false', public=True, course=course[0]))
+
+ session.commit()
+
+def downgrade():
+ pass
diff --git a/migrations/versions/ee50ab5f3371_added_appointments_tables.py b/migrations/versions/ee50ab5f3371_added_appointments_tables.py
index a56c41a..f4736e5 100644
--- a/migrations/versions/ee50ab5f3371_added_appointments_tables.py
+++ b/migrations/versions/ee50ab5f3371_added_appointments_tables.py
@@ -14,6 +14,8 @@
from alembic import op
import sqlalchemy as sa
+import os, sys
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
import oh_queue.models
from oh_queue.models import *
diff --git a/oh_queue/static/js/components/admin_appointments_manager.js b/oh_queue/static/js/components/admin_appointments_manager.js
index 382cc3b..3b3cf19 100644
--- a/oh_queue/static/js/components/admin_appointments_manager.js
+++ b/oh_queue/static/js/components/admin_appointments_manager.js
@@ -32,6 +32,17 @@ function AdminAppointmentsManager({ state }) {
/>
|
+
|
diff --git a/oh_queue/static/js/components/app.js b/oh_queue/static/js/components/app.js
index e6caa68..d8066bc 100644
--- a/oh_queue/static/js/components/app.js
+++ b/oh_queue/static/js/components/app.js
@@ -81,6 +81,7 @@ class App extends React.Component {
"slack_notif_appt_summary",
"slack_notif_missed_appt",
"party_enabled",
+ "appointment_fields_required"
]) {
this.state.config[key] = JSON.parse(this.state.config[key]);
}
diff --git a/oh_queue/static/js/components/appointment_overlay.js b/oh_queue/static/js/components/appointment_overlay.js
index adb24be..635169f 100644
--- a/oh_queue/static/js/components/appointment_overlay.js
+++ b/oh_queue/static/js/components/appointment_overlay.js
@@ -1,4 +1,4 @@
-function AppointmentOverlay({ staffMode, appointment, assignments, signup, onSubmit, isOpen }) {
+function AppointmentOverlay({ staffMode, appointment, assignments, signup, onSubmit, isOpen, state }) {
const [email, setEmail] = React.useState("");
const [assignment, setAssignment] = React.useState("");
const [question, setQuestion] = React.useState("");
@@ -38,7 +38,7 @@ function AppointmentOverlay({ staffMode, appointment, assignments, signup, onSub
};
const handleSubmit = () => {
- if (assignment && question && description) {
+ if (state.config.appointment_fields_required && assignment && question && description) {
app.makeRequest(
'assign_appointment', {
appointment_id: appointment,
diff --git a/oh_queue/static/js/components/confirmed_appointment_card.js b/oh_queue/static/js/components/confirmed_appointment_card.js
index bbbcec5..01c81a8 100644
--- a/oh_queue/static/js/components/confirmed_appointment_card.js
+++ b/oh_queue/static/js/components/confirmed_appointment_card.js
@@ -1,4 +1,4 @@
-function ConfirmedAppointmentCard({ appointment, signup, locations, assignments }) {
+function ConfirmedAppointmentCard({ appointment, signup, locations, assignments , state}) {
const assignmentName = signup.assignment_id && assignments[signup.assignment_id].name;
const questionName = signup.question ? " Question " + signup.question : "";
@@ -53,6 +53,7 @@ function ConfirmedAppointmentCard({ appointment, signup, locations, assignments
signup={signup}
isOpen={modalOpen}
onSubmit={() => setModalOpen(false)}
+ state={state}
/>
)
diff --git a/oh_queue/static/js/components/future_slots.js b/oh_queue/static/js/components/future_slots.js
index 36f3c68..c4b5a7e 100644
--- a/oh_queue/static/js/components/future_slots.js
+++ b/oh_queue/static/js/components/future_slots.js
@@ -127,6 +127,7 @@ function FutureSlots({ state }) {
staffMode={currentUser && currentUser.isStaff}
isOpen={modalOpen}
onSubmit={handleSubmit}
+ state={state}
/>
);
diff --git a/oh_queue/static/js/components/my_appointments.js b/oh_queue/static/js/components/my_appointments.js
index 705a276..59b249d 100644
--- a/oh_queue/static/js/components/my_appointments.js
+++ b/oh_queue/static/js/components/my_appointments.js
@@ -10,6 +10,7 @@ function MyAppointments({ state }) {
appointment={appointment}
signup={signup}
onClick={handleClick}
+ state={state}
/>
)
});
diff --git a/oh_queue/views.py b/oh_queue/views.py
index 0701526..74ae20b 100644
--- a/oh_queue/views.py
+++ b/oh_queue/views.py
@@ -355,6 +355,12 @@ def init_config():
public=True,
course=get_course(),
))
+ db.session.add(ConfigEntry(
+ key='appointment_fields_required',
+ value='false',
+ public=True,
+ course=get_course(),
+ ))
db.session.commit()
# We run a React app, so serve index.html on all routes
|