Created
May 24, 2023 22:00
-
-
Save marksparrish/105796f6afe01401ebf8172cb0fd279c to your computer and use it in GitHub Desktop.
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
<?php | |
/** | |
* Updated app/Policies/TeamPolicy.php | |
*/ | |
namespace App\Policies; | |
use App\Models\Team; | |
use App\Models\User; | |
use Illuminate\Auth\Access\HandlesAuthorization; | |
class TeamPolicy | |
{ | |
use HandlesAuthorization; | |
/** | |
* Determine whether the user can view any models. | |
*/ | |
public function viewAny(User $user): bool | |
{ | |
return false; | |
} | |
/** | |
* Determine whether the user can view the model. | |
*/ | |
public function view(User $user, Team $team): bool | |
{ | |
return $user->belongsToTeam($team); | |
} | |
/** | |
* Determine whether the user can create models. | |
* | |
* @param \App\Models\User $user | |
* @return mixed | |
*/ | |
public function create(User $user) | |
{ | |
return false; | |
} | |
/** | |
* Determine whether the user can update the model. | |
* | |
* @param \App\Models\User $user | |
* @param \App\Models\Team $team | |
* @return mixed | |
*/ | |
public function update(User $user, Team $team) | |
{ | |
// return true if the team is the users personal team | |
if ($team->id == $user->personalTeam()->id) return true; | |
return false; | |
} | |
/** | |
* Determine whether the user can add team members. | |
* | |
* @param \App\Models\User $user | |
* @param \App\Models\Team $team | |
* @return mixed | |
*/ | |
public function addTeamMember(User $user, Team $team) | |
{ | |
// return true if the current team is the users personal team | |
if ($team->id == $user->personalTeam()->id) return true; | |
return false; | |
} | |
/** | |
* Determine whether the user can update team member permissions. | |
* | |
* @param \App\Models\User $user | |
* @param \App\Models\Team $team | |
* @return mixed | |
*/ | |
public function updateTeamMember(User $user, Team $team) | |
{ | |
if ($team->id == $user->personalTeam()->id) return true; | |
return false; | |
} | |
/** | |
* Determine whether the user can remove team members. | |
* | |
* @param \App\Models\User $user | |
* @param \App\Models\Team $team | |
* @return mixed | |
*/ | |
public function removeTeamMember(User $user, Team $team) | |
{ | |
if ($team->id == $user->personalTeam()->id) return true; | |
return false; | |
} | |
/** | |
* Determine whether the user can delete the model. | |
* | |
* @param \App\Models\User $user | |
* @param \App\Models\Team $team | |
* @return mixed | |
*/ | |
public function delete(User $user, Team $team) | |
{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment