Change companies table property domain to subdomain (#3141)

This commit is contained in:
David Bomba 2019-12-11 07:53:41 +11:00 committed by GitHub
parent 550cb42722
commit 9d8e4fdb06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 20 additions and 38 deletions

View File

@ -81,7 +81,6 @@ class CreateTestData extends Command
$account = factory(\App\Models\Account::class)->create();
$company = factory(\App\Models\Company::class)->create([
'account_id' => $account->id,
'domain' => 'ninja.test:8000',
]);
$account->default_company_id = $company->id;
@ -137,7 +136,6 @@ class CreateTestData extends Command
$account = factory(\App\Models\Account::class)->create();
$company = factory(\App\Models\Company::class)->create([
'account_id' => $account->id,
'domain' => 'ninja.test:8000',
]);
$account->default_company_id = $company->id;
@ -194,7 +192,6 @@ class CreateTestData extends Command
$account = factory(\App\Models\Account::class)->create();
$company = factory(\App\Models\Company::class)->create([
'account_id' => $account->id,
'domain' => 'ninja.test:8000',
]);
$account->default_company_id = $company->id;

View File

@ -32,7 +32,7 @@ class CompanyFactory
$company->settings = CompanySettings::defaults();
$company->db = config('database.default');
$company->custom_fields = (object) ['custom1' => '1', 'custom2' => '2', 'custom3'=>'3'];
$company->domain = '';
$company->subdomain = '';
return $company;
}

View File

@ -7,7 +7,7 @@
* @OA\Property(property="size_id", type="string", example="1", description="The company size ID"),
* @OA\Property(property="industry_id", type="string", example="1", description="The company industry ID"),
* @OA\Property(property="portal_mode", type="string", example="subdomain", description="Determines the client facing urls ie: subdomain,domain,iframe"),
* @OA\Property(property="domain", type="string", example="http://acmeco.invoicing.co", description="Determines the client facing url "),
* @OA\Property(property="subdomain", type="string", example="aceme", description="Specifies the first part of the company domain ie acme in acme.domain.com"),
* @OA\Property(property="portal_domain", type="string", example="https://subdomain.invoicing.co", description="The fully qualified domain for client facing URLS"),
* @OA\Property(property="enabled_tax_rates", type="integer", example="1", description="Number of taxes rates used per entity"),
* @OA\Property(property="fill_products", type="boolean", example=true, description="Toggles filling a product description based on product key"),

View File

@ -59,7 +59,7 @@ class CreateCompany
$company->ip = request()->ip();
$company->settings = $settings;
$company->db = config('database.default');
$company->domain = isset($this->request['domain']) ? $this->request['domain'] : config('ninja.site_url');
$company->subdomain = isset($this->request['subdomain']) ? $this->request['subdomain'] : '';
$company->save();

View File

