updated permissions
This commit is contained in:
parent
8f47f40b03
commit
83f7073b18
31 changed files with 1467 additions and 901 deletions
|
|
@ -4,6 +4,7 @@ namespace App\Livewire;
|
|||
|
||||
use App\Models\Movie;
|
||||
use Livewire\Component;
|
||||
use function Laravel\Prompts\select;
|
||||
|
||||
class MovieDetailsPanel extends Component
|
||||
{
|
||||
|
|
@ -14,7 +15,19 @@ class MovieDetailsPanel extends Component
|
|||
|
||||
public function openPanel(int $movieId): void
|
||||
{
|
||||
$this->selectedMovie = Movie::find($movieId);
|
||||
$this->selectedMovie = Movie::where('id', $movieId)
|
||||
->select(
|
||||
'id',
|
||||
'title',
|
||||
'plot',
|
||||
'poster',
|
||||
'director',
|
||||
'year',
|
||||
'actors',
|
||||
'genre',
|
||||
'mpaa_rating'
|
||||
)
|
||||
->first();
|
||||
$this->showDetails = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class MovieList extends Component
|
|||
|
||||
public function getList()
|
||||
{
|
||||
$list = MovieListModel::with('movies')
|
||||
$list = MovieListModel::with('movies:id,poster')
|
||||
->find($this->id);
|
||||
|
||||
if ($list) {
|
||||
|
|
@ -45,6 +45,12 @@ class MovieList extends Component
|
|||
}
|
||||
}
|
||||
|
||||
public function deleteList(): void
|
||||
{
|
||||
$this->list->delete();
|
||||
$this->redirectRoute('lists');
|
||||
}
|
||||
|
||||
public function filterMovies(): void
|
||||
{
|
||||
$this->filteredMovies = collect($this->list->movies)
|
||||
|
|
@ -62,7 +68,7 @@ class MovieList extends Component
|
|||
$this->getList();
|
||||
}
|
||||
|
||||
public function updatedSettingsForm(): void
|
||||
public function updatedSettingsFormIsPublic(): void
|
||||
{
|
||||
$this->settingsForm->save();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,33 @@ use App\Livewire\Forms\MovieListForm;
|
|||
use App\Models\MovieList;
|
||||
use Exception;
|
||||
use Livewire\Component;
|
||||
use function Laravel\Prompts\select;
|
||||
|
||||
class MovieLists extends Component
|
||||
{
|
||||
public MovieListForm $form;
|
||||
public $lists = [];
|
||||
public $lists;
|
||||
public $sharedLists;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->lists = collect();
|
||||
$this->sharedLists = collect();
|
||||
|
||||
$this->getLists();
|
||||
}
|
||||
|
||||
public function getLists()
|
||||
{
|
||||
$user = auth()->user();
|
||||
if ($user) {
|
||||
$this->lists = MovieList::where('user_id', $user->id)
|
||||
->select("name", "id", "is_public")
|
||||
->get();
|
||||
} else {
|
||||
$this->redirectRoute('login');
|
||||
}
|
||||
}
|
||||
|
||||
public function addList(): void
|
||||
{
|
||||
|
|
@ -32,14 +54,8 @@ class MovieLists extends Component
|
|||
$this->form->reset();
|
||||
}
|
||||
|
||||
public function getLists()
|
||||
{
|
||||
$this->lists = MovieList::all();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->getLists();
|
||||
return view('livewire.lists');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
|
|
@ -18,4 +19,9 @@ class MovieList extends Model
|
|||
{
|
||||
return $this->belongsToMany(Movie::class);
|
||||
}
|
||||
|
||||
public function owner(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
app/Models/Permission.php
Normal file
10
app/Models/Permission.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Permission extends Model
|
||||
{
|
||||
//
|
||||
}
|
||||
10
app/Models/Role.php
Normal file
10
app/Models/Role.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Role extends Model
|
||||
{
|
||||
//
|
||||
}
|
||||
|
|
@ -5,9 +5,12 @@ namespace App\Models;
|
|||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Context;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||
|
||||
|
|
@ -44,6 +47,19 @@ class User extends Authenticatable
|
|||
return $this->hasOne(UserProfile::class);
|
||||
}
|
||||
|
||||
public function roles(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Role::class);
|
||||
}
|
||||
|
||||
public function hasRole(string $role): bool
|
||||
{
|
||||
if (Context::hasHidden('roles')) {
|
||||
return in_array(strtolower($role), Context::getHidden('roles'));
|
||||
}
|
||||
|
||||
return $this->roles->contains('name', strtolower($role));
|
||||
}
|
||||
/**
|
||||
* Get the user's initials
|
||||
*/
|
||||
|
|
|
|||
25
app/Policies/MovieListPolicy.php
Normal file
25
app/Policies/MovieListPolicy.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\MovieList;
|
||||
use App\Models\User;
|
||||
|
||||
class MovieListPolicy
|
||||
{
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function update(User $user, MovieList $movieList)
|
||||
{
|
||||
// If the user is the owner of the movie list or has been added as an editor for
|
||||
// the movie list, allow them to update it.
|
||||
|
||||
return $movieList->owner()->id = $user->id; //|| $movieList->editors->contains($user->id);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ namespace App\Providers;
|
|||
|
||||
use App\Models\Interfaces\MovieDbInterface;
|
||||
use App\Services\OmdbService;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
|
|
@ -15,6 +16,14 @@ class AppServiceProvider extends ServiceProvider
|
|||
public function register(): void
|
||||
{
|
||||
$this->app->bind(MovieDbInterface::class, OmdbService::class);
|
||||
|
||||
Blade::directive('role', function ($role) {
|
||||
return "<?php if(auth()->user()->hasRole({$role})) : ?>";
|
||||
});
|
||||
|
||||
Blade::directive('endrole', function ($role) {
|
||||
return "<?php endif; ?>";
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue