From 886ca7f1e060d66e04d1624a9c01134e90ecfcc5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 29 Jan 2023 19:56:13 +1100 Subject: [PATCH 1/9] Fixes for staticmodel scopes --- .../Requests/Activity/ShowActivityRequest.php | 4 ++-- app/Models/Activity.php | 14 ----------- app/Models/ClientGatewayToken.php | 14 +---------- app/Models/CompanyGateway.php | 8 ------- app/Models/Currency.php | 1 - app/Models/GroupSetting.php | 24 +++++++++++++++++-- app/Models/Payment.php | 8 ------- app/Models/StaticModel.php | 3 +-- 8 files changed, 26 insertions(+), 50 deletions(-) diff --git a/app/Http/Requests/Activity/ShowActivityRequest.php b/app/Http/Requests/Activity/ShowActivityRequest.php index 24dec84689b5..d7c745cb5d10 100644 --- a/app/Http/Requests/Activity/ShowActivityRequest.php +++ b/app/Http/Requests/Activity/ShowActivityRequest.php @@ -23,7 +23,7 @@ class ShowActivityRequest extends Request */ public function authorize() : bool { - return auth()->user()->isAdmin(); - // return auth()->user()->can('view', Activity::class); + // return auth()->user()->isAdmin(); + return auth()->user()->can('view', Activity::class); } } diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 442621808921..5c2af53d3ab9 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -375,18 +375,4 @@ class Activity extends StaticModel return $this->belongsTo(Company::class); } -// /** -// * @return mixed -// */ -// public function resolveRouteBinding($value, $field = null) -// { -// if (is_numeric($value)) { -// throw new ModelNotFoundException("Record with value {$value} not found"); -// } - -// return $this -// //->withTrashed() -// ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); -// } - } \ No newline at end of file diff --git a/app/Models/ClientGatewayToken.php b/app/Models/ClientGatewayToken.php index 50f616398195..5efcea44ad83 100644 --- a/app/Models/ClientGatewayToken.php +++ b/app/Models/ClientGatewayToken.php @@ -69,17 +69,5 @@ class ClientGatewayToken extends BaseModel { return $this->belongsTo(User::class)->withTrashed(); } - - // /** - // * Retrieve the model for a bound value. - // * - // * @param mixed $value - // * @param null $field - // * @return Model|null - // */ - // public function resolveRouteBinding($value, $field = null) - // { - // return $this - // ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); - // } + } diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index b5c26fd6975b..a31dc174602d 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -412,12 +412,4 @@ class CompanyGateway extends BaseModel return route('payment_webhook', ['company_key' => $this->company->company_key, 'company_gateway_id' => $this->hashed_id]); } - // public function resolveRouteBinding($value, $field = null) - // { - - // return $this - // ->where('id', $this->decodePrimaryKey($value))->withTrashed()->firstOrFail(); - // } - - } diff --git a/app/Models/Currency.php b/app/Models/Currency.php index 6a1ae1d5c15f..2da76e6541e0 100644 --- a/app/Models/Currency.php +++ b/app/Models/Currency.php @@ -23,7 +23,6 @@ class Currency extends StaticModel 'updated_at' => 'timestamp', 'created_at' => 'timestamp', 'deleted_at' => 'timestamp', - //'precision' => 'string', 'precision' => 'integer', ]; } diff --git a/app/Models/GroupSetting.php b/app/Models/GroupSetting.php index 539dc9b8fd32..b465c8a03039 100644 --- a/app/Models/GroupSetting.php +++ b/app/Models/GroupSetting.php @@ -14,14 +14,13 @@ namespace App\Models; use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException; class GroupSetting extends StaticModel { use MakesHash; use SoftDeletes; - //public $timestamps = false; - protected $casts = [ 'settings' => 'object', 'updated_at' => 'timestamp', @@ -65,4 +64,25 @@ class GroupSetting extends StaticModel return $this->morphMany(Document::class, 'documentable'); } + /** + * Retrieve the model for a bound value. + * + * @param mixed $value + * @param null $field + * @return Model|null + */ + public function resolveRouteBinding($value, $field = null) + { + + if (is_numeric($value)) { + throw new ModelNotFoundException("Record with value {$value} not found"); + } + + return $this + ->withTrashed() + ->company() + ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); + + } } + diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 12c90bbecfd8..32a3e2cf3101 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -292,14 +292,6 @@ class Payment extends BaseModel return new PaymentService($this); } - - // public function resolveRouteBinding($value, $field = null) - // { - // return $this - // ->withTrashed() - // ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); - // } - public function refund(array $data) :self { return $this->service()->refundPayment($data); diff --git a/app/Models/StaticModel.php b/app/Models/StaticModel.php index f20b97ff147a..5f5b9df0bd13 100644 --- a/app/Models/StaticModel.php +++ b/app/Models/StaticModel.php @@ -57,8 +57,7 @@ class StaticModel extends Model } return $this - ->withTrashed() - ->company() ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); + } } From 091b798b5b4be02ef407354735de91927f39fe8b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 29 Jan 2023 21:13:33 +1100 Subject: [PATCH 2/9] Seed company logo size variables into vendor HTML engine --- app/Utils/HtmlEngine.php | 54 ++-------------------- app/Utils/Traits/DesignCalculator.php | 66 +++++++++++++++++++++++++++ app/Utils/VendorHtmlEngine.php | 5 +- 3 files changed, 73 insertions(+), 52 deletions(-) create mode 100644 app/Utils/Traits/DesignCalculator.php diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 493c1975aaa6..9461b87734ff 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -23,6 +23,7 @@ use App\Models\RecurringInvoiceInvitation; use App\Utils\Ninja; use App\Utils\Number; use App\Utils\Traits\AppSetup; +use App\Utils\Traits\DesignCalculator; use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesHash; use Exception; @@ -34,7 +35,8 @@ class HtmlEngine use MakesDates; use AppSetup; use MakesHash; - + use DesignCalculator; + public $entity; public $invitation; @@ -100,56 +102,6 @@ class HtmlEngine } } - private function resolveCompanyLogoSize() - { - $design_map = [ - "VolejRejNm" => "65%", // "Plain", - "Wpmbk5ezJn" => "65%", //"Clean", - "Opnel5aKBz" => "65%", //"Bold", - "wMvbmOeYAl" => "55%", //Modern", - "4openRe7Az" => "65%", //"Business", - "WJxbojagwO" => "65%", //"Creative", - "k8mep2bMyJ" => "55%", //"Elegant", - "l4zbq2dprO" => "65%", //"Hipster", - "yMYerEdOBQ" => "65%", //"Playful", - "gl9avmeG1v" => "65%", //"Tech", - "7LDdwRb1YK" => "65%", //"Calm", - "APdRoy0eGy" => "65%", //"Calm-DB2", - "y1aK83rbQG" => "65%", //"Calm-DB1", - ]; - - $design_int_map = [ - "1" => "65%", // "Plain", - "2" => "65%", //"Clean", - "3" => "65%", //"Bold", - "4" => "55%", //Modern", - "5" => "65%", //"Business", - "6" => "65%", //"Creative", - "7" => "55%", //"Elegant", - "8" => "65%", //"Hipster", - "9" => "65%", //"Playful", - "10" => "65%", //"Tech", - "11" => "65%", //"Calm", - "6972" => "65%", //"C-DB2" - "11221" => "65%", //"C-DB1" - ]; - - if(isset($this->settings->company_logo_size) && strlen($this->settings->company_logo_size) > 1) - return $this->settings->company_logo_size; - - if($this->entity->design_id && array_key_exists($this->entity->design_id, $design_int_map)) - return $design_int_map[$this->entity->design_id]; - - $default_design_id = $this->entity_string."_design_id"; - $design_id = $this->settings->{$default_design_id}; - - if(array_key_exists($design_id, $design_map)) - return $design_map[$design_id]; - - return '65%'; - - } - public function buildEntityDataArray() :array { if (! $this->client->currency()) { diff --git a/app/Utils/Traits/DesignCalculator.php b/app/Utils/Traits/DesignCalculator.php new file mode 100644 index 000000000000..75a46078e73d --- /dev/null +++ b/app/Utils/Traits/DesignCalculator.php @@ -0,0 +1,66 @@ + "65%", // "Plain", + "Wpmbk5ezJn" => "65%", //"Clean", + "Opnel5aKBz" => "65%", //"Bold", + "wMvbmOeYAl" => "55%", //Modern", + "4openRe7Az" => "65%", //"Business", + "WJxbojagwO" => "65%", //"Creative", + "k8mep2bMyJ" => "55%", //"Elegant", + "l4zbq2dprO" => "65%", //"Hipster", + "yMYerEdOBQ" => "65%", //"Playful", + "gl9avmeG1v" => "65%", //"Tech", + "7LDdwRb1YK" => "65%", //"Calm", + "APdRoy0eGy" => "65%", //"Calm-DB2", + "y1aK83rbQG" => "65%", //"Calm-DB1", + ]; + + $design_int_map = [ + "1" => "65%", // "Plain", + "2" => "65%", //"Clean", + "3" => "65%", //"Bold", + "4" => "55%", //Modern", + "5" => "65%", //"Business", + "6" => "65%", //"Creative", + "7" => "55%", //"Elegant", + "8" => "65%", //"Hipster", + "9" => "65%", //"Playful", + "10" => "65%", //"Tech", + "11" => "65%", //"Calm", + "6972" => "65%", //"C-DB2" + "11221" => "65%", //"C-DB1" + ]; + + if(isset($this->settings->company_logo_size) && strlen($this->settings->company_logo_size) > 1) + return $this->settings->company_logo_size; + + if($this->entity->design_id && array_key_exists($this->entity->design_id, $design_int_map)) + return $design_int_map[$this->entity->design_id]; + + $default_design_id = $this->entity_string."_design_id"; + $design_id = $this->settings->{$default_design_id}; + + if(array_key_exists($design_id, $design_map)) + return $design_map[$design_id]; + + return '65%'; + + } +} \ No newline at end of file diff --git a/app/Utils/VendorHtmlEngine.php b/app/Utils/VendorHtmlEngine.php index 422f51c36484..da513836f642 100644 --- a/app/Utils/VendorHtmlEngine.php +++ b/app/Utils/VendorHtmlEngine.php @@ -23,6 +23,7 @@ use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; use App\Utils\Ninja; use App\Utils\Number; use App\Utils\Traits\AppSetup; +use App\Utils\Traits\DesignCalculator; use App\Utils\Traits\MakesDates; use App\Utils\transformTranslations; use Exception; @@ -38,7 +39,8 @@ class VendorHtmlEngine { use MakesDates; use AppSetup; - + use DesignCalculator; + public $entity; public $invitation; @@ -127,6 +129,7 @@ class VendorHtmlEngine $data = []; $data['$global_margin'] = ['value' => '6.35mm', 'label' => '']; $data['$tax'] = ['value' => '', 'label' => ctrans('texts.tax')]; + $data['$company_logo_size'] = ['value' => $this->resolveCompanyLogoSize(), 'label' => '']; $data['$app_url'] = ['value' => $this->generateAppUrl(), 'label' => '']; $data['$from'] = ['value' => '', 'label' => ctrans('texts.from')]; $data['$to'] = ['value' => '', 'label' => ctrans('texts.to')]; From e750f4575035b777d71e0aa2bcbc6148bd9876ad Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 30 Jan 2023 07:47:29 +1100 Subject: [PATCH 3/9] cast recurring invoice design invoice to invoice design when assessing logo size --- app/Utils/Traits/DesignCalculator.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Utils/Traits/DesignCalculator.php b/app/Utils/Traits/DesignCalculator.php index 75a46078e73d..97e887dfe39f 100644 --- a/app/Utils/Traits/DesignCalculator.php +++ b/app/Utils/Traits/DesignCalculator.php @@ -55,6 +55,10 @@ trait DesignCalculator return $design_int_map[$this->entity->design_id]; $default_design_id = $this->entity_string."_design_id"; + + if($default_design_id == 'recurring_invoice_design_id') + $default_design_id = 'invoice_design_id'; + $design_id = $this->settings->{$default_design_id}; if(array_key_exists($design_id, $design_map)) From 5c16821fb98a5a4b48cb3e070e45e3c0d07126f1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 30 Jan 2023 11:12:28 +1100 Subject: [PATCH 4/9] Fixes for null exception in failed method --- app/Jobs/Util/WebhookSingle.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Jobs/Util/WebhookSingle.php b/app/Jobs/Util/WebhookSingle.php index 2e80af61ea4b..5ecbad2aad4a 100644 --- a/app/Jobs/Util/WebhookSingle.php +++ b/app/Jobs/Util/WebhookSingle.php @@ -244,10 +244,10 @@ class WebhookSingle implements ShouldQueue return $this->company->clients()->first(); } - public function failed($exception) + public function failed($exception = null) { - - nlog(print_r($exception->getMessage(), 1)); + if($exception) + nlog($exception->getMessage()); } } From cb7897b75ed4fae6109414763a885e44288baf99 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 30 Jan 2023 12:59:47 +1100 Subject: [PATCH 5/9] Roll back for selective permission loads --- app/Http/Controllers/BaseController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 8fd1165fbed1..fa88269d8f54 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -267,7 +267,7 @@ class BaseController extends Controller $updated_at = request()->has('updated_at') ? request()->input('updated_at') : 0; - if ($user->getCompany()->is_large && $updated_at == 0 && $this->complexPermissionsUser()) { + if ($user->getCompany()->is_large && $updated_at == 0) { $updated_at = time(); } From a8982cde44ef5c5a7c99471df539c12c940701c2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 30 Jan 2023 17:08:21 +1100 Subject: [PATCH 6/9] Clean up --- app/Console/Commands/CheckData.php | 2 -- app/Http/Controllers/Auth/LoginController.php | 24 +++++++++---------- app/Http/Controllers/BaseController.php | 2 +- app/Jobs/Account/CreateAccount.php | 1 + app/Jobs/Ninja/CompanySizeCheck.php | 6 ++--- app/Jobs/User/CreateUser.php | 1 - app/Repositories/TaskStatusRepository.php | 1 - 7 files changed, 17 insertions(+), 20 deletions(-) diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index c273b87a597b..fa74167ae275 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -175,8 +175,6 @@ class CheckData extends Command }); - - } private function checkOauthSanity() diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index db657097c02c..7c02d2f37924 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -291,11 +291,11 @@ class LoginController extends BaseController return response()->json(['message' => 'User found, but not attached to any companies, please see your administrator'], 400); } - $cu->first()->account->companies->each(function ($company) use ($cu, $request) { - if ($company->tokens()->where('is_system', true)->count() == 0) { - (new CreateCompanyToken($company, $cu->first()->user, $request->server('HTTP_USER_AGENT')))->handle(); - } - }); + // $cu->first()->account->companies->each(function ($company) use ($cu, $request) { + // if ($company->tokens()->where('is_system', true)->count() == 0) { + // (new CreateCompanyToken($company, $cu->first()->user, $request->server('HTTP_USER_AGENT')))->handle(); + // } + // }); if ($request->has('current_company') && $request->input('current_company') == 'true') { $cu->where('company_id', $company_token->company_id); @@ -480,13 +480,13 @@ class LoginController extends BaseController return $cu; } - if (auth()->user()->company_users()->count() != auth()->user()->tokens()->distinct('company_id')->count()) { - auth()->user()->companies->each(function ($company) { - if (!CompanyToken::where('user_id', auth()->user()->id)->where('company_id', $company->id)->exists()) { - (new CreateCompanyToken($company, auth()->user(), 'Google_O_Auth'))->handle(); - } - }); - } + // if (auth()->user()->company_users()->count() != auth()->user()->tokens()->distinct('company_id')->count()) { + // auth()->user()->companies->each(function ($company) { + // if (!CompanyToken::where('user_id', auth()->user()->id)->where('company_id', $company->id)->exists()) { + // (new CreateCompanyToken($company, auth()->user(), 'Google_O_Auth'))->handle(); + // } + // }); + // } $truth->setCompanyToken(CompanyToken::where('user_id', auth()->user()->id)->where('company_id', $set_company->id)->first()); diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index fa88269d8f54..c7f6db9b8615 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -633,7 +633,7 @@ class BaseController extends Controller { $user = auth()->user(); - if ($user->getCompany()->is_large || $this->complexPermissionsUser()) { + if ($user->getCompany()->is_large) { $this->manager->parseIncludes($this->mini_load); return $this->miniLoadResponse($query); diff --git a/app/Jobs/Account/CreateAccount.php b/app/Jobs/Account/CreateAccount.php index d208afed67f2..c416b1eb798e 100644 --- a/app/Jobs/Account/CreateAccount.php +++ b/app/Jobs/Account/CreateAccount.php @@ -115,6 +115,7 @@ class CreateAccount $spafe62e = isset($this->request['token_name']) ? $this->request['token_name'] : request()->server('HTTP_USER_AGENT'); $sp2d97e8 = (new CreateCompanyToken($sp035a66, $spaa9f78, $spafe62e))->handle(); + if ($spaa9f78) { event(new AccountCreated($spaa9f78, $sp035a66, Ninja::eventVars())); } diff --git a/app/Jobs/Ninja/CompanySizeCheck.php b/app/Jobs/Ninja/CompanySizeCheck.php index ceaf205621cd..d83e5f1bba2a 100644 --- a/app/Jobs/Ninja/CompanySizeCheck.php +++ b/app/Jobs/Ninja/CompanySizeCheck.php @@ -43,7 +43,7 @@ class CompanySizeCheck implements ShouldQueue { if (! config('ninja.db.multi_db_enabled')) { - Company::where('is_large', false)->withCount(['invoices', 'clients', 'products'])->cursor()->each(function ($company) { + Company::where('is_large', false)->withCount(['invoices', 'clients', 'products', 'quotes'])->cursor()->each(function ($company) { if ($company->invoices_count > 500 || $company->products_count > 500 || $company->clients_count > 500) { nlog("Marking company {$company->id} as large"); @@ -69,8 +69,8 @@ class CompanySizeCheck implements ShouldQueue nlog("Company size check db {$db}"); - Company::where('is_large', false)->withCount(['invoices', 'clients', 'products'])->cursor()->each(function ($company) { - if ($company->invoices_count > 500 || $company->products_count > 500 || $company->clients_count > 500) { + Company::where('is_large', false)->withCount(['invoices', 'clients', 'products', 'quotes'])->cursor()->each(function ($company) { + if ($company->invoices_count > 500 || $company->products_count > 500 || $company->clients_count > 500 || $company->quotes_count > 500) { nlog("Marking company {$company->id} as large"); $company->account->companies()->update(['is_large' => true]); diff --git a/app/Jobs/User/CreateUser.php b/app/Jobs/User/CreateUser.php index 8bccbd976280..2835eed92fff 100644 --- a/app/Jobs/User/CreateUser.php +++ b/app/Jobs/User/CreateUser.php @@ -79,7 +79,6 @@ class CreateUser 'is_locked' => 0, 'permissions' => '', 'notifications' => CompanySettings::notificationDefaults(), - //'settings' => DefaultSettings::userSettings(), 'settings' => null, ]); diff --git a/app/Repositories/TaskStatusRepository.php b/app/Repositories/TaskStatusRepository.php index bc8772dd7bc3..88f7bbb83df4 100644 --- a/app/Repositories/TaskStatusRepository.php +++ b/app/Repositories/TaskStatusRepository.php @@ -40,7 +40,6 @@ class TaskStatusRepository extends BaseRepository public function archive($task_status) { - $task_status = TaskStatus::where('id', $task_status->id) ->where('company_id', $task_status->company_id) ->first(); From ea1f2945b27ce218a5f58bc604201083f3f13e82 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 30 Jan 2023 18:28:19 +1100 Subject: [PATCH 7/9] Ensure companies have the correct size when there are heterogeneous user permissions --- app/Jobs/Ninja/CompanySizeCheck.php | 33 +++++++++++++++++++++++++++++ app/Jobs/Util/WebhookHandler.php | 8 +++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/Jobs/Ninja/CompanySizeCheck.php b/app/Jobs/Ninja/CompanySizeCheck.php index d83e5f1bba2a..89c07bdcdc11 100644 --- a/app/Jobs/Ninja/CompanySizeCheck.php +++ b/app/Jobs/Ninja/CompanySizeCheck.php @@ -12,6 +12,7 @@ namespace App\Jobs\Ninja; use App\Libraries\MultiDB; +use App\Models\Account; use App\Models\Client; use App\Models\Company; use Illuminate\Bus\Queueable; @@ -62,6 +63,22 @@ class CompanySizeCheck implements ShouldQueue }); + /* Ensures lower permissioned users return the correct dataset and refresh responses */ + Account::whereHas('companies', function ($query){ + $query->where('is_large',0); + }) + ->whereHas('company_users', function ($query){ + + $query->where('is_admin', 0); + + }) + ->cursor()->each(function ($account){ + + $account->companies()->update(['is_large' => true]); + + }); + + } else { //multiDB environment, need to foreach (MultiDB::$dbs as $db) { @@ -88,6 +105,22 @@ class CompanySizeCheck implements ShouldQueue }); + Account::where('plan', 'enterprise') + ->whereDate('plan_expires', '>', now()) + ->whereHas('companies', function ($query){ + $query->where('is_large',0); + }) + ->whereHas('company_users', function ($query){ + + $query->where('is_admin', 0); + + }) + ->cursor()->each(function ($account){ + + $account->companies()->update(['is_large' => true]); + + }); + } } } diff --git a/app/Jobs/Util/WebhookHandler.php b/app/Jobs/Util/WebhookHandler.php index 57c6c9b22aba..1d728faefb98 100644 --- a/app/Jobs/Util/WebhookHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -79,18 +79,16 @@ class WebhookHandler implements ShouldQueue ->cursor() ->each(function ($subscription) { - // $this->process($subscription); - WebhookSingle::dispatch($subscription->id, $this->entity, $this->company->db, $this->includes); }); } - public function failed($exception) + public function failed($exception = null) { - - nlog(print_r($exception->getMessage(), 1)); + if($exception) + nlog(print_r($exception->getMessage(), 1)); } } From 2f9fcbd42e5bdf536ad2a5f63ed8860abc0143df Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 30 Jan 2023 19:50:27 +1100 Subject: [PATCH 8/9] Ensure companies have the correct size when there are heterogeneous user permissions --- app/Repositories/UserRepository.php | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 11e315809591..cf66bf09a9ee 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -93,6 +93,7 @@ class UserRepository extends BaseRepository $user->companies()->attach($company->id, $data['company_user']); } else { if (auth()->user()->isAdmin()) { + $cu->fill($data['company_user']); $cu->restore(); $cu->tokens()->restore(); @@ -117,6 +118,8 @@ class UserRepository extends BaseRepository } $user->restore(); + $this->verifyCorrectCompanySizeForPermissions($user); + return $user->fresh(); } @@ -211,4 +214,35 @@ class UserRepository extends BaseRepository event(new UserWasRestored($user, auth()->user(), auth()->user()->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); } + + + /** + * If we have multiple users in the system, + * and there are some that are not admins, + * we force all companies to large to ensure + * the queries are appropriate for all users + * + * @param User $user + * @return void + */ + private function verifyCorrectCompanySizeForPermissions(User $user): void + { + + if(Ninja::isSelfHost() || (Ninja::isHosted() && $user->account->isEnterpriseClient())) + { + + $user->account() + ->whereHas('companies', function ($query){ + $query->where('is_large',0); + }) + ->whereHas('company_users', function ($query){ + $query->where('is_admin', 0); + }) + ->cursor()->each(function ($account){ + $account->companies()->update(['is_large' => true]); + }); + + } + + } } From 8f8bee02c1d149e64f35fc224be62ad1e92b1973 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 30 Jan 2023 19:52:13 +1100 Subject: [PATCH 9/9] version bump --- VERSION.txt | 2 +- config/ninja.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index bce494672536..0a4a575a8314 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.5.64 \ No newline at end of file +5.5.65 \ No newline at end of file diff --git a/config/ninja.php b/config/ninja.php index f491829379c5..88cb863725bd 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.5.64', - 'app_tag' => '5.5.64', + 'app_version' => '5.5.65', + 'app_tag' => '5.5.65', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''),