Merge pull request #7880 from turbo124/v5-develop

Fixes for entity policies
This commit is contained in:
David Bomba 2022-10-19 09:33:52 +11:00 committed by GitHub
commit f1582ba1b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 136 additions and 108 deletions

View File

@ -36,6 +36,10 @@ class ExpenseMap
17 => 'expense.tax_rate3', 17 => 'expense.tax_rate3',
18 => 'expense.uses_inclusive_taxes', 18 => 'expense.uses_inclusive_taxes',
19 => 'expense.payment_date', 19 => 'expense.payment_date',
20 => 'expense.custom_value1',
21 => 'expense.custom_value2',
22 => 'expense.custom_value3',
23 => 'expense.custom_value4',
]; ];
} }
@ -63,6 +67,10 @@ class ExpenseMap
17 => 'texts.tax_rate3', 17 => 'texts.tax_rate3',
18 => 'texts.uses_inclusive_taxes', 18 => 'texts.uses_inclusive_taxes',
19 => 'texts.payment_date', 19 => 'texts.payment_date',
20 => 'texts.custom_value1',
21 => 'texts.custom_value2',
22 => 'texts.custom_value3',
23 => 'texts.custom_value4',
]; ];
} }

View File

@ -86,7 +86,7 @@ class CreateAccount
$sp794f3f->hosted_company_count = config('ninja.quotas.free.max_companies'); $sp794f3f->hosted_company_count = config('ninja.quotas.free.max_companies');
$sp794f3f->account_sms_verified = true; $sp794f3f->account_sms_verified = true;
if(in_array($this->getDomain($this->request['email']), ['gmail.com', 'hotmail.com', 'outlook.com', 'yahoo.com', 'aol.com', 'mail.ru'])){ if(in_array($this->getDomain($this->request['email']), ['yopmail.com','gmail.com', 'hotmail.com', 'outlook.com', 'yahoo.com', 'aol.com', 'mail.ru'])){
$sp794f3f->account_sms_verified = false; $sp794f3f->account_sms_verified = false;
} }

View File

@ -602,11 +602,11 @@ class BaseDriver extends AbstractPaymentDriver
} }
} }
if ($this->company_gateway->require_contact_email) { // if ($this->company_gateway->require_contact_email) {
if ($this->checkRequiredResource($this->email)) { // if ($this->checkRequiredResource($this->email)) {
$this->required_fields[] = 'contact_email'; // $this->required_fields[] = 'contact_email';
} // }
} // }
// if ($this->company_gateway->require_contact_name) { // if ($this->company_gateway->require_contact_name) {
// if ($this->checkRequiredResource($this->first_name)) { // if ($this->checkRequiredResource($this->first_name)) {

View File

@ -14,9 +14,11 @@ namespace App\PaymentDrivers\CheckoutCom;
use App\Exceptions\PaymentFailed; use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken; use App\Models\ClientGatewayToken;
use App\Models\GatewayType; use App\Models\GatewayType;
use App\Models\Payment; use App\Models\Payment;
use App\Models\SystemLog;
use App\PaymentDrivers\CheckoutComPaymentDriver; use App\PaymentDrivers\CheckoutComPaymentDriver;
use App\PaymentDrivers\Common\MethodInterface; use App\PaymentDrivers\Common\MethodInterface;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
@ -242,6 +244,16 @@ class CreditCard implements MethodInterface
if ($response['status'] == 'Declined') { if ($response['status'] == 'Declined') {
$this->checkout->unWindGatewayFees($this->checkout->payment_hash); $this->checkout->unWindGatewayFees($this->checkout->payment_hash);
//18-10-2022
SystemLogger::dispatch(
$response,
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_ERROR,
SystemLog::TYPE_CHECKOUT,
$this->checkout->client,
$this->checkout->client->company,
);
return $this->processUnsuccessfulPayment($response); return $this->processUnsuccessfulPayment($response);
} }
} catch (CheckoutApiException $e) { } catch (CheckoutApiException $e) {

View File

@ -49,8 +49,8 @@ class EntityPolicy
return ($user->isAdmin() && $entity->company_id == $user->companyId()) return ($user->isAdmin() && $entity->company_id == $user->companyId())
|| ($user->hasPermission('edit_'.strtolower(\Illuminate\Support\Str::snake(class_basename($entity)))) && $entity->company_id == $user->companyId()) || ($user->hasPermission('edit_'.strtolower(\Illuminate\Support\Str::snake(class_basename($entity)))) && $entity->company_id == $user->companyId())
|| ($user->hasPermission('edit_all') && $entity->company_id == $user->companyId()) || ($user->hasPermission('edit_all') && $entity->company_id == $user->companyId())
|| $user->owns($entity) || ($user->owns($entity) && $entity->company_id == $user->companyId())
|| $user->assigned($entity); || ($user->assigned($entity) && $entity->company_id == $user->companyId());
} }
/** /**
@ -66,7 +66,7 @@ class EntityPolicy
return ($user->isAdmin() && $entity->company_id == $user->companyId()) return ($user->isAdmin() && $entity->company_id == $user->companyId())
|| ($user->hasPermission('view_'.strtolower(\Illuminate\Support\Str::snake(class_basename($entity)))) && $entity->company_id == $user->companyId()) || ($user->hasPermission('view_'.strtolower(\Illuminate\Support\Str::snake(class_basename($entity)))) && $entity->company_id == $user->companyId())
|| ($user->hasPermission('view_all') && $entity->company_id == $user->companyId()) || ($user->hasPermission('view_all') && $entity->company_id == $user->companyId())
|| $user->owns($entity) || ($user->owns($entity) && $entity->company_id == $user->companyId())
|| $user->assigned($entity); || ($user->assigned($entity) && $entity->company_id == $user->companyId());
} }
} }

View File

@ -54,17 +54,33 @@ class Number
* Formats a given value based on the clients currency. * Formats a given value based on the clients currency.
* *
* @param float $value The number to be formatted * @param float $value The number to be formatted
* @param object $currency The client currency object
* *
* @return string The formatted value * @return string The formatted value
*/ */
public static function formatValueNoTrailingZeroes($value, $currency) :string public static function formatValueNoTrailingZeroes($value, $entity) :string
{ {
$value = floatval($value); $value = floatval($value);
$currency = $entity->currency();
$thousand = $currency->thousand_separator; $thousand = $currency->thousand_separator;
$decimal = $currency->decimal_separator; $decimal = $currency->decimal_separator;
$precision = $currency->precision; // $precision = $currency->precision;
if ($entity instanceof Company) {
$country = $entity->country();
} else {
$country = $entity->country;
}
/* Country settings override client settings */
if (isset($country->thousand_separator) && strlen($country->thousand_separator) >= 1) {
$thousand = $country->thousand_separator;
}
if (isset($country->decimal_separator) && strlen($country->decimal_separator) >= 1) {
$decimal = $country->decimal_separator;
}
$precision = 10; $precision = 10;

View File

@ -306,7 +306,7 @@ trait MakesInvoiceValues
$data[$key][$table_type.".{$_table_type}4"] = strlen($item->custom_value4) >= 1 ? $helpers->formatCustomFieldValue($this->company->custom_fields, "{$_table_type}4", $item->custom_value4, $entity) : ''; $data[$key][$table_type.".{$_table_type}4"] = strlen($item->custom_value4) >= 1 ? $helpers->formatCustomFieldValue($this->company->custom_fields, "{$_table_type}4", $item->custom_value4, $entity) : '';
if ($item->quantity > 0 || $item->cost > 0) { if ($item->quantity > 0 || $item->cost > 0) {
$data[$key][$table_type.'.quantity'] = Number::formatValueNoTrailingZeroes($item->quantity, $entity_currency); $data[$key][$table_type.'.quantity'] = Number::formatValueNoTrailingZeroes($item->quantity, $entity);
$data[$key][$table_type.'.unit_cost'] = Number::formatMoneyNoRounding($item->cost, $entity); $data[$key][$table_type.'.unit_cost'] = Number::formatMoneyNoRounding($item->cost, $entity);

View File

@ -12,6 +12,7 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\Models\Country; use App\Models\Country;
use App\Utils\Number;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
@ -401,4 +402,89 @@ class ClientApiTest extends TestCase
$response->assertStatus(302); $response->assertStatus(302);
} }
public function testRoundingDecimalsTwo()
{
$currency = $this->company;
$x = Number::formatValueNoTrailingZeroes(0.05, $currency);
$this->assertEquals(0.05, $x);
}
public function testRoundingDecimalsThree()
{
$currency = $this->company;
$x = Number::formatValueNoTrailingZeroes(0.005, $currency);
$this->assertEquals(0.005, $x);
}
public function testRoundingDecimalsFour()
{
$currency = $this->company;
$x = Number::formatValueNoTrailingZeroes(0.0005, $currency);
$this->assertEquals(0.0005, $x);
}
public function testRoundingDecimalsFive()
{
$currency = $this->company;
$x = Number::formatValueNoTrailingZeroes(0.00005, $currency);
$this->assertEquals(0.00005, $x);
}
public function testRoundingDecimalsSix()
{
$currency = $this->company;
$x = Number::formatValueNoTrailingZeroes(0.000005, $currency);
$this->assertEquals(0.000005, $x);
}
public function testRoundingDecimalsSeven()
{
$currency = $this->company;
$x = Number::formatValueNoTrailingZeroes(0.0000005, $currency);
$this->assertEquals(0.0000005, $x);
}
public function testRoundingDecimalsEight()
{
$currency = $this->company;
$x = Number::formatValueNoTrailingZeroes(0.00000005, $currency);
$this->assertEquals(0.00000005, $x);
}
public function testRoundingPositive()
{
$currency = $this->company;
$x = Number::formatValueNoTrailingZeroes(1.5, $currency);
$this->assertEquals(1.5, $x);
$x = Number::formatValueNoTrailingZeroes(1.50, $currency);
$this->assertEquals(1.5, $x);
$x = Number::formatValueNoTrailingZeroes(1.500, $currency);
$this->assertEquals(1.5, $x);
$x = Number::formatValueNoTrailingZeroes(1.50005, $currency);
$this->assertEquals(1.50005, $x);
$x = Number::formatValueNoTrailingZeroes(1.50000005, $currency);
$this->assertEquals(1.50000005, $x);
}
} }

