Skip to content

Commit

Permalink
Merge b40f013 into 841d9ca
Browse files Browse the repository at this point in the history
  • Loading branch information
Incompleteusern committed Oct 16, 2023
2 parents 841d9ca + b40f013 commit 1195a4c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
29 changes: 29 additions & 0 deletions roster/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
UserProfileFactory,
)
from core.models import Semester, Unit, UnitGroup
from dashboard.factories import PSetFactory
from evans_django_tools.testsuite import EvanTestCase
from roster.factories import ( # NOQA
AssistantFactory,
Expand Down Expand Up @@ -457,6 +458,34 @@ def test_inquiry(self) -> None:
self.assertEqual(alice.curriculum.count(), 8)
self.assertEqual(alice.unlocked_units.count(), 5)

self.login(alice)
secret_group = UnitGroupFactory.create(
name="Spooky Unit", subject="K", hidden=True
)
secret_unit = UnitFactory.create(code="BKV", group=secret_group)
alice.curriculum.add(secret_unit)

# Alice hit the hold limit earlier
PSetFactory.create_batch(30, student=alice)

alice.save()

self.assertHas(
self.post(
"inquiry",
alice.pk,
data={
"unit": secret_unit.pk,
"action_type": "INQ_ACT_UNLOCK",
"explanation": "its almost halloween and my family wants to host it at our house.",
},
),
"Petition automatically processed",
)

self.assertEqual(alice.curriculum.count(), 9)
self.assertEqual(alice.unlocked_units.count(), 6)

bob: Student = StudentFactory.create(
semester=SemesterFactory.create(active=False)
)
Expand Down
19 changes: 12 additions & 7 deletions roster/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def handle_inquiry(request: AuthHttpRequest, inquiry: UnitInquiry, student: Stud
+ student.unlocked_units.count()
)

# auto reject criteria
# auto reject criteria - the current petition counts toward the unlock count
auto_reject_criteria = (
inquiry.action_type == "INQ_ACT_UNLOCK" and unlocked_count > 9
)
Expand Down Expand Up @@ -333,12 +333,17 @@ def handle_inquiry(request: AuthHttpRequest, inquiry: UnitInquiry, student: Stud
return

# auto-acceptance criteria
auto_accept_criteria = num_past_unlock_inquiries <= 6 and unlocked_count <= 9
# auto dropping locked units
auto_accept_criteria |= (
inquiry.action_type == "INQ_ACT_DROP"
and not student.unlocked_units.contains(inquiry.unit)
)
auto_accept_criteria = False

# auto accepting criteria for unlocking
if inquiry.action_type == "INQ_ACT_UNLOCK" and unlocked_count <= 9:
# when less than 6 past unlock (newbie) or a secret unit (currently uses subject to determine this)
auto_accept_criteria |= (
num_past_unlock_inquiries <= 6 or inquiry.unit.group.subject == "K"
)
elif inquiry.action_type == "INQ_ACT_DROP":
# auto dropping locked units
auto_accept_criteria |= not student.unlocked_units.contains(inquiry.unit)

if auto_accept_criteria:
inquiry.run_accept()
Expand Down

0 comments on commit 1195a4c

Please sign in to comment.