Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
WIP #132 Add 'canViewProfiles' permission
Browse files Browse the repository at this point in the history
  • Loading branch information
JN-Jones committed May 24, 2015
1 parent dc88d8d commit c24c0db
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
14 changes: 11 additions & 3 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -43,25 +45,31 @@ public function __construct(
* @param int $id
* @param ProfileFieldGroupRepositoryInterface $profileFieldGroups
* @param Breadcrumbs $breadcrumbs
* @param PermissionChecker $permissionChecker
*
* @return \Illuminate\View\View
*/
public function profile(
$slug,
$id,
ProfileFieldGroupRepositoryInterface $profileFieldGroups,
Breadcrumbs $breadcrumbs
Breadcrumbs $breadcrumbs,
PermissionChecker $permissionChecker
) {
$user = $this->users->find($id);

if (!$user) {
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
Expand Down
6 changes: 6 additions & 0 deletions database/seeds/PermissionRoleTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions database/seeds/PermissionsTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c24c0db

Please sign in to comment.