Skip to content

Commit

Permalink
added connected account policy and publishable auth service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Butcher committed Mar 2, 2021
1 parent ea12356 commit c5f4e08
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ protected function installLivewireStack()
(new Filesystem)->ensureDirectoryExists(resource_path('views/components'));

// Service Providers...
copy(__DIR__.'/../../stubs/app/Providers/AuthServiceProvider.php', app_path('Providers/AuthServiceProvider.php'));
copy(__DIR__.'/../../stubs/app/Providers/SocialstreamServiceProvider.php', app_path('Providers/SocialstreamServiceProvider.php'));
$this->installServiceProviderAfter('JetstreamServiceProvider', 'SocialstreamServiceProvider');

Expand Down Expand Up @@ -132,6 +133,7 @@ protected function installInertiaStack()
(new Filesystem)->ensureDirectoryExists(resource_path('js/Pages/Profile'));

// Service Providers...
copy(__DIR__.'/../../stubs/app/Providers/AuthServiceProvider.php', app_path('Providers/AuthServiceProvider.php'));
copy(__DIR__.'/../../stubs/app/Providers/SocialstreamServiceProvider.php', app_path('Providers/SocialstreamServiceProvider.php'));
$this->installServiceProviderAfter('JetstreamServiceProvider', 'SocialstreamServiceProvider');

Expand Down Expand Up @@ -170,7 +172,10 @@ protected function installInertiaStack()
*/
protected function ensureTeamsCompatibility()
{
// User model...
// Service Provider...
copy(__DIR__.'/../../stubs/app/Providers/TeamsAuthServiceProvider.php', app_path('Providers/AuthServiceProvider.php'));

// User Model...
copy(__DIR__.'/../../stubs/app/Models/UserWithTeams.php', app_path('Models/User.php'));

// Jetstream Actions...
Expand Down
70 changes: 70 additions & 0 deletions stubs/app/Policies/ConnectedAccountPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace App\Policies;

use App\Models\ConnectedAccount;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class ConnectedAccountPolicy
{
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\ConnectedAccount $connectedAccount
* @return mixed
*/
public function view(User $user, ConnectedAccount $connectedAccount)
{
return $user->ownsConnectedAccount($connectedAccount);
}

/**
* Determine whether the user can create models.
*
* @param \App\Models\User $user
* @return mixed
*/
public function create(User $user)
{
return true;
}

/**
* Determine whether the user can update the model.
*
* @param \App\Models\User $user
* @param \App\Models\ConnectedAccount $connectedAccount
* @return mixed
*/
public function update(User $user, ConnectedAccount $connectedAccount)
{
return $user->ownsConnectedAccount($connectedAccount);
}

/**
* Determine whether the user can delete the model.
*
* @param \App\Models\User $user
* @param \App\Models\ConnectedAccount $connectedAccount
* @return mixed
*/
public function delete(User $user, ConnectedAccount $connectedAccount)
{
return $user->ownsConnectedAccount($connectedAccount);
}
}
31 changes: 31 additions & 0 deletions stubs/app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Providers;

use App\Models\ConnectedAccount;
use App\Policies\ConnectedAccountPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
ConnectedAccount::class => ConnectedAccountPolicy::class,
];

/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();

//
}
}
34 changes: 34 additions & 0 deletions stubs/app/Providers/TeamsAuthServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Providers;

use App\Models\ConnectedAccount;
use App\Models\Team;
use App\Policies\ConnectedAccountPolicy;
use App\Policies\TeamPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
Team::class => TeamPolicy::class,
ConnectedAccount::class => ConnectedAccountPolicy::class,
];

/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();

//
}
}

0 comments on commit c5f4e08

Please sign in to comment.