added customer scopes to user model
This commit is contained in:
parent
980fd9a198
commit
1b648a2598
@ -83,7 +83,7 @@ class Login extends Controller
|
||||
}
|
||||
|
||||
// Redirect to portal if is customer
|
||||
if ($user->can('read-client-portal')) {
|
||||
if ($user->isCustomer()) {
|
||||
$path = session('url.intended', '');
|
||||
|
||||
// Path must start with company id and 'portal' prefix
|
||||
|
@ -104,7 +104,7 @@ class Reset extends Controller
|
||||
}
|
||||
|
||||
// Redirect to portal if is customer
|
||||
if ($user->can('read-client-portal')) {
|
||||
if ($user->isCustomer()) {
|
||||
$this->redirectTo = route('portal.dashboard', ['company_id' => $company->id]);
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ class Users extends Controller
|
||||
|
||||
$landing_pages = $u->landing_pages;
|
||||
|
||||
if ($user->can('read-client-portal')) {
|
||||
if ($user->isCustomer()) {
|
||||
// Show only roles with customer permission
|
||||
$roles = Role::all()->reject(function ($r) {
|
||||
return !$r->hasPermission('read-client-portal');
|
||||
|
@ -26,7 +26,7 @@ class Header
|
||||
|
||||
if (!empty($user)) {
|
||||
// Get customer company
|
||||
if ($user->can('read-client-portal')) {
|
||||
if ($user->isCustomer()) {
|
||||
$company = (object) [
|
||||
'company_name' => setting('company.name'),
|
||||
'company_email' => setting('company.email'),
|
||||
|
@ -39,7 +39,7 @@ class CreateDocumentTransaction
|
||||
return $this->getResponse('signed.' . $type . '.show', $document, $message);
|
||||
}
|
||||
|
||||
if ($user->can('read-client-portal')) {
|
||||
if ($user->isCustomer()) {
|
||||
flash($message)->error()->important();
|
||||
|
||||
return $this->getResponse('portal.' . $type . '.show', $document, $message);
|
||||
|
@ -182,7 +182,7 @@ class User extends Authenticatable implements HasLocalePreference
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only include active currencies.
|
||||
* Scope to only include active users.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
@ -192,6 +192,28 @@ class User extends Authenticatable implements HasLocalePreference
|
||||
return $query->where('enabled', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only customers.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeIsCustomer($query)
|
||||
{
|
||||
return $query->wherePermissionIs('read-client-portal');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only users.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeIsNotCustomer($query)
|
||||
{
|
||||
return $query->wherePermissionIs('read-admin-panel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach company_ids attribute to model.
|
||||
*
|
||||
@ -216,6 +238,26 @@ class User extends Authenticatable implements HasLocalePreference
|
||||
$this->offsetUnset('company_ids');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if user is a customer.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isCustomer()
|
||||
{
|
||||
return (bool) $this->can('read-client-portal');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if user is not a customer.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isNotCustomer()
|
||||
{
|
||||
return (bool) $this->can('read-admin-panel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's preferred locale.
|
||||
*
|
||||
|
@ -100,7 +100,7 @@ trait Users
|
||||
return route('login');
|
||||
}
|
||||
|
||||
$route_name = $user->can('read-client-portal') ? 'portal.dashboard' : $user->landing_page;
|
||||
$route_name = $user->isCustomer() ? 'portal.dashboard' : $user->landing_page;
|
||||
|
||||
$company_id = company_id() ?: optional($this->getFirstCompanyOfUser())->id;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user