View File

@ -89,18 +89,6 @@ class NumberTest extends TestCase
$this->assertEquals(2.15, $rounded); $this->assertEquals(2.15, $rounded);
} }
//this method proved an error! removing this method from production
// public function testImportFloatConversion()
// {
// $amount = '€7,99';
// $converted_amount = Number::parseStringFloat($amount);
// $this->assertEquals(799, $converted_amount);
// }
public function testParsingStringCurrency() public function testParsingStringCurrency()
{ {
$amount = '€7,99'; $amount = '€7,99';
@ -110,86 +98,4 @@ class NumberTest extends TestCase
$this->assertEquals(7.99, $converted_amount); $this->assertEquals(7.99, $converted_amount);
} }
public function testRoundingDecimalsTwo()
{
$currency = Currency::find(1);
$x = Number::formatValueNoTrailingZeroes(0.05, $currency);
$this->assertEquals(0.05, $x);
}
public function testRoundingDecimalsThree()
{
$currency = Currency::find(1);
$x = Number::formatValueNoTrailingZeroes(0.005, $currency);
$this->assertEquals(0.005, $x);
}
public function testRoundingDecimalsFour()
{
$currency = Currency::find(1);
$x = Number::formatValueNoTrailingZeroes(0.0005, $currency);
$this->assertEquals(0.0005, $x);
}
public function testRoundingDecimalsFive()
{
$currency = Currency::find(1);
$x = Number::formatValueNoTrailingZeroes(0.00005, $currency);
$this->assertEquals(0.00005, $x);
}
public function testRoundingDecimalsSix()
{
$currency = Currency::find(1);
$x = Number::formatValueNoTrailingZeroes(0.000005, $currency);
$this->assertEquals(0.000005, $x);
}
public function testRoundingDecimalsSeven()
{
$currency = Currency::find(1);
$x = Number::formatValueNoTrailingZeroes(0.0000005, $currency);
$this->assertEquals(0.0000005, $x);
}
public function testRoundingDecimalsEight()
{
$currency = Currency::find(1);
$x = Number::formatValueNoTrailingZeroes(0.00000005, $currency);
$this->assertEquals(0.00000005, $x);
}
public function testRoundingPositive()
{
$currency = Currency::find(1);
$x = Number::formatValueNoTrailingZeroes(1.5, $currency);
$this->assertEquals(1.5, $x);
$x = Number::formatValueNoTrailingZeroes(1.50, $currency);
$this->assertEquals(1.5, $x);
$x = Number::formatValueNoTrailingZeroes(1.500, $currency);
$this->assertEquals(1.5, $x);
$x = Number::formatValueNoTrailingZeroes(1.50005, $currency);
$this->assertEquals(1.50005, $x);
$x = Number::formatValueNoTrailingZeroes(1.50000005, $currency);
$this->assertEquals(1.50000005, $x);
}
} }