1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Fixes for deleting / restoring / removing users

This commit is contained in:
David Bomba 2021-03-26 19:07:43 +11:00
parent 8eb8f6e098
commit fd24449f95
4 changed files with 33 additions and 7 deletions

View File

@ -572,7 +572,6 @@ class QuoteController extends BaseController
* description="Performs a custom action on an Quote.
The current range of actions are as follows
- clone_to_Quote
- clone_to_quote
- history
- delivery_note
@ -580,6 +579,8 @@ class QuoteController extends BaseController
- download
- archive
- delete
- convert
- convert_to_invoice
- email",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
@ -640,6 +641,14 @@ class QuoteController extends BaseController
private function performAction(Quote $quote, $action, $bulk = false)
{
switch ($action) {
case 'convert':
case 'convert_to_invoice':
$this->entity_type = Invoice::class;
$this->entity_transformer = InvoiceTransformer::class;
return $this->itemResponse($quote->service()->convertToInvoice());
break;
case 'clone_to_invoice':
$this->entity_type = Invoice::class;

View File

@ -608,14 +608,19 @@ class UserController extends BaseController
*/
public function detach(DetachCompanyUserRequest $request, User $user)
{
if($user->isOwner())
return response()->json(['message', 'Cannot detach owner.'],400);
if ($request->entityIsDeleted($user)) {
return $request->disallowUpdate();
}
$company_user = CompanyUser::whereUserId($user->id)
->whereCompanyId(auth()->user()->companyId())
->withTrashed()
->first();
if($company_user->is_owner)
return response()->json(['message', 'Cannot detach owner.'], 401);
$token = $company_user->token->where('company_id', $company_user->company_id)->where('user_id', $company_user->user_id)->first();
if ($token) {

View File

@ -13,12 +13,14 @@ namespace App\Http\Requests\User;
use App\Http\Requests\Request;
use App\Models\User;
use App\Utils\Traits\ChecksEntityStatus;
use App\Utils\Traits\MakesHash;
class DetachCompanyUserRequest extends Request
{
use MakesHash;
use ChecksEntityStatus;
/**
* Determine if the user is authorized to make this request.
*

View File

@ -148,9 +148,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();
@ -177,7 +177,17 @@ class UserRepository extends BaseRepository
return;
}
$user->is_deleted = false;
$user->save();
$user->restore();
// $user->company_user->restore();
$cu = CompanyUser::withTrashed()
->where('user_id', $user->id)
->where('company_id', auth()->user()->company()->id)
->first();
$cu->restore();
event(new UserWasRestored($user, auth()->user(), auth()->user()->company, Ninja::eventVars()));