Skip to content
Permalink
Browse files
Merge branch 'MDL-62309-master-optionalpolicies' of git://github.com/…
…mudrd8mz/moodle
  • Loading branch information
David Monllao committed Oct 22, 2018
2 parents d10643f + aa7e539 commit 14f70eda2872b7095d606fd77eaba1c1c72dc96a
Showing with 1,814 additions and 498 deletions.
  1. +5 −7 admin/tool/policy/accept.php
  2. +1 −1 admin/tool/policy/amd/build/acceptmodal.min.js
  3. +25 −40 admin/tool/policy/amd/src/acceptmodal.js
  4. +24 −26 admin/tool/policy/classes/acceptances_table.php
  5. +199 −60 admin/tool/policy/classes/api.php
  6. +36 −17 admin/tool/policy/classes/form/accept_policy.php
  7. +2 −0 admin/tool/policy/classes/form/policydoc.php
  8. +14 −10 admin/tool/policy/classes/output/acceptances.php
  9. +3 −4 admin/tool/policy/classes/output/acceptances_filter.php
  10. +53 −14 admin/tool/policy/classes/output/page_agreedocs.php
  11. +6 −0 admin/tool/policy/classes/output/page_managedocs_list.php
  12. +3 −2 admin/tool/policy/classes/output/page_nopermission.php
  13. +9 −1 admin/tool/policy/classes/output/page_viewdoc.php
  14. +246 −31 admin/tool/policy/classes/output/user_agreement.php
  15. +36 −0 admin/tool/policy/classes/policy_version.php
  16. +20 −9 admin/tool/policy/classes/privacy/local/sitepolicy/handler.php
  17. +88 −0 admin/tool/policy/classes/test/helper.php
  18. +32 −0 admin/tool/policy/db/caches.php
  19. +2 −1 admin/tool/policy/db/install.xml
  20. +12 −1 admin/tool/policy/db/upgrade.php
  21. +21 −6 admin/tool/policy/index.php
  22. +34 −18 admin/tool/policy/lang/en/tool_policy.php
  23. +4 −3 admin/tool/policy/lib.php
  24. BIN admin/tool/policy/pix/{agreedyes.png → agreed.png}
  25. 0 admin/tool/policy/pix/{agreedyes.svg → agreed.svg}
  26. BIN admin/tool/policy/pix/agreedyesonbehalf.png
  27. +0 −3 admin/tool/policy/pix/agreedyesonbehalf.svg
  28. BIN admin/tool/policy/pix/{agreedno.png → declined.png}
  29. 0 admin/tool/policy/pix/{agreedno.svg → declined.svg}
  30. BIN admin/tool/policy/pix/partial.png
  31. +61 −0 admin/tool/policy/pix/partial.svg
  32. BIN admin/tool/policy/pix/pending.png
  33. +58 −0 admin/tool/policy/pix/pending.svg
  34. +9 −4 admin/tool/policy/templates/acceptances.mustache
  35. +22 −3 admin/tool/policy/templates/page_agreedocs.mustache
  36. +10 −5 admin/tool/policy/templates/page_managedocs_list.mustache
  37. +3 −0 admin/tool/policy/templates/page_viewdoc.mustache
  38. +22 −59 admin/tool/policy/templates/user_agreement.mustache
  39. +253 −73 admin/tool/policy/tests/api_test.php
  40. +45 −47 admin/tool/policy/tests/behat/acceptances.feature
  41. +2 −0 admin/tool/policy/tests/behat/behat_tool_policy.php
  42. +23 −23 admin/tool/policy/tests/behat/consent.feature
  43. +29 −29 admin/tool/policy/tests/behat/managepolicies.feature
  44. +264 −0 admin/tool/policy/tests/behat/optional.feature
  45. +137 −0 admin/tool/policy/tests/sitepolicy_handler_test.php
  46. +1 −1 admin/tool/policy/version.php
@@ -39,6 +39,10 @@
$PAGE->set_context($context);
$PAGE->set_url(new moodle_url('/admin/tool/policy/accept.php'));

if (!in_array($action, ['accept', 'decline', 'revoke'])) {
throw new moodle_exception('invalidaccessparameter');
}

if ($returnurl) {
$returnurl = new moodle_url($returnurl);
} else if (count($userids) == 1) {
@@ -59,14 +63,8 @@
redirect($returnurl);
}

