From dd3f4976165d8b5a122e6bc018fa97f2d73fa514 Mon Sep 17 00:00:00 2001 From: Conn Warwicker Date: Wed, 12 Aug 2026 15:41:41 +0100 Subject: [PATCH] CTP-6662: Fix submission button not visible when personal deadline exists. --- classes/ability.php | 39 ++++++++++++++++++++++++++++++++++++ tests/behat/deadline.feature | 15 ++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/classes/ability.php b/classes/ability.php index 9142fba9..8a55dc24 100644 --- a/classes/ability.php +++ b/classes/ability.php @@ -80,6 +80,7 @@ function (coursework $coursework) { $this->allow_new_submissions_when_deadline_has_not_passed(); $this->allow_new_submissions_if_late_submissions_allowed(); $this->allow_new_submissions_if_there_is_an_active_extension(); + $this->allow_new_submissions_if_there_is_a_personal_deadline(); // Create submission $this->allow_create_submission_if_can_new_submission(); @@ -327,6 +328,44 @@ function (submission $submission) { ); } + /** + * Allow submissions if the user has a personal deadline which has not yet passed. + * @return void + */ + protected function allow_new_submissions_if_there_is_a_personal_deadline() { + $this->allow( + 'new', + 'mod_coursework\models\submission', + function (submission $submission) { + $coursework = $submission->get_coursework(); + + // Make sure that personal deadlines are enabled. + if (!$coursework->personaldeadlines_enabled()) { + return false; + } + + // Get the right user or group, depending on group submissions. + $submittingallocatable = $coursework->submiting_allocatable_for_student($this->get_user()); + if (!$submittingallocatable) { + return false; + } + + // Find the personal deadline for this user/group. + $personaldeadline = personaldeadline::get_cached_object( + $coursework->id(), + ['allocatableid' => $submittingallocatable->id(), 'allocatabletype' => $submittingallocatable->type()] + ); + + // If it's set and the deadline hasn't passed, we can create a new submission. + if ($personaldeadline && $personaldeadline->personaldeadline > time()) { + return true; + } + + return false; + } + ); + } + protected function prevent_new_submissions_if_no_capability() { $this->prevent( 'new', diff --git a/tests/behat/deadline.feature b/tests/behat/deadline.feature index 9f962383..095bbfbf 100644 --- a/tests/behat/deadline.feature +++ b/tests/behat/deadline.feature @@ -96,3 +96,18 @@ Feature: Deadlines extensions for submissions Then I should not see "Extension" in the "student student1" "table_row" When I am on the "Coursework" "coursework activity" page Then I should not see "Extension" in the "student student1" "table_row" + + @javascript + Scenario: The student can submit after the deadline if they have a personal deadline + Given the following "activity" exists: + | activity | coursework | + | course | C1 | + | name | Coursework2 | + | deadline | ##yesterday## | + | extensionsenabled | 1 | + | personaldeadlineenabled | 1 | + And the following "mod_coursework > personaldeadlines" exist: + | allocatable | coursework | deadline | + | student1 | Coursework2 | ##+2 weeks## | + When I am on the "Coursework2" "coursework activity" page logged in as "student1" + Then I should see "Upload your submission"