Skip to content

Commit

Permalink
MDL-74169 core_message: Hide preferences link when permissions lacking
Browse files Browse the repository at this point in the history
  • Loading branch information
FMCorz committed Mar 21, 2022
1 parent 0d0f09b commit bee1bb3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions message/classes/helper.php
Expand Up @@ -622,6 +622,7 @@ public static function render_messaging_widget(
'isdrawer' => $isdrawer,
'showemojipicker' => !empty($CFG->allowemojipicker),
'messagemaxlength' => api::MESSAGE_MAX_LENGTH,
'caneditownmessageprofile' => has_capability('moodle/user:editownmessageprofile', \context_system::instance())
];

if ($sendtouser || $conversationid) {
Expand Down
4 changes: 3 additions & 1 deletion message/output/popup/lib.php
Expand Up @@ -44,12 +44,14 @@ function message_popup_render_navbar_output(\renderer_base $renderer) {
$enabled = \core_message\api::is_processor_enabled("popup");
if ($enabled) {
$unreadcount = \message_popup\api::count_unread_popup_notifications($USER->id);
$caneditownmessageprofile = has_capability('moodle/user:editownmessageprofile', context_system::instance());
$preferencesurl = $caneditownmessageprofile ? new moodle_url('/message/notificationpreferences.php') : null;
$context = [
'userid' => $USER->id,
'unreadcount' => $unreadcount,
'urls' => [
'seeall' => (new moodle_url('/message/output/popup/notifications.php'))->out(),
'preferences' => (new moodle_url('/message/notificationpreferences.php', ['userid' => $USER->id]))->out(),
'preferences' => $preferencesurl ? $preferencesurl->out() : null,
],
];
$output .= $renderer->render_from_template('message_popup/notification_popover', $context);
Expand Down
11 changes: 6 additions & 5 deletions message/output/popup/templates/notification_popover.mustache
Expand Up @@ -62,11 +62,12 @@
<span class="normal-icon">{{#pix}} t/markasread, core {{/pix}}</span>
{{> core/loading }}
</a>
<a href="{{{urls.preferences}}}"
title="{{#str}} notificationpreferences, message {{/str}}"
aria-label="{{#str}} notificationpreferences, message {{/str}}">
{{#pix}} i/settings, core {{/pix}}
</a>
{{# urls.preferences }}
<a href="{{{ . }}}"
title="{{#str}} notificationpreferences, message {{/str}}"
aria-label="{{#str}} notificationpreferences, message {{/str}}">
{{#pix}} i/settings, core {{/pix}}</a>
{{/ urls.preferences }}
{{/headeractions}}

{{$content}}
Expand Down
Expand Up @@ -49,6 +49,7 @@
</span>
</div>
</div>
{{#caneditownmessageprofile}}
<div class="ml-2">
<a
href="#"
Expand All @@ -60,6 +61,7 @@
{{#pix}} t/edit, core {{/pix}}
</a>
</div>
{{/caneditownmessageprofile}}
</div>
<div class="text-right mt-sm-3">
<a href="#" data-route="view-contacts" role="button">
Expand Down

0 comments on commit bee1bb3

Please sign in to comment.