Google Sheet - OAuth "client" powered integrations (#415)
* fix `helpers.php` * fix `.eslintrc.cjs` * spreadsheet manager * fetch providers. set `oauth_id` for integrations * create spreadsheet on integration create event * connect OAuth accounts * display actions. connect account if missing * cleanup * handle form field change * map integration data object to `SpreadsheetData` * validate request * wip * redirect to integrations page * fix refresh token * add helper text * add extra integration info * refactor * refresh google token * fix validation * add tests * Fix linting issue * Update composer lock file --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
@@ -21,9 +21,9 @@ class FormIntegrationsRequest extends FormRequest
|
||||
// Load integration class, and get rules
|
||||
$integration = FormIntegration::getIntegration($request->integration_id);
|
||||
if ($integration && isset($integration['file_name']) && class_exists(
|
||||
'App\Service\Forms\Integrations\\' . $integration['file_name']
|
||||
'App\Integrations\Handlers\\' . $integration['file_name']
|
||||
)) {
|
||||
$this->integrationClassName = 'App\Service\Forms\Integrations\\' . $integration['file_name'];
|
||||
$this->integrationClassName = 'App\Integrations\Handlers\\' . $integration['file_name'];
|
||||
$this->loadIntegrationRules();
|
||||
return;
|
||||
}
|
||||
@@ -40,9 +40,13 @@ class FormIntegrationsRequest extends FormRequest
|
||||
{
|
||||
return array_merge([
|
||||
'integration_id' => ['required', Rule::in(array_keys(FormIntegration::getAllIntegrations()))],
|
||||
'oauth_id' => [
|
||||
$this->isOAuthRequired() ? 'required' : 'nullable',
|
||||
Rule::exists('oauth_providers', 'id')
|
||||
],
|
||||
'settings' => 'present|array',
|
||||
'status' => 'required|boolean',
|
||||
'logic' => [new IntegrationLogicRule()]
|
||||
'logic' => [new IntegrationLogicRule()],
|
||||
], $this->integrationRules);
|
||||
}
|
||||
|
||||
@@ -53,16 +57,24 @@ class FormIntegrationsRequest extends FormRequest
|
||||
*/
|
||||
public function attributes()
|
||||
{
|
||||
$attributes = $this->integrationClassName::getValidationAttributes();
|
||||
|
||||
$fields = [];
|
||||
foreach ($this->rules() as $key => $value) {
|
||||
$fields[$key] = Str::of($key)
|
||||
$fields[$key] = $attributes[$key] ?? Str::of($key)
|
||||
->replace('settings.', '')
|
||||
->headline();
|
||||
->headline()
|
||||
->toString();
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
protected function isOAuthRequired(): bool
|
||||
{
|
||||
return $this->integrationClassName::isOAuthRequired();
|
||||
}
|
||||
|
||||
private function loadIntegrationRules()
|
||||
{
|
||||
foreach ($this->integrationClassName::getValidationRules() as $key => $value) {
|
||||
@@ -78,7 +90,8 @@ class FormIntegrationsRequest extends FormRequest
|
||||
)) ? FormIntegration::STATUS_ACTIVE : FormIntegration::STATUS_INACTIVE,
|
||||
'integration_id' => $this->validated('integration_id'),
|
||||
'data' => $this->validated('settings') ?? [],
|
||||
'logic' => $this->validated('logic') ?? []
|
||||
'logic' => $this->validated('logic') ?? [],
|
||||
'oauth_id' => $this->validated('oauth_id'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user