Skip to content

Commit

Permalink
Added User Management
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Geurts committed Jan 24, 2024
1 parent aca4863 commit fd373b1
Show file tree
Hide file tree
Showing 40 changed files with 2,635 additions and 62 deletions.
9 changes: 7 additions & 2 deletions app/Http/Controllers/Back/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ class PageController extends Controller
{
public function dependencies(Request $request)
{
return view('back.dependencies', []);
return view('back.dependencies');
}

public function session(Request $request)
{
return view('back.session', []);
return view('back.session');
}

public function users(Request $request)
{
return view('back.users');
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Front/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class HomeController extends Controller
*/
public function __invoke(Request $request)
{
return view('front.home', []);
return view('front.home');
}
}
107 changes: 107 additions & 0 deletions app/Livewire/users.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace App\Livewire;

use App\Models\user;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Tables;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Enums\FiltersLayout;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Livewire\Component;

class users extends Component implements HasForms, HasTable
{
use InteractsWithForms;
use InteractsWithTable;

public function table(Table $table): Table
{
return $table
->query(user::query())
->columns([
Tables\Columns\TextColumn::make('surname')
->label(__('user.surname'))
->searchable(),
Tables\Columns\TextColumn::make('firstname')
->label(__('user.firstname'))
->searchable(),
Tables\Columns\TextColumn::make('email')
->label(__('user.email'))
->searchable(),
Tables\Columns\TextColumn::make('email_verified_at')
->label(__('user.email_verified_at'))
->dateTime('Y-m-d h:i')
->sortable(),
Tables\Columns\TextColumn::make('two_factor_confirmed_at')
->label(__('user.two_factor_confirmed_at'))
->dateTime('Y-m-d h:i')
->sortable(),
Tables\Columns\TextColumn::make('current_team.name')
->label(__('user.current_team')),
// Tables\Columns\TextColumn::make('profile_photo_path')
// ->searchable(),
Tables\Columns\TextColumn::make('language')
->label(__('user.language'))
->getStateUsing(function (User $record) {
return strtoupper($record->language);
})
->searchable(),
Tables\Columns\IconColumn::make('is_developer')
->label(__('user.developer') . ' ?')
->boolean(),
Tables\Columns\TextColumn::make('created_at')
->label(__('user.created_at'))
->dateTime('Y-m-d h:i')
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->label(__('user.updated_at'))
->dateTime('Y-m-d h:i')
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->label(__('user.deleted_at'))
->dateTime('Y-m-d h:i')
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
Filter::make('is_developer')
->query(fn (Builder $query): Builder => $query->where('is_developer', true)),
Tables\Filters\TrashedFilter::make(),
], layout: FiltersLayout::AboveContent)
->actions([
Tables\Actions\DeleteAction::make()->iconButton(),
Tables\Actions\ForceDeleteAction::make()->iconButton(),
Tables\Actions\RestoreAction::make()->iconButton(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
])
->striped();
}

public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}

public function render(): View
{
return view('livewire.users');
}
}
13 changes: 10 additions & 3 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Jetstream\HasTeams;
Expand All @@ -16,7 +17,8 @@
// ------------------------------------------------------------------------------------------------------
// ATTENTION :
// the user attribute "is_developer" should be set directly in the database
// by the application developer on the user account he want to use to manage the whole applacation
// by the application developer on the one user account he wants to use to manage the whole applacation
// including user management and managing all people in all teams
// ------------------------------------------------------------------------------------------------------

class User extends Authenticatable
Expand All @@ -42,7 +44,6 @@ class User extends Authenticatable
'password',

'language',
'is_developer',
];

protected $hidden = [
Expand Down Expand Up @@ -79,6 +80,12 @@ public function hasPermission(string $permission): bool
/* -------------------------------------------------------------------------------------------- */
// Relations
/* -------------------------------------------------------------------------------------------- */
/* OK : returns the currently actiated team */
public function current_team(): HasOne
{
return $this->hasone(Team::class, 'id', 'current_team_id');
}

/* OK : returns ALL USERLOG (N USERLOG) */
public function userlogs(): HasMany
{
Expand Down
91 changes: 91 additions & 0 deletions app/Policies/UserPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace App\Policies;

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

class UserPolicy
{
use HandlesAuthorization;

/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->is_developer;
}

/**
* Determine whether the user can view the model.
*/
public function view(User $user, User $model): bool
{
return $user->is_developer;
}

/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->is_developer;
}

/**
* Determine whether the user can update the model.
*/
public function update(User $user, User $model): bool
{
return $user->is_developer;
}

/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, User $model): bool
{
return false;
}

/**
* Determine whether the user can delete the model in bulk.
*/
public function deleteAny(User $user, User $model): bool
{
return false;
}

/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, User $model): bool
{
return $user->is_developer;
}

/**
* Determine whether the user can restore the model in bulk.
*/
public function restoreAny(User $user, User $model): bool
{
return $user->is_developer;
}

/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, User $model): bool
{
return false;
}

/**
* Determine whether the user can permanently delete the model in bulk.
*/
public function forceDeleteAny(User $user, User $model): bool
{
return false;
}
}
8 changes: 7 additions & 1 deletion app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
namespace App\Providers;

// use Illuminate\Support\Facades\Gate;

use App\Models\Team;
use App\Models\User;
use App\Policies\TeamPolicy;
use App\Policies\UserPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
Expand All @@ -13,7 +18,8 @@ class AuthServiceProvider extends ServiceProvider
* @var array<class-string, class-string>
*/
protected $policies = [
//
Team::class => TeamPolicy::class,
User::class => UserPolicy::class,
];

/**
Expand Down
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
"name": "laravel/laravel",
"type": "project",
"description": "The skeleton application for the Laravel framework.",
"keywords": ["laravel", "framework"],
"keywords": [
"laravel",
"framework"
],
"license": "MIT",
"require": {
"php": "^8.1",
"arcanedev/log-viewer": "^10.0",
"filament/tables": "^3.2",
"guzzlehttp/guzzle": "^7.2",
"intervention/image": "^3.2",
"khill/lavacharts": "^3.1",
Expand Down Expand Up @@ -46,7 +50,8 @@
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
"@php artisan package:discover --ansi",
"@php artisan filament:upgrade"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
Expand Down
Loading

0 comments on commit fd373b1

Please sign in to comment.