Skip to content

Commit

Permalink
Merge pull request #9302 from turbo124/v5-develop
Browse files Browse the repository at this point in the history
v5.8.26
  • Loading branch information
turbo124 committed Feb 18, 2024
2 parents 49dfee7 + 9d5e11a commit 8e50ae9
Show file tree
Hide file tree
Showing 61 changed files with 1,010 additions and 321 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
@@ -1 +1 @@
5.8.25
5.8.26
3 changes: 3 additions & 0 deletions app/DataMapper/CompanySettings.php
Expand Up @@ -495,7 +495,10 @@ class CompanySettings extends BaseSettings

public $show_pdfhtml_on_mobile = true;

public $use_unapplied_payment = 'off'; //always, option, off //@implemented

public static $casts = [
'use_unapplied_payment' => 'string',
'show_pdfhtml_on_mobile' => 'bool',
'payment_email_all_contacts' => 'bool',
'statement_design_id' => 'string',
Expand Down
8 changes: 8 additions & 0 deletions app/Factory/CompanyFactory.php
Expand Up @@ -49,6 +49,14 @@ public function create(int $account_id): Company
$company->markdown_enabled = false;
$company->tax_data = new TaxModel();
$company->first_month_of_year = 1;
$company->smtp_encryption = 'tls';
$company->smtp_host = '';
$company->smtp_local_domain = '';
$company->smtp_password = '';
$company->smtp_port = '';
$company->smtp_username = '';
$company->smtp_verify_peer = true;

return $company;
}
}
5 changes: 3 additions & 2 deletions app/Filters/PaymentFilters.php
Expand Up @@ -12,8 +12,9 @@
namespace App\Filters;

use App\Models\Payment;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Eloquent\Builder;

/**
* PaymentFilters.
Expand Down Expand Up @@ -163,7 +164,7 @@ public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);

if (!is_array($sort_col) || count($sort_col) != 2) {
if (!is_array($sort_col) || count($sort_col) != 2 || !in_array($sort_col, Schema::getColumnListing('payments'))) {
return $this->builder;
}

Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/BaseController.php
Expand Up @@ -140,6 +140,7 @@ class BaseController extends Controller
'company.quotes.invitations.company',
'company.quotes.documents',
'company.tasks.documents',
// 'company.tasks.project',
'company.subscriptions',
'company.tax_rates',
'company.tokens_hashed',
Expand Down Expand Up @@ -458,7 +459,7 @@ protected function refreshResponse($query)
}
},
'company.tasks' => function ($query) use ($updated_at, $user) {
$query->where('updated_at', '>=', $updated_at)->with('documents');
$query->where('updated_at', '>=', $updated_at)->with('project','documents');

if (! $user->hasPermission('view_task')) {
$query->whereNested(function ($query) use ($user) {
Expand Down Expand Up @@ -796,7 +797,7 @@ protected function timeConstrainedResponse($query)
}
},
'company.tasks' => function ($query) use ($created_at, $user) {
$query->where('created_at', '>=', $created_at)->with('documents');
$query->where('created_at', '>=', $created_at)->with('project.documents','documents');

if (! $user->hasPermission('view_task')) {
$query->whereNested(function ($query) use ($user) {
Expand Down
33 changes: 19 additions & 14 deletions app/Http/Controllers/ConnectedAccountController.php
Expand Up @@ -169,13 +169,16 @@ private function handleGoogleOauth()
'email_verified_at' => now(),
];

auth()->user()->update($connected_account);
auth()->user()->email_verified_at = now();
auth()->user()->save();
/** @var \App\Models\User $logged_in_user */
$logged_in_user = auth()->user();

$this->setLoginCache(auth()->user());
$logged_in_user->update($connected_account);
$logged_in_user->email_verified_at = now();
$logged_in_user->save();

return $this->itemResponse(auth()->user());
$this->setLoginCache($logged_in_user);

return $this->itemResponse($logged_in_user);
}

return response()
Expand Down Expand Up @@ -214,20 +217,22 @@ public function handleGmailOauth(Request $request)
// 'email_verified_at' =>now(),
];

