mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Hosted version - add user rules. (#3653)
* Add users in hosted platform * Increment num_users when adding a user on enterprised hosted plan * Fixes for user repo
This commit is contained in:
parent
ab8b05dd56
commit
ffa3550e4a
@ -43,6 +43,9 @@ class StoreUserRequest extends Request
|
||||
$rules['email'] = new ValidUserForCompany();
|
||||
}
|
||||
|
||||
if(auth()->user()->company()->account->isFreeHostedClient())
|
||||
$rules['hosted_users'] = new CanAddUserRule(auth()->user()->company()->account);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ class CanAddUserRule implements Rule
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
|
||||
return $this->account->num_users < $this->account->pending_num_users;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,7 +43,7 @@ class CanAddUserRule implements Rule
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return ctrans('texts.limit_users', ['limit' => 1]);
|
||||
return ctrans('texts.limit_users', ['limit' => $this->account->pending_num_users]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -203,6 +203,14 @@ class Account extends BaseModel
|
||||
return $this->plan == 'free';
|
||||
}
|
||||
|
||||
public function isEnterpriseClient()
|
||||
{
|
||||
if(!Ninja::isNinja())
|
||||
return false;
|
||||
|
||||
return $this->plan == 'enterprise';
|
||||
}
|
||||
|
||||
public function isTrial()
|
||||
{
|
||||
if (! Ninja::isNinja()) {
|
||||
|
@ -23,10 +23,6 @@ use Illuminate\Http\Request;
|
||||
*/
|
||||
class UserRepository extends BaseRepository
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the class name.
|
||||
*
|
||||
@ -60,10 +56,16 @@ class UserRepository extends BaseRepository
|
||||
}
|
||||
|
||||
$company = auth()->user()->company();
|
||||
$account_id = $company->account->id;
|
||||
$account = $company->account;;
|
||||
|
||||
/* If hosted and Enterprise we need to increment the num_users field on the accounts table*/
|
||||
if(!$user->id && $account->isEnterpriseClient()){
|
||||
$account->num_users++;
|
||||
$account->save();
|
||||
}
|
||||
|
||||
$user->fill($details);
|
||||
$user->account_id = $account_id;
|
||||
$user->account_id = $account->id;
|
||||
$user->save();
|
||||
|
||||
if (isset($data['company_user'])) {
|
||||
@ -71,7 +73,7 @@ class UserRepository extends BaseRepository
|
||||
|
||||
/*No company user exists - attach the user*/
|
||||
if (!$cu) {
|
||||
$data['company_user']['account_id'] = $account_id;
|
||||
$data['company_user']['account_id'] = $account->id;
|
||||
$data['company_user']['notifications'] = CompanySettings::notificationDefaults();
|
||||
$data['company_user']['is_migrating'] = $is_migrating;
|
||||
$user->companies()->attach($company->id, $data['company_user']);
|
||||
@ -112,7 +114,6 @@ class UserRepository extends BaseRepository
|
||||
|
||||
event(new UserWasDeleted($user, $company));
|
||||
|
||||
|
||||
return $user->fresh();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user