Skip to content

Commit

Permalink
MDL-62309 tool_policy: Update user acceptances reports
Browse files Browse the repository at this point in the history
This adds support for optional policies to the user acceptance reports.
Distinguished are "Pending" acceptances (we did not hear yet) from
"Declined" (user did not agree). The status workflow updated to support
new transitions: pending -> declined and declined -> accepted.
  • Loading branch information
mudrd8mz committed Oct 22, 2018
1 parent 56390aa commit 4a742e4
Show file tree
Hide file tree
Showing 14 changed files with 468 additions and 279 deletions.
12 changes: 5 additions & 7 deletions admin/tool/policy/accept.php
Expand Up @@ -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) {
Expand All @@ -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();
2 changes: 1 addition & 1 deletion admin/tool/policy/amd/build/acceptmodal.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 25 additions & 40 deletions admin/tool/policy/amd/src/acceptmodal.js
Expand Up @@ -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
Expand Down Expand Up @@ -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));
};
Expand All @@ -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: ''
Expand All @@ -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);
};

/**
Expand Down
50 changes: 24 additions & 26 deletions admin/tool/policy/classes/acceptances_table.php
Expand Up @@ -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);
}

Expand All @@ -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).")";
}
Expand Down Expand Up @@ -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]);
}
}
Expand All @@ -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]);
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions admin/tool/policy/classes/api.php
Expand Up @@ -760,14 +760,14 @@ public static function get_policies_with_acceptances($userid) {
if (isset($acceptances[$policy->currentversion->id])) {
$policy->currentversion->acceptance = $acceptances[$policy->currentversion->id];
} else {
$policy->currentversion->acceptance = 0;
$policy->currentversion->acceptance = null;
}
$versions[] = $policy->currentversion;
}
foreach ($policy->archivedversions as $version) {
if ($version->audience != policy_version::AUDIENCE_GUESTS
&& static::can_user_view_policy_version($version, $userid)) {
$version->acceptance = isset($acceptances[$version->id]) ? $acceptances[$version->id] : 0;
$version->acceptance = isset($acceptances[$version->id]) ? $acceptances[$version->id] : null;
$versions[] = $version;
}
}
Expand Down

0 comments on commit 4a742e4

Please sign in to comment.