Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions classes/ability.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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',
Expand Down
15 changes: 15 additions & 0 deletions tests/behat/deadline.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading