From cb9892b280d9051d30fc015aa608bcc9635f5143 Mon Sep 17 00:00:00 2001
From: "Soare Robert Daniel (Mac 2023)"
Date: Thu, 4 Jul 2024 17:24:50 +0300
Subject: [PATCH 01/20] feat: add account saving for hooks prototype
---
includes/admin/class-rop-global-settings.php | 4 +
includes/admin/class-rop-rest-api.php | 50 ++++++
.../services/class-rop-webhook-service.php | 151 ++++++++++++++++++
vue/src/vue-elements/sign-in-btn.vue | 128 ++++++++++++++-
4 files changed, 330 insertions(+), 3 deletions(-)
create mode 100644 includes/admin/services/class-rop-webhook-service.php
diff --git a/includes/admin/class-rop-global-settings.php b/includes/admin/class-rop-global-settings.php
index 0497abd55..3614bdec5 100644
--- a/includes/admin/class-rop-global-settings.php
+++ b/includes/admin/class-rop-global-settings.php
@@ -126,6 +126,10 @@ class Rop_Global_Settings {
'active' => false,
'name' => 'Vk',
),
+ 'webhook' => array(
+ 'active' => false,
+ 'name' => 'Webhook',
+ ),
);
/**
diff --git a/includes/admin/class-rop-rest-api.php b/includes/admin/class-rop-rest-api.php
index 517c56ada..9fbcc6945 100644
--- a/includes/admin/class-rop-rest-api.php
+++ b/includes/admin/class-rop-rest-api.php
@@ -1293,6 +1293,56 @@ private function add_account_vk( $data ) {
return $this->response->to_array();
}
+ /**
+ * API method called to add Webhook account.
+ *
+ * @SuppressWarnings(PHPMD.UnusedPrivateMethod) As it is called dynamically.
+ *
+ * @since 9.1.0
+ * @access private
+ *
+ * @param array $data Webhook account data.
+ *
+ * @return array
+ */
+ private function add_account_webhook( $data ) {
+ error_log( 'webhook data: ' . print_r( $data, true ) );
+ $services = array();
+ $webhook_service = new Rop_Webhook_Service();
+ $model = new Rop_Services_Model();
+ $db = new Rop_Db_Upgrade();
+
+ if( ! $webhook_service->process_registration( $data ) ) {
+ $this->response->set_code( '422' )
+ ->set_data( array() );
+
+ return $this->response->to_array();
+ }
+
+ $services[ $webhook_service->get_service_id() ] = $webhook_service->get_service();
+ $active_accounts = $webhook_service->get_service_active_accounts();
+
+ if ( ! empty( $services ) ) {
+ $model->add_authenticated_service( $services );
+ }
+
+ if ( ! empty( $active_accounts ) ) {
+ $db->migrate_schedule( $active_accounts );
+ $db->migrate_post_formats( $active_accounts );
+ } else {
+ $this->response->set_code( '500' )
+ ->set_data( array() );
+
+ return $this->response->to_array();
+ }
+
+ $this->response->set_code( '200' )
+ ->set_message( 'OK' )
+ ->set_data( array() );
+
+ return $this->response->to_array();
+ }
+
/**
* API method called to toggle tracking.
*
diff --git a/includes/admin/services/class-rop-webhook-service.php b/includes/admin/services/class-rop-webhook-service.php
new file mode 100644
index 000000000..0dbe8bbc6
--- /dev/null
+++ b/includes/admin/services/class-rop-webhook-service.php
@@ -0,0 +1,151 @@
+display_name = 'Webhook';
+ }
+
+ /**
+ * Method to register credentials for the service.
+ *
+ * @since 8.0.0
+ * @access public
+ *
+ * @param array $args The credentials array.
+ */
+ public function set_credentials( $args ) {
+ $this->credentials = $args;
+ }
+
+ /**
+ * Returns information for the current service.
+ *
+ * @since 8.0.0
+ * @access public
+ * @return mixed
+ */
+ public function get_service() {
+ return $this->service;
+ }
+
+ /**
+ * Method for publishing with Twitter service.
+ *
+ * @since 8.0.0
+ * @access public
+ *
+ * @param array $post_details The post details to be published by the service.
+ * @param array $args Optional arguments needed by the method.
+ *
+ * @return mixed
+ */
+ public function share( $post_details, $args = array() ) {
+
+ if ( Rop_Admin::rop_site_is_staging( $post_details['post_id'] ) ) {
+ $this->logger->alert_error( Rop_I18n::get_labels( 'sharing.share_attempted_on_staging' ) );
+ return false;
+ }
+
+ return false;
+ }
+
+ public function process_registration( $data ) {
+ if ( empty( $data['url'] ) ) {
+ return false;
+ }
+
+ $id = base64_encode( $data['url'] );
+ $display_name = ! empty( $data['display_name'] ) ? $data['display_name'] : 'Webhook';
+
+ $this->service = array(
+ 'id' => $id,
+ 'service' => $this->service_name,
+ 'credentials' => array(
+ 'url' => $data['url'],
+ 'headers' => ! empty( $data['headers'] ) && is_array( $data['headers'] ) ? $data['headers'] : array(),
+ 'display_name' => $display_name,
+ ),
+ 'available_accounts' => array(
+ array(
+ 'id' => $id,
+ 'user' => $display_name,
+ 'service' => $this->service_name,
+ 'account' => $this->normalize_string( $data['url'] ),
+ 'created' => date( 'd/m/Y H:i' )
+ ),
+ ),
+ );
+
+ return true;
+ }
+
+ public function expose_endpoints()
+ {
+
+ }
+
+ public function get_api()
+ {
+
+ }
+
+ public function set_api()
+ {
+
+ }
+
+ public function populate_additional_data($account)
+ {
+ return $account;
+ }
+
+ public function maybe_authenticate()
+ {
+
+ }
+
+ public function authenticate($args)
+ {
+
+ }
+
+ public function request_api_token() {
+
+ }
+}
diff --git a/vue/src/vue-elements/sign-in-btn.vue b/vue/src/vue-elements/sign-in-btn.vue
index b4675c1c1..d3aec57cd 100644
--- a/vue/src/vue-elements/sign-in-btn.vue
+++ b/vue/src/vue-elements/sign-in-btn.vue
@@ -11,7 +11,7 @@
@click="requestAuthorization( network )"
>
@@ -34,6 +34,30 @@
+
+
+
+
{{ displayName( service.name, false, true ) }}
@@ -242,6 +266,42 @@
+
@@ -324,6 +384,12 @@ export default {
showLiAppBtn: ropApiSettings.show_li_app_btn,
showTmblrAppBtn: ropApiSettings.show_tmblr_app_btn,
hideOwnAppOption: ropApiSettings.hide_own_app_option,
+ currentWebhookHeader: '',
+ webhooksHeaders: [
+ 'Authorization: Bearer XXX',
+ 'Content-Type: application/json',
+ 'X-My-Header: Value',
+ ],
showBtn: false
}
},
@@ -382,6 +448,10 @@ export default {
return this.modal.serviceName === 'Pinterest';
},
+ isWebhook() {
+ return this.modal.serviceName === 'Webhook';
+ },
+
isAllowedTumblr: function () {
let showButton = true;
if (!this.showTmblrAppBtn) {
@@ -545,13 +615,19 @@ export default {
}
}
- if (!valid) {
+ if ( ! valid ) {
this.$forceUpdate()
return;
}
this.activePopup = this.selected_network
- this.getUrlAndGo(credentials)
+
+ if( this.isWebhook ) {
+ credentials['headers'] = this.webhooksHeaders;
+ this.addAccountWebhook( credentials );
+ } else {
+ this.getUrlAndGo(credentials)
+ }
this.modal.isOpen = false
},
cancelModal: function () {
@@ -661,6 +737,19 @@ export default {
Vue.$log.error('Got nothing from server. Prompt user to check internet connection and try again', error)
});
},
+ addAccountWebhook(data) {
+ console.log( data );
+ this.$store.dispatch('fetchAJAXPromise', {
+ req: 'add_account_webhook',
+ updateState: false,
+ data: data
+ }).then(() => {
+ window.removeEventListener("message", this.getChildWindowMessage );
+ }, error => {
+ this.is_loading = false;
+ Vue.$log.error('Got nothing from server. Prompt user to check internet connection and try again', error)
+ });
+ },
/**
* Get message from child window.
* @param {MessageEvent} event Event.
@@ -685,6 +774,8 @@ export default {
this.addAccountGmb( accountData );
} else if ('Vk' === this.modal.serviceName) {
this.addAccountVk( accountData );
+ } else if ('Webhook' === this.modal.serviceName) {
+ this.addAccountWebhook( accountData );
}
try {
@@ -700,6 +791,13 @@ export default {
window.location.reload();
},
+ addWebhookHeader() {
+ if ( ! this.currentWebhookHeader ) {
+ return;
+ }
+
+ this.webhooksHeaders.push( this.currentWebhookHeader );
+ },
openPopupFB: function () {
let loginUrl = this.appOrigin + this.appPathFB + '?callback_url=' + this.siteAdminUrl + '&token=' + this.appUniqueId + '&signature=' + this.appSignature + '&data=' + this.appAdminEmail;
try {
@@ -790,4 +888,28 @@ export default {
.btn-gmb {
text-transform: uppercase;
}
+
+@media (min-width: 768px) {
+ .content:has(.webhook-headers) {
+ display: grid;
+ grid-template-columns: auto auto;
+ gap: 10px;
+ }
+
+ .content:has(.webhook-headers) .auth-app {
+ min-width: 200px;
+ }
+}
+
+.webhook-headers {
+ background-color: #f7f7f7;
+ padding: 10px;
+ min-width: 400px;
+ border-radius: 10px;
+
+ display: flex;
+ flex-direction: column;
+ gap: 10px;
+}
+
From 70c48df4f5250ae4234126166f427ec700f3d7b0 Mon Sep 17 00:00:00 2001
From: "Soare Robert Daniel (Mac 2023)"
Date: Fri, 5 Jul 2024 15:38:38 +0300
Subject: [PATCH 02/20] chore: phpcs
---
includes/admin/class-rop-global-settings.php | 22 +++
includes/admin/class-rop-rest-api.php | 12 +-
.../services/class-rop-webhook-service.php | 148 ++++++++++++++----
includes/class-rop-i18n.php | 5 +
4 files changed, 151 insertions(+), 36 deletions(-)
diff --git a/includes/admin/class-rop-global-settings.php b/includes/admin/class-rop-global-settings.php
index 3614bdec5..b076b1ab7 100644
--- a/includes/admin/class-rop-global-settings.php
+++ b/includes/admin/class-rop-global-settings.php
@@ -330,6 +330,28 @@ class Rop_Global_Settings {
'utm_campaign_medium' => 'social',
'utm_campaign_name' => 'ReviveOldPost',
),
+ 'webhook' => array(
+ 'wpml_language' => '',
+ 'post_content' => 'post_title',
+ 'custom_meta_field' => '',
+ 'maximum_length' => '1000',
+ 'custom_text' => '',
+ 'custom_text_pos' => 'beginning',
+ 'include_link' => true,
+ 'url_from_meta' => false,
+ 'url_meta_key' => '',
+ 'short_url' => false,
+ 'short_url_service' => 'is.gd',
+ 'hashtags' => 'no-hashtags',
+ 'hashtags_length' => '200',
+ 'hashtags_common' => '',
+ 'hashtags_custom' => '',
+ 'hashtags_randomize' => false,
+ 'shortner_credentials' => array(),
+ 'image' => false,
+ 'utm_campaign_medium' => 'social',
+ 'utm_campaign_name' => 'ReviveOldPost',
+ ),
);
/**
diff --git a/includes/admin/class-rop-rest-api.php b/includes/admin/class-rop-rest-api.php
index 9fbcc6945..c94b9b73c 100644
--- a/includes/admin/class-rop-rest-api.php
+++ b/includes/admin/class-rop-rest-api.php
@@ -1295,14 +1295,14 @@ private function add_account_vk( $data ) {
/**
* API method called to add Webhook account.
- *
+ *
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) As it is called dynamically.
- *
+ *
* @since 9.1.0
* @access private
- *
+ *
* @param array $data Webhook account data.
- *
+ *
* @return array
*/
private function add_account_webhook( $data ) {
@@ -1312,7 +1312,7 @@ private function add_account_webhook( $data ) {
$model = new Rop_Services_Model();
$db = new Rop_Db_Upgrade();
- if( ! $webhook_service->process_registration( $data ) ) {
+ if ( ! $webhook_service->add_webhook( $data ) ) {
$this->response->set_code( '422' )
->set_data( array() );
@@ -1341,7 +1341,7 @@ private function add_account_webhook( $data ) {
->set_data( array() );
return $this->response->to_array();
- }
+ }
/**
* API method called to toggle tracking.
diff --git a/includes/admin/services/class-rop-webhook-service.php b/includes/admin/services/class-rop-webhook-service.php
index 0dbe8bbc6..16fe9fed5 100644
--- a/includes/admin/services/class-rop-webhook-service.php
+++ b/includes/admin/services/class-rop-webhook-service.php
@@ -6,7 +6,7 @@
* It extends the Rop_Services_Abstract class.
*
* @link https://themeisle.com/
- * @since 8.0.0
+ * @since 9.1.0
*
* @package Rop
* @subpackage Rop/includes/admin/services
@@ -23,7 +23,7 @@ class Rop_Webhook_Service extends Rop_Services_Abstract {
/**
* Defines the service name in slug format.
*
- * @since 8.0.0
+ * @since 9.1.0
* @access protected
* @var string $service_name The service name.
*/
@@ -34,7 +34,7 @@ class Rop_Webhook_Service extends Rop_Services_Abstract {
* Method to inject functionality into constructor.
* Defines the defaults and settings for this service.
*
- * @since 8.0.0
+ * @since 9.1.0
* @access public
*/
public function init() {
@@ -44,7 +44,7 @@ public function init() {
/**
* Method to register credentials for the service.
*
- * @since 8.0.0
+ * @since 9.1.0
* @access public
*
* @param array $args The credentials array.
@@ -52,11 +52,11 @@ public function init() {
public function set_credentials( $args ) {
$this->credentials = $args;
}
-
+
/**
* Returns information for the current service.
*
- * @since 8.0.0
+ * @since 9.1.0
* @access public
* @return mixed
*/
@@ -67,7 +67,7 @@ public function get_service() {
/**
* Method for publishing with Twitter service.
*
- * @since 8.0.0
+ * @since 9.1.0
* @access public
*
* @param array $post_details The post details to be published by the service.
@@ -82,16 +82,64 @@ public function share( $post_details, $args = array() ) {
return false;
}
+ $url = isset( $this->credentials['url'] ) ? $this->credentials['url'] : '';
+
+ if ( empty( $url ) ) {
+ $this->logger->alert_error( Rop_I18n::get_labels( 'sharing.webhook_url_not_set' ) );
+ return false;
+ }
+
+ $args = array(
+ 'headers' => array(),
+ );
+
+ $payload = array(
+ 'postId' => isset( $post_details['post_id'] ) ? $post_details['post_id'] : '',
+ 'message' => isset( $post_details['content'] ) ? $post_details['content'] : '',
+ 'postUrl' => isset( $post_details['post_url'] ) ? $post_details['post_url'] : '',
+ 'featuredImage' => isset( $post_details['featured_image'] ) ? $post_details['featured_image'] : '',
+ );
+
+ if ( ! class_exists( 'ROP_Pro_Webhook_Helper' ) ) {
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
+
+ if ( is_plugin_active( 'tweet-old-post-pro/tweet-old-post-pro.php' ) ) {
+ require_once ROP_PRO_PATH . 'includes/helpers/class-rop-pro-webhook-helper.php';
+ }
+ }
+
+ if ( class_exists( 'ROP_Pro_Webhook_Helper' ) ) {
+ $response = ROP_Pro_Webhook_Helper::send_webhook_payload( $this->credentials['url'], $payload, $args );
+ } else {
+ $this->logger->alert_error( Rop_I18n::get_labels( 'sharing.webhook_extension_not_found' ) );
+ return false;
+ }
+
+ if ( is_wp_error( $response ) ) {
+ $this->logger->alert_error( Rop_I18n::get_labels( 'errors.webhook_error' ) . ': ' . $response->get_error_message() );
+ return false;
+ }
+
return false;
}
- public function process_registration( $data ) {
+ /**
+ * Add the webhook to the service data.
+ *
+ * @since 9.1.0
+ * @access public
+ *
+ * @param array $data The webhook data.
+ *
+ * @return bool
+ */
+ public function add_webhook( $data ) {
if ( empty( $data['url'] ) ) {
return false;
}
- $id = base64_encode( $data['url'] );
- $display_name = ! empty( $data['display_name'] ) ? $data['display_name'] : 'Webhook';
+ $id = empty( $data['id'] ) ? base64_encode( $data['url'] ) : empty( $data['id'] );
+ $display_name = ! empty( $data['display_name'] ) ? $data['display_name'] : 'Webhook';
$this->service = array(
'id' => $id,
@@ -107,7 +155,7 @@ public function process_registration( $data ) {
'user' => $display_name,
'service' => $this->service_name,
'account' => $this->normalize_string( $data['url'] ),
- 'created' => date( 'd/m/Y H:i' )
+ 'created' => date( 'd/m/Y H:i' ),
),
),
);
@@ -115,37 +163,77 @@ public function process_registration( $data ) {
return true;
}
- public function expose_endpoints()
- {
-
+
+ /**
+ * Expose the endpoints for the webhook service.
+ *
+ * @since 9.1.0
+ * @access public
+ * @return void
+ */
+ public function expose_endpoints() {
}
- public function get_api()
- {
-
+ /**
+ * Retrieve the API object.
+ *
+ * @since 9.1.0
+ * @access public
+ * @return mixed The API object.
+ */
+ public function get_api() {
}
- public function set_api()
- {
-
+ /**
+ * Define the API object.
+ *
+ * @since 9.1.0
+ * @access public
+ * @return void
+ */
+ public function set_api() {
}
- public function populate_additional_data($account)
- {
+ /**
+ * Populate additional data for the account.
+ *
+ * @since 9.1.0
+ * @access public
+ * @param mixed $account The account data.
+ * @return mixed The populated account data.
+ */
+ public function populate_additional_data( $account ) {
return $account;
}
- public function maybe_authenticate()
- {
-
+ /**
+ * Check if authentication is needed.
+ *
+ * @since 9.1.0
+ * @access public
+ * @return void
+ */
+ public function maybe_authenticate() {
}
- public function authenticate($args)
- {
-
+ /**
+ * Authenticate the user with the given arguments.
+ *
+ * @since 9.1.0
+ * @access public
+ * @param mixed $args The arguments for authentication.
+ * @return void
+ */
+ public function authenticate( $args ) {
}
-
- public function request_api_token() {
+ /**
+ * Request an API token.
+ *
+ * @since 9.1.0
+ * @access public
+ * @return mixed The API token.
+ */
+ public function request_api_token() {
}
}
diff --git a/includes/class-rop-i18n.php b/includes/class-rop-i18n.php
index b7bb19912..9ec0ea636 100644
--- a/includes/class-rop-i18n.php
+++ b/includes/class-rop-i18n.php
@@ -414,6 +414,8 @@ public static function get_labels( $key = '' ) {
'share_attempted_on_staging' => __( 'ROP has detected that this is a development website. Share process skipped.', 'tweet-old-post' ),
'reached_sharing_limit' => __( 'You\'ve reached your daily post sharing limit of %1$d posts. Want to share more? Consider upgrading to enjoy a higher limit.', 'tweet-old-post' ),
'invalid_license' => __( 'Sorry, your license is invalid.', 'tweet-old-post' ),
+ 'webhook_extension_not_found' => __( 'Webhook extension not found. Please install the Pro add-on.', 'tweet-old-post' ),
+ 'webhook_url_not_set' => __( 'Webhook URL not set.', 'tweet-old-post' ),
),
'errors' => array(
'wordpress_api_error' => __( 'Cannot post to network. WordPress Error: ', 'tweet-old-post' ),
@@ -426,6 +428,9 @@ public static function get_labels( $key = '' ) {
'linkedin_issue_fetching_token' => __( 'There was an issue fetching the LinkedIn Token. Please contact Revive Old Posts support for assistance.', 'tweet-old-post' ),
'no_image_found' => __( 'No image was found for post %1$s cannot share as an image post to: %2$s. Please double check that you have a featured image set.', 'tweet-old-post' ),
'license_not_active' => __( 'An active Pro license is needed to share to %1$s', 'tweet-old-post' ),
+ 'could_not_send_webhook' => __( 'Could not send webhook.', 'tweet-old-post' ),
+ 'webhook_error' => __( 'An error occurred for Webhook post sharing.', 'tweet-old-post' ),
+
),
'generic' => array(
'only_pro_suffix' => ' (' . __( 'Available in Pro', 'tweet-old-post' ) . ')',
From 0f1241bfda58b57bf2ac980e0bed231dab56005b Mon Sep 17 00:00:00 2001
From: "Soare Robert Daniel (Mac 2023)"
Date: Mon, 8 Jul 2024 19:16:06 +0300
Subject: [PATCH 03/20] feat: add edit webhook
---
assets/css/rop_core.css | 27 ++++
includes/admin/class-rop-rest-api.php | 59 ++++++++
.../services/class-rop-webhook-service.php | 1 +
includes/class-rop-i18n.php | 1 +
vue/src/models/rop_store.js | 12 ++
vue/src/vue-elements/accounts-tab-panel.vue | 2 +
.../vue-elements/reusables/account-modal.vue | 57 ++++++++
.../reusables/webhook-account-modal.vue | 120 ++++++++++++++++
.../reusables/webhook-headers.vue | 108 +++++++++++++++
vue/src/vue-elements/service-user-tile.vue | 31 ++++-
vue/src/vue-elements/sign-in-btn.vue | 131 ++++++++++--------
11 files changed, 488 insertions(+), 61 deletions(-)
create mode 100644 vue/src/vue-elements/reusables/account-modal.vue
create mode 100644 vue/src/vue-elements/reusables/webhook-account-modal.vue
create mode 100644 vue/src/vue-elements/reusables/webhook-headers.vue
diff --git a/assets/css/rop_core.css b/assets/css/rop_core.css
index e9bb43d9b..28a596999 100644
--- a/assets/css/rop_core.css
+++ b/assets/css/rop_core.css
@@ -869,6 +869,33 @@ a.active {
border-left-color: #fff;
}
+#rop_core .btn.btn-webhook {
+ border-color: #0071a6;
+ color: #fff;
+ background: #458e82;
+}
+
+#rop_core .btn.btn-webhook:focus {
+ box-shadow: 0 0 0 0.1rem rgba(0, 123, 181, 0.2);
+}
+
+#rop_core .btn.btn-webhook:is( :focus, :hover ) {
+ border-color: #006a9c;
+ color: #fff;
+ background: #0074ab;
+}
+
+#rop_core .btn.btn-webhook:is( :active, .active ) {
+ border-color: #005882;
+ color: #fff;
+ background: #006391;
+}
+
+#rop_core .btn.btn-webhook.loading::after {
+ border-bottom-color: #fff;
+ border-left-color: #fff;
+}
+
#rop_core .btn.btn-sm {
height: 1.2rem;
padding: 0.05rem 0.3rem;
diff --git a/includes/admin/class-rop-rest-api.php b/includes/admin/class-rop-rest-api.php
index c94b9b73c..09f485887 100644
--- a/includes/admin/class-rop-rest-api.php
+++ b/includes/admin/class-rop-rest-api.php
@@ -1343,6 +1343,65 @@ private function add_account_webhook( $data ) {
return $this->response->to_array();
}
+ /**
+ * API method called to edit Webhook account.
+ *
+ * @SuppressWarnings(PHPMD.UnusedPrivateMethod) As it is called dynamically.
+ *
+ * @since 9.1.0
+ * @access private
+ *
+ * @param array $data Webhook account data.
+ *
+ * @return array
+ */
+ private function edit_account_webhook( $data ) {
+ error_log( 'edit webhook data: ' . print_r( $data, true ) );
+ $services = array();
+ $webhook_service = new Rop_Webhook_Service();
+ $model = new Rop_Services_Model();
+
+ if ( ! $webhook_service->add_webhook( $data ) ) {
+ $this->response->set_code( '422' )
+ ->set_data( array() );
+
+ return $this->response->to_array();
+ }
+
+ $service_id = ! empty( $data['service_id'] ) ? $data['service_id'] : '';
+
+ $authenticated_services = $model->get_authenticated_services();
+
+ // We should find the service id in the authenticated services. Otherwise, we reject the request.
+ $account_present = false;
+ foreach ( $authenticated_services as $auth_service_id => $service ) {
+ if ( $service_id === $auth_service_id ) {
+ $account_present = true;
+ break;
+ }
+ }
+
+ if ( ! $account_present ) {
+ $this->response->set_code( '422' )
+ ->set_data( array() );
+
+ return $this->response->to_array();
+ }
+
+ $services[ $service_id ] = $webhook_service->get_service();
+
+ if ( ! empty( $services ) ) {
+ $model->add_authenticated_service( $services );
+ $model->add_active_accounts( $service_id );
+ }
+
+ $this->response->set_code( '200' )
+ ->set_message( 'OK' )
+ ->set_data( array() );
+
+ return $this->response->to_array();
+ }
+
/**
* API method called to toggle tracking.
*
diff --git a/includes/admin/services/class-rop-webhook-service.php b/includes/admin/services/class-rop-webhook-service.php
index 16fe9fed5..d51c97cd7 100644
--- a/includes/admin/services/class-rop-webhook-service.php
+++ b/includes/admin/services/class-rop-webhook-service.php
@@ -156,6 +156,7 @@ public function add_webhook( $data ) {
'service' => $this->service_name,
'account' => $this->normalize_string( $data['url'] ),
'created' => date( 'd/m/Y H:i' ),
+ 'active' => isset( $data['active'] ) ? $data['active'] : true,
),
),
);
diff --git a/includes/class-rop-i18n.php b/includes/class-rop-i18n.php
index 9ec0ea636..bafb757f5 100644
--- a/includes/class-rop-i18n.php
+++ b/includes/class-rop-i18n.php
@@ -94,6 +94,7 @@ public static function get_labels( $key = '' ) {
'field_required' => __( 'This field is required', 'tweet-old-post' ),
'at' => __( 'at', 'tweet-old-post' ),
'remove_account' => __( 'Remove account from the list.', 'tweet-old-post' ),
+ 'edit_account' => __( 'Edit account details.', 'tweet-old-post' ),
'no_accounts' => __( 'You Need to Connect an Account', 'tweet-old-post' ),
'no_active_accounts' => __( 'No active accounts!', 'tweet-old-post' ),
'no_active_accounts_desc' => __( 'Add one from the "Accounts" section.', 'tweet-old-post' ),
diff --git a/vue/src/models/rop_store.js b/vue/src/models/rop_store.js
index 0e5e9d548..68b5edddf 100644
--- a/vue/src/models/rop_store.js
+++ b/vue/src/models/rop_store.js
@@ -39,6 +39,10 @@ export default new Vuex.Store({
view: 'accounts',
template: 'accounts',
},
+ editPopup: {
+ accountId: '',
+ canShow: false,
+ },
cron_status: {},
toast: {
type: 'success',
@@ -111,6 +115,14 @@ export default new Vuex.Store({
},
mutations: {
+ setEditPopup(state, data) {
+ state.editPopup = data
+ },
+
+ setEditPopupShowPermission(state, canShow) {
+ state.editPopup.canShow = canShow
+ },
+
setTabView(state, view) {
Vue.$log.debug('Changing tab to ', view);
for (let tab in state.displayTabs) {
diff --git a/vue/src/vue-elements/accounts-tab-panel.vue b/vue/src/vue-elements/accounts-tab-panel.vue
index c2873a92f..45bb48fc6 100644
--- a/vue/src/vue-elements/accounts-tab-panel.vue
+++ b/vue/src/vue-elements/accounts-tab-panel.vue
@@ -104,6 +104,7 @@
import ServiceUserTile from './service-user-tile.vue'
import AddAccountTile from './reusables/add-account-tile.vue'
import vue_spinner from './reusables/vue-spinner.vue'
+ import WebhookAccountModal from './reusables/webhook-account-modal.vue'
export default {
name: 'AccountView',
@@ -111,6 +112,7 @@
SignInBtn,
ServiceUserTile,
AddAccountTile,
+ WebhookAccountModal,
'vue_spinner': vue_spinner
},
data: function () {
diff --git a/vue/src/vue-elements/reusables/account-modal.vue b/vue/src/vue-elements/reusables/account-modal.vue
new file mode 100644
index 000000000..dec511eb0
--- /dev/null
+++ b/vue/src/vue-elements/reusables/account-modal.vue
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/vue/src/vue-elements/reusables/webhook-account-modal.vue b/vue/src/vue-elements/reusables/webhook-account-modal.vue
new file mode 100644
index 000000000..14b09dc1d
--- /dev/null
+++ b/vue/src/vue-elements/reusables/webhook-account-modal.vue
@@ -0,0 +1,120 @@
+
+
+
+ {{ modal.serviceName }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/vue/src/vue-elements/reusables/webhook-headers.vue b/vue/src/vue-elements/reusables/webhook-headers.vue
new file mode 100644
index 000000000..5bde4db5c
--- /dev/null
+++ b/vue/src/vue-elements/reusables/webhook-headers.vue
@@ -0,0 +1,108 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/vue/src/vue-elements/service-user-tile.vue b/vue/src/vue-elements/service-user-tile.vue
index 79aa4897c..8369cc069 100644
--- a/vue/src/vue-elements/service-user-tile.vue
+++ b/vue/src/vue-elements/service-user-tile.vue
@@ -47,7 +47,20 @@
-
+
+
+
+
diff --git a/vue/src/vue-elements/sign-in-btn.vue b/vue/src/vue-elements/sign-in-btn.vue
index d3aec57cd..8cf6d7d33 100644
--- a/vue/src/vue-elements/sign-in-btn.vue
+++ b/vue/src/vue-elements/sign-in-btn.vue
@@ -266,42 +266,10 @@ q2 -17 -1.5 -33t-13.5 -30q-16 -22 -41 -32q-17 -7 -35.5 -6.5t-35.5 7.5q-28 12 -43
-
+ :headers.sync="webhooksHeaders"
+ />
@@ -341,7 +309,7 @@ q2 -17 -1.5 -33t-13.5 -30q-16 -22 -41 -32q-17 -7 -35.5 -6.5t-35.5 7.5q-28 12 -43
class="btn btn-primary"
@click="closeModal()"
>
- {{ labels.sign_in_btn }}
+ {{ isOpenToEdit ? labels.save_selector_btn : labels.sign_in_btn }}
@@ -350,11 +318,12 @@ q2 -17 -1.5 -33t-13.5 -30q-16 -22 -41 -32q-17 -7 -35.5 -6.5t-35.5 7.5q-28 12 -43