Skip to content

Commit

Permalink
MDL-63013 tool_policy: Policy agreement style can be defined now
Browse files Browse the repository at this point in the history
The patch introduces a new property of a policy document called
"Agreement style". It allows the admin to define if the policy should be
accepted together with all others on the consent page (legacy and
default behaviour) or on its page before the consent page is reached
(the new optional behaviour).
  • Loading branch information
mudrd8mz committed Sep 19, 2018
1 parent 674ef9b commit 23b663e
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 5 deletions.
2 changes: 2 additions & 0 deletions admin/tool/policy/classes/form/policydoc.php
Expand Up @@ -89,6 +89,8 @@ public function definition() {
api::policy_content_field_options());
$mform->addRule('content_editor', null, 'required', null, 'client');

$mform->addElement('selectyesno', 'agreementstyle', get_string('policypriorityagreement', 'tool_policy'));

if (!$formdata->id || $formdata->status == policy_version::STATUS_DRAFT) {
// Creating a new version or editing a draft/archived version.
$mform->addElement('hidden', 'minorchange');
Expand Down
14 changes: 14 additions & 0 deletions admin/tool/policy/classes/policy_version.php
Expand Up @@ -69,6 +69,12 @@ class policy_version extends persistent {
/** @var int Policy version has been archived. */
const STATUS_ARCHIVED = 2;

/** @var int Policy to be accepted together with others on the consent page. */
const AGREEMENTSTYLE_CONSENTPAGE = 0;

/** @var int Policy to be accepted on its own page before reaching the consent page. */
const AGREEMENTSTYLE_OWNPAGE = 1;

/**
* Return the definition of the properties of this model.
*
Expand Down Expand Up @@ -106,6 +112,14 @@ protected static function define_properties() {
'policyid' => [
'type' => PARAM_INT,
],
'agreementstyle' => [
'type' => PARAM_INT,
'choices' => [
self::AGREEMENTSTYLE_CONSENTPAGE,
self::AGREEMENTSTYLE_OWNPAGE,
],
'default' => self::AGREEMENTSTYLE_CONSENTPAGE,
],
'revision' => [
'type' => PARAM_TEXT,
'default' => '',
Expand Down
3 changes: 2 additions & 1 deletion admin/tool/policy/db/install.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="admin/tool/policy/db" VERSION="20180307" COMMENT="The plugin allows to manage various policy documents that users have to accept to use the site."
<XMLDB PATH="admin/tool/policy/db" VERSION="20180829" COMMENT="The plugin allows to manage various policy documents that users have to accept to use the site."
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
Expand All @@ -26,6 +26,7 @@
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Timestamp of when the policy version was created."/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Timestamp of when the policy version was last modified."/>
<FIELD NAME="policyid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="ID of the policy document we are version of."/>
<FIELD NAME="agreementstyle" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="How this agreement should flow: 0 - on the consent page, 1 - on a separate page before reaching the consent page."/>
<FIELD NAME="revision" TYPE="char" LENGTH="1333" NOTNULL="true" SEQUENCE="false" COMMENT="Human readable version of the policy document"/>
<FIELD NAME="summary" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Policy text summary"/>
<FIELD NAME="summaryformat" TYPE="int" LENGTH="3" NOTNULL="true" SEQUENCE="false" COMMENT="Format of the summary field"/>
Expand Down
53 changes: 53 additions & 0 deletions admin/tool/policy/db/upgrade.php
@@ -0,0 +1,53 @@
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Plugin upgrade steps are defined here.
*
* @package tool_policy
* @category upgrade
* @copyright 2018 David Mudrák <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* Execute the plugin upgrade steps from the given old version.
*
* @param int $oldversion
* @return bool
*/
function xmldb_tool_policy_upgrade($oldversion) {
global $DB;

$dbman = $DB->get_manager();

if ($oldversion < 2018082900) {
// Add field agreementstyle to the table tool_policy_versions.
$table = new xmldb_table('tool_policy_versions');
$field = new xmldb_field('agreementstyle', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0', 'policyid');

if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

upgrade_plugin_savepoint(true, 2018082900, 'tool', 'policy');
}

return true;
}

1 change: 1 addition & 0 deletions admin/tool/policy/lang/en/tool_policy.php
Expand Up @@ -129,6 +129,7 @@
$string['policydoctype99'] = 'Other policy';
$string['policydocuments'] = 'Policy documents';
$string['policynamedversion'] = 'Policy {$a->name} (version {$a->revision} - {$a->id})';
$string['policypriorityagreement'] = 'Show policy before showing other policies';
$string['policyversionacceptedinbehalf'] = 'Consent for this policy has been given on your behalf.';
$string['policyversionacceptedinotherlang'] = 'Consent for this policy version has been given in a different language.';
$string['previousversions'] = '{$a} previous versions';
Expand Down
10 changes: 7 additions & 3 deletions admin/tool/policy/lib.php
Expand Up @@ -85,9 +85,13 @@ function tool_policy_before_standard_html_head() {
&& empty($USER->policyagreed)
&& (isguestuser() || !isloggedin())) {
$output = $PAGE->get_renderer('tool_policy');
$page = new \tool_policy\output\guestconsent();

$message = $output->render($page);
try {
$page = new \tool_policy\output\guestconsent();
$message = $output->render($page);
} catch (dml_read_exception $e) {
// During upgrades, the new plugin code with new SQL could be in place but the DB not upgraded yet.
$message = null;
}
}

return $message;
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/policy/version.php
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2018051400; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2018082900; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2018050800; // Requires this Moodle version.
$plugin->component = 'tool_policy'; // Full name of the plugin (used for diagnostics).

0 comments on commit 23b663e

Please sign in to comment.