if (auth()->user()->email != $google->harvestEmail($user)) {
/** @var \App\Models\User $logged_in_user */
$logged_in_user = auth()->user();

if ($logged_in_user->email != $google->harvestEmail($user)) {
return response()->json(['message' => 'Primary Email differs to OAuth email. Emails must match.'], 400);
}

auth()->user()->update($connected_account);
auth()->user()->email_verified_at = now();
auth()->user()->oauth_user_token = $token;
auth()->user()->oauth_user_refresh_token = $refresh_token;

auth()->user()->save();
$logged_in_user->update($connected_account);
$logged_in_user->email_verified_at = now();
$logged_in_user->oauth_user_token = $token;
$logged_in_user->oauth_user_refresh_token = $refresh_token;
$logged_in_user->save();

$this->activateGmail(auth()->user());
$this->activateGmail($logged_in_user);

return $this->itemResponse(auth()->user());
return $this->itemResponse($logged_in_user);
}

return response()
Expand Down
64 changes: 64 additions & 0 deletions app/Http/Controllers/SmtpController.php
@@ -0,0 +1,64 @@
<?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\Http\Controllers;

use App\Http\Requests\Smtp\CheckSmtpRequest;
use App\Mail\TestMailServer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;

class SmtpController extends BaseController
{

public function __construct()
{
parent::__construct();
}

public function check(CheckSmtpRequest $request)
{
/** @var \App\Models\User $user */
$user = auth()->user();
$company = $user->company();



config([
'mail.mailers.smtp' => [
'transport' => 'smtp',
'host' => $request->input('smtp_host', $company->smtp_host),
'port' => $request->input('smtp_port', $company->smtp_port),
'username' => $request->input('smtp_username', $company->smtp_username),
'password' => $request->input('smtp_password', $company->smtp_password),
'encryption' => $request->input('smtp_encryption', $company->smtp_encryption ?? 'tls'),
'local_domain' => $request->input('smtp_local_domain', strlen($company->smtp_local_domain) > 2 ? $company->smtp_local_domain : null),
'verify_peer' => $request->input('verify_peer', $company->smtp_verify_peer ?? true),
'timeout' => 5,
],
]);

(new \Illuminate\Mail\MailServiceProvider(app()))->register();

try {
Mail::to($user->email, $user->present()->name())->send(new TestMailServer('Email Server Works!', strlen($company->settings->custom_sending_email) > 1 ? $company->settings->custom_sending_email : $user->email));
} catch (\Exception $e) {
app('mail.manager')->forgetMailers();
return response()->json(['message' => $e->getMessage()], 400);
}

app('mail.manager')->forgetMailers();

return response()->json(['message' => 'Ok'], 200);

}

}
3 changes: 3 additions & 0 deletions app/Http/Requests/Client/StoreClientRequest.php
Expand Up @@ -49,6 +49,9 @@ public function rules()
} elseif ($this->file('documents')) {
$rules['documents'] = $this->file_validation;
}
else {
$rules['documents'] = 'bail|sometimes|array';
}

if ($this->file('file') && is_array($this->file('file'))) {
$rules['file.*'] = $this->file_validation;
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Requests/Client/UpdateClientRequest.php
Expand Up @@ -53,6 +53,8 @@ public function rules()
$rules['file.*'] = $this->file_validation;
} elseif ($this->file('file')) {
$rules['file'] = $this->file_validation;
} else {
$rules['documents'] = 'bail|sometimes|array';
}

$rules['company_logo'] = 'mimes:jpeg,jpg,png,gif|max:10000';
Expand Down
24 changes: 22 additions & 2 deletions app/Http/Requests/Company/StoreCompanyRequest.php
Expand Up @@ -56,6 +56,15 @@ public function rules()
}
}

$rules['smtp_host'] = 'sometimes|string|nullable';
$rules['smtp_port'] = 'sometimes|string|nullable';
$rules['smtp_encryption'] = 'sometimes|string';
$rules['smtp_local_domain'] = 'sometimes|string|nullable';
$rules['smtp_encryption'] = 'sometimes|string|nullable';
$rules['smtp_local_domain'] = 'sometimes|string|nullable';

// $rules['smtp_verify_peer'] = 'sometimes|in:true,false';

return $rules;
}

Expand All @@ -67,18 +76,29 @@ public function prepareForValidation()
$input['name'] = 'Untitled Company';
}

