improved tenant identification

This commit is contained in:
Denis Duliçi
2021-04-16 00:59:43 +03:00
parent 9635e6be5d
commit 2b07442260
126 changed files with 1719 additions and 999 deletions

View File

@ -29,11 +29,18 @@ trait Users
return false;
}
$company = $user->companies()->where('id', $id)->first();
$company = $user->withoutEvents(function () use ($user, $id) {
return $user->companies()->where('id', $id)->first();
});
return !empty($company);
}
public function isNotUserCompany($id)
{
return !$this->isUserCompany($id);
}
/**
* Check user dashboard assignment
*
@ -49,8 +56,54 @@ trait Users
return app()->runningInConsole() ? true : false;
}
$dashboard = $user->dashboards()->where('id', $id)->first();
$dashboard = $user->withoutEvents(function () use ($user, $id) {
return $user->dashboards()->where('id', $id)->first();
});
return !empty($dashboard);
}
public function isNotUserDashboard($id)
{
return !$this->isUserDashboard($id);
}
/**
* Get the fist company of active user
*
* @return null|\App\Models\Common\Company
*/
public function getFirstCompanyOfUser()
{
$user = user();
if (empty($user)) {
return null;
}
$company = $user->withoutEvents(function () use ($user) {
return $user->companies()->enabled()->first();
});
if (empty($company)) {
return null;
}
return $company;
}
public function getLandingPageOfUser()
{
$user = user();
if (empty($user)) {
return route('login');
}
$route_name = $user->contact ? 'portal.dashboard' : $user->landing_page;
$company_id = company_id() ?: optional($this->getFirstCompanyOfUser())->id;
return route($route_name, ['company_id' => $company_id]);
}
}