Last active
October 19, 2021 20:52
-
-
Save marksparrish/6a65998a6502a69d92eb3614c5c106d9 to your computer and use it in GitHub Desktop.
Personal Teams can add members
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 | |
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. | |
* | |
* @param \App\Models\User $user | |
* @return mixed | |
*/ | |
public function viewAny(User $user) | |
{ | |
return true; | |
} | |
/** | |
* Determine whether the user can view the model. | |
* | |
* @param \App\Models\User $user | |
* @param \App\Models\Team $team | |
* @return mixed | |
*/ | |
public function view(User $user, Team $team) | |
{ | |
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