Skip to content

Commit

Permalink
fix(comments): give comment authors edit privileges
Browse files Browse the repository at this point in the history
It's pretty typical for other networks to allow comment authors
to edit their comments after posting. Also, discussion replies
used to be editable, so we are restoring the logic to match the
old behavior.

Fixes #6724
  • Loading branch information
ewinslow committed Apr 20, 2014
1 parent 6ab0249 commit 68c6ded
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
24 changes: 0 additions & 24 deletions engine/classes/ElggComment.php
Expand Up @@ -33,30 +33,6 @@ public function canComment($user_guid = 0) {
return false;
}

/**
* Can a user edit this comment?
*
* @tip Can be overridden by registering for the permissions_check plugin hook.
*
* @param int $user_guid The user GUID, optionally (default: logged in user)
*
* @return bool Whether this comment is editable by the given user.
* @see elgg_set_ignore_access()
*/
public function canEdit($user_guid = 0) {
$user_guid = (int)$user_guid;
$user = get_entity($user_guid);
if (!$user) {
$user = elgg_get_logged_in_user_entity();
}

// default is to only allow admins to edit.
$return = ($user && $user->isAdmin());

$params = array('entity' => $this, 'user' => $user);
return elgg_trigger_plugin_hook('permissions_check', $this->type, $params, $return);
}

/**
* Update container entity last action on successful save.
*
Expand Down
24 changes: 23 additions & 1 deletion engine/lib/comments.php
Expand Up @@ -20,6 +20,7 @@ function _elgg_comments_init() {
elgg_register_plugin_hook_handler('register', 'menu:entity', '_elgg_comment_setup_entity_menu', 900);
elgg_register_plugin_hook_handler('entity:url', 'object', '_elgg_comment_url_handler');
elgg_register_plugin_hook_handler('container_permissions_check', 'object', '_elgg_comments_container_permissions_override');
elgg_register_plugin_hook_handler('permissions_check', 'object', '_elgg_comments_permissions_override');

elgg_register_page_handler('comment', '_elgg_comments_page_handler');

Expand Down Expand Up @@ -170,4 +171,25 @@ function _elgg_comments_container_permissions_override($hook, $type, $return, $p
}

return $return;
}
}

/**
* By default, only authors can edit their comments.
*
* @param string $hook 'permissions_check'
* @param string $type 'object'
* @param boolean $return Can the given user edit the given entity?
* @param array $params Array of parameters (entity, user)
*
* @return boolean Whether the given user is allowed to edit the given comment.
*/
function _elgg_comments_permissions_override($hook, $type, $return, $params) {
$entity = $params['entity'];
$user = $params['user'];

if (elgg_instanceof($entity, 'object', 'comment') && $user) {
return $entity->getOwnerGUID() == $user->getGUID();
}

return $return;
}
4 changes: 4 additions & 0 deletions mod/groups/start.php
Expand Up @@ -1120,6 +1120,10 @@ function discussion_can_edit_reply($hook, $type, $return, $params) {
if (!elgg_instanceof($reply, 'object', 'discussion_reply', 'ElggDiscussionReply')) {
return $return;
}

if ($reply->owner_guid == $user->guid) {
return true;
}

$discussion = $reply->getContainerEntity();
if ($discussion->owner_guid == $user->guid) {
Expand Down

0 comments on commit 68c6ded

Please sign in to comment.