mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 02:34:35 -04:00
V2 (#3089)
* Set default templates in Company Settings * Working on Company User creation * Working on company_user relationship * Fixes for company_user relation * Clean up
This commit is contained in:
parent
69efd4d574
commit
5c9ada0f77
@ -12,6 +12,7 @@
|
|||||||
namespace App\DataMapper;
|
namespace App\DataMapper;
|
||||||
|
|
||||||
use App\DataMapper\CompanySettings;
|
use App\DataMapper\CompanySettings;
|
||||||
|
use App\DataMapper\EmailTemplateDefaults;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -400,6 +401,9 @@ class CompanySettings extends BaseSettings
|
|||||||
$data->country_id = (string)config('ninja.i18n.country_id');
|
$data->country_id = (string)config('ninja.i18n.country_id');
|
||||||
$data->translations = (object) [];
|
$data->translations = (object) [];
|
||||||
|
|
||||||
|
$data->email_subject_invoice = EmailTemplateDefaults::emailInvoiceSubject();
|
||||||
|
$data->email_template_invoice = EmailTemplateDefaults:: emailInvoiceTemplate();
|
||||||
|
|
||||||
return self::setCasts($data, self::$casts);
|
return self::setCasts($data, self::$casts);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
32
app/DataMapper/EmailTemplateDefaults.php
Normal file
32
app/DataMapper/EmailTemplateDefaults.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\DataMapper;
|
||||||
|
|
||||||
|
use Parsedown;
|
||||||
|
|
||||||
|
class EmailTemplateDefaults
|
||||||
|
{
|
||||||
|
public static function emailInvoiceSubject()
|
||||||
|
{
|
||||||
|
return Parsedown::instance()->line(self::transformText('invoice_subject'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function emailInvoiceTemplate()
|
||||||
|
{
|
||||||
|
return Parsedown::instance()->line(self::transformText('invoice_message'));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function transformText($string)
|
||||||
|
{
|
||||||
|
return str_replace(":", "$", ctrans('texts.'.$string));
|
||||||
|
}
|
||||||
|
}
|
@ -114,7 +114,7 @@ class UserFilters extends QueryFilters
|
|||||||
{
|
{
|
||||||
//return $this->builder->user_companies()->whereCompanyId(auth()->user()->company()->id);
|
//return $this->builder->user_companies()->whereCompanyId(auth()->user()->company()->id);
|
||||||
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
||||||
return $this->builder->whereHas('user_companies', function($q)
|
return $this->builder->whereHas('company_users', function($q)
|
||||||
{
|
{
|
||||||
$q->where('company_id', '=', auth()->user()->company()->id);
|
$q->where('company_id', '=', auth()->user()->company()->id);
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ class LoginController extends BaseController
|
|||||||
|
|
||||||
$user = $this->guard()->user();
|
$user = $this->guard()->user();
|
||||||
|
|
||||||
$user->setCompany($user->user_companies->first()->account->default_company);
|
$user->setCompany($user->company_user->account->default_company);
|
||||||
|
|
||||||
$ct = CompanyUser::whereUserId($user->id);
|
$ct = CompanyUser::whereUserId($user->id);
|
||||||
return $this->listResponse($ct);
|
return $this->listResponse($ct);
|
||||||
|
@ -22,6 +22,7 @@ use App\Http\Requests\User\StoreUserRequest;
|
|||||||
use App\Http\Requests\User\UpdateUserRequest;
|
use App\Http\Requests\User\UpdateUserRequest;
|
||||||
use App\Jobs\Company\CreateCompanyToken;
|
use App\Jobs\Company\CreateCompanyToken;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\DataMapper\DefaultSettings;
|
||||||
use App\Repositories\UserRepository;
|
use App\Repositories\UserRepository;
|
||||||
use App\Transformers\UserTransformer;
|
use App\Transformers\UserTransformer;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
@ -200,24 +201,14 @@ class UserController extends BaseController
|
|||||||
{
|
{
|
||||||
|
|
||||||
$company = auth()->user()->company();
|
$company = auth()->user()->company();
|
||||||
//save user
|
|
||||||
|
|
||||||
$user = $this->user_repo->save($request->all(), UserFactory::create($company->id, auth()->user()->id));
|
$user = $this->user_repo->save($request->all(), UserFactory::create());
|
||||||
|
|
||||||
$user->companies()->attach($company->id, [
|
$user_agent = request()->input('token_name') ?: request()->server('HTTP_USER_AGENT');
|
||||||
'account_id' => $company->account->id,
|
|
||||||
'is_owner' => 0,
|
|
||||||
'is_admin' => $request->input('is_admin'),
|
|
||||||
'is_locked' => 0,
|
|
||||||
'permissions' => $request->input('permissions'),
|
|
||||||
'settings' => $request->input('settings'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
CreateCompanyToken::dispatchNow($company, $user, request()->server('HTTP_USER_AGENT'));
|
$ct = CreateCompanyToken::dispatchNow($company, $user, $user_agent);
|
||||||
|
|
||||||
$user->load('companies');
|
return $this->itemResponse($user->fresh());
|
||||||
|
|
||||||
return $this->itemResponse($user);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class TokenAuth
|
|||||||
$user->setCompany($company_token->company);
|
$user->setCompany($company_token->company);
|
||||||
|
|
||||||
//user who once existed, but has been soft deleted
|
//user who once existed, but has been soft deleted
|
||||||
if($user->user_company()->is_locked){
|
if($user->company_user->is_locked){
|
||||||
|
|
||||||
$error = [
|
$error = [
|
||||||
'message' => 'User access locked',
|
'message' => 'User access locked',
|
||||||
|
@ -50,6 +50,8 @@ class StoreUserRequest extends Request
|
|||||||
|
|
||||||
if(isset($input['company_user']))
|
if(isset($input['company_user']))
|
||||||
{
|
{
|
||||||
|
if(!isset($input['company_user']['is_admin']))
|
||||||
|
$input['company_user']['is_admin'] = false;
|
||||||
|
|
||||||
if(!isset($input['company_user']['permissions']))
|
if(!isset($input['company_user']['permissions']))
|
||||||
$input['company_user']['permissions'] = '';
|
$input['company_user']['permissions'] = '';
|
||||||
@ -66,17 +68,11 @@ class StoreUserRequest extends Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->replace($input);
|
$this->replace($input);
|
||||||
|
\Log::error($input);
|
||||||
return $this->all();
|
return $this->all();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function messages()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'company_user' => 'T',
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -46,6 +46,7 @@ class Company extends BaseModel
|
|||||||
protected $presenter = 'App\Models\Presenters\CompanyPresenter';
|
protected $presenter = 'App\Models\Presenters\CompanyPresenter';
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
'fill_products',
|
||||||
'industry_id',
|
'industry_id',
|
||||||
'domain',
|
'domain',
|
||||||
'size_id',
|
'size_id',
|
||||||
|
@ -15,7 +15,10 @@ use Illuminate\Database\Eloquent\Relations\Pivot;
|
|||||||
|
|
||||||
class CompanyUser extends Pivot
|
class CompanyUser extends Pivot
|
||||||
{
|
{
|
||||||
protected $guarded = ['id'];
|
// protected $guarded = ['id'];
|
||||||
|
|
||||||
|
protected $dateFormat = 'Y-m-d H:i:s.u';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that should be cast to native types.
|
* The attributes that should be cast to native types.
|
||||||
@ -72,6 +75,7 @@ class CompanyUser extends Pivot
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(CompanyToken::class, 'user_id','user_id');
|
return $this->belongsTo(CompanyToken::class, 'user_id','user_id');
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
return $this->hasOneThrough(
|
return $this->hasOneThrough(
|
||||||
CompanyToken::class,
|
CompanyToken::class,
|
||||||
|
@ -39,6 +39,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
use UserSessionAttributes;
|
use UserSessionAttributes;
|
||||||
use UserSettings;
|
use UserSettings;
|
||||||
use Filterable;
|
use Filterable;
|
||||||
|
use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||||
|
|
||||||
protected $guard = 'user';
|
protected $guard = 'user';
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
|
|
||||||
protected $presenter = 'App\Models\Presenters\UserPresenter';
|
protected $presenter = 'App\Models\Presenters\UserPresenter';
|
||||||
|
|
||||||
protected $with = ['companies','user_companies'];
|
protected $with = ['companies'];
|
||||||
|
|
||||||
protected $dateFormat = 'Y-m-d H:i:s.u';
|
protected $dateFormat = 'Y-m-d H:i:s.u';
|
||||||
|
|
||||||
@ -169,52 +170,16 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function company_users()
|
||||||
* Returns the pivot tables for Company / User
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function user_companies()
|
|
||||||
{
|
{
|
||||||
return $this->hasMany(CompanyUser::class);
|
return $this->hasMany(CompanyUser::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Alias of user_companies()
|
|
||||||
*/
|
|
||||||
public function company_users()
|
|
||||||
{
|
|
||||||
return $this->user_companies();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the current company by
|
|
||||||
* querying directly on the pivot table relationship
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public function user_company()
|
|
||||||
{
|
|
||||||
|
|
||||||
return $this->user_companies->where('company_id', $this->companyId())->first();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function company_user()
|
public function company_user()
|
||||||
{
|
{
|
||||||
return $this->hasOneThrough(CompanyUser::class, CompanyToken::class,
|
return $this->hasOneThrough(CompanyUser::class, CompanyToken::class, 'user_id', 'company_id','id','company_id')->where('company_user.user_id', $this->id);
|
||||||
'user_id', // Foreign key on CompanyToken table...
|
|
||||||
'company_id', // Foreign key on CompanyUser table...
|
|
||||||
'id', // Local key on suppliers table...
|
|
||||||
'company_id' // Local key on CompanyToken table...
|
|
||||||
);
|
|
||||||
|
|
||||||
// return $this->user_companies->where('company_id', $this->companyId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the currently set company id for the user
|
* Returns the currently set company id for the user
|
||||||
*
|
*
|
||||||
@ -235,7 +200,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
public function permissions()
|
public function permissions()
|
||||||
{
|
{
|
||||||
|
|
||||||
$permissions = json_decode($this->user_company()->permissions);
|
$permissions = json_decode($this->company_user->permissions);
|
||||||
|
|
||||||
if (! $permissions)
|
if (! $permissions)
|
||||||
return [];
|
return [];
|
||||||
@ -251,7 +216,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
public function settings()
|
public function settings()
|
||||||
{
|
{
|
||||||
|
|
||||||
return json_decode($this->user_company()->settings);
|
return json_decode($this->company_user->settings);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +228,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
public function isAdmin() : bool
|
public function isAdmin() : bool
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->user_company()->is_admin;
|
return $this->company_user->is_admin;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,7 +293,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
return (stripos($this->user_company()->permissions, $permission) !== false);
|
return (stripos($this->company_user->permissions, $permission) !== false);
|
||||||
|
|
||||||
|
|
||||||
// return $this->permissionsFlat()->contains($permission);
|
// return $this->permissionsFlat()->contains($permission);
|
||||||
|
@ -62,11 +62,14 @@ class UserRepository extends BaseRepository
|
|||||||
|
|
||||||
$cu = CompanyUser::whereUserId($user->id)->whereCompanyId($company->id)->first();
|
$cu = CompanyUser::whereUserId($user->id)->whereCompanyId($company->id)->first();
|
||||||
|
|
||||||
if(!$cu)
|
|
||||||
$cu = CompanyUserFactory::create($user->id, $company->id, $account_id);
|
|
||||||
|
|
||||||
$cu->fill($data['company_user']);
|
if(!$cu){
|
||||||
$cu->save();
|
//$cu = CompanyUserFactory::create($user->id, $company->id, $account_id);
|
||||||
|
$data['company_user']['account_id'] = $account_id;
|
||||||
|
|
||||||
|
$user->companies()->attach($company->id, $data['company_user']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +80,8 @@ class CompanyTransformer extends EntityTransformer
|
|||||||
'custom_surcharge_taxes2' => (bool)$company->custom_surcharge_taxes2,
|
'custom_surcharge_taxes2' => (bool)$company->custom_surcharge_taxes2,
|
||||||
'custom_surcharge_taxes3' => (bool)$company->custom_surcharge_taxes3,
|
'custom_surcharge_taxes3' => (bool)$company->custom_surcharge_taxes3,
|
||||||
'custom_surcharge_taxes4' => (bool)$company->custom_surcharge_taxes4,
|
'custom_surcharge_taxes4' => (bool)$company->custom_surcharge_taxes4,
|
||||||
|
'show_product_cost' => (bool)$company->show_product_cost,
|
||||||
|
'enable_invoice_quantity' => (bool)$company->enable_invoice_quantity,
|
||||||
'enable_product_cost' => (bool)$company->enable_product_cost,
|
'enable_product_cost' => (bool)$company->enable_product_cost,
|
||||||
'enable_product_quantity' => (bool)$company->enable_product_quantity,
|
'enable_product_quantity' => (bool)$company->enable_product_quantity,
|
||||||
'default_quantity' => (bool)$company->default_quantity,
|
'default_quantity' => (bool)$company->default_quantity,
|
||||||
@ -88,7 +90,11 @@ class CompanyTransformer extends EntityTransformer
|
|||||||
'industry_id' => (string) $company->industry_id ?: '',
|
'industry_id' => (string) $company->industry_id ?: '',
|
||||||
'first_month_of_year' => (string) $company->first_month_of_year ?: '',
|
'first_month_of_year' => (string) $company->first_month_of_year ?: '',
|
||||||
'first_day_of_week' => (string) $company->first_day_of_week ?: '',
|
'first_day_of_week' => (string) $company->first_day_of_week ?: '',
|
||||||
|
'domain' => (string) $company->domain ?: '',
|
||||||
|
'portal_mode' => (string) $company->portal_mode ?: '',
|
||||||
|
'portal_domain' => (string) $company->portal_domain ?: '',
|
||||||
'settings' => $company->settings ?: '',
|
'settings' => $company->settings ?: '',
|
||||||
|
'enabled_tax_rates' => (int)$company->enabled_tax_rates,
|
||||||
'updated_at' => (int)$company->updated_at,
|
'updated_at' => (int)$company->updated_at,
|
||||||
'deleted_at' => (int)$company->deleted_at,
|
'deleted_at' => (int)$company->deleted_at,
|
||||||
];
|
];
|
||||||
|
@ -46,13 +46,17 @@ class CompanyUserTransformer extends EntityTransformer
|
|||||||
public function transform(CompanyUser $company_user)
|
public function transform(CompanyUser $company_user)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'id' => $company_user->id,
|
||||||
|
'account_id' => $company_user->account_id,
|
||||||
|
'user_id' => $company_user->user_id,
|
||||||
|
'company_id' => $company_user->company_id,
|
||||||
'permissions' => $company_user->permissions ?: '',
|
'permissions' => $company_user->permissions ?: '',
|
||||||
'settings' => $company_user->settings ?: '',
|
'settings' => $company_user->settings ?: '',
|
||||||
'is_owner' => (bool) $company_user->is_owner,
|
'is_owner' => (bool) $company_user->is_owner,
|
||||||
'is_admin' => (bool) $company_user->is_admin,
|
'is_admin' => (bool) $company_user->is_admin,
|
||||||
'is_locked' => (bool) $company_user->is_locked,
|
'is_locked' => (bool) $company_user->is_locked,
|
||||||
'updated_at' => $company_user->updated_at,
|
'updated_at' => (int)$company_user->updated_at,
|
||||||
'deleted_at' => $company_user->deleted_at,
|
'deleted_at' => (int)$company_user->deleted_at,
|
||||||
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ class UserTransformer extends EntityTransformer
|
|||||||
|
|
||||||
$transformer = new CompanyUserTransformer($this->serializer);
|
$transformer = new CompanyUserTransformer($this->serializer);
|
||||||
|
|
||||||
return $this->includeCollection($user->user_companies, $transformer, CompanyUser::class);
|
return $this->includeCollection($user->company_users, $transformer, CompanyUser::class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,14 +52,14 @@ trait Inviteable
|
|||||||
|
|
||||||
switch ($this->company->portal_mode) {
|
switch ($this->company->portal_mode) {
|
||||||
case 'subdomain':
|
case 'subdomain':
|
||||||
return $domain .'client/'. $entity_type .'/'. $this->key;
|
return $domain .'/client/'. $entity_type .'/'. $this->key;
|
||||||
break;
|
break;
|
||||||
case 'iframe':
|
case 'iframe':
|
||||||
return $domain .'client/'. $entity_type .'/'. $this->key;
|
return $domain .'/client/'. $entity_type .'/'. $this->key;
|
||||||
//return $domain . $entity_type .'/'. $this->contact->client->client_hash .'/'. $this->key;
|
//return $domain . $entity_type .'/'. $this->contact->client->client_hash .'/'. $this->key;
|
||||||
break;
|
break;
|
||||||
case 'domain':
|
case 'domain':
|
||||||
return $domain .'client/'. $entity_type .'/'. $this->key;
|
return $domain .'/client/'. $entity_type .'/'. $this->key;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
"sentry/sentry-laravel": "^1.0",
|
"sentry/sentry-laravel": "^1.0",
|
||||||
"simshaun/recurr": "^4.0",
|
"simshaun/recurr": "^4.0",
|
||||||
"spatie/browsershot": "^3.29",
|
"spatie/browsershot": "^3.29",
|
||||||
|
"staudenmeir/eloquent-has-many-deep": "^1.11",
|
||||||
"stripe/stripe-php": "^7.0",
|
"stripe/stripe-php": "^7.0",
|
||||||
"superbalist/laravel-google-cloud-storage": "^2.2",
|
"superbalist/laravel-google-cloud-storage": "^2.2",
|
||||||
"webpatser/laravel-countries": "dev-master#75992ad",
|
"webpatser/laravel-countries": "dev-master#75992ad",
|
||||||
|
@ -72,7 +72,7 @@ class RandomDataSeeder extends Seeder
|
|||||||
'is_owner' => 1,
|
'is_owner' => 1,
|
||||||
'is_admin' => 1,
|
'is_admin' => 1,
|
||||||
'is_locked' => 0,
|
'is_locked' => 0,
|
||||||
'permissions' => json_encode([]),
|
'permissions' => '',
|
||||||
'settings' => json_encode(DefaultSettings::userSettings()),
|
'settings' => json_encode(DefaultSettings::userSettings()),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -171,9 +171,9 @@ class LoginTest extends TestCase
|
|||||||
$user->fresh();
|
$user->fresh();
|
||||||
|
|
||||||
$this->assertTrue($user->companies !== null);
|
$this->assertTrue($user->companies !== null);
|
||||||
$this->assertTrue($user->user_companies !== null);
|
$this->assertTrue($user->company_users !== null);
|
||||||
$this->assertTrue($user->user_companies->first() !== null);
|
$this->assertTrue($user->company_users->first() !== null);
|
||||||
$this->assertTrue($user->user_companies->first()->account !== null);
|
$this->assertTrue($user->company_user->account !== null);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'email' => 'test@example.com',
|
'email' => 'test@example.com',
|
||||||
|
@ -37,45 +37,44 @@ class UserTest extends TestCase
|
|||||||
|
|
||||||
Model::reguard();
|
Model::reguard();
|
||||||
|
|
||||||
|
$this->makeTestData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUserList()
|
public function testUserList()
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = [
|
|
||||||
'first_name' => $this->faker->firstName,
|
|
||||||
'last_name' => $this->faker->lastName,
|
|
||||||
'name' => $this->faker->company,
|
|
||||||
'email' => $this->faker->unique()->safeEmail,
|
|
||||||
'password' => 'ALongAndBrilliantPassword123',
|
|
||||||
'_token' => csrf_token(),
|
|
||||||
'privacy_policy' => 1,
|
|
||||||
'terms_of_service' => 1
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
])->post('/api/v1/signup?include=account', $data);
|
'X-API-TOKEN' => $this->token,
|
||||||
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
|
||||||
|
|
||||||
$acc = $response->json();
|
|
||||||
|
|
||||||
|
|
||||||
$account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
|
|
||||||
|
|
||||||
$token = $account->default_company->tokens->first()->token;
|
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
|
||||||
'X-API-TOKEN' => $token,
|
|
||||||
])->get('/api/v1/users');
|
])->get('/api/v1/users');
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUserStore()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'first_name' => 'hey',
|
||||||
|
'last_name' => 'you',
|
||||||
|
'email' => 'bob@good.ole.boys.com',
|
||||||
|
'company_user' => [
|
||||||
|
'is_admin' => false,
|
||||||
|
'is_owner' => false,
|
||||||
|
'permissions' => 'create_client,create_invoice'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->post('/api/v1/users?include=company_user', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user