diff --git a/common/php/class-module.php b/common/php/class-module.php
index dff2dd17c..8c6ac5527 100755
--- a/common/php/class-module.php
+++ b/common/php/class-module.php
@@ -472,7 +472,11 @@ function users_select_form( $selected = null, $args = null ) {
ID, $selected) ) ? 'checked="checked"' : ''; ?>
diff --git a/modules/notifications/lib/notifications.css b/modules/notifications/lib/notifications.css
index 85e70084d..493664b13 100644
--- a/modules/notifications/lib/notifications.css
+++ b/modules/notifications/lib/notifications.css
@@ -6,31 +6,46 @@
background-position: 5px 7px;
}
-.ef-post_following_list {
+.ef-post_following_list li {
+ padding: 10px 5px 5px 5px;
+ margin: 0;
+ border-bottom: 1px solid #ccc;
+ min-height: 36px;
}
- .ef-post_following_list li {
- padding: 10px 5px 5px 5px;
- margin: 0;
- border-bottom: 1px solid #ccc;
- }
- .ef-post_following_list li:hover {
- background: #EAF2FA;
- }
- .ef-post_following_list li input {
- float: right;
- }
- .ef-post_following_list .ef-user_displayname,
- .ef-post_following_list .ef-usergroup_name {
- display: block;
- font-size: 14px;
- }
- .ef-post_following_list .ef-user_useremail,
- .ef-post_following_list .ef-usergroup_description {
- display: block;
- color: #ccc;
- font-size: 12px;
- }
+.ef-post_following_list li:hover {
+ background: #EAF2FA;
+}
+
+.ef-post_following_list li input {
+ float: right;
+ margin-top: 0;
+}
+
+.ef-post_following_list .ef-user_displayname,
+.ef-post_following_list .ef-usergroup_name {
+ display: block;
+ font-size: 14px;
+}
+
+.ef-post_following_list .ef-user_useremail,
+.ef-post_following_list .ef-usergroup_description {
+ display: block;
+ color: #ccc;
+ font-size: 12px;
+}
+
+.ef-post_following_list li .ef-user-subscribe-actions {
+ float: right;
+ margin-top: 5px;
+}
+
+.ef-post_following_list li .ef-user-subscribe-actions span {
+ margin-right: 10px;
+ border: solid 2px #FFCCCC;
+ color: #FFCCCC;
+ padding: 4px;
+}
#ef-post_following_box {
margin:10px 0;
@@ -91,4 +106,4 @@
#ef-usergroup-users h4 {
margin-top: 0;
-}
\ No newline at end of file
+}
diff --git a/modules/notifications/lib/notifications.js b/modules/notifications/lib/notifications.js
index a611f3486..c7e1163a2 100644
--- a/modules/notifications/lib/notifications.js
+++ b/modules/notifications/lib/notifications.js
@@ -6,6 +6,16 @@ jQuery(document).ready(function($) {
post_id: $('#post_ID').val(),
};
+ var toggle_no_access_badge = function( container, user_has_no_access ) {
+ if ( $( container ).siblings( 'span' ).length ) {
+ $( container ).siblings( 'span' ).remove();
+ } else if ( user_has_no_access ) {
+ var span = $( '' );
+ span.text( ef_notifications_localization.no_access );
+ $( container ).parent().prepend( span );
+ }
+ }
+
$(document).on('click','.ef-post_following_list li input:checkbox, .ef-following_usergroups li input:checkbox', function() {
var user_group_ids = [];
var parent_this = $(this);
@@ -13,9 +23,7 @@ jQuery(document).ready(function($) {
params._nonce = $("#ef_notifications_nonce").val();
$(this)
- .parent()
- .parent()
- .parent()
+ .parents('.ef-post_following_list')
.find('input:checked')
.map(function(){
user_group_ids.push($(this).val());
@@ -27,15 +35,22 @@ jQuery(document).ready(function($) {
type : 'POST',
url : (ajaxurl) ? ajaxurl : wpListL10n.url,
data : params,
- success : function(x) {
+
+ success : function( response ) {
// This event is used to show an updated list of who will be notified of editorial comments and status updates.
$( '#ef-post_following_box' ).trigger( 'following_list_updated' );
var backgroundColor = parent_this.css( 'background-color' );
- $(parent_this.parent().parent())
+ $(parent_this.parents('li'))
.animate( { 'backgroundColor':'#CCEEBB' }, 200 )
.animate( { 'backgroundColor':backgroundColor }, 200 );
+
+ // Toggle the "No Access" badge if the selected user does not have access.
+ if ( undefined !== response.data ) {
+ var user_has_no_access = response.data.subscribers_with_no_access.includes( parseInt( $( parent_this ).val() ) );
+ toggle_no_access_badge( $( parent_this ), user_has_no_access );
+ }
},
error : function(r) {
$('#ef-post_following_users_box').prev().append(' There was an error. Please reload the page.
');
diff --git a/modules/notifications/notifications.php b/modules/notifications/notifications.php
index a78062ebe..f48eb7d62 100644
--- a/modules/notifications/notifications.php
+++ b/modules/notifications/notifications.php
@@ -69,6 +69,9 @@ function init() {
// Set up metabox and related actions
add_action( 'add_meta_boxes', array( $this, 'add_post_meta_box' ) );
+
+ // Add "access badge" to the subscribers list.
+ add_action( 'ef_user_subscribe_actions', array( $this, 'display_subscriber_access_badge' ), 10, 2 );
// Saving post actions
// self::save_post_subscriptions() is hooked into transition_post_status so we can ensure usergroup data
@@ -191,6 +194,13 @@ function enqueue_admin_scripts() {
wp_enqueue_script( 'jquery-listfilterizer' );
wp_enqueue_script( 'jquery-quicksearch' );
wp_enqueue_script( 'edit-flow-notifications-js', $this->module_url . 'lib/notifications.js', array( 'jquery', 'jquery-listfilterizer', 'jquery-quicksearch' ), EDIT_FLOW_VERSION, true );
+ wp_localize_script(
+ 'edit-flow-notifications-js',
+ 'ef_notifications_localization',
+ array(
+ 'no_access' => esc_html__( 'No Access', 'edit-flow' )
+ )
+ );
}
}
@@ -354,6 +364,21 @@ function notifications_meta_box() {
user_can_be_notified( get_user_by( 'id', $user_id ), $post->ID ) ) {
+ echo '' . esc_html__( 'No Access', 'edit-flow' ) . '';
+ }
+ }
/**
* Called when a notification editorial metadata checkbox is checked. Handles saving of a user/usergroup to a post.
@@ -381,6 +406,14 @@ function ajax_save_post_subscriptions() {
if ( 'ef-selected-users[]' === $_POST['ef_notifications_name'] ) {
$this->save_post_following_users( $post, $user_group_ids );
+
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_POST['post_id'] ) ) {
+ $subscribers_with_no_access = array_filter( $user_group_ids, function( $user_id ) {
+ return ! $this->user_can_be_notified( get_user_by( 'id', $user_id ), $_POST['post_id'] );
+ } );
+
+ wp_send_json_success( array( 'subscribers_with_no_access' => array_values( $subscribers_with_no_access ) ) );
+ }
}
$groups_enabled = $this->module_enabled( 'user_groups' ) && in_array( get_post_type( $post_id ), $this->get_post_types_for_module( $edit_flow->user_groups->module ) );
@@ -838,6 +871,33 @@ function user_can_be_notified( $user, $post_id ) {
return (bool) apply_filters( 'ef_notification_user_can_be_notified', $can_be_notified, $user, $post_id );
}
+ /**
+ * TODO: Remove this before merge. Duplicated function originally in PR #449
+ *
+ * Check if a user can be notified.
+ * This is based off of the ability to edit the post/page by default.
+ *
+ * @since 0.8.3
+ * @param WP_User $user
+ * @param int $post_id
+ * @return bool True if the user can be notified, false otherwise.
+ */
+ function user_can_be_notified( $user, $post_id ) {
+ $can_be_notified = false;
+ if ( $user instanceof WP_User && is_user_member_of_blog( $user->ID ) && is_numeric( $post_id ) ) {
+ // The 'edit_post' cap check also covers the undocumented 'edit_page' cap.
+ $can_be_notified = $user->has_cap( 'edit_post', $post_id );
+ }
+ /**
+ * Filters if a user can be notified. Defaults to true if they can edit the post/page.
+ *
+ * @param bool $can_be_notified True if the user can be notified.
+ * @param WP_User|bool $user The user object, otherwise false.
+ * @param int $post_id The post the user will be notified about.
+ */
+ return (bool) apply_filters( 'ef_notification_user_can_be_notified', $can_be_notified, $user, $post_id );
+ }
+
/**
* Set a user or users to follow a post
*