diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index d9843fc34963..161356302fd7 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -12,9 +12,11 @@ namespace App\Http\Controllers; use App\Http\Requests\Account\CreateAccountRequest; +use App\Http\Requests\Account\UpdateAccountRequest; use App\Jobs\Account\CreateAccount; use App\Models\Account; use App\Models\CompanyUser; +use App\Transformers\AccountTransformer; use App\Transformers\CompanyUserTransformer; use App\Utils\TruthSource; use Illuminate\Foundation\Bus\DispatchesJobs; @@ -157,4 +159,17 @@ class AccountController extends BaseController return $this->listResponse($ct); } + + public function update(UpdateAccountRequest $request, Account $account) + { + + $account->fill($request->all()); + $account->save(); + + $this->entity_type = Account::class; + + $this->entity_transformer = AccountTransformer::class; + + return $this->itemResponse($account); + } } diff --git a/app/Http/Requests/Account/UpdateAccountRequest.php b/app/Http/Requests/Account/UpdateAccountRequest.php new file mode 100644 index 000000000000..9267bcefae2a --- /dev/null +++ b/app/Http/Requests/Account/UpdateAccountRequest.php @@ -0,0 +1,53 @@ +user()->isAdmin() || auth()->user()->isOwner(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + 'set_react_as_default_ap' => 'required|bail|bool' + ]; + } + + protected function prepareForValidation() + { + $input = $this->all(); + + $cleaned_input = array_intersect_key( $input, array_flip(['set_react_as_default_ap'])); + + $this->replace($cleaned_input); + + } +} diff --git a/app/Models/Account.php b/app/Models/Account.php index 1692ac7d6ea4..2aef2603d7c1 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -11,6 +11,7 @@ namespace App\Models; +use App\Exceptions\ModelNotFoundException; use App\Jobs\Mail\NinjaMailerJob; use App\Jobs\Mail\NinjaMailerObject; use App\Mail\Ninja\EmailQuotaExceeded; @@ -472,4 +473,14 @@ class Account extends BaseModel } + public function resolveRouteBinding($value, $field = null) + { + if (is_numeric($value)) { + throw new ModelNotFoundException("Record with value {$value} not found"); + } + + return $this + ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); + } + } diff --git a/routes/api.php b/routes/api.php index 74d277181c70..e37eabb84bfa 100644 --- a/routes/api.php +++ b/routes/api.php @@ -24,6 +24,7 @@ Route::group(['middleware' => ['throttle:10,1','api_secret_check','email_db']], }); Route::group(['middleware' => ['throttle:100,1', 'api_db', 'token_auth', 'locale'], 'prefix' => 'api/v1', 'as' => 'api.'], function () { + Route::put('accounts/{account}', 'AccountController@update')->name('account.update'); Route::post('check_subdomain', 'SubdomainController@index')->name('check_subdomain'); Route::get('ping', 'PingController@index')->name('ping'); Route::get('health_check', 'PingController@health')->name('health_check');