-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,27 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
|
||
class EnsureHasTeam | ||
{ | ||
public function handle(Request $request, Closure $next) | ||
{ | ||
if (!auth()->user()->isMemberOfATeam()) { | ||
return redirect()->route('teams.create'); | ||
} | ||
$this->ensureUserHasCurrentTeamSet(); | ||
return $next($request); | ||
} | ||
|
||
protected function ensureUserHasCurrentTeamSet(): void | ||
{ | ||
if (is_null(auth()->user()->current_team_id)) { | ||
$user = auth()->user(); | ||
$user->current_team_id = $user->allTeams()->first()->id; | ||
$user->save(); | ||
} | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace App\Traits; | ||
|
||
trait HasNoPersonalTeam | ||
{ | ||
|
||
/** | ||
* Determine if the user owns the given team. | ||
* | ||
* @param mixed $team | ||
* @return bool | ||
*/ | ||
public function ownsTeam($team) | ||
{ | ||
// return $this->id == $team->user_id; | ||
return $this->id == optional($team)->user_id; | ||
} | ||
|
||
/** | ||
* Determine if the given team is the current team. | ||
* | ||
* @param mixed $team | ||
* @return bool | ||
*/ | ||
public function isCurrentTeam($team) | ||
{ | ||
return optional($team)->id === $this->currentTeam->id; | ||
} | ||
|
||
/** | ||
* Determine if the user is apart of any team. | ||
* | ||
* @param mixed $team | ||
* @return bool | ||
*/ | ||
public function isMemberOfATeam(): bool | ||
{ | ||
return (bool) ($this->teams()->count() || $this->ownedTeams()->count()); | ||
} | ||
|
||
} |
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