if ($action == 'revoke') {
$title = get_string('revokedetails', 'tool_policy');
} else {
$title = get_string('consentdetails', 'tool_policy');
}

$output = $PAGE->get_renderer('tool_policy');
echo $output->header();
echo $output->heading($title);
echo $output->heading(get_string('statusformtitle'.$action, 'tool_policy'));
$form->display();
echo $output->footer();

Some generated files are not rendered by default. Learn more.

@@ -52,36 +52,6 @@ define(['jquery', 'core/str', 'core/modal_factory', 'core/modal_events', 'core/n
*/
AcceptOnBehalf.prototype.contextid = -1;

/**
* @var {Array} strings
* @private
*/
AcceptOnBehalf.prototype.stringKeys = [
{
key: 'consentdetails',
component: 'tool_policy'
},
{
key: 'iagreetothepolicy',
component: 'tool_policy'
},
{
key: 'selectusersforconsent',
component: 'tool_policy'
},
{
key: 'ok'
},
{
key: 'revokedetails',
component: 'tool_policy'
},
{
key: 'irevokethepolicy',
component: 'tool_policy'
}
];

/**
* @var {object} currentTrigger The triggered HTML jQuery object
* @private
@@ -121,9 +91,14 @@ define(['jquery', 'core/str', 'core/modal_factory', 'core/modal_events', 'core/n
var formData = form.serialize();
this.showFormModal(formData);
} else {
Str.get_strings(this.stringKeys).done(function(strings) {
Notification.alert('', strings[2], strings[3]);
});
Str.get_strings([
{key: 'notice'},
{key: 'selectusersforconsent', component: 'tool_policy'},
{key: 'ok'}
]).then(function(strings) {
Notification.alert(strings[0], strings[1], strings[2]);
return;
}).fail(Notification.exception);
}
}.bind(this));
};
@@ -143,18 +118,28 @@ define(['jquery', 'core/str', 'core/modal_factory', 'core/modal_events', 'core/n
}
}
// Fetch the title string.
Str.get_strings(this.stringKeys).done(function(strings) {
Str.get_strings([
{key: 'statusformtitleaccept', component: 'tool_policy'},
{key: 'iagreetothepolicy', component: 'tool_policy'},
{key: 'statusformtitlerevoke', component: 'tool_policy'},
{key: 'irevokethepolicy', component: 'tool_policy'},
{key: 'statusformtitledecline', component: 'tool_policy'},
{key: 'declinethepolicy', component: 'tool_policy'}
]).then(function(strings) {
var title;
var saveText;
if (action == 'revoke') {
title = strings[4];
saveText = strings[5];
} else {
if (action == 'accept') {
title = strings[0];
saveText = strings[1];
} else if (action == 'revoke') {
title = strings[2];
saveText = strings[3];
} else if (action == 'decline') {
title = strings[4];
saveText = strings[5];
}
// Create the modal.
ModalFactory.create({
return ModalFactory.create({
type: ModalFactory.types.SAVE_CANCEL,
title: title,
body: ''
@@ -163,7 +148,7 @@ define(['jquery', 'core/str', 'core/modal_factory', 'core/modal_events', 'core/n
this.setupFormModal(formData, saveText);
}.bind(this));
}.bind(this))
.fail(Notification.exception);
.catch(Notification.exception);
};

/**
@@ -177,21 +177,23 @@ protected function configure_for_single_version() {
$filterstatus = $this->acceptancesfilter->get_status_filter();
if ($filterstatus == 1) {
$this->sql->from .= " $join AND a{$v}.status=1";
} else if ($filterstatus == 2) {
$this->sql->from .= " $join AND a{$v}.status=0";
} else {
$this->sql->from .= " LEFT $join";
}

$this->sql->from .= " LEFT JOIN {user} m ON m.id = a{$v}.usermodified AND m.id <> u.id AND a{$v}.status = 1";
$this->sql->from .= " LEFT JOIN {user} m ON m.id = a{$v}.usermodified AND m.id <> u.id AND a{$v}.status IS NOT NULL";

$this->sql->params['versionid' . $v] = $v;

if ($filterstatus === 0) {
$this->sql->where .= " AND (a{$v}.status IS NULL OR a{$v}.status = 0)";
$this->sql->where .= " AND a{$v}.status IS NULL";
}

$this->add_column_header('status' . $v, get_string('agreed', 'tool_policy'), true, 'mdl-align');
$this->add_column_header('timemodified', get_string('agreedon', 'tool_policy'));
$this->add_column_header('usermodified' . $v, get_string('agreedby', 'tool_policy'));
$this->add_column_header('status' . $v, get_string('response', 'tool_policy'));
$this->add_column_header('timemodified', get_string('responseon', 'tool_policy'));
$this->add_column_header('usermodified' . $v, get_string('responseby', 'tool_policy'));
$this->add_column_header('note', get_string('acceptancenote', 'tool_policy'), false);
}

@@ -207,19 +209,21 @@ protected function configure_for_multiple_versions() {
$join = "JOIN {tool_policy_acceptances} a{$v} ON a{$v}.userid = u.id AND a{$v}.policyversionid=:versionid{$v}";
if ($filterstatus == 1) {
$this->sql->from .= " {$join} AND a{$v}.status=1";
} else if ($filterstatus == 2) {
$this->sql->from .= " {$join} AND a{$v}.status=0";
} else {
$this->sql->from .= " LEFT {$join}";
}
$this->sql->params['versionid' . $v] = $v;
$this->add_column_header('status' . $v, $versionname, true, 'mdl-align');
$this->add_column_header('status' . $v, $versionname);
$statusall[] = "COALESCE(a{$v}.status, 0)";
}
$this->sql->fields .= ",".join('+', $statusall)." AS statusall";

if ($filterstatus === 0) {
$statussql = [];
foreach ($this->versionids as $v => $versionname) {
$statussql[] = "a{$v}.status IS NULL OR a{$v}.status = 0";
$statussql[] = "a{$v}.status IS NULL";
}
$this->sql->where .= " AND (u.policyagreed = 0 OR ".join(" OR ", $statussql).")";
}
@@ -420,7 +424,7 @@ public function wrap_html_start() {
echo \html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'returnurl',
'value' => $this->get_return_url()]);
foreach (array_keys($this->versionids) as $versionid) {
echo \html_writer::empty_tag('input', ['type' => 'hidden', 'name' => "versionids[{$versionid}]",
echo \html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'versionids[]',
'value' => $versionid]);
}
}
@@ -433,6 +437,7 @@ public function wrap_html_start() {
public function wrap_html_finish() {
global $PAGE;
if ($this->canagreeany) {
echo \html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'action', 'value' => 'accept']);
echo \html_writer::empty_tag('input', ['type' => 'submit', 'data-action' => 'acceptmodal',
'value' => get_string('consentbulk', 'tool_policy'), 'class' => 'btn btn-primary m-t-1']);
$PAGE->requires->js_call_amd('tool_policy/acceptmodal', 'getInstance', [\context_system::instance()->id]);
@@ -529,36 +534,29 @@ protected function status($versionid, $row) {
$onbehalf = false;
$versions = $versionid ? [$versionid => $this->versionids[$versionid]] : $this->versionids; // List of versions.
$accepted = []; // List of versionids that user has accepted.
$declined = [];

foreach ($versions as $v => $name) {
if (!empty($row->{'status' . $v})) {
$accepted[] = $v;
if ($row->{'status' . $v} !== null) {
if (empty($row->{'status' . $v})) {
$declined[] = $v;
} else {
$accepted[] = $v;
}
$agreedby = $row->{'usermodified' . $v};
if ($agreedby && $agreedby != $row->id) {
$onbehalf = true;
}
}
}

if ($versionid) {
$str = new \lang_string($accepted ? 'yes' : 'no');
} else {
$str = new \lang_string('acceptancecount', 'tool_policy', (object)[
'agreedcount' => count($accepted),
'policiescount' => count($versions)
]);
}
$ua = new user_agreement($row->id, $accepted, $declined, $this->get_return_url(), $versions, $onbehalf, $row->canaccept);

if ($this->is_downloading()) {
return $str->out();
return $ua->export_for_download();

} else {
$s = $this->output->render(new user_agreement($row->id, $accepted, $this->get_return_url(),
$versions, $onbehalf, $row->canaccept));
if (!$versionid) {
$s .= '<br>' . \html_writer::link(new \moodle_url('/admin/tool/policy/user.php',
['userid' => $row->id, 'returnurl' => $this->get_return_url()]), $str);
}
return $s;
return $this->output->render($ua);
}
}

0 comments on commit 14f70ed

Please sign in to comment.