Merge pull request #8931 from turbo124/v5-develop

Updates for user filters
This commit is contained in:
David Bomba 2023-11-01 13:12:34 +11:00 committed by GitHub
commit 31556cd9f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 280 additions and 554 deletions

View File

@ -130,4 +130,50 @@ class UserFilters extends QueryFilters
$query->whereNotIn('id', $user_array);
});
}
/**
* Filters the list based on the status
* archived, active, deleted.
*
* @param string $filter
* @return Builder
*/
public function status(string $filter = ''): Builder
{
if (strlen($filter) == 0) {
return $this->builder;
}
$filters = explode(',', $filter);
return $this->builder->where(function ($query) use ($filters) {
/** @var \App\Models\User $user */
$user = auth()->user();
if (in_array(self::STATUS_ACTIVE, $filters)) {
$query = $query->orWhereHas('company_users', function ($q) use($user){
$q->where('company_id', $user->company()->id)->whereNull('deleted_at');
});
}
if (in_array(self::STATUS_ARCHIVED, $filters)) {
$query = $query->orWhereHas('company_users', function ($q) use($user){
$q->where('company_id', $user->company()->id)->whereNotNull('deleted_at')->where('is_deleted', 0);
});
}
if (in_array(self::STATUS_DELETED, $filters)) {
$query = $query->orWhereHas('company_users', function ($q) use($user){
$q->where('company_id', $user->company()->id)->where('is_deleted', 1);
});
}
});
}
}

View File

@ -166,7 +166,7 @@ class SwissQrGenerator
// Now get the QR code image and save it as a file.
try {
$output = new QrBill\PaymentPart\Output\HtmlOutput\HtmlOutput($qrBill, $this->client->locale() ?: 'en');
$output = new QrBill\PaymentPart\Output\HtmlOutput\HtmlOutput($qrBill, $this->resolveLanguage());
$html = $output
->setPrintable(false)
@ -190,4 +190,28 @@ class SwissQrGenerator
// return $e->getMessage();
}
}
private function resolveLanguage(): string
{
$language = $this->client->locale() ?: 'en';
switch ($language) {
case 'de':
return 'de';
case 'en':
case 'en_GB':
return 'en';
case 'it':
return 'it';
case 'fr':
case 'fr_CA':
case 'fr_CH':
return 'fr';
default:
return 'en';
}
}
}

View File

@ -493,8 +493,9 @@ class InvoiceController extends BaseController
return response(['message' => 'Please verify your account to send emails.'], 400);
}
/**@var \App\Models\User $user */
$user = auth()->user();
if (Ninja::isHosted() && (stripos($action, 'email') !== false) && $user->account->emailQuotaExceeded()) {
return response(['message' => ctrans('texts.email_quota_exceeded_subject')], 400);
}
if(in_array($request->action, ['auto_bill','mark_paid']) && $user->cannot('create', \App\Models\Payment::class)) {
return response(['message' => ctrans('texts.not_authorized'), 'errors' => ['ids' => [ctrans('texts.not_authorized')]]], 422);

View File

@ -86,16 +86,22 @@ class SendEmailRequest extends Request
{
$input = $this->all();
if (Ninja::isHosted() && !auth()->user()->account->account_sms_verified) {
/** @var \App\Models\User $user */
$user = auth()->user();
if (Ninja::isHosted() && !$user->account->account_sms_verified) {
$this->error_message = ctrans('texts.authorization_sms_failure');
return false;
}
if (Ninja::isHosted() && $user->account->emailQuotaExceeded()) {
$this->error_message = ctrans('texts.email_quota_exceeded_subject');
return false;
}
/*Make sure we have all the require ingredients to send a template*/
if (isset($input['entity']) && array_key_exists('entity_id', $input) && is_string($input['entity']) && $input['entity_id']) {
/** @var \App\Models\User $user */
$user = auth()->user();
$company = $user->company();

View File

@ -85,14 +85,14 @@ class NinjaMailerJob implements ShouldQueue
/* Serializing models from other jobs wipes the primary key */
$this->company = Company::query()->where('company_key', $this->nmo->company->company_key)->first();
/* Set the email driver */
$this->setMailDriver();
/* If any pre conditions fail, we return early here */
if (!$this->company || $this->preFlightChecksFail()) {
return;
}
/* Set the email driver */
$this->setMailDriver();
/* Run time we set Reply To Email*/
if (strlen($this->nmo->settings->reply_to_email) > 1) {
if (property_exists($this->nmo->settings, 'reply_to_name')) {
@ -513,7 +513,7 @@ class NinjaMailerJob implements ShouldQueue
}
/* GMail users are uncapped */
if (Ninja::isHosted() && ($this->nmo->settings->email_sending_method == 'gmail' || $this->nmo->settings->email_sending_method == 'office365')) {
if (Ninja::isHosted() && (in_array($this->nmo->settings->email_sending_method, ['gmail', 'office365', 'client_postmark', 'client_mailgun']))) {
return false;
}

View File

@ -44,6 +44,8 @@ class PreviewReport implements ShouldQueue
else
$report = $export->run();
// nlog($report);
Cache::put($this->hash, $report, 60 * 60);
}

View File

@ -87,6 +87,9 @@ class Email implements ShouldQueue
->setDefaults()
->buildMailable();
/** Ensure quota's on hosted platform are respected. :) */
$this->setMailDriver();
if ($this->preFlightChecksFail()) {
return;
}
@ -228,7 +231,7 @@ class Email implements ShouldQueue
*/
public function email()
{
$this->setMailDriver();
// $this->setMailDriver();
/* Init the mailer*/
$mailer = Mail::mailer($this->mailer);

View File

@ -73,7 +73,7 @@ class ZugferdEInvoice extends AbstractService
} else {
$this->xrechnung->setDocumentBuyerReference($client->routing_id);
}
if (!empty($client->shipping_address1) && $client->shipping_country->exists()) {
if (!empty($client->shipping_address1) && $client->shipping_country) {
$this->xrechnung->setDocumentShipToAddress($client->shipping_address1, $client->shipping_address2, "", $client->shipping_postal_code, $client->shipping_city, $client->shipping_country->iso_3166_2, $client->shipping_state);
}

View File

@ -87,7 +87,7 @@
"socialiteproviders/apple": "^5.2",
"socialiteproviders/microsoft": "^4.1",
"spatie/laravel-data": "^3.5",
"sprain/swiss-qr-bill": "^3.2",
"sprain/swiss-qr-bill": "^4.3",
"square/square": "30.0.0.*",
"stripe/stripe-php": "^12",
"symfony/http-client": "^6.0",

722
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,7 @@ return [
'company_id' => 0,
'hash_salt' => env('HASH_SALT', ''),
'currency_converter_api_key' => env('OPENEXCHANGE_APP_ID', ''),
'enabled_modules' => 32767,
'enabled_modules' => 65535,
'phantomjs_key' => env('PHANTOMJS_KEY', 'a-demo-key-with-low-quota-per-ip-address'),
'phantomjs_secret' => env('PHANTOMJS_SECRET', false),
'phantomjs_pdf_generation' => env('PHANTOMJS_PDF_GENERATION', false),

2
package-lock.json generated
View File

@ -1,5 +1,5 @@
{
"name": "@invoiceninja/invoiceninja",
"name": "invoiceninja",
"lockfileVersion": 2,
"requires": true,
"packages": {