1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Merge remote-tracking branch 'upstream/v5-develop' into v5-develop

This commit is contained in:
paulwer 2023-01-30 12:13:36 +01:00
commit 270647981d
23 changed files with 197 additions and 134 deletions

View File

@ -1 +1 @@
5.5.64
5.5.65

View File

@ -175,8 +175,6 @@ class CheckData extends Command
});
}
private function checkOauthSanity()

View File

@ -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());

View File

@ -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();
}
@ -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);

View File

@ -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);
}
}

View File

@ -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()));
}

View File

@ -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;
@ -43,7 +44,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");
@ -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) {
@ -69,8 +86,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]);
@ -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]);
});
}
}
}

View File

@ -79,7 +79,6 @@ class CreateUser
'is_locked' => 0,
'permissions' => '',
'notifications' => CompanySettings::notificationDefaults(),
//'settings' => DefaultSettings::userSettings(),
'settings' => null,
]);

View File

@ -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));
}
}

View File

@ -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());
}
}

View File

@ -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();
// }
}

View File

@ -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();
// }
}

View File

@ -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();
// }
}

View File

@ -23,7 +23,6 @@ class Currency extends StaticModel
'updated_at' => 'timestamp',
'created_at' => 'timestamp',
'deleted_at' => 'timestamp',
//'precision' => 'string',
'precision' => 'integer',
];
}

View File

@ -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();
}
}

View File

@ -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);

View File

@ -57,8 +57,7 @@ class StaticModel extends Model
}
return $this
->withTrashed()
->company()
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
}
}

View File

@ -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();

View File

@ -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]);
});
}
}
}

View File

@ -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()) {

View File

@ -0,0 +1,70 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Utils\Traits;
trait DesignCalculator
{
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";
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))
return $design_map[$design_id];
return '65%';
}
}

View File

@ -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')];

View File

@ -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', ''),