mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for Token Name (#3095)
* Fix for CORs error where file download were being prevented by headers * Fixes for CORs and File downloads * give contextual error messages for invalid route actions * Clean up LoginController for OAuth Testing * Quote Actions * Invoice and Quote Actions * Fixes for Token Name * Change test data seeder to create separate small,medium,large companies
This commit is contained in:
parent
0908893180
commit
0606973035
@ -63,8 +63,17 @@ class CreateTestData extends Command
|
||||
|
||||
$this->warmCache();
|
||||
|
||||
$this->createSmallAccount();
|
||||
$this->createMediumAccount();
|
||||
$this->createLargeAccount();
|
||||
|
||||
$this->info('Creating Account and Company');
|
||||
}
|
||||
|
||||
|
||||
private function createSmallAccount()
|
||||
{
|
||||
|
||||
$this->info('Creating Small Account and Company');
|
||||
|
||||
$account = factory(\App\Models\Account::class)->create();
|
||||
$company = factory(\App\Models\Company::class)->create([
|
||||
@ -75,13 +84,13 @@ class CreateTestData extends Command
|
||||
$account->default_company_id = $company->id;
|
||||
$account->save();
|
||||
|
||||
$user = User::whereEmail('user@example.com')->first();
|
||||
$user = User::whereEmail('small@example.com')->first();
|
||||
|
||||
if(!$user)
|
||||
{
|
||||
$user = factory(\App\Models\User::class)->create([
|
||||
// 'account_id' => $account->id,
|
||||
'email' => 'user@example.com',
|
||||
'email' => 'small@example.com',
|
||||
'confirmation_code' => $this->createDbHash(config('database.default'))
|
||||
]);
|
||||
}
|
||||
@ -101,7 +110,7 @@ class CreateTestData extends Command
|
||||
'is_owner' => 1,
|
||||
'is_admin' => 1,
|
||||
'is_locked' => 0,
|
||||
'permissions' => json_encode([]),
|
||||
'permissions' => '',
|
||||
'settings' => json_encode(DefaultSettings::userSettings()),
|
||||
]);
|
||||
|
||||
@ -115,6 +124,121 @@ class CreateTestData extends Command
|
||||
|
||||
$this->createClient($company, $user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function createMediumAccount()
|
||||
{
|
||||
$this->info('Creating Medium Account and Company');
|
||||
|
||||
$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;
|
||||
$account->save();
|
||||
|
||||
$user = User::whereEmail('medium@example.com')->first();
|
||||
|
||||
if(!$user)
|
||||
{
|
||||
$user = factory(\App\Models\User::class)->create([
|
||||
// 'account_id' => $account->id,
|
||||
'email' => 'medium@example.com',
|
||||
'confirmation_code' => $this->createDbHash(config('database.default'))
|
||||
]);
|
||||
}
|
||||
|
||||
$token = \Illuminate\Support\Str::random(64);
|
||||
|
||||
$company_token = CompanyToken::create([
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $company->id,
|
||||
'account_id' => $account->id,
|
||||
'name' => 'test token',
|
||||
'token' => $token,
|
||||
]);
|
||||
|
||||
$user->companies()->attach($company->id, [
|
||||
'account_id' => $account->id,
|
||||
'is_owner' => 1,
|
||||
'is_admin' => 1,
|
||||
'is_locked' => 0,
|
||||
'permissions' => '',
|
||||
'settings' => json_encode(DefaultSettings::userSettings()),
|
||||
]);
|
||||
|
||||
$this->count = $this->count*10;
|
||||
|
||||
$this->info('Creating '.$this->count. ' clients');
|
||||
|
||||
|
||||
for($x=0; $x<$this->count; $x++) {
|
||||
$z = $x+1;
|
||||
$this->info("Creating client # ".$z);
|
||||
|
||||
$this->createClient($company, $user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function createLargeAccount()
|
||||
{
|
||||
$this->info('Creating Large Account and Company');
|
||||
|
||||
$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;
|
||||
$account->save();
|
||||
|
||||
$user = User::whereEmail('large@example.com')->first();
|
||||
|
||||
if(!$user)
|
||||
{
|
||||
$user = factory(\App\Models\User::class)->create([
|
||||
// 'account_id' => $account->id,
|
||||
'email' => 'large@example.com',
|
||||
'confirmation_code' => $this->createDbHash(config('database.default'))
|
||||
]);
|
||||
}
|
||||
|
||||
$token = \Illuminate\Support\Str::random(64);
|
||||
|
||||
$company_token = CompanyToken::create([
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $company->id,
|
||||
'account_id' => $account->id,
|
||||
'name' => 'test token',
|
||||
'token' => $token,
|
||||
]);
|
||||
|
||||
$user->companies()->attach($company->id, [
|
||||
'account_id' => $account->id,
|
||||
'is_owner' => 1,
|
||||
'is_admin' => 1,
|
||||
'is_locked' => 0,
|
||||
'permissions' => '',
|
||||
'settings' => json_encode(DefaultSettings::userSettings()),
|
||||
]);
|
||||
|
||||
$this->count = $this->count*100;
|
||||
|
||||
$this->info('Creating '.$this->count. ' clients');
|
||||
|
||||
|
||||
for($x=0; $x<$this->count; $x++) {
|
||||
$z = $x+1;
|
||||
$this->info("Creating client # ".$z);
|
||||
|
||||
$this->createClient($company, $user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function createClient($company, $user)
|
||||
|
@ -71,6 +71,17 @@ class AccountController extends BaseController
|
||||
* description="Attempts a new account signup and returns a CompanyUser object on success",
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(
|
||||
* name="token_name",
|
||||
* in="path",
|
||||
* description="A custom name for the user company token",
|
||||
* example="Daves iOS Device",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="string",
|
||||
* format="string",
|
||||
* ),
|
||||
* ),
|
||||
* @OA\RequestBody(
|
||||
* description="Signup credentials",
|
||||
* required=true,
|
||||
|
@ -228,7 +228,9 @@ class CompanyController extends BaseController
|
||||
/*
|
||||
* Create token
|
||||
*/
|
||||
$company_token = CreateCompanyToken::dispatchNow($company, auth()->user(), request()->server('HTTP_USER_AGENT'));
|
||||
$user_agent = request()->input('token_name') ?: request()->server('HTTP_USER_AGENT');
|
||||
|
||||
$company_token = CreateCompanyToken::dispatchNow($company, auth()->user(), $user_agent);
|
||||
|
||||
$this->entity_transformer = CompanyUserTransformer::class;
|
||||
$this->entity_type = CompanyUser::class;
|
||||
|
@ -136,7 +136,7 @@ class MigrationController extends BaseController
|
||||
$company->client->delete();
|
||||
$company->save();
|
||||
|
||||
return response()->json(['message'=>'Setting preserved'], 200);
|
||||
return response()->json(['message'=>'Settings preserved'], 200);
|
||||
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,9 @@ class CreateAccount
|
||||
/*
|
||||
* Create token
|
||||
*/
|
||||
$company_token = CreateCompanyToken::dispatchNow($company, $user, $this->request['user_agent']);
|
||||
$user_agent = isset($this->request['token_name']) ? $this->request['token_name'] : request()->server('HTTP_USER_AGENT');
|
||||
|
||||
$company_token = CreateCompanyToken::dispatchNow($company, $user, $user_agent);
|
||||
|
||||
/*
|
||||
* Fire related events
|
||||
|
@ -29,19 +29,19 @@ class CreateCompanyToken implements ShouldQueue
|
||||
|
||||
protected $user;
|
||||
|
||||
protected $user_agent;
|
||||
protected $custom_token_name;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Company $company, User $user, string $user_agent)
|
||||
public function __construct(Company $company, User $user, string $custom_token_name)
|
||||
{
|
||||
$this->company = $company;
|
||||
|
||||
$this->user = $user;
|
||||
|
||||
$this->user_agent = $user_agent;
|
||||
$this->custom_token_name = $custom_token_name;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,14 +51,14 @@ class CreateCompanyToken implements ShouldQueue
|
||||
*/
|
||||
public function handle() : ?CompanyToken
|
||||
{
|
||||
$this->custom_token_name = $this->custom_token_name ?: $this->user->first_name. ' '. $this->user->last_name;
|
||||
|
||||
$ct = CompanyToken::create([
|
||||
'user_id' => $this->user->id,
|
||||
'account_id' => $this->company->account->id,
|
||||
'token' => Str::random(64),
|
||||
'name' => $this->user->first_name. ' '. $this->user->last_name,
|
||||
'name' => $this->custom_token_name ?: $this->user->first_name. ' '. $this->user->last_name,
|
||||
'company_id' => $this->company->id,
|
||||
'user_agent' => $this->user_agent,
|
||||
]);
|
||||
|
||||
return $ct;
|
||||
|
@ -44,7 +44,6 @@ class CompanyTokenTransformer extends EntityTransformer
|
||||
return [
|
||||
'token' => $company_token->token,
|
||||
'name' => $company_token->name ?: '',
|
||||
'user_agent' => $company_token->user_agent ?: 'Unidentified',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -273,7 +273,6 @@ class CreateUsersTable extends Migration
|
||||
$table->unsignedInteger('user_id');
|
||||
$table->string('token')->nullable();
|
||||
$table->string('name')->nullable();
|
||||
$table->string('user_agent')->nullable();
|
||||
|
||||
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
||||
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
|
||||
|
Loading…
x
Reference in New Issue
Block a user