Skip to content

Commit

Permalink
Changes in prep for official 4.5 release (#67)
Browse files Browse the repository at this point in the history
* Add setting to toggle optout email links

Fixes #57

* Add deletion email

Fixes #56

* add capability to allow access to non admins

Fixes #40

* Find last access when bringing up save points

Fixes #65
  • Loading branch information
Syxton authored Feb 6, 2025
1 parent fd2ffe8 commit d085a6d
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 154 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

services:
postgres:
image: postgres:13
image: postgres:latest
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
Expand All @@ -30,13 +30,13 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1']
moodle-branch: ['MOODLE_403_STABLE', 'MOODLE_402_STABLE']
php: ['8.2', '8.3']
moodle-branch: ['main']
database: [pgsql, mariadb]

steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: plugin

Expand All @@ -50,7 +50,7 @@ jobs:

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
Expand All @@ -66,11 +66,6 @@ jobs:
if: ${{ always() }}
run: moodle-plugin-ci phplint

- name: PHP Copy/Paste Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
run: moodle-plugin-ci phpcpd

- name: PHP Mess Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
Expand Down
6 changes: 4 additions & 2 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
// This file is part of Moodle - http://moodle.org/
// This file is part of
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -13,13 +13,15 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Privacy Subsystem implementation for tool_coursearchiver.
* File containing processor class.
*
* @package tool_coursearchiver
* @copyright 2015 Matthew Davidson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_coursearchiver\privacy;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\contextlist;
Expand Down
81 changes: 55 additions & 26 deletions classes/processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,20 @@ class tool_coursearchiver_processor {
*/
const MODE_ARCHIVEEMAIL = 7;

/**
* Send emails about pending course deletion.
*/
const MODE_DELETEEMAIL = 8;

/**
* Delete courses.
*/
const MODE_DELETE = 8;
const MODE_DELETE = 9;

/**
* Optout courses.
*/
const MODE_OPTOUT = 9;
const MODE_OPTOUT = 10;

/** @var int processor mode. */
protected $mode;
Expand Down Expand Up @@ -146,6 +151,7 @@ public function __construct(array $options) {
self::MODE_DELETE,
self::MODE_HIDEEMAIL,
self::MODE_ARCHIVEEMAIL,
self::MODE_DELETEEMAIL,
self::MODE_OPTOUT,
])) {
throw new coding_exception('Unknown process mode');
Expand Down Expand Up @@ -183,6 +189,7 @@ public function execute($outputtype = tool_coursearchiver_tracker::NO_OUTPUT, $t
self::MODE_DELETE,
self::MODE_HIDEEMAIL,
self::MODE_ARCHIVEEMAIL,
self::MODE_DELETEEMAIL,
self::MODE_OPTOUT,
])) {
if (empty($mform)) {
Expand Down Expand Up @@ -366,6 +373,7 @@ public function execute($outputtype = tool_coursearchiver_tracker::NO_OUTPUT, $t
break;
case self::MODE_HIDEEMAIL:
case self::MODE_ARCHIVEEMAIL:
case self::MODE_DELETEEMAIL:
$tracker->start();
if (!empty($this->data)) {
// Loop over the user array.
Expand Down Expand Up @@ -819,17 +827,21 @@ protected function sendemail($obj) {
$subject = get_string('archivewarningsubject', 'tool_coursearchiver');
$message = $config->archivewarningemailsetting;
break;
case self::MODE_DELETEEMAIL:
$subject = get_string('deletewarningsubject', 'tool_coursearchiver');
$message = $config->deletewarningemailsetting;
break;
default:
$this->errors[] = get_string('invalidmode', 'tool_coursearchiver');
return false;
}

// Note: get_email_courses() may return an empty HTML table.
if (strstr($message, '%courses_nolink')) {
$courses = $this->get_email_courses($obj, false);
$courses = $this->get_email_courses($obj, $config->optoutbyemailsetting);
$placeholder = '%courses_nolink';
} else {
$courses = $this->get_email_courses($obj);
$courses = $this->get_email_courses($obj, $config->optoutbyemailsetting);
$placeholder = '%courses';
}

Expand Down Expand Up @@ -1340,6 +1352,16 @@ public function get_list_of_admins_and_managers() {
return $adminsandmanagers;
}

/**
* Static method to get list of the userid's of admin and other users with course view capability
*
* @return string
*/
public static function get_list_of_admins_and_managers_static() {
$processor = new self(["mode" => self::MODE_COURSELIST, "data" => []]);
return $processor->get_list_of_admins_and_managers();
}

/**
* Get an HTML table listing courses to put in the email.
*
Expand All @@ -1354,6 +1376,8 @@ public function get_email_courses($obj, $links = true) {
$optoutbutton = get_string('optouthide', 'tool_coursearchiver');
} else if ($this->mode == self::MODE_ARCHIVEEMAIL) {
$optoutbutton = get_string('optoutarchive', 'tool_coursearchiver');
} else if ($this->mode == self::MODE_DELETEEMAIL) {
$optoutbutton = get_string('optoutdelete', 'tool_coursearchiver');
}

$tablehtml = [];
Expand All @@ -1365,30 +1389,35 @@ public function get_email_courses($obj, $links = true) {
// Create security key for each link.
$key = sha1($CFG->dbpass . $course->id . $obj["user"]->id);

// Only add courses that are visible if mode is HIDEEMAIL.
if ($this->mode == self::MODE_ARCHIVEEMAIL || $course->visible) {
$rowcolor = $rowcolor == "#FFF" ? "#EEE" : "#FFF";
$linkstring = "";
if ($links) {
$linkstring = html_writer::tag('td', '', ['width' => '5px']) .
html_writer::tag('td',
html_writer::link(new moodle_url('/admin/tool/coursearchiver/optout.php',
['courseid' => $course->id,
'userid' => $obj["user"]->id,
'key' => $key,
]),
$optoutbutton));
}

$tablehtml[] = html_writer::tag('tr',
html_writer::tag('td',
html_writer::link(new moodle_url('/course/view.php',
['id' => $course->id]),
$course->fullname)) . $linkstring,
['style' => 'background-color:' . $rowcolor]);
} else { // This course is not included in the email.
// Only add courses that are not hidden if mode is HIDEEMAIL.
if ($this->mode == self::MODE_HIDEEMAIL && !$course->visible) {
$this->notices[] = get_string('noticecoursehidden', 'tool_coursearchiver', $course);
continue;
}

// Change rowcolor.
$rowcolor = $rowcolor == "#FFF" ? "#EEE" : "#FFF";

// Add optout links.
$linkstring = "";
if ($links) {
$linkstring = html_writer::tag('td', '', ['width' => '5px']) .
html_writer::tag('td',
html_writer::link(new moodle_url('/admin/tool/coursearchiver/optout.php',
['courseid' => $course->id,
'userid' => $obj["user"]->id,
'key' => $key,
]),
$optoutbutton));
}

$tablehtml[] = html_writer::tag('tr',
html_writer::tag('td',
html_writer::link(new moodle_url('/course/view.php',
['id' => $course->id]),
$course->fullname)) . $linkstring,
['style' => 'background-color:' . $rowcolor]);

}
$tablehtml[] = html_writer::end_tag('table');

Expand Down
2 changes: 1 addition & 1 deletion classes/step1_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class tool_coursearchiver_step1_form extends moodleform {
* The standard form definiton.
* @return void
*/
public function definition () {
public function definition() {
$mform = $this->_form;
$mform->addElement('header', 'searchhdr', get_string('search'));

Expand Down
2 changes: 1 addition & 1 deletion classes/step2_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class tool_coursearchiver_step2_form extends moodleform {
* The standard form definiton.
* @return void.
*/
public function definition () {
public function definition() {
$mform = $this->_form;
$data = $this->_customdata['processor_data'];

Expand Down
3 changes: 2 additions & 1 deletion classes/step3_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class tool_coursearchiver_step3_form extends moodleform {
* The standard form definiton.
* @return void.
*/
public function definition () {
public function definition() {
$mform = $this->_form;
$data = $this->_customdata['processor_data'];

Expand All @@ -56,6 +56,7 @@ public function definition () {
$buttonarray = [];
$buttonarray[] = &$mform->createElement('submit', 'submit_button', get_string('hideemail', 'tool_coursearchiver'));
$buttonarray[] = &$mform->createElement('submit', 'submit_button', get_string('archiveemail', 'tool_coursearchiver'));
$buttonarray[] = &$mform->createElement('submit', 'submit_button', get_string('deleteemail', 'tool_coursearchiver'));
$mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
$mform->closeHeaderBefore('buttonar');

Expand Down
10 changes: 9 additions & 1 deletion classes/step4_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class tool_coursearchiver_step4_form extends moodleform {
* The standard form definiton.
* @return void.
*/
public function definition () {
public function definition() {
$mform = $this->_form;
$data = $this->_customdata['processor_data'];

Expand Down Expand Up @@ -72,6 +72,14 @@ public function definition () {
}
$message = get_string('confirmmessagearchiveemail', 'tool_coursearchiver', $count);
break;
case tool_coursearchiver_processor::MODE_DELETEEMAIL:
foreach (unserialize($data["formdata"]) as $r) { // Loop through every possible user.
if (substr($r, 0, 1) == 'x') { // Determine if they were NOT selected.
$count--; // Remove 1 from count.
}
}
$message = get_string('confirmmessagedeleteemail', 'tool_coursearchiver', $count);
break;
case tool_coursearchiver_processor::MODE_HIDE:
$message = get_string('confirmmessagehide', 'tool_coursearchiver', $count);
break;
Expand Down
Loading

0 comments on commit d085a6d

Please sign in to comment.