Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Webhooks integration #985

Merged
merged 24 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cb9892b
feat: add account saving for hooks prototype
Soare-Robert-Daniel Jul 4, 2024
70c48df
chore: phpcs
Soare-Robert-Daniel Jul 5, 2024
0f1241b
feat: add edit webhook
Soare-Robert-Daniel Jul 8, 2024
024cf89
Merge branch 'development' into feat/webhooks
Soare-Robert-Daniel Jul 8, 2024
f06eef9
fix: header processing and account edit selection
Soare-Robert-Daniel Jul 9, 2024
1b72364
fix: close button for header editor
Soare-Robert-Daniel Jul 9, 2024
dac2483
fix: edit button position
Soare-Robert-Daniel Jul 9, 2024
fd8365a
fix: box icon color
Soare-Robert-Daniel Jul 9, 2024
ebf6c54
fix: edit modal on hidden sign in
Soare-Robert-Daniel Jul 9, 2024
bcc5d89
fix: edit webhook data
Soare-Robert-Daniel Jul 9, 2024
32dd7e5
feat: use only one spinner
Soare-Robert-Daniel Jul 9, 2024
c061796
chore: update e2e tests
Soare-Robert-Daniel Jul 9, 2024
046af99
chore: add tests for webhook endpoint
Soare-Robert-Daniel Jul 9, 2024
21ebae1
Merge branch 'development' into feat/webhooks
Soare-Robert-Daniel Jul 10, 2024
572a9a8
chore: change webhook button color
Soare-Robert-Daniel Jul 10, 2024
678a72f
fix: secondary btn border
Soare-Robert-Daniel Jul 10, 2024
8371c5c
chore: webhook icon instant sharing
Soare-Robert-Daniel Jul 11, 2024
5e22161
chore: log the webhook share result
Soare-Robert-Daniel Jul 11, 2024
67e4bb4
Merge branch 'development' into feat/webhooks
Soare-Robert-Daniel Jul 11, 2024
9dcd4bd
chore: webhook free sign in
Soare-Robert-Daniel Jul 11, 2024
fc0ce67
fix: prevent crashing when `sign_in_url` does not exists
Soare-Robert-Daniel Jul 11, 2024
72381a0
chore: phpcs
Soare-Robert-Daniel Jul 11, 2024
d30b8b0
Merge branch 'development' into feat/webhooks
Soare-Robert-Daniel Jul 11, 2024
c5dd746
chore: remove logs
Soare-Robert-Daniel Jul 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions assets/css/rop_core.css
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,33 @@ a.active {
border-left-color: #fff;
}

#rop_core .btn.btn-webhook {
border-color: #0071a6;
color: #fff;
background: #FFBC42;
}

#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;
Expand Down Expand Up @@ -2849,14 +2876,17 @@ a.active {
cursor: default;
}

#rop_core .modal:target .modal-container,
#rop_core .modal.active .modal-container {
#rop_core :is( .modal:target, .modal.active ) .modal-container {
z-index: 99999;
max-width: 640px;
-webkit-animation: slide-down 0.2s ease 1;
animation: slide-down 0.2s ease 1;
}

#rop_core :is( .modal:target, .modal.active ) .modal-container:has(.webhook-headers) {
max-width: 960px;
}

#rop_core .modal.modal-sm .modal-container {
max-width: 320px;
}
Expand Down Expand Up @@ -4168,6 +4198,10 @@ a.active {
background-color: #bd081c;
}

.icon_box.webhook {
background-color: #FFBC42;;
}

#rop_core .avatar .avatar-icon {
border-radius: 50%;
background: #333;
Expand Down
4 changes: 2 additions & 2 deletions includes/admin/class-rop-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1268,8 +1268,8 @@ public function check_cron_status() {
* @access public
*/
public function rop_wp_cron_notice() {
//TODO - we need to rework this as the constant is not saying that cron is not working only that the default scheduling is, the user can still use server cron instead.
return;
// TODO - we need to rework this as the constant is not saying that cron is not working only that the default scheduling is, the user can still use server cron instead.
return;
if ( ! defined( 'DISABLE_WP_CRON' ) ) {
return;
}
Expand Down
27 changes: 27 additions & 0 deletions includes/admin/class-rop-global-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ class Rop_Global_Settings {
'active' => false,
'name' => 'Vk',
),
'webhook' => array(
'active' => false,
'name' => 'Webhook',
'two_step_sign_in' => true,
),
);

/**
Expand Down Expand Up @@ -327,6 +332,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',
),
);

/**
Expand Down
104 changes: 102 additions & 2 deletions includes/admin/class-rop-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -896,8 +896,11 @@ function ( $value ) {
}
}
if ( ${$data['service'] . '_services'} ) {
/* @noinspection PhpUndefinedMethodInspection */
$url = ${$data['service'] . '_services'}->sign_in_url( $data );
if ( method_exists( ${$data['service'] . '_services'}, 'sign_in_url' ) ) {
$url = ${$data['service'] . '_services'}->sign_in_url( $data );
} else {
$url = '';
}
}
} catch ( Exception $exception ) {
// Service can't be built. Not found or otherwise. Maybe log this.
Expand Down Expand Up @@ -1320,4 +1323,101 @@ 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 ) {
$services = array();
$webhook_service = new Rop_Webhook_Service();
$model = new Rop_Services_Model();
$db = new Rop_Db_Upgrade();

if ( ! $webhook_service->add_webhook( $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 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 ) {
$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();

if ( ! isset( $authenticated_services[ $service_id ] ) ) {
$this->response->set_code( '422' )
->set_data( array() );

return $this->response->to_array();
}

$authenticated_services[ $service_id ] = array_merge( $authenticated_services[ $service_id ], $webhook_service->get_service() );

$model->update_authenticated_services( $authenticated_services );

if ( ! empty( $data['active'] ) && ! empty( $data['full_id'] ) ) {
$model->add_active_accounts( array( $data['full_id'] ) );
}

$this->response->set_code( '200' )
->set_message( 'OK' )
->set_data( array() );

return $this->response->to_array();
}
}
2 changes: 1 addition & 1 deletion includes/admin/models/class-rop-scheduler-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ function ( $value ) use ( &$prev ) {
* @since 8.0.0
* @access public
*/
public function generate_upcoming_events( $base = 0, $account_id, $limit = 0 ) {
public function generate_upcoming_events( $base = 0, $account_id = null, $limit = 0 ) {

$schedule = $this->get_schedule( $account_id );
if ( empty( $schedule ) ) {
Expand Down
Loading
Loading