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 'canUseCustomTitle' permission
Browse files Browse the repository at this point in the history
  • Loading branch information
JN-Jones committed May 24, 2015
1 parent 3012ea8 commit 335c4cb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
21 changes: 17 additions & 4 deletions app/Http/Controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use MyBB\Core\Database\Repositories\ProfileFieldGroupRepositoryInterface;
use MyBB\Core\Database\Repositories\UserProfileFieldRepositoryInterface;
use MyBB\Core\Http\Requests\Account\UpdateProfileRequest;
use MyBB\Core\Permissions\PermissionChecker;
use MyBB\Core\Services\ConfirmationManager;
use MyBB\Settings\Store;

Expand All @@ -26,14 +27,21 @@ class AccountController extends AbstractController
*/
private $guard;

/**
* @var PermissionChecker
*/
private $permissionChecker;

/**
* Create a new controller instance.
*
* @param Guard $guard
* @param PermissionChecker $permissionChecker
*/
public function __construct(Guard $guard)
public function __construct(Guard $guard, PermissionChecker $permissionChecker)
{
$this->guard = $guard;
$this->permissionChecker = $permissionChecker;
}

/**
Expand Down Expand Up @@ -74,11 +82,16 @@ public function getProfile(ProfileFieldGroupRepositoryInterface $profileFieldGro
public function postProfile(UpdateProfileRequest $request, UserProfileFieldRepositoryInterface $userProfileFields)
{
// handle updates to the user model
$input = $request->only(['usertitle']);
$input['dob'] = $request->get('date_of_birth_day') .
$update = array();

if($this->permissionChecker->hasPermission('user', null, 'canUseCustomTitle')) {
$update['usertitle'] = $request->get('usertitle');
}

$update['dob'] = $request->get('date_of_birth_day') .
'-' . $request->get('date_of_birth_month') .
'-' . $request->get('date_of_birth_year');
$this->guard->user()->update($input);
$this->guard->user()->update($update);

// handle profile field updates
$profileFieldData = $request->get('profile_fields');
Expand Down
12 changes: 12 additions & 0 deletions app/Presenters/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ public function styled_name()
return e($this->wrappedObject->name);
}

/**
* @return string
*/
public function usertitle()
{
if (!$this->hasPermission('canUseCustomTitle')) {
return '';
}

return $this->wrappedObject->usertitle;
}

/**
* @return string
*/
Expand Down
12 changes: 12 additions & 0 deletions database/seeds/PermissionRoleTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ public function run()
'value' => PermissionChecker::NEVER,
'content_id' => null
],
[
'permission_id' => $this->perm('canUseCustomTitle'),
'role_id' => $this->role('guest'),
'value' => PermissionChecker::NO,
'content_id' => null
],
[
'permission_id' => $this->perm('canUseCustomTitle'),
'role_id' => $this->role('banned'),
'value' => PermissionChecker::NO,
'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 @@ -87,6 +87,11 @@ public function run()
'content_name' => null,
'default_value' => PermissionChecker::YES
],
[
'permission_name' => 'canUseCustomTitle',
'content_name' => null,
'default_value' => PermissionChecker::YES
],
];

DB::table('permissions')->insert($permissions);
Expand Down
12 changes: 7 additions & 5 deletions resources/views/account/profile.twig
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@
{{ form_selectMonth('date_of_birth_month', dob.month) }}
{{ form_text('date_of_birth_year', dob.year, {'maxlength': 4, 'class': 'short'}) }}
</div>
<div class="form__row">
<h3><label for="usertitle">{{ trans('account.usertitle') }}</label></h3>
<p class="form__description">{{ trans('account.usertitle_desc') }}</p>
{{ form_text('usertitle', auth_user().usertitle) }}
</div>
{% if auth_user.hasPermission('canUseCustomTitle') %}
<div class="form__row">
<h3><label for="usertitle">{{ trans('account.usertitle') }}</label></h3>
<p class="form__description">{{ trans('account.usertitle_desc') }}</p>
{{ form_text('usertitle', auth_user().usertitle) }}
</div>
{% endif %}
</div>
</div>
</section>
Expand Down

0 comments on commit 335c4cb

Please sign in to comment.