Prevent ninja company from being deleted

This commit is contained in:
David Bomba 2021-07-11 10:16:27 +10:00
parent 8790278350
commit ad0b2b8ec3
14 changed files with 30 additions and 11 deletions

View File

@ -22,7 +22,7 @@ class ExpenseCategoryFactory
$expense->company_id = $company_id;
$expense->name = '';
$expense->is_deleted = false;
$expense->color = '#fff';
$expense->color = '';
return $expense;
}

View File

@ -21,7 +21,7 @@ class TaskStatusFactory
$task_status->user_id = $user_id;
$task_status->company_id = $company_id;
$task_status->name = '';
$task_status->color = '#fff';
$task_status->color = '';
$task_status->status_order = 9999;
return $task_status;

View File

@ -474,6 +474,10 @@ class CompanyController extends BaseController
*/
public function destroy(DestroyCompanyRequest $request, Company $company)
{
if(Ninja::isHosted() && config('ninja.ninja_default_company_id') == $company->id)
return response()->json(['message' => 'Cannot purge this company'], 400);
$company_count = $company->account->companies->count();
$account = $company->account;
$account_key = $account->key;

View File

@ -82,6 +82,9 @@ class MigrationController extends BaseController
*/
public function purgeCompany(Company $company)
{
if(Ninja::isHosted() && config('ninja.ninja_default_company_id') == $company->id)
return response()->json(['message' => 'Cannot purge this company'], 400);
$account = $company->account;
$company_id = $company->id;
@ -102,6 +105,9 @@ class MigrationController extends BaseController
private function purgeCompanyWithForceFlag(Company $company)
{
if(Ninja::isHosted() && config('ninja.ninja_default_company_id') == $company->id)
return response()->json(['message' => 'Cannot purge this company'], 400);
$account = $company->account;
$company_id = $company->id;

View File

@ -30,17 +30,22 @@ class UrlSetDb
*/
public function handle($request, Closure $next)
{
if (config('ninja.db.multi_db_enabled')) {
$hashids = new Hashids('', 10); //decoded output is _always_ an array.
$hashids = new Hashids(config('ninja.hash_salt'), 10);
//parse URL hash and set DB
$segments = explode('-', $request->route('confirmation_code'));
if(!is_array($segments))
return response()->json(['message' => 'Invalid confirmation code'], 403);
$hashed_db = $hashids->decode($segments[0]);
MultiDB::setDB(MultiDB::DB_PREFIX.str_pad($hashed_db[0], 2, '0', STR_PAD_LEFT));
}
return $next($request);
}
}

View File

@ -59,7 +59,7 @@ class StoreExpenseRequest extends Request
}
if(array_key_exists('color', $input) && is_null($input['color']))
$input['color'] = '#fff';
$input['color'] = '';
$this->replace($input);
}

View File

@ -43,7 +43,7 @@ class StoreExpenseCategoryRequest extends Request
$input = $this->decodePrimaryKeys($input);
if(array_key_exists('color', $input) && is_null($input['color']))
$input['color'] = '#fff';
$input['color'] = '';
$this->replace($input);
}

View File

@ -47,7 +47,7 @@ class UpdateExpenseCategoryRequest extends Request
$input = $this->all();
if(array_key_exists('color', $input) && is_null($input['color']))
$input['color'] = '#fff';
$input['color'] = '';
$this->replace($input);
}

View File

@ -51,7 +51,7 @@ class StoreProjectRequest extends Request
if(array_key_exists('color', $input) && is_null($input['color']))
$input['color'] = '#fff';
$input['color'] = '';
$this->replace($input);
}

View File

@ -49,7 +49,7 @@ class UpdateProjectRequest extends Request
}
if(array_key_exists('color', $input) && is_null($input['color']))
$input['color'] = '#fff';
$input['color'] = '';
$this->replace($input);
}

View File

@ -51,7 +51,7 @@ class UpdateTaskRequest extends Request
}
if(array_key_exists('color', $input) && is_null($input['color']))
$input['color'] = '#fff';
$input['color'] = '';
$this->replace($input);
}

View File

@ -33,7 +33,7 @@ class StoreTaskStatusRequest extends Request
$input = $this->all();
if(array_key_exists('color', $input) && is_null($input['color']))
$input['color'] = '#fff';
$input['color'] = '';
$this->replace($input);
}

View File

@ -46,7 +46,7 @@ class UpdateTaskStatusRequest extends Request
$input = $this->all();
if(array_key_exists('color', $input) && is_null($input['color']))
$input['color'] = '#fff';
$input['color'] = '';
$this->replace($input);
}

View File

@ -16,6 +16,7 @@ use App\Models\Company;
use App\Models\Credit;
use App\Models\CreditInvitation;
use App\Models\User;
use App\Utils\Traits\AppSetup;
use Tests\MockUnitData;
use Tests\TestCase;
@ -25,6 +26,7 @@ use Tests\TestCase;
class CreditBalanceTest extends TestCase
{
use MockUnitData;
use AppSetup;
public function setUp() :void
{
@ -35,6 +37,8 @@ class CreditBalanceTest extends TestCase
});
$this->makeTestData();
$this->buildCache(true);
}
public function testCreditBalance()