mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +02:00
MDL-78300 block: Determine if users can comment based on context
This commit is contained in:
parent
f3790e330a
commit
9d97e933e8
1 changed files with 20 additions and 1 deletions
|
@ -59,7 +59,26 @@ function block_comments_comment_validate($comment_param) {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function block_comments_comment_permissions($args) {
|
function block_comments_comment_permissions($args) {
|
||||||
return array('post'=>true, 'view'=>true);
|
global $DB, $USER;
|
||||||
|
// By default, anyone can post and view comments.
|
||||||
|
$canpost = $canview = true;
|
||||||
|
// Check if it's the user context and not the owner's profile.
|
||||||
|
if ($args->context->contextlevel == CONTEXT_USER && $USER->id != $args->context->instanceid) {
|
||||||
|
// Check whether the context owner has a comment block in the user's profile.
|
||||||
|
$sqlparam = [
|
||||||
|
'blockname' => 'comments',
|
||||||
|
'parentcontextid' => $args->context->id,
|
||||||
|
'pagetypepattern' => 'user-profile',
|
||||||
|
];
|
||||||
|
// If the comment block is not present at the target user's profile,
|
||||||
|
// then the logged-in user cannot post or view comments.
|
||||||
|
$canpost = $canview = $DB->record_exists_select(
|
||||||
|
'block_instances',
|
||||||
|
'blockname = :blockname AND parentcontextid = :parentcontextid AND pagetypepattern = :pagetypepattern',
|
||||||
|
$sqlparam,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return ['post' => $canpost, 'view' => $canview];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue