mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Quote webhooks and default company setter
This commit is contained in:
parent
b38cd1ef32
commit
af8f559466
@ -15,6 +15,7 @@ use App\DataMapper\Analytics\AccountDeleted;
|
|||||||
use App\DataMapper\CompanySettings;
|
use App\DataMapper\CompanySettings;
|
||||||
use App\DataMapper\DefaultSettings;
|
use App\DataMapper\DefaultSettings;
|
||||||
use App\Http\Requests\Company\CreateCompanyRequest;
|
use App\Http\Requests\Company\CreateCompanyRequest;
|
||||||
|
use App\Http\Requests\Company\DefaultCompanyRequest;
|
||||||
use App\Http\Requests\Company\DestroyCompanyRequest;
|
use App\Http\Requests\Company\DestroyCompanyRequest;
|
||||||
use App\Http\Requests\Company\EditCompanyRequest;
|
use App\Http\Requests\Company\EditCompanyRequest;
|
||||||
use App\Http\Requests\Company\ShowCompanyRequest;
|
use App\Http\Requests\Company\ShowCompanyRequest;
|
||||||
@ -598,8 +599,66 @@ class CompanyController extends BaseController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function default(DefaultCompanyRequest $request, Company $company)
|
/**
|
||||||
// {
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
// }
|
* @param UploadCompanyRequest $request
|
||||||
|
* @param Company $client
|
||||||
|
* @return Response
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/v1/companies/{company}/default",
|
||||||
|
* operationId="setDefaultCompany",
|
||||||
|
* tags={"companies"},
|
||||||
|
* summary="Sets the company as the default company.",
|
||||||
|
* description="Sets the company as the default company.",
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||||
|
* @OA\Parameter(
|
||||||
|
* name="company",
|
||||||
|
* in="path",
|
||||||
|
* description="The Company Hashed ID",
|
||||||
|
* example="D2J234DFA",
|
||||||
|
* required=true,
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="string",
|
||||||
|
* format="string",
|
||||||
|
* ),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="Returns the company object",
|
||||||
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||||
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||||
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/Company"),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=422,
|
||||||
|
* description="Validation error",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||||
|
*
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response="default",
|
||||||
|
* description="Unexpected Error",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function default(DefaultCompanyRequest $request, Company $company)
|
||||||
|
{
|
||||||
|
|
||||||
|
$account = $company->account;
|
||||||
|
$account->default_company_id = $company->id;
|
||||||
|
$account->save();
|
||||||
|
|
||||||
|
return $this->itemResponse($company->fresh());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
36
app/Http/Requests/Company/DefaultCompanyRequest.php
Normal file
36
app/Http/Requests/Company/DefaultCompanyRequest.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?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\Company;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
|
||||||
|
class DefaultCompanyRequest 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 = [];
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
47
app/Listeners/Quote/QuoteApprovedWebhook.php
Normal file
47
app/Listeners/Quote/QuoteApprovedWebhook.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Quote Ninja (https://quoteninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/quoteninja/quoteninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Quote Ninja LLC (https://quoteninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Listeners\Quote;
|
||||||
|
|
||||||
|
use App\Jobs\Util\WebhookHandler;
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
|
use App\Models\Webhook;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
|
class QuoteApprovedWebhook implements ShouldQueue
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param object $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle($event)
|
||||||
|
{
|
||||||
|
MultiDB::setDb($event->company->db);
|
||||||
|
|
||||||
|
$quote = $event->quote;
|
||||||
|
|
||||||
|
$subscriptions = Webhook::where('company_id', $quote->company_id)
|
||||||
|
->where('event_id', Webhook::EVENT_APPROVE_QUOTE)
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($subscriptions) {
|
||||||
|
WebhookHandler::dispatch(Webhook::EVENT_APPROVE_QUOTE, $quote, $quote->company);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -51,6 +51,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
|
|||||||
Route::resource('companies', 'CompanyController'); // name = (companies. index / create / show / update / destroy / edit
|
Route::resource('companies', 'CompanyController'); // name = (companies. index / create / show / update / destroy / edit
|
||||||
|
|
||||||
Route::put('companies/{company}/upload', 'CompanyController@upload');
|
Route::put('companies/{company}/upload', 'CompanyController@upload');
|
||||||
|
Route::post('companies/{company}/default', 'CompanyController@default');
|
||||||
|
|
||||||
Route::get('company_ledger', 'CompanyLedgerController@index')->name('company_ledger.index');
|
Route::get('company_ledger', 'CompanyLedgerController@index')->name('company_ledger.index');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user