Skip to content

Commit

Permalink
Merge pull request #1525 from rappasoft/development
Browse files Browse the repository at this point in the history
v8.2.0
  • Loading branch information
rappasoft authored Apr 23, 2021
2 parents 83f3102 + addf782 commit e533b18
Show file tree
Hide file tree
Showing 21 changed files with 1,334 additions and 1,183 deletions.
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [8.2.0] - 2021-04-22

### Added

- User search scope
- Role Scope class
- Korean (ko) language pack (https://github.com/rappasoft/laravel-boilerplate/pull/1521)

### Changed

- Updated lock files
- Updated all tables to laravel-livewire-tables 1.x
- Updated to Laravel commit: a6ffdbdf416d60c38443725807a260a84dca5045

### Removed

- codedungeon/phpunit-result-printer, should use `composer test` for parallel testing.

## [8.1.0] - 2021-04-05

### Added
Expand Down Expand Up @@ -435,7 +453,8 @@ Started from scratch with a blank Laravel 7.* installation. This release is not
- Fix yarn tests
- Fix: Socially logged in users get assigned the default role

[Unreleased]: https://github.com/rappasoft/laravel-boilerplate/compare/v8.1.0...development
[Unreleased]: https://github.com/rappasoft/laravel-boilerplate/compare/v8.2.0...development
[8.2.0]: https://github.com/rappasoft/laravel-boilerplate/compare/v8.0.3...v8.2.0
[8.1.0]: https://github.com/rappasoft/laravel-boilerplate/compare/v8.0.3...v8.1.0
[8.0.3]: https://github.com/rappasoft/laravel-boilerplate/compare/v8.0.2...v8.0.3
[8.0.2]: https://github.com/rappasoft/laravel-boilerplate/compare/v8.0.1...v8.0.2
Expand Down
4 changes: 3 additions & 1 deletion app/Domains/Auth/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Domains\Auth\Models\Traits\Attribute\RoleAttribute;
use App\Domains\Auth\Models\Traits\Method\RoleMethod;
use App\Domains\Auth\Models\Traits\Scope\RoleScope;
use Database\Factories\RoleFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Spatie\Permission\Models\Role as SpatieRole;
Expand All @@ -15,7 +16,8 @@ class Role extends SpatieRole
{
use HasFactory,
RoleAttribute,
RoleMethod;
RoleMethod,
RoleScope;

/**
* @var string[]
Expand Down
25 changes: 25 additions & 0 deletions app/Domains/Auth/Models/Traits/Scope/RoleScope.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Domains\Auth\Models\Traits\Scope;

/**
* Class RoleScope.
*/
trait RoleScope
{
/**
* @param $query
* @param $term
*
* @return mixed
*/
public function scopeSearch($query, $term)
{
return $query->where(function ($query) use ($term) {
$query->where('name', 'like', '%'.$term.'%')
->orWhereHas('permissions', function ($query) use ($term) {
$query->where('description', 'like', '%'.$term.'%');
});
});
}
}
14 changes: 14 additions & 0 deletions app/Domains/Auth/Models/Traits/Scope/UserScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
*/
trait UserScope
{
/**
* @param $query
* @param $term
*
* @return mixed
*/
public function scopeSearch($query, $term)
{
return $query->where(function ($query) use ($term) {
$query->where('name', 'like', '%'.$term.'%')
->orWhere('email', 'like', '%'.$term.'%');
});
}

/**
* @param $query
*
Expand Down
65 changes: 14 additions & 51 deletions app/Http/Livewire/Backend/RolesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,41 @@
namespace App\Http\Livewire\Backend;

use App\Domains\Auth\Models\Role;
use App\Domains\Auth\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\TableComponent;
use Rappasoft\LaravelLivewireTables\Traits\HtmlComponents;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;

/**
* Class RolesTable.
*/
class RolesTable extends TableComponent
class RolesTable extends DataTableComponent
{
use HtmlComponents;

/**
* @var string
*/
public $sortField = 'name';

/**
* @var array
*/
protected $options = [
'bootstrap.container' => false,
'bootstrap.classes.table' => 'table table-striped',
];

/**
* @return Builder
*/
public function query(): Builder
{
return Role::with('permissions:id,name,description')
->withCount('users');
->withCount('users')
->when($this->getFilter('search'), fn ($query, $term) => $query->search($term));
}

/**
* @return array
*/
public function columns(): array
{
return [
Column::make(__('Type'), 'type')
->sortable()
->format(function (Role $model) {
if ($model->type === User::TYPE_ADMIN) {
return __('Administrator');
}

if ($model->type === User::TYPE_USER) {
return __('User');
}

return 'N/A';
}),
Column::make(__('Name'), 'name')
->searchable()
Column::make(__('Type'))
->sortable(),
Column::make(__('Name'))
->sortable(),
Column::make(__('Permissions'), 'permissions_label')
->searchable(function ($builder, $term) {
return $builder->orWhereHas('permissions', function ($query) use ($term) {
return $query->where('name', 'like', '%'.$term.'%');
});
})
->format(function (Role $model) {
return $this->html($model->permissions_label);
}),
Column::make(__('Permissions')),
Column::make(__('Number of Users'), 'users_count')
->sortable(),
Column::make(__('Actions'))
->format(function (Role $model) {
return view('backend.auth.role.includes.actions', ['model' => $model]);
}),
Column::make(__('Actions')),
];
}

public function rowView(): string
{
return 'backend.auth.role.includes.row';
}
}
134 changes: 69 additions & 65 deletions app/Http/Livewire/Backend/UsersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,34 @@

use App\Domains\Auth\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\TableComponent;
use Rappasoft\LaravelLivewireTables\Traits\HtmlComponents;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Filter;

/**
* Class UsersTable.
*/
class UsersTable extends TableComponent
class UsersTable extends DataTableComponent
{
use HtmlComponents;

/**
* @var string
* @var
*/
public $sortField = 'name';
public $status;

/**
* @var string
* @var array|string[]
*/
public $status;
public array $sortNames = [
'email_verified_at' => 'Verified',
'two_factor_auth_count' => '2FA',
];

/**
* @var array
* @var array|string[]
*/
protected $options = [
'bootstrap.container' => false,
'bootstrap.classes.table' => 'table table-striped',
public array $filterNames = [
'type' => 'User Type',
'verified' => 'E-mail Verified',
];

/**
Expand All @@ -46,18 +47,48 @@ public function mount($status = 'active'): void
*/
public function query(): Builder
{
$query = User::with('roles', 'twoFactorAuth')
->withCount('twoFactorAuth');
$query = User::with('roles', 'twoFactorAuth')->withCount('twoFactorAuth');

if ($this->status === 'deleted') {
return $query->onlyTrashed();
$query = $query->onlyTrashed();
} elseif ($this->status === 'deactivated') {
$query = $query->onlyDeactivated();
} else {
$query = $query->onlyActive();
}

if ($this->status === 'deactivated') {
return $query->onlyDeactivated();
}
return $query
->when($this->getFilter('search'), fn ($query, $term) => $query->search($term))
->when($this->getFilter('type'), fn ($query, $type) => $query->where('type', $type))
->when($this->getFilter('active'), fn ($query, $active) => $query->where('active', $active === 'yes'))
->when($this->getFilter('verified'), fn ($query, $verified) => $verified === 'yes' ? $query->whereNotNull('email_verified_at') : $query->whereNull('email_verified_at'));
}

return $query->onlyActive();
/**
* @return array
*/
public function filters(): array
{
return [
'type' => Filter::make('User Type')
->select([
'' => 'Any',
User::TYPE_ADMIN => 'Administrators',
User::TYPE_USER => 'Users',
]),
'active' => Filter::make('Active')
->select([
'' => 'Any',
'yes' => 'Yes',
'no' => 'No',
]),
'verified' => Filter::make('E-mail Verified')
->select([
'' => 'Any',
'yes' => 'Yes',
'no' => 'No',
]),
];
}

/**
Expand All @@ -66,54 +97,27 @@ public function query(): Builder
public function columns(): array
{
return [
Column::make(__('Type'), 'type')
->sortable()
->format(function (User $model) {
return view('backend.auth.user.includes.type', ['user' => $model]);
}),
Column::make(__('Name'), 'name')
->searchable()
Column::make(__('Type'))
->sortable(),
Column::make(__('Name'))
->sortable(),
Column::make(__('E-mail'), 'email')
->searchable()
->sortable()
->format(function (User $model) {
return $this->mailto($model->email);
}),
->sortable(),
Column::make(__('Verified'), 'email_verified_at')
->sortable()
->format(function (User $model) {
return view('backend.auth.user.includes.verified', ['user' => $model]);
}),
Column::make(__('2FA'))
->sortable(function ($builder, $direction) {
return $builder->orderBy('two_factor_auth_count', $direction);
})
->format(function (User $model) {
return view('backend.auth.user.includes.2fa', ['user' => $model]);
}),
Column::make(__('Roles'), 'roles_label')
->searchable(function ($builder, $term) {
return $builder->orWhereHas('roles', function ($query) use ($term) {
return $query->where('name', 'like', '%'.$term.'%');
});
})
->format(function (User $model) {
return $this->html($model->roles_label);
}),
Column::make(__('Additional Permissions'), 'permissions_label')
->searchable(function ($builder, $term) {
return $builder->orWhereHas('permissions', function ($query) use ($term) {
return $query->where('name', 'like', '%'.$term.'%');
});
})
->format(function (User $model) {
return $this->html($model->permissions_label);
}),
Column::make(__('Actions'))
->format(function (User $model) {
return view('backend.auth.user.includes.actions', ['user' => $model]);
}),
->sortable(),
Column::make(__('2FA'), 'two_factor_auth_count')
->sortable(),
Column::make(__('Roles')),
Column::make(__('Additional Permissions')),
Column::make(__('Actions')),
];
}

/**
* @return string
*/
public function rowView(): string
{
return 'backend.auth.user.includes.row';
}
}
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"laravel/tinker": "^2.5",
"laravel/ui": "^3.0",
"livewire/livewire": "^2.0",
"rappasoft/laravel-livewire-tables": "^0.3",
"rappasoft/laravel-livewire-tables": "^1.0",
"rappasoft/lockout": "^3.0",
"spatie/laravel-activitylog": "^3.14",
"spatie/laravel-permission": "^3.11",
Expand All @@ -33,7 +33,6 @@
"barryvdh/laravel-debugbar": "^3.2",
"barryvdh/laravel-ide-helper": "^2.6",
"brianium/paratest": "^6.2",
"codedungeon/phpunit-result-printer": "^0.29",
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"friendsofphp/php-cs-fixer": "^2.16",
Expand Down
Loading

0 comments on commit e533b18

Please sign in to comment.