1
0
mirror of https://github.com/flarum/core.git synced 2025-10-18 10:16:09 +02:00

Rename viewDiscussions => viewForum, viewUserList => searchUsers (#2854)

This naming is clearer as to the intended effect. Changes include:

- A migration to rename all permissions
- Updating the seed migration to use the original naming from the start
- Replacing usage of the old names with new names in code
- Throwing warnings when the old names are used.
This commit is contained in:
Alexander Skvortsov
2021-05-11 15:15:27 -04:00
committed by GitHub
parent 06f63a2087
commit d64750b3eb
17 changed files with 82 additions and 37 deletions

View File

@@ -75,7 +75,7 @@ class ListUsersController extends AbstractListController
{
$actor = RequestUtil::getActor($request);
$actor->assertCan('viewUserList');
$actor->assertCan('searchUsers');
if (! $actor->hasPermission('user.viewLastSeenAt')) {
// If a user cannot see everyone's last online date, we prevent them from sorting by it

View File

@@ -88,9 +88,9 @@ class ForumSerializer extends AbstractSerializer
'footerHtml' => $this->settings->get('custom_footer'),
'allowSignUp' => (bool) $this->settings->get('allow_sign_up'),
'defaultRoute' => $this->settings->get('default_route'),
'canViewDiscussions' => $this->actor->can('viewDiscussions'),
'canViewForum' => $this->actor->can('viewForum'),
'canStartDiscussion' => $this->actor->can('startDiscussion'),
'canViewUserList' => $this->actor->can('viewUserList')
'canSearchUsers' => $this->actor->can('searchUsers')
];
if ($this->actor->can('administrate')) {

View File

@@ -20,7 +20,7 @@ class ScopeDiscussionVisibility
*/
public function __invoke(User $actor, $query)
{
if ($actor->cannot('viewDiscussions')) {
if ($actor->cannot('viewForum')) {
$query->whereRaw('FALSE');
return;

View File

@@ -20,7 +20,7 @@ class ScopeUserVisibility
*/
public function __invoke(User $actor, $query)
{
if ($actor->cannot('viewDiscussions')) {
if ($actor->cannot('viewForum')) {
if ($actor->isGuest()) {
$query->whereRaw('FALSE');
} else {

View File

@@ -404,6 +404,15 @@ class User extends AbstractModel
return false;
}
private function checkForDeprecatedPermissions($permission)
{
foreach (['viewDiscussions', 'viewUserList'] as $deprecated) {
if (strpos($permission, $deprecated) !== false) {
trigger_error('The `viewDiscussions` and `viewUserList` permissions have been renamed to `viewForum` and `searchUsers` respectively. Please use those instead.', E_USER_DEPRECATED);
}
}
}
/**
* Get the notification types that should be alerted to this user, according
* to their preferences.