Merge branch 'master' of github.com:akaunting/akaunting into 2.1-dev
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Abstracts;
|
||||
|
||||
use App\Scopes\Company;
|
||||
use App\Traits\Tenants;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
@@ -11,7 +12,9 @@ use Lorisleiva\LaravelSearchString\Concerns\SearchString;
|
||||
|
||||
abstract class Model extends Eloquent
|
||||
{
|
||||
use Cachable, SearchString, SoftDeletes, Sortable;
|
||||
use Cachable, SearchString, SoftDeletes, Sortable, Tenants;
|
||||
|
||||
protected $tenantable = true;
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
|
@@ -11,6 +11,7 @@ use App\Jobs\Banking\UpdateReconciliation;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Banking\Reconciliation;
|
||||
use App\Models\Banking\Transaction;
|
||||
use Date;
|
||||
|
||||
class Reconciliations extends Controller
|
||||
{
|
||||
@@ -48,8 +49,8 @@ class Reconciliations extends Controller
|
||||
$accounts = Account::enabled()->pluck('name', 'id');
|
||||
|
||||
$account_id = request('account_id', setting('default.account'));
|
||||
$started_at = request('started_at', '0000-00-00');
|
||||
$ended_at = request('ended_at', '0000-00-00');
|
||||
$started_at = request('started_at', Date::now()->firstOfMonth()->toDateString());
|
||||
$ended_at = request('ended_at', Date::now()->endOfMonth()->toDateString());
|
||||
|
||||
$account = Account::find($account_id);
|
||||
|
||||
|
@@ -51,7 +51,7 @@ class Dashboards extends Controller
|
||||
{
|
||||
$dashboard_id = session('dashboard_id', 0);
|
||||
|
||||
if ($dashboard) {
|
||||
if (!empty($dashboard->id)) {
|
||||
$dashboard_id = $dashboard->id;
|
||||
}
|
||||
|
||||
|
@@ -44,18 +44,24 @@ class CreateUser extends Job
|
||||
$user->permissions()->attach($this->request->get('permissions'));
|
||||
}
|
||||
|
||||
$user->roles()->attach($this->request->get('roles'));
|
||||
if ($this->request->has('roles')) {
|
||||
$user->roles()->attach($this->request->get('roles'));
|
||||
}
|
||||
|
||||
$user->companies()->attach($this->request->get('companies'));
|
||||
if ($this->request->has('companies')) {
|
||||
$user->companies()->attach($this->request->get('companies'));
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
// Add User Dashboard
|
||||
foreach ($user->companies as $company) {
|
||||
Artisan::call('user:seed', [
|
||||
'user' => $user->id,
|
||||
'company' => $company->id,
|
||||
]);
|
||||
if (!empty($user->companies)) {
|
||||
foreach ($user->companies as $company) {
|
||||
Artisan::call('user:seed', [
|
||||
'user' => $user->id,
|
||||
'company' => $company->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
@@ -26,9 +26,11 @@ class AddAdminItems
|
||||
if ($dashboards->count() > 1) {
|
||||
$menu->dropdown(trim(trans_choice('general.dashboards', 2)), function ($sub) use ($user, $attr, $dashboards) {
|
||||
foreach ($dashboards as $key => $dashboard) {
|
||||
$path = (session('dashboard_id') == $dashboard->id) ? '/' : '/?dashboard_id=' . $dashboard->id;
|
||||
|
||||
$sub->url($path, $dashboard->name, $key, $attr);
|
||||
if (session('dashboard_id') != $dashboard->id) {
|
||||
$sub->route('dashboards.switch', $dashboard->name, ['dashboard' => $dashboard->id], $key, $attr);
|
||||
} else {
|
||||
$sub->url('/', $dashboard->name, $key, $attr);
|
||||
}
|
||||
}
|
||||
}, 1, [
|
||||
'url' => '/',
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use App\Traits\Tenants;
|
||||
use Laratrust\Models\LaratrustPermission;
|
||||
use Laratrust\Traits\LaratrustPermissionTrait;
|
||||
use Kyslik\ColumnSortable\Sortable;
|
||||
@@ -9,10 +10,12 @@ use Lorisleiva\LaravelSearchString\Concerns\SearchString;
|
||||
|
||||
class Permission extends LaratrustPermission
|
||||
{
|
||||
use LaratrustPermissionTrait, SearchString, Sortable;
|
||||
use LaratrustPermissionTrait, SearchString, Sortable, Tenants;
|
||||
|
||||
protected $table = 'permissions';
|
||||
|
||||
protected $tenantable = false;
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use App\Traits\Tenants;
|
||||
use Laratrust\Models\LaratrustRole;
|
||||
use Laratrust\Traits\LaratrustRoleTrait;
|
||||
use Kyslik\ColumnSortable\Sortable;
|
||||
@@ -9,10 +10,12 @@ use Lorisleiva\LaravelSearchString\Concerns\SearchString;
|
||||
|
||||
class Role extends LaratrustRole
|
||||
{
|
||||
use LaratrustRoleTrait, SearchString, Sortable;
|
||||
use LaratrustRoleTrait, SearchString, Sortable, Tenants;
|
||||
|
||||
protected $table = 'roles';
|
||||
|
||||
protected $tenantable = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use App\Traits\Tenants;
|
||||
use App\Notifications\Auth\Reset;
|
||||
use App\Traits\Media;
|
||||
use Date;
|
||||
@@ -15,10 +16,12 @@ use Lorisleiva\LaravelSearchString\Concerns\SearchString;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use LaratrustUserTrait, Notifiable, SearchString, SoftDeletes, Sortable, Media;
|
||||
use LaratrustUserTrait, Notifiable, SearchString, SoftDeletes, Sortable, Media, Tenants;
|
||||
|
||||
protected $table = 'users';
|
||||
|
||||
protected $tenantable = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace App\Models\Common;
|
||||
|
||||
use App\Traits\Media;
|
||||
use App\Traits\Tenants;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Kyslik\ColumnSortable\Sortable;
|
||||
@@ -10,10 +11,12 @@ use Lorisleiva\LaravelSearchString\Concerns\SearchString;
|
||||
|
||||
class Company extends Eloquent
|
||||
{
|
||||
use Media, SearchString, SoftDeletes, Sortable;
|
||||
use Media, SearchString, SoftDeletes, Sortable, Tenants;
|
||||
|
||||
protected $table = 'companies';
|
||||
|
||||
protected $tenantable = false;
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
protected $fillable = ['domain', 'enabled'];
|
||||
|
@@ -9,5 +9,7 @@ class Media extends BaseMedia
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $tenantable = false;
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
}
|
||||
|
@@ -3,12 +3,17 @@
|
||||
namespace App\Models\Setting;
|
||||
|
||||
use App\Scopes\Company;
|
||||
use App\Traits\Tenants;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
|
||||
class Setting extends Eloquent
|
||||
{
|
||||
use Tenants;
|
||||
|
||||
protected $table = 'settings';
|
||||
|
||||
protected $tenantable = true;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
|
@@ -17,13 +17,16 @@ class Company implements Scope
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model)
|
||||
{
|
||||
if (method_exists($model, 'isNotTenantable') && $model->isNotTenantable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$table = $model->getTable();
|
||||
|
||||
// Skip for specific tables
|
||||
$skip_tables = [
|
||||
'companies', 'jobs', 'firewall_ips', 'firewall_logs', 'media', 'mediables', 'migrations', 'notifications',
|
||||
'permissions', 'roles', 'role_companies', 'role_permissions', 'sessions', 'users', 'user_companies',
|
||||
'user_dashboards', 'user_permissions', 'user_roles',
|
||||
'jobs', 'firewall_ips', 'firewall_logs', 'media', 'mediables', 'migrations', 'notifications', 'role_companies',
|
||||
'role_permissions', 'sessions', 'user_companies', 'user_dashboards', 'user_permissions', 'user_roles',
|
||||
];
|
||||
|
||||
if (in_array($table, $skip_tables)) {
|
||||
|
16
app/Traits/Tenants.php
Normal file
16
app/Traits/Tenants.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait Tenants
|
||||
{
|
||||
public function isTenantable()
|
||||
{
|
||||
return (isset($this->tenantable) && ($this->tenantable === true));
|
||||
}
|
||||
|
||||
public function isNotTenantable()
|
||||
{
|
||||
return !$this->isTenantable();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user