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 support for Slack notifications #730

Merged
merged 29 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ec5e133
Add slack notifications
hanifn Jun 11, 2024
8bf4f9f
Escape form element names
hanifn Jun 12, 2024
31ab216
Simplify slack alert texts
hanifn Jun 12, 2024
2fb73da
Switch to generic webhook notifications
hanifn Jun 13, 2024
8d2487e
Hide webhook url input if it’s disabled
hanifn Jun 13, 2024
48bda0c
Fix phpcs errors
hanifn Jun 13, 2024
79e565a
Fix more phpcs errors
hanifn Jun 13, 2024
d7962a1
Add filters for webhook message and payload
hanifn Jun 13, 2024
d3bd8e7
Rename methods and setting names
hanifn Jun 13, 2024
4df9210
Fix phpcs errors
hanifn Jun 13, 2024
4ce2556
More phpcs fixes
hanifn Jun 13, 2024
d757db0
Fix repeat fetching of POST variables
hanifn Jun 14, 2024
0d6ddf2
Use single string literal for i18n function
hanifn Jun 14, 2024
8c0adc7
Verify nonce before saving ef post subs
hanifn Jun 14, 2024
5919a69
Update module description
hanifn Jun 14, 2024
d410b67
Run the production build for the js/css files
ingeniumed Jun 17, 2024
57a6806
Fix editorial comment error handling
hanifn Jun 19, 2024
331166c
Fix phpcs errors
hanifn Jun 19, 2024
586e779
Refactor send to webhook method for versatility
hanifn Jun 19, 2024
69676fd
Update module descriptions
hanifn Jun 21, 2024
6458d6b
Add some TODOs
hanifn Jun 21, 2024
34906df
Update PHPCS ruleset
hanifn Jun 21, 2024
a551fcd
Use short array syntax instead
hanifn Jun 21, 2024
653f3d2
Change webhook error message
hanifn Jun 21, 2024
81fa03c
Add form validation for webhook settings
hanifn Jun 21, 2024
caf723f
Revert "Add form validation for webhook settings"
hanifn Jun 24, 2024
902bc04
Update notifications meta box description
hanifn Jun 24, 2024
a540e18
Sanitize webhook URL
hanifn Jun 24, 2024
157ec5c
Refactor validation for brevity
hanifn Jun 24, 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
30 changes: 18 additions & 12 deletions common/php/class-module.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,18 +296,24 @@ function update_user_meta( $user_id, $key, $value, $previous = null ) {

}

/**
* Take a status and a message, JSON encode and print
*
* @since 0.7
*
* @param string $status Whether it was a 'success' or an 'error'
*/
function print_ajax_response( $status, $message = '' ) {
header( 'Content-type: application/json;' );
echo json_encode( array( 'status' => $status, 'message' => $message ) );
exit;
}
/**
* Take a status and a message, JSON encode and print
*
* @since 0.7
*
* @param string $status Whether it was a 'success' or an 'error'
*/
protected function print_ajax_response( $status, $message = '', $http_code = 200 ) {
header( 'Content-type: application/json;' );
http_response_code( $http_code );
echo wp_json_encode(
array(
'status' => $status,
'message' => $message,
)
);
exit;
}

/**
* Whether or not the current page is a user-facing Edit Flow View
Expand Down
171 changes: 87 additions & 84 deletions modules/editorial-comments/lib/editorial-comments.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,92 +16,95 @@
border-top: 1px solid #e5e5e5;
background: #eee;
}
#ef-comments li {
padding: 5px;
margin: 0px 0;
border-left: 5px solid #e5e5e5;
border-right: 5px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
background: #fff;
}

.row-actions {
margin-top: 0;
}

#ef-comments li:hover p.row-actions,
#ef-comments li:hover .ef-notification-meta {
visibility: visible;
}

#ef-comments li p.row-actions {
text-align: right;
}
#ef-comments ul.children {
margin-left: 30px;
margin-bottom: 10px;
}
#ef-comments ul.children li {
/*background: #EAF2FA;*/
border-left: 5px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
}
/*
#ef-comments li {
padding: 5px;
margin: 0px 0;
border-left: 5px solid #e5e5e5;
border-right: 5px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
background: #fff;
}

.row-actions {
margin-top: 0;
}

#ef-comments li:hover p.row-actions,
#ef-comments li:hover .ef-notification-meta {
visibility: visible;
}

#ef-comments li p.row-actions {
text-align: right;
}

#ef-comments ul.children {
margin-left: 30px;
margin-bottom: 10px;
}
#ef-comments ul.children li {
/*background: #EAF2FA;*/
border-left: 5px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
}
/*
#ef-comments .even { background: none; }
#ef-comments .odd { background: none; }
*/
#ef-comments img.avatar {
border:1px solid #CCCCCC;
float:left;
margin-left:2px;
margin-right:15px;
margin-top:0;
}

