Hum, nobody struggles with that problem? Same goes with delete functionality by the way.
I've dived into it a little more. In the DiscussionPolicy
class, I've found the methods rename
and hide
. For testing purpose I changed the method rename
from
public function rename(User $actor, Discussion $discussion)
{
if ($discussion->user_id == $actor->id && $actor->can('reply', $discussion)) {
$allowRenaming = $this->settings->get('allow_renaming');
if ($allowRenaming === '-1'
|| ($allowRenaming === 'reply' && $discussion->participant_count <= 1)
|| ($discussion->created_at->diffInMinutes() < $allowRenaming)) {
return true;
}
}
}
to a simple
public function rename(User $actor, Discussion $discussion)
{
return false;
}
and tested on tag A and tag B. No renaming was possible anywhere in the Flarum. That's good, I'm at the right place, I thought. So I changed again to
public function rename(User $actor, Discussion $discussion)
{
return true;
}
and tag A works as before and tag B...tag B still does not work. I have absolutely no idea how this is possible. There is still no renaming functionality even if I do a return true
.
Anyone any clues?
What else does affect the display of the rename and deletion options?
edit (some time later)
I was able to find the relevant position now. I was talking about the Flarum\Discussion\DiscussionPolicy
class right before, but the issue is connected to the permission restricted by tags so I needed to have a look at the tags extension. There you will find the Flarum\Tags\Access\DiscussionPolicy
class with the method
public function can(User $actor, $ability, Discussion $discussion)
{
(...)
if (! $actor->hasPermission('tag'.$tag->id.'.discussion.'.$ability)) {
return false;
}
(...)
}
which does not include the exceptional permissions for the author of the discussion. So I changed the if
condition to
public function can(User $actor, $ability, Discussion $discussion)
{
(...)
if (
$discussion->user_id == $actor->id
&& ($ability == 'hide' || $ability == 'rename')
) {
return true;
} elseif (! $actor->hasPermission('tag'.$tag->id.'.discussion.'.$ability)) {
return false;
}
(...)
}
which now will grant access to renaming and deleting (hide) for the author even if it's a restricted tag.
This workaround looks to work for my use case, but have to test even more. However, it will grant access to these option everytime now! Even if you explicitly restrict it for a tag or restrict the renaming time.