-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add disciplinary controller for banning and unbanning members
- Loading branch information
Showing
8 changed files
with
127 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace BB\Http\Controllers; | ||
|
||
use BB\Entities\User; | ||
use BB\Helpers\GoCardlessHelper; | ||
use Illuminate\Http\Request; | ||
|
||
class DisciplinaryController extends Controller | ||
{ | ||
protected $goCardlessHelper; | ||
public function __construct(GoCardlessHelper $goCardlessHelper) { | ||
$this->goCardlessHelper = $goCardlessHelper; | ||
} | ||
|
||
public function ban(User $user, Request $request) | ||
{ | ||
$this->authorize('ban', $user); | ||
|
||
// validation | ||
$this->validate($request, [ | ||
'reason' => 'required|string|max:255', | ||
]); | ||
|
||
$user->update([ | ||
'active' => false, | ||
'status' => 'left', | ||
'banned' => true, | ||
'banned_reason' => $request->get('reason'), | ||
'banned_date' => \Carbon\Carbon::now(), | ||
]); | ||
|
||
// Cancel the user's subscription (if they have one) | ||
if ($user->subscription_id) { | ||
$this->goCardlessHelper->cancelSubscription($user->subscription_id); | ||
} | ||
|
||
return redirect()->back(); | ||
} | ||
|
||
public function unban(User $user) | ||
{ | ||
$this->authorize('unban', $user); | ||
|
||
$user->update([ | ||
'banned' => false, | ||
'banned_reason' => null, | ||
'banned_date' => null, | ||
]); | ||
|
||
return redirect()->back(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace BB\Policies; | ||
|
||
use BB\Entities\User; | ||
use Illuminate\Auth\Access\HandlesAuthorization; | ||
|
||
class UserPolicy | ||
{ | ||
use HandlesAuthorization; | ||
|
||
public function ban(User $authedUser, User $user) | ||
{ | ||
// Can't ban yourself | ||
if ($authedUser->id == $user->id) { | ||
return false; | ||
} | ||
|
||
// Admins can ban others | ||
return $authedUser->isAdmin(); | ||
} | ||
|
||
public function unban(User $authedUser, User $user) | ||
{ | ||
// Admins can ban others | ||
return $authedUser->isAdmin(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters