From c24c0db3d07d90116d03206c2f5fdf2391a2bcad Mon Sep 17 00:00:00 2001 From: JN-Jones Date: Sun, 24 May 2015 20:44:51 +0200 Subject: [PATCH] WIP #132 Add 'canViewProfiles' permission --- app/Http/Controllers/UserController.php | 14 +++++++++++--- database/seeds/PermissionRoleTableSeeder.php | 6 ++++++ database/seeds/PermissionsTableSeeder.php | 5 +++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 2efe5ad..235f147 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -13,6 +13,8 @@ use MyBB\Core\Database\Repositories\ProfileFieldGroupRepositoryInterface; use MyBB\Core\Database\Repositories\UserProfileFieldRepositoryInterface; use MyBB\Core\Exceptions\UserNotFoundException; +use MyBB\Core\Permissions\PermissionChecker; +use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; class UserController extends AbstractController { @@ -43,6 +45,7 @@ public function __construct( * @param int $id * @param ProfileFieldGroupRepositoryInterface $profileFieldGroups * @param Breadcrumbs $breadcrumbs + * @param PermissionChecker $permissionChecker * * @return \Illuminate\View\View */ @@ -50,7 +53,8 @@ public function profile( $slug, $id, ProfileFieldGroupRepositoryInterface $profileFieldGroups, - Breadcrumbs $breadcrumbs + Breadcrumbs $breadcrumbs, + PermissionChecker $permissionChecker ) { $user = $this->users->find($id); @@ -58,10 +62,14 @@ public function profile( throw new UserNotFoundException; } - $groups = $profileFieldGroups->getAll(); - $breadcrumbs->setCurrentRoute('user.profile', $user); + if (!$permissionChecker->hasPermission('user', null, 'canViewProfiles')) { + throw new AccessDeniedHttpException; + } + + $groups = $profileFieldGroups->getAll(); + return view('user.profile', [ 'user' => $user, 'profile_field_groups' => $groups diff --git a/database/seeds/PermissionRoleTableSeeder.php b/database/seeds/PermissionRoleTableSeeder.php index 0923d2f..726bc3b 100644 --- a/database/seeds/PermissionRoleTableSeeder.php +++ b/database/seeds/PermissionRoleTableSeeder.php @@ -119,6 +119,12 @@ public function run() 'value' => PermissionChecker::NO, 'content_id' => 0 ], + [ + 'permission_id' => $this->perm('canViewProfiles'), + 'role_id' => $this->role('banned'), + 'value' => PermissionChecker::NEVER, + 'content_id' => null + ], ]; DB::table('permission_role')->insert($permissions_role); diff --git a/database/seeds/PermissionsTableSeeder.php b/database/seeds/PermissionsTableSeeder.php index 5494743..5c2b88f 100644 --- a/database/seeds/PermissionsTableSeeder.php +++ b/database/seeds/PermissionsTableSeeder.php @@ -82,6 +82,11 @@ public function run() 'content_name' => 'forum', 'default_value' => PermissionChecker::NO ], + [ + 'permission_name' => 'canViewProfiles', + 'content_name' => null, + 'default_value' => PermissionChecker::YES + ], ]; DB::table('permissions')->insert($permissions);