mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 05:24:34 -04:00
Fixes for adding and restoring users
This commit is contained in:
parent
5f4e40162b
commit
88dfa3601b
@ -19,6 +19,7 @@ use App\Factory\UserFactory;
|
|||||||
use App\Filters\UserFilters;
|
use App\Filters\UserFilters;
|
||||||
use App\Http\Controllers\Traits\VerifiesUserEmail;
|
use App\Http\Controllers\Traits\VerifiesUserEmail;
|
||||||
use App\Http\Requests\User\AttachCompanyUserRequest;
|
use App\Http\Requests\User\AttachCompanyUserRequest;
|
||||||
|
use App\Http\Requests\User\BulkUserRequest;
|
||||||
use App\Http\Requests\User\CreateUserRequest;
|
use App\Http\Requests\User\CreateUserRequest;
|
||||||
use App\Http\Requests\User\DestroyUserRequest;
|
use App\Http\Requests\User\DestroyUserRequest;
|
||||||
use App\Http\Requests\User\DetachCompanyUserRequest;
|
use App\Http\Requests\User\DetachCompanyUserRequest;
|
||||||
@ -534,7 +535,7 @@ class UserController extends BaseController
|
|||||||
* ),
|
* ),
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function bulk()
|
public function bulk(BulkUserRequest $request)
|
||||||
{
|
{
|
||||||
/* Validate restore() here and check if restoring the user will exceed their user quote (hosted only)*/
|
/* Validate restore() here and check if restoring the user will exceed their user quote (hosted only)*/
|
||||||
$action = request()->input('action');
|
$action = request()->input('action');
|
||||||
|
48
app/Http/Requests/User/BulkUserRequest.php
Normal file
48
app/Http/Requests/User/BulkUserRequest.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Http\Requests\User;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
use App\Http\ValidationRules\Ninja\CanRestoreUserRule;
|
||||||
|
use App\Http\ValidationRules\UniqueUserRule;
|
||||||
|
use App\Utils\Ninja;
|
||||||
|
|
||||||
|
class BulkUserRequest extends Request
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize() : bool
|
||||||
|
{
|
||||||
|
return auth()->user()->isAdmin();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
|
||||||
|
$rules = [];
|
||||||
|
|
||||||
|
if(Ninja::isHosted() && $this->action && $this->action == 'restore')
|
||||||
|
$rules['ids'] = new CanRestoreUserRule();
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function prepareForValidation()
|
||||||
|
{
|
||||||
|
$input = $this->all();
|
||||||
|
|
||||||
|
$this->replace($input);
|
||||||
|
}
|
||||||
|
}
|
@ -31,12 +31,15 @@ class CanAddUserRule implements Rule
|
|||||||
*/
|
*/
|
||||||
public function passes($attribute, $value)
|
public function passes($attribute, $value)
|
||||||
{
|
{
|
||||||
// $count = CompanyUser::query()
|
|
||||||
// ->where('account_id', auth()->user()->account_id)
|
|
||||||
// ->distinct('user_id')
|
|
||||||
// ->count();
|
|
||||||
|
|
||||||
// return $count < auth()->user()->company()->account->num_users;
|
$count = CompanyUser::query()
|
||||||
|
->with('user')
|
||||||
|
->where('account_id', auth()->user()->account_id)
|
||||||
|
->distinct()
|
||||||
|
->select('user_id')
|
||||||
|
->count();
|
||||||
|
|
||||||
|
return $count < auth()->user()->company()->account->num_users;
|
||||||
//return auth()->user()->company()->account->users->count() < auth()->user()->company()->account->num_users;
|
//return auth()->user()->company()->account->users->count() < auth()->user()->company()->account->num_users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
56
app/Http/ValidationRules/Ninja/CanRestoreUserRule.php
Normal file
56
app/Http/ValidationRules/Ninja/CanRestoreUserRule.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Http\ValidationRules\Ninja;
|
||||||
|
|
||||||
|
use App\Models\CompanyUser;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Contracts\Validation\Rule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CanAddUserRule.
|
||||||
|
*/
|
||||||
|
class CanRestoreUserRule implements Rule
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $attribute
|
||||||
|
* @param mixed $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function passes($attribute, $value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$count = User::query()
|
||||||
|
->with(['company_user' => function ($query){
|
||||||
|
return $query->whereNull('company_user.deleted_at');
|
||||||
|
}])
|
||||||
|
->where('account_id', 1)
|
||||||
|
->distinct()
|
||||||
|
->select('users.id')
|
||||||
|
->count();
|
||||||
|
|
||||||
|
return $count < auth()->user()->company()->account->num_users;
|
||||||
|
//return auth()->user()->company()->account->users->count() < auth()->user()->company()->account->num_users;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function message()
|
||||||
|
{
|
||||||
|
return ctrans('texts.limit_users', ['limit' => auth()->user()->company()->account->num_users]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user