#ef-comments h5 {
font-style: normal;
font-size:1em;
line-height:1.1em;
margin-top: 10px;
margin-bottom: 10px;
}

#ef-comments h5 span.meta {
color:#666666;
font-size:0.85em;
margin:0 0 1.5em;
font-style: normal;
}

#ef-comments .comment-content {
margin-left: 67px;
}

#ef-comments .comment-content p {
color:#555555;
font-size:1em;
line-height:1.4em;
margin:0.7em 0;
}

#ef-replyrow {
}
#ef-replyrow #ef-replycontent {
width: 100%;
height: 100px;
}
#ef-replyrow #ef-replysubmit {
margin: 6px 0;
}
#ef-replyrow #ef-replysubmit * {
margin-left: 3px;
}
#ef-replyrow #ef-replysubmit .error {
margin: 6px 6px 0 0;
line-height:1.2em;
padding:4px 10px;
}
#ef-comments img.avatar {
border: 1px solid #cccccc;
float: left;
margin-left: 2px;
margin-right: 15px;
margin-top: 0;
}

#ef-comments h5 {
font-style: normal;
font-size: 1em;
line-height: 1.1em;
margin-top: 10px;
margin-bottom: 10px;
}

#ef-comments h5 span.meta {
color: #666666;
font-size: 0.85em;
margin: 0 0 1.5em;
font-style: normal;
}

#ef-comments .comment-content {
margin-left: 67px;
}

#ef-comments .comment-content p {
color: #555555;
font-size: 1em;
line-height: 1.4em;
margin: 0.7em 0;
}

#ef-replyrow {
}
#ef-replyrow #ef-replycontent {
width: 100%;
height: 100px;
}
#ef-replyrow #ef-replysubmit {
margin: 6px 0;
}
#ef-replyrow #ef-replysubmit * {
margin-left: 3px;
}
#ef-replyrow #ef-replysubmit .error {
background-color: #f4a2a2;
border-left: 4px solid #cc1818;
display: block;
margin: 6px 0 0;
line-height: 1.2em;
padding: 4px 10px;
}

.ef-comment {
font-size: 14px;
Expand Down Expand Up @@ -129,7 +132,7 @@ input[readonly].ef-reply-notifier-message {
border-left: 4px solid #46b450;
}

label[for="ef-reply-notifier"] {
label[for='ef-reply-notifier'] {
margin: 0.75em 0;
display: block;
cursor: default;
Expand Down
10 changes: 9 additions & 1 deletion modules/editorial-comments/lib/editorial-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,16 @@ editorialCommentReply = {
er = r.responseText.replace( /<.[^<>]*?>/g, '' );
}

let message = '';
try {
er = JSON.parse( er );
message = er.message ?? er;
} catch ( parseErr ) {
message = er;
}

if ( er ) {
jQuery( '#ef-replysubmit .error' ).html( er ).show();
jQuery( '#ef-replysubmit .error' ).html( message ).show();
}
},
};
14 changes: 14 additions & 0 deletions modules/notifications/lib/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,18 @@ jQuery( document ).ready( function ( $ ) {
} );
}
);

hanifn marked this conversation as resolved.
Show resolved Hide resolved
// TODO: Should change this to _not_ use JQuery
const webhookUrl = $( 'input#webhook_url' ).closest( 'tr' );
const sendToWebhook = $( 'select#send_to_webhook' );
if ( sendToWebhook.val() === 'off' ) {
webhookUrl.hide();
}
sendToWebhook.on( 'change', function () {
if ( $( this ).val() === 'off' ) {
webhookUrl.hide();
} else {
webhookUrl.show();
}
} );
} );
Loading
Loading