@ -53,18 +53,18 @@ class MultiDB
}
public static function checkDomainAvailable($domain) : bool
public static function checkDomainAvailable($subdomain) : bool
{
if (! config('ninja.db.multi_db_enabled'))
{
return Company::whereDomain($domain)->get()->count() == 0;
return Company::whereSubdomain($subdomain)->get()->count() == 0;
}
//multi-db active
foreach (self::$dbs as $db)
{
if(Company::whereDomain($domain)->get()->count() >=1)
if(Company::whereSubdomain($subdomain)->get()->count() >=1)
return false;
}
@ -209,14 +209,14 @@ class MultiDB
}
public static function findAndSetDbByDomain($domain) :bool
public static function findAndSetDbByDomain($subdomain) :bool
{
//\Log::error("searching for {$domain}");
foreach (self::$dbs as $db)
{
if($company = Company::on($db)->whereDomain($domain)->first())
if($company = Company::on($db)->whereSubdomain($subdomain)->first())
{
self::setDb($company->db);

View File

@ -50,7 +50,7 @@ class Company extends BaseModel
protected $fillable = [
'fill_products',
'industry_id',
'domain',
'subdomain',
'size_id',
'custom_fields',
'enable_product_cost',
@ -265,5 +265,9 @@ class Company extends BaseModel
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
}
public function domain()
{
return 'https://' . $this->subdomain . config('ninja.app_domain');
}
}

View File

@ -191,7 +191,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
private function buildReturnUrl($input) : string
{
$url = $this->client->company->domain . "client/payments/process/response";
$url = $this->client->company->domain() . "client/payments/process/response";
$url .= "?company_gateway_id={$this->company_gateway->id}&gateway_type_id=".GatewayType::PAYPAL;
$url .= "&hashed_ids=" . implode(",", $input['hashed_ids']);
$url .= "&amount=".$input['amount'];
@ -202,7 +202,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
private function buildCancelUrl($input) : string
{
$url = $this->client->company->domain . '/client/invoices';
$url = $this->client->company->domain() . '/client/invoices';
return $url;
}

View File

@ -94,7 +94,7 @@ class CompanyTransformer extends EntityTransformer
'industry_id' => (string) $company->industry_id ?: '',
'first_month_of_year' => (string) $company->first_month_of_year ?: '',
'first_day_of_week' => (string) $company->first_day_of_week ?: '',
'domain' => (string) $company->domain ?: '',
'subdomain' => (string) $company->subdomain ?: '',
'portal_mode' => (string) $company->portal_mode ?: '',
'portal_domain' => (string) $company->portal_domain ?: '',
'settings' => $company->settings ?: '',

View File

@ -48,7 +48,7 @@ trait Inviteable
//$this->with('company','contact',$this->entity_type);
$this->with('company');
$domain = isset($this->company->portal_domain) ?: $this->company->domain;
$domain = isset($this->company->portal_domain) ?: $this->company->domain();
switch ($this->company->portal_mode) {
case 'subdomain':

View File

@ -30,7 +30,7 @@ trait Uploadable
if($path){
$settings = $entity->settings;
$settings->company_logo = $company->domain . $path;
$settings->company_logo = $company->domain() . $path;
$entity->settings = $settings;
$entity->save();
}

View File

@ -4,7 +4,7 @@ return [
'web_url' => 'https://www.invoiceninja.com',
'app_name' => env('APP_NAME'),
'site_url' => env('APP_URL', 'https://admin.invoiceninja.com'),
'site_url' => env('APP_URL', ''),
'app_domain' => env('APP_DOMAIN', 'invoiceninja.com'),
'app_version' => '0.0.1',
'api_version' => '0.0.1',

View File

@ -162,7 +162,7 @@ class CreateUsersTable extends Migration
$table->boolean('enable_product_quantity')->default(1);
$table->boolean('default_quantity')->default(1);
$table->string('domain')->nullable();
$table->string('subdomain')->nullable();
$table->string('db')->nullable();
$table->unsignedInteger('size_id')->nullable();
$table->string('first_day_of_week')->nullable();

View File

@ -74,7 +74,6 @@ class RandomDataSeeder extends Seeder
$account = factory(\App\Models\Account::class)->create();
$company = factory(\App\Models\Company::class)->create([
'account_id' => $account->id,
'domain' => config('ninja.site_url'),
]);
$account->default_company_id = $company->id;

View File

@ -42,7 +42,6 @@ class ClientPortalTest extends DuskTestCase
$account = factory(\App\Models\Account::class)->create();
$company = factory(\App\Models\Company::class)->create([
'account_id' => $account->id,
'domain' => 'ninja.test',
]);
$account->default_company_id = $company->id;

View File

@ -191,7 +191,6 @@ class ClientTest extends TestCase
$account = factory(\App\Models\Account::class)->create();
$company = factory(\App\Models\Company::class)->create([
'account_id' => $account->id,
'domain' => 'ninja.test',
]);
$account->default_company_id = $company->id;

View File

@ -51,7 +51,6 @@ class InvitationTest extends TestCase
$account = factory(\App\Models\Account::class)->create();
$company = factory(\App\Models\Company::class)->create([
'account_id' => $account->id,
'domain' => 'ninja.test',
]);
$account->default_company_id = $company->id;

View File

@ -51,8 +51,6 @@ class LoginTest extends TestCase
]);
$company = factory(\App\Models\Company::class)->make([
'account_id' => $account->id,
'domain' => 'ninja.test',
]);
$user->companies()->attach($company->id, [
@ -85,8 +83,6 @@ class LoginTest extends TestCase
]);
$company = factory(\App\Models\Company::class)->make([
'account_id' => $account->id,
'domain' => 'ninja.test',
]);
$user->companies()->attach($company->id, [
@ -117,8 +113,6 @@ class LoginTest extends TestCase
]);
$company = factory(\App\Models\Company::class)->make([
'account_id' => $account->id,
'domain' => 'ninja.test',
]);
$user->companies()->attach($company->id, [
@ -146,8 +140,6 @@ class LoginTest extends TestCase
$company = factory(\App\Models\Company::class)->create([
'account_id' => $account->id,
'domain' => 'ninja.test',
]);
$account->default_company_id = $account->id;

View File

@ -123,7 +123,6 @@ class UserTest extends TestCase
/* Create New Company */
$company2 = factory(\App\Models\Company::class)->create([
'account_id' => $this->account->id,
'domain' => 'ninja.test:8000',
]);
/* Create New Company Token*/

View File

@ -43,12 +43,10 @@ class MultiDBUserTest extends TestCase
$company = factory(\App\Models\Company::class)->make([
'account_id' => $account->id,
'domain' => 'ninja.test',
]);
$company2 = factory(\App\Models\Company::class)->make([
'account_id' => $account2->id,
'domain' => 'ninja.test',
]);

View File

@ -38,7 +38,6 @@ class UniqueEmailTest extends TestCase
$company = factory(\App\Models\Company::class)->make([
'account_id' => $account->id,
'domain' => 'ninja.test',
]);
$company->setHidden(['settings', 'settings_object', 'hashed_id']);
@ -52,8 +51,6 @@ class UniqueEmailTest extends TestCase
$company2 = factory(\App\Models\Company::class)->make([
'account_id' => $account2->id,
'domain' => 'ninja.test',
]);
$company2->setHidden(['settings', 'settings_object', 'hashed_id']);

View File

@ -89,7 +89,6 @@ trait MockAccountData
$this->account = factory(\App\Models\Account::class)->create();
$this->company = factory(\App\Models\Company::class)->create([
'account_id' => $this->account->id,
'domain' => 'ninja.test:8000',
]);
$this->account->default_company_id = $this->company->id;