Added role_model_class `helper`
This commit is contained in:
parent
560f25c8cf
commit
19ebcf0cc9
|
|
@ -6,7 +6,6 @@ use App\Abstracts\BulkAction;
|
||||||
use App\Events\Auth\LandingPageShowing;
|
use App\Events\Auth\LandingPageShowing;
|
||||||
use App\Jobs\Auth\DeleteUser;
|
use App\Jobs\Auth\DeleteUser;
|
||||||
use App\Jobs\Auth\UpdateUser;
|
use App\Jobs\Auth\UpdateUser;
|
||||||
use App\Models\Auth\Role;
|
|
||||||
|
|
||||||
class Users extends BulkAction
|
class Users extends BulkAction
|
||||||
{
|
{
|
||||||
|
|
@ -58,7 +57,7 @@ class Users extends BulkAction
|
||||||
{
|
{
|
||||||
$selected = $this->getSelectedInput($request);
|
$selected = $this->getSelectedInput($request);
|
||||||
|
|
||||||
$roles = Role::all()->reject(function ($r) {
|
$roles = role_model_class()::all()->reject(function ($r) {
|
||||||
$status = $r->hasPermission('read-client-portal');
|
$status = $r->hasPermission('read-client-portal');
|
||||||
|
|
||||||
if ($r->name == 'employee') {
|
if ($r->name == 'employee') {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ use App\Jobs\Auth\CreateInvitation;
|
||||||
use App\Jobs\Auth\CreateUser;
|
use App\Jobs\Auth\CreateUser;
|
||||||
use App\Jobs\Auth\DeleteUser;
|
use App\Jobs\Auth\DeleteUser;
|
||||||
use App\Jobs\Auth\UpdateUser;
|
use App\Jobs\Auth\UpdateUser;
|
||||||
use App\Models\Auth\Role;
|
|
||||||
use App\Traits\Cloud;
|
use App\Traits\Cloud;
|
||||||
use App\Traits\Uploads;
|
use App\Traits\Uploads;
|
||||||
use Illuminate\Http\Request as BaseRequest;
|
use Illuminate\Http\Request as BaseRequest;
|
||||||
|
|
@ -77,7 +76,7 @@ class Users extends Controller
|
||||||
|
|
||||||
$landing_pages = $u->landing_pages;
|
$landing_pages = $u->landing_pages;
|
||||||
|
|
||||||
$roles = Role::all()->reject(function ($r) {
|
$roles = role_model_class()::all()->reject(function ($r) {
|
||||||
$status = $r->hasPermission('read-client-portal');
|
$status = $r->hasPermission('read-client-portal');
|
||||||
|
|
||||||
if ($r->name == 'employee') {
|
if ($r->name == 'employee') {
|
||||||
|
|
@ -147,15 +146,15 @@ class Users extends Controller
|
||||||
|
|
||||||
if ($user->isCustomer()) {
|
if ($user->isCustomer()) {
|
||||||
// Show only roles with customer permission
|
// Show only roles with customer permission
|
||||||
$roles = Role::all()->reject(function ($r) {
|
$roles = role_model_class()::all()->reject(function ($r) {
|
||||||
return ! $r->hasPermission('read-client-portal');
|
return ! $r->hasPermission('read-client-portal');
|
||||||
})->pluck('display_name', 'id');
|
})->pluck('display_name', 'id');
|
||||||
} else if ($user->isEmployee()) {
|
} else if ($user->isEmployee()) {
|
||||||
// Show only roles with employee permission
|
// Show only roles with employee permission
|
||||||
$roles = Role::where('name', 'employee')->get()->pluck('display_name', 'id');
|
$roles = role_model_class()::where('name', 'employee')->get()->pluck('display_name', 'id');
|
||||||
} else {
|
} else {
|
||||||
// Don't show roles with customer permission
|
// Don't show roles with customer permission
|
||||||
$roles = Role::all()->reject(function ($r) {
|
$roles = role_model_class()::all()->reject(function ($r) {
|
||||||
$status = $r->hasPermission('read-client-portal');
|
$status = $r->hasPermission('read-client-portal');
|
||||||
|
|
||||||
if ($r->name == 'employee') {
|
if ($r->name == 'employee') {
|
||||||
|
|
@ -399,7 +398,7 @@ class Users extends Controller
|
||||||
/**
|
/**
|
||||||
* Process request for reinviting the specified resource.
|
* Process request for reinviting the specified resource.
|
||||||
*
|
*
|
||||||
* @param Role $role
|
* @param role_model_class() $role
|
||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
|
|
@ -408,7 +407,7 @@ class Users extends Controller
|
||||||
$role = false;
|
$role = false;
|
||||||
|
|
||||||
if ($request->has('role_id')) {
|
if ($request->has('role_id')) {
|
||||||
$role = Role::find($request->get('role_id'));
|
$role = role_model_class()::find($request->get('role_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$u = new \stdClass();
|
$u = new \stdClass();
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ use App\Interfaces\Job\HasSource;
|
||||||
use App\Interfaces\Job\ShouldCreate;
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Jobs\Auth\CreateUser;
|
use App\Jobs\Auth\CreateUser;
|
||||||
use App\Jobs\Common\CreateContactPersons;
|
use App\Jobs\Common\CreateContactPersons;
|
||||||
use App\Models\Auth\Role;
|
|
||||||
use App\Models\Common\Contact;
|
use App\Models\Common\Contact;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
|
@ -45,7 +44,7 @@ class CreateContact extends Job implements HasOwner, HasSource, ShouldCreate
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
$customer_role_id = Role::all()->filter(function ($role) {
|
$customer_role_id = role_model_class()::all()->filter(function ($role) {
|
||||||
return $role->hasPermission('read-client-portal');
|
return $role->hasPermission('read-client-portal');
|
||||||
})->pluck('id')->first();
|
})->pluck('id')->first();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ use App\Abstracts\Job;
|
||||||
use App\Interfaces\Job\ShouldUpdate;
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Jobs\Auth\CreateUser;
|
use App\Jobs\Auth\CreateUser;
|
||||||
use App\Jobs\Common\CreateContactPersons;
|
use App\Jobs\Common\CreateContactPersons;
|
||||||
use App\Models\Auth\Role;
|
|
||||||
use App\Models\Common\Contact;
|
use App\Models\Common\Contact;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
|
@ -65,7 +64,7 @@ class UpdateContact extends Job implements ShouldUpdate
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
$customer_role_id = Role::all()->filter(function ($role) {
|
$customer_role_id = role_model_class()::all()->filter(function ($role) {
|
||||||
return $role->hasPermission('read-client-portal');
|
return $role->hasPermission('read-client-portal');
|
||||||
})->pluck('id')->first();
|
})->pluck('id')->first();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ class User extends Authenticatable implements HasLocalePreference
|
||||||
|
|
||||||
public function roles()
|
public function roles()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany('App\Models\Auth\Role', 'App\Models\Auth\UserRole');
|
return $this->belongsToMany(role_model_class(), 'App\Models\Auth\UserRole');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,6 @@ class UserRole extends Model
|
||||||
|
|
||||||
public function role()
|
public function role()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Models\Auth\Role');
|
return $this->belongsTo(role_model_class());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
namespace App\Traits;
|
namespace App\Traits;
|
||||||
|
|
||||||
use App\Models\Auth\Permission;
|
use App\Models\Auth\Permission;
|
||||||
use App\Models\Auth\Role;
|
|
||||||
use App\Traits\SearchString;
|
use App\Traits\SearchString;
|
||||||
use App\Traits\Translations;
|
use App\Traits\Translations;
|
||||||
use App\Utilities\Reports;
|
use App\Utilities\Reports;
|
||||||
|
|
@ -275,7 +274,7 @@ trait Permissions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Role::firstOrCreate([
|
return role_model_class()::firstOrCreate([
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
], [
|
], [
|
||||||
'display_name' => $display_name,
|
'display_name' => $display_name,
|
||||||
|
|
@ -311,7 +310,7 @@ trait Permissions
|
||||||
public function detachPermission($role, $permission, $delete = true)
|
public function detachPermission($role, $permission, $delete = true)
|
||||||
{
|
{
|
||||||
if (is_string($role)) {
|
if (is_string($role)) {
|
||||||
$role = Role::where('name', $role)->first();
|
$role = role_model_class()::where('name', $role)->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($role)) {
|
if (empty($role)) {
|
||||||
|
|
@ -391,14 +390,14 @@ trait Permissions
|
||||||
|
|
||||||
public function getRoles($require = 'read-admin-panel')
|
public function getRoles($require = 'read-admin-panel')
|
||||||
{
|
{
|
||||||
return Role::all()->filter(function ($role) use ($require) {
|
return role_model_class()::all()->filter(function ($role) use ($require) {
|
||||||
return $require ? $role->hasPermission($require) : true;
|
return $require ? $role->hasPermission($require) : true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDefaultAdminRoles($custom = null)
|
public function getDefaultAdminRoles($custom = null)
|
||||||
{
|
{
|
||||||
$roles = Role::whereIn('name', $custom ?? ['admin', 'manager'])->get();
|
$roles = role_model_class()::whereIn('name', $custom ?? ['admin', 'manager'])->get();
|
||||||
|
|
||||||
if ($roles->isNotEmpty()) {
|
if ($roles->isNotEmpty()) {
|
||||||
return $roles;
|
return $roles;
|
||||||
|
|
@ -409,7 +408,7 @@ trait Permissions
|
||||||
|
|
||||||
public function getDefaultPortalRoles($custom = null)
|
public function getDefaultPortalRoles($custom = null)
|
||||||
{
|
{
|
||||||
$roles = Role::whereIn('name', $custom ?? ['customer'])->get();
|
$roles = role_model_class()::whereIn('name', $custom ?? ['customer'])->get();
|
||||||
|
|
||||||
if ($roles->isNotEmpty()) {
|
if ($roles->isNotEmpty()) {
|
||||||
return $roles;
|
return $roles;
|
||||||
|
|
|
||||||
|
|
@ -290,6 +290,15 @@ if (! function_exists('user_model_class')) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! function_exists('role_model_class')) {
|
||||||
|
function role_model_class(): string
|
||||||
|
{
|
||||||
|
return module_is_enabled('roles')
|
||||||
|
? config('roles.models.role')
|
||||||
|
: \App\Models\Auth\Role::class;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (! function_exists('search_string_value')) {
|
if (! function_exists('search_string_value')) {
|
||||||
function search_string_value(string $name, string $default = '', string $input = ''): string|array
|
function search_string_value(string $name, string $default = '', string $input = ''): string|array
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue