mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Fixes for attaching a user to different companies
This commit is contained in:
parent
b818e7204c
commit
c23b9b147d
@ -467,7 +467,7 @@ class UserController extends BaseController
|
||||
public function destroy(DestroyUserRequest $request, User $user)
|
||||
{
|
||||
/* If the user passes the company user we archive the company user */
|
||||
$user = $this->user_repo->destroy($request->all(), $user);
|
||||
$user = $this->user_repo->delete($request->all(), $user);
|
||||
|
||||
event(new UserWasDeleted($user, auth()->user(), auth()->user()->company, Ninja::eventVars()));
|
||||
|
||||
|
@ -49,7 +49,7 @@ class CompanyUser extends Pivot
|
||||
'shop_restricted',
|
||||
];
|
||||
|
||||
protected $touches = [];
|
||||
protected $touches = ['user'];
|
||||
|
||||
public function getEntityType()
|
||||
{
|
||||
|
@ -141,9 +141,9 @@ class UserRepository extends BaseRepository
|
||||
|
||||
event(new UserWasDeleted($user, auth()->user(), $company, Ninja::eventVars()));
|
||||
|
||||
$user->is_deleted = true;
|
||||
$user->save();
|
||||
$user->delete();
|
||||
// $user->is_deleted = true;
|
||||
// $user->save();
|
||||
// $user->delete();
|
||||
|
||||
|
||||
return $user->fresh();
|
||||
|
@ -8,11 +8,13 @@
|
||||
|
||||
@section('body')
|
||||
<div class="grid lg:grid-cols-3">
|
||||
@if(!\App\Models\Account::first()->isPaid())
|
||||
<div class="hidden lg:block col-span-1 bg-red-100 h-screen">
|
||||
<img src="https://www.invoiceninja.com/wp-content/uploads/2018/04/bg-home2018b.jpg"
|
||||
class="w-full h-screen object-cover"
|
||||
alt="Background image">
|
||||
</div>
|
||||
@endif
|
||||
<div class="col-span-2 h-screen flex">
|
||||
<div class="m-auto md:w-1/2 lg:w-1/4">
|
||||
<div class="flex flex-col">
|
||||
|
@ -3,11 +3,13 @@
|
||||
|
||||
@section('body')
|
||||
<div class="grid lg:grid-cols-3">
|
||||
@if(!\App\Models\Account::first()->isPaid())
|
||||
<div class="hidden lg:block col-span-1 bg-red-100 h-screen">
|
||||
<img src="https://www.invoiceninja.com/wp-content/uploads/2018/04/bg-home2018b.jpg"
|
||||
class="w-full h-screen object-cover"
|
||||
alt="Background image">
|
||||
</div>
|
||||
@endif
|
||||
<div class="col-span-2 h-screen flex">
|
||||
<div class="m-auto w-1/2 md:w-1/3 lg:w-1/4">
|
||||
<div class="flex flex-col">
|
||||
|
@ -3,11 +3,13 @@
|
||||
|
||||
@section('body')
|
||||
<div class="grid lg:grid-cols-3">
|
||||
@if(!\App\Models\Account::first()->isPaid())
|
||||
<div class="hidden lg:block col-span-1 bg-red-100 h-screen">
|
||||
<img src="https://www.invoiceninja.com/wp-content/uploads/2018/04/bg-home2018b.jpg"
|
||||
class="w-full h-screen object-cover"
|
||||
alt="Background image">
|
||||
</div>
|
||||
@endif
|
||||
<div class="col-span-2 h-screen flex">
|
||||
<div class="m-auto w-1/2 md:w-1/3 lg:w-1/4">
|
||||
<div class="flex flex-col">
|
||||
|
@ -160,8 +160,8 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
|
||||
Route::get('users', 'UserController@index');
|
||||
Route::put('users/{user}', 'UserController@update')->middleware('password_protected');
|
||||
Route::post('users', 'UserController@store')->middleware('password_protected');
|
||||
Route::post('users/{user}/attach_to_company', 'UserController@attach')->middleware('password_protected');
|
||||
Route::delete('users/{user}/detach_from_company', 'UserController@detach')->middleware('password_protected');
|
||||
//Route::post('users/{user}/attach_to_company', 'UserController@attach')->middleware('password_protected');
|
||||
Route::delete('users/{user}/', 'UserController@detach')->middleware('password_protected');
|
||||
Route::post('users/bulk', 'UserController@bulk')->name('users.bulk')->middleware('password_protected');
|
||||
Route::post('/user/{user}/reconfirm', 'UserController@reconfirm')->middleware('password_protected');
|
||||
|
||||
|
@ -21,6 +21,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -33,6 +34,8 @@ class UserTest extends TestCase
|
||||
use MockAccountData;
|
||||
use DatabaseTransactions;
|
||||
|
||||
private $default_email = 'attach@gmail.com';
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
@ -45,6 +48,8 @@ class UserTest extends TestCase
|
||||
|
||||
Model::reguard();
|
||||
|
||||
$this->withoutExceptionHandling();
|
||||
|
||||
$this->withoutMiddleware(
|
||||
ThrottleRequests::class,
|
||||
PasswordProtection::class
|
||||
@ -97,13 +102,23 @@ class UserTest extends TestCase
|
||||
$user = UserFactory::create($this->account->id);
|
||||
$user->first_name = 'Test';
|
||||
$user->last_name = 'Palloni';
|
||||
$user->email = $this->default_email;
|
||||
$user->save();
|
||||
|
||||
$data = $user->toArray();
|
||||
|
||||
try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
|
||||
])->post('/api/v1/users/'.$this->encodePrimaryKey($user->id).'/attach_to_company?include=company_user');
|
||||
])->post('/api/v1/users?include=company_user', $data);
|
||||
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
nlog($message);
|
||||
$this->assertNotNull($message);
|
||||
}
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
@ -114,7 +129,7 @@ class UserTest extends TestCase
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
|
||||
])->delete('/api/v1/users/'.$this->encodePrimaryKey($user->id).'/detach_from_company?include=company_user');
|
||||
])->delete('/api/v1/users/'.$this->encodePrimaryKey($user->id).'?include=company_user');
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
@ -153,12 +168,15 @@ class UserTest extends TestCase
|
||||
$new_user = UserFactory::create($this->account->id);
|
||||
$new_user->first_name = 'Test';
|
||||
$new_user->last_name = 'Palloni';
|
||||
$new_user->email = $this->default_email;
|
||||
$new_user->save();
|
||||
|
||||
$data = $new_user->toArray();
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $company_token->token,
|
||||
])->post('/api/v1/users/'.$this->encodePrimaryKey($new_user->id).'/attach_to_company?include=company_user');
|
||||
])->post('/api/v1/users?include=company_user', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user