if (array_key_exists('google_analytics_url', $input)) {
if (isset($input['google_analytics_url'])) {
$input['google_analytics_key'] = $input['google_analytics_url'];
}

if (array_key_exists('portal_domain', $input)) {
if (isset($input['portal_domain'])) {
$input['portal_domain'] = rtrim(strtolower($input['portal_domain']), "/");
}

if(Ninja::isHosted() && !isset($input['subdomain'])) {
$input['subdomain'] = MultiDB::randomSubdomainGenerator();
}

if(isset($input['smtp_username']) && strlen(str_replace("*", "", $input['smtp_username'])) < 2) {
unset($input['smtp_username']);
}

if(isset($input['smtp_password']) && strlen(str_replace("*", "", $input['smtp_password'])) < 2) {
unset($input['smtp_password']);
}

if(isset($input['smtp_verify_peer']) && is_string($input['smtp_verify_peer']))
$input['smtp_verify_peer'] == 'true' ? true : false;

$this->replace($input);
}
}
28 changes: 23 additions & 5 deletions app/Http/Requests/Company/UpdateCompanyRequest.php
Expand Up @@ -57,8 +57,14 @@ public function rules()
$rules['matomo_id'] = 'nullable|integer';
$rules['e_invoice_certificate_passphrase'] = 'sometimes|nullable';
$rules['e_invoice_certificate'] = 'sometimes|nullable|file|mimes:p12,pfx,pem,cer,crt,der,txt,p7b,spc,bin';
// $rules['client_registration_fields'] = 'array';

$rules['smtp_host'] = 'sometimes|string|nullable';
$rules['smtp_port'] = 'sometimes|string|nullable';
$rules['smtp_encryption'] = 'sometimes|string|nullable';
$rules['smtp_local_domain'] = 'sometimes|string|nullable';
// $rules['smtp_verify_peer'] = 'sometimes|string';


if (isset($input['portal_mode']) && ($input['portal_mode'] == 'domain' || $input['portal_mode'] == 'iframe')) {
$rules['portal_domain'] = 'bail|nullable|sometimes|url';
}
Expand All @@ -74,23 +80,35 @@ public function prepareForValidation()
{
$input = $this->all();

if (array_key_exists('portal_domain', $input) && strlen($input['portal_domain']) > 1) {
if (isset($input['portal_domain']) && strlen($input['portal_domain']) > 1) {
$input['portal_domain'] = $this->addScheme($input['portal_domain']);
$input['portal_domain'] = rtrim(strtolower($input['portal_domain']), "/");
}

if (array_key_exists('settings', $input)) {
if (isset($input['settings'])) {
$input['settings'] = (array)$this->filterSaveableSettings($input['settings']);
}

if(array_key_exists('subdomain', $input) && $this->company->subdomain == $input['subdomain']) {
if(isset($input['subdomain']) && $this->company->subdomain == $input['subdomain']) {
unset($input['subdomain']);
}

if(array_key_exists('e_invoice_certificate_passphrase', $input) && empty($input['e_invoice_certificate_passphrase'])) {
if(isset($input['e_invoice_certificate_passphrase']) && empty($input['e_invoice_certificate_passphrase'])) {
unset($input['e_invoice_certificate_passphrase']);
}

if(isset($input['smtp_username']) && strlen(str_replace("*","", $input['smtp_username'])) < 2) {
unset($input['smtp_username']);
}

if(isset($input['smtp_password']) && strlen(str_replace("*", "", $input['smtp_password'])) < 2) {
unset($input['smtp_password']);
}

if(isset($input['smtp_verify_peer']) && is_string($input['smtp_verify_peer'])) {
$input['smtp_verify_peer'] == 'true' ? true : false;
}

$this->replace($input);
}

Expand Down
2 changes: 2 additions & 0 deletions app/Http/Requests/Credit/StoreCreditRequest.php
Expand Up @@ -50,6 +50,8 @@ public function rules()
$rules['documents.*'] = $this->file_validation;
} elseif ($this->file('documents')) {
$rules['documents'] = $this->file_validation;
}else {
$rules['documents'] = 'bail|sometimes|array';
}

if ($this->file('file') && is_array($this->file('file'))) {
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Requests/Credit/UpdateCreditRequest.php
Expand Up @@ -52,6 +52,8 @@ public function rules()
$rules['documents.*'] = $this->file_validation;
} elseif ($this->file('documents')) {
$rules['documents'] = $this->file_validation;
}else {
$rules['documents'] = 'bail|sometimes|array';
}

if ($this->file('file') && is_array($this->file('file'))) {
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/Expense/StoreExpenseRequest.php
Expand Up @@ -52,6 +52,7 @@ public function rules()
$rules['category_id'] = 'bail|nullable|sometimes|exists:expense_categories,id,company_id,'.$user->company()->id.',is_deleted,0';
$rules['payment_date'] = 'bail|nullable|sometimes|date:Y-m-d';
$rules['date'] = 'bail|sometimes|date:Y-m-d';
$rules['documents'] = 'bail|sometimes|array';

return $this->globalRules($rules);
}
Expand Down

0 comments on commit 8e50ae9

Please sign in to comment.