Merge pull request #7410 from turbo124/v5-develop

Email blacklists
This commit is contained in:
David Bomba 2022-05-01 15:41:21 +10:00 committed by GitHub
commit d901ec7ce9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 150 additions and 72 deletions

View File

@ -12,7 +12,7 @@ jobs:
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
strategy: strategy:
matrix: matrix:
operating-system: ['ubuntu-18.04', 'ubuntu-20.04', 'ubuntu-22.04'] operating-system: ['ubuntu-18.04', 'ubuntu-20.04']
php-versions: ['7.4','8.0','8.1'] php-versions: ['7.4','8.0','8.1']
phpunit-versions: ['latest'] phpunit-versions: ['latest']

View File

@ -12,7 +12,10 @@
namespace App\Http\Requests\Account; namespace App\Http\Requests\Account;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use App\Http\ValidationRules\Account\BlackListRule;
use App\Http\ValidationRules\Account\EmailBlackListRule;
use App\Http\ValidationRules\NewUniqueUserRule; use App\Http\ValidationRules\NewUniqueUserRule;
use App\Utils\Ninja;
class CreateAccountRequest extends Request class CreateAccountRequest extends Request
{ {
@ -33,13 +36,18 @@ class CreateAccountRequest extends Request
*/ */
public function rules() public function rules()
{ {
if(Ninja::isHosted())
$email_rules = ['required', 'email:rfc,dns', new NewUniqueUserRule, new BlackListRule, new EmailBlackListRule];
else
$email_rules = ['required', 'email:rfc,dns', new NewUniqueUserRule];
return [ return [
'first_name' => 'string|max:100', 'first_name' => 'string|max:100',
'last_name' => 'string:max:100', 'last_name' => 'string:max:100',
'password' => 'required|string|min:6|max:1000', 'password' => 'required|string|min:6|max:1000',
// 'email' => 'bail|required|email:rfc,dns', 'email' => $email_rules,
// 'email' => new NewUniqueUserRule(),
'email' => ['required', 'email:rfc,dns', new NewUniqueUserRule],
'privacy_policy' => 'required|boolean', 'privacy_policy' => 'required|boolean',
'terms_of_service' => 'required|boolean', 'terms_of_service' => 'required|boolean',
]; ];

View File

@ -14,6 +14,7 @@ namespace App\Http\Requests\Login;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use App\Http\ValidationRules\Account\BlackListRule; use App\Http\ValidationRules\Account\BlackListRule;
use App\Http\ValidationRules\Account\EmailBlackListRule;
use App\Utils\Ninja; use App\Utils\Ninja;
class LoginRequest extends Request class LoginRequest extends Request
@ -38,7 +39,7 @@ class LoginRequest extends Request
{ {
if(Ninja::isHosted()) if(Ninja::isHosted())
$email_rules = ['required', new BlackListRule]; $email_rules = ['required', new BlackListRule, new EmailBlackListRule];
else else
$email_rules = 'required'; $email_rules = 'required';

View File

@ -0,0 +1,47 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\ValidationRules\Account;
use App\Libraries\MultiDB;
use Illuminate\Contracts\Validation\Rule;
/**
* Class EmailBlackListRule.
*/
class EmailBlackListRule implements Rule
{
public array $blacklist = [
];
/**
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return !in_array($value, $this->blacklist);
}
/**
* @return string
*/
public function message()
{
return "This email address is blacklisted, if you think this is in error, please email contact@invoiceninja.com";
}
}

View File

@ -156,45 +156,6 @@ class CreateAccount
return $sp794f3f; return $sp794f3f;
} }
// private function processSettings($settings)
// {
// if(Ninja::isHosted() && Cache::get('currencies'))
// {
// $currency = Cache::get('currencies')->filter(function ($item) use ($currency_code) {
// return strtolower($item->code) == $currency_code;
// })->first();
// if ($currency) {
// $settings->currency_id = (string)$currency->id;
// }
// $country = Cache::get('countries')->filter(function ($item) use ($country_code) {
// return strtolower($item->iso_3166_2) == $country_code || strtolower($item->iso_3166_3) == $country_code;
// })->first();
// if ($country) {
// $settings->country_id = (string)$country->id;
// }
// $language = Cache::get('languages')->filter(function ($item) use ($currency_code) {
// return strtolower($item->locale) == $currency_code;
// })->first();
// if ($language) {
// $settings->language_id = (string)$language->id;
// }
// if($timezone) {
// $settings->timezone_id = (string)$timezone->id;
// }
// return $settings;
// }
// return $settings;
// }
} }

View File

@ -132,7 +132,6 @@ class StartMigration implements ShouldQueue
$this->company->update_products = $update_product_flag; $this->company->update_products = $update_product_flag;
$this->company->save(); $this->company->save();
if(Ninja::isHosted()) if(Ninja::isHosted())
app('sentry')->captureException($e); app('sentry')->captureException($e);

View File

@ -1,5 +1,6 @@
<?php <?php
use App\Utils\Ninja;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@ -20,7 +21,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -29,7 +30,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -38,16 +39,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
});
Schema::table('clients', function (Blueprint $table) {
$table->text('custom_value1')->change();
$table->text('custom_value2')->change();
$table->text('custom_value3')->change();
$table->text('custom_value3')->change();
}); });
@ -56,7 +48,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -65,7 +57,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -74,7 +66,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -83,7 +75,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -92,7 +84,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -101,7 +93,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -110,7 +102,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -119,7 +111,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -128,7 +120,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -137,7 +129,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -146,7 +138,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -155,7 +147,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -164,7 +156,7 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
@ -173,10 +165,10 @@ class ConvertCustomFieldsColumnFromVarcharToText extends Migration
$table->text('custom_value1')->change(); $table->text('custom_value1')->change();
$table->text('custom_value2')->change(); $table->text('custom_value2')->change();
$table->text('custom_value3')->change(); $table->text('custom_value3')->change();
$table->text('custom_value3')->change(); $table->text('custom_value4')->change();
}); });
} }
/** /**

View File

@ -0,0 +1,70 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace Tests\Unit\ValidationRules;
use App\Http\ValidationRules\Account\BlackListRule;
use App\Http\ValidationRules\Account\EmailBlackListRule;
use App\Models\Invoice;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
* @covers App\Http\ValidationRules\Account\EmailBlackListRule
*/
class EmailBlacklistValidationTest extends TestCase
{
public function setUp() :void
{
parent::setUp();
}
public function testValidEmailRule()
{
$email_rule = new EmailBlackListRule;
$email_rule->blacklist = ['gimmy@gmail.com'];
$rules = [
'email' => [$email_rule]
];
$data = [
'email' => "gimmy@gmail.com",
];
$v = $this->app['validator']->make($data, $rules);
$this->assertFalse($v->passes());
}
public function testInValidEmailRule()
{
$rules = [
'email' => [new EmailBlackListRule]
];
$data = [
'email' => "jimmy@candassociates.com",
];
$v = $this->app['validator']->make($data, $rules);
$this->assertTrue($v->passes());
}
}