Changeset 2147085
- Timestamp:
- 08/28/2019 12:33:26 PM (7 years ago)
- Location:
- wp-issues-crm/trunk/php
- Files:
-
- 2 edited
-
admin/class-wic-admin-access.php (modified) (4 diffs)
-
entity/class-wic-entity-email-inbox.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-issues-crm/trunk/php/admin/class-wic-admin-access.php
r2146005 r2147085 108 108 //'get_issue_options' //not taking ajax calls 109 109 //'get_inbox_options' //not taking ajax calls 110 'load_inbox' => ' ', // check required capability within function to scope what shown (only email sees all)110 'load_inbox' => 'check_record', 111 111 'load_sent' => 'view_edit_unassigned', 112 112 'load_outbox' => 'view_edit_unassigned', … … 352 352 private static function current_user_can_access_this_email_message ( $action, $id, $data ) { // for email, function is false only if people cannot access email ( could have email without otherwise accessing unassigned ) 353 353 switch ( $action ) { 354 case 'load_inbox': 355 return self::can_user_access_this_inbox_page ( $data ); 354 356 case 'load_message_detail': // from inbox, loading for reply 355 357 return self::can_user_access_this_folder_message ( $data->fullFolderString, $id ); … … 363 365 } 364 366 367 private static function can_user_access_this_inbox_page ( $data) { 368 if ( in_array( $data->tab, array( 'CATEGORY_ASSIGNED', 'CATEGORY_READY') ) ) { 369 return true; 370 } else { 371 return current_user_can ( WIC_Admin_Access::check_required_capability( 'email' ) ); 372 } 373 } 374 365 375 366 376 private static function can_user_access_this_folder_message( $folder, $uid ) { … … 399 409 return true; 400 410 } else { 401 $message_vals = $wpdb->get_results ( $wpdb->prepare ( "SELECT case_assigned, last_updated_by FROM $constituent_table c INNER JOIN $activity_table a on a.constituent_id = c.id WHERE related_inbox_record = %d" , array( $message_id ) ) );411 $message_vals = $wpdb->get_results ( $wpdb->prepare ( "SELECT case_assigned, c.last_updated_by FROM $constituent_table c INNER JOIN $activity_table a on a.constituent_id = c.id WHERE related_inbox_record = %d" , array( $message_id ) ) ); 402 412 } 403 413 // if outbox, check only assigned constituent 404 414 } else { 405 $message_vals = $wpdb->get_results ( $wpdb->prepare ( "SELECT case_assigned, last_updated_by FROM $constituent_table c INNER JOIN $activity_table a on a.constituent_id = c.id WHERE related_outbox_record = %s", array( $message_id ) ) );415 $message_vals = $wpdb->get_results ( $wpdb->prepare ( "SELECT case_assigned, c.last_updated_by FROM $constituent_table c INNER JOIN $activity_table a on a.constituent_id = c.id WHERE related_outbox_record = %s", array( $message_id ) ) ); 406 416 } 407 417 -
wp-issues-crm/trunk/php/entity/class-wic-entity-email-inbox.php
r2146005 r2147085 68 68 69 69 public static function load_inbox ( $dummy_id, $data ) { 70 /* 71 * $data->mode coming from the client is "single" or "grouped" 72 * 73 */ 74 75 /* 76 * 77 * only have full access to email with email capacity; view_edit_unassigned only gives access to constituents/issues/activities, not emails 78 * 79 */ 70 71 // set up variables 72 $current_user_id = get_current_user_id(); 73 // note that if !$user_can_see_all, then WIC_Admin_Access will have bounced a tab request other than for CATEGORY_ASSIGNED, CATEGORY_READY 80 74 $user_can_see_all = current_user_can ( WIC_Admin_Access::check_required_capability( 'email' ) ); 81 if ( ! $user_can_see_all && !in_array( $data->tab, array( 'CATEGORY_ASSIGNED', 'CATEGORY_READY') ) ) {82 $data->tab = 'CATEGORY_ASSIGNED' ;83 }84 85 86 // get date limits87 75 $form_variables_object = WIC_Entity_Email_Process::get_processing_options()['output']; 88 76 $parse_strictness = isset ( $form_variables_object->parse_strictness ) ? $form_variables_object->parse_strictness : '5'; // default to loosest standard (max strictness = 1; 6 = no email address) … … 106 94 * (2) They all have content mapped to the same issue/pro-con, which agrees with the subject mapped result 107 95 * (3) The content match meets both the required confidence percentage and the required word count percentage 108 * (4) HAVE NOT HAD ANY INDIVIDUAL MESSAGE INBOX DEFINITION ACTIVITY 96 * (4) HAVE NOT HAD ANY INDIVIDUAL MESSAGE INBOX DEFINITION ACTIVITY (since 4.5, added draft capacity) 109 97 * NOTE: There may or may not be a reply already assigned to the issue -- could be just recording 110 98 * 111 * Note: not grouping without a subject line match -- can hit high confidence numbers on reply and forward strings, possibly in other ways. 112 * Solution for variable subject lines is wild card. 113 * 114 * most of the inbox is cosmetic: the only processing consequences of the inbox line content flow from 99 * most of the inbox (as opposed to message detail view) is security and cosmetics: the only processing consequences of the inbox line content flow from 115 100 * * "have_trained_issue" (which determines, by adding a class below, whether a line is grouped and so eligible for sweeps per above strict criterion) 116 101 * * and the folder_uid list (which is the basis of all line processing) … … 140 125 * sweep_definition is critical concept that enforces strictness of automated reply processing per notes above 141 126 * 142 * added inbox_defined terms exclude items that have had individual attention from the inbox in any grouping127 * added 4 inbox_defined terms exclude items that have had individual attention from the inbox in any grouping 143 128 */ 144 129 $inbox_image_table = $wpdb->prefix . 'wic_inbox_image'; … … 156 141 "; 157 142 143 // user supplied filter string from in box email -- $data->filter is not blank, from email, from personal (name), subject and snippet will be scanned for it 144 // only emails with a positive scan will be returned 158 145 $filter = sanitize_text_field ( $data->filter ); 159 146 $filter_where = self::filter_where ( $filter ); 160 147 161 // add tab selection terms -- CATEGORY_ADVOCACY, CATEGORY_ASSIGNED, CATEGORY_READY special, dynamically applied 162 $category_where = $wpdb->prepare ( 163 "IF( 164 assigned_subject is NULL AND constituent_assigned_staff is NULL, 165 IF( mapped_issue > 0, 'CATEGORY_ADVOCACY', category ), 166 IF( subject_is_final, 'CATEGORY_READY', 'CATEGORY_ASSIGNED' ) 167 ) = %s AND ", 168 array ( $data->tab ) 169 ); 170 171 // limit selection to inbox content 148 /* 149 * add tab selection terms -- CATEGORY_ADVOCACY, CATEGORY_ASSIGNED, CATEGORY_READY special, dynamically applied 150 * 151 * assigned_subject is the subject from $assigned_subject_join subselection query below 152 * if assigned_subject is null, 153 * no email with that subject is currently in the inbox and assigned 154 * the email should be displayed in its parsed catogery or if mapped in CATEGORY_ADVOCACY 155 * 156 * if assigned_subject is not null, 157 * the email is assigned or has a subject line that is assigned and should be displayed as 158 * CATEGORY_ASSIGNED or if a response has been drafted in CATEGORY_READY 159 * 160 * if ! $user_can_see_all, just choosing between two allowed tabs -- 161 * CATEGORY_ASSIGNED or if a response has been drafted in CATEGORY_READY 162 */ 163 $category_where = $user_can_see_all ? 164 $wpdb->prepare ( 165 " IF( 166 assigned_subject is NULL, 167 IF( mapped_issue > 0, 'CATEGORY_ADVOCACY', category ), 168 IF( subject_is_final, 'CATEGORY_READY', 'CATEGORY_ASSIGNED' ) 169 ) = %s AND ", 170 array ( $data->tab ) 171 ) : 172 $wpdb->prepare ( 173 " IF( inbox_defined_reply_is_final , 'CATEGORY_READY', 'CATEGORY_ASSIGNED' ) = %s AND ", 174 array ( $data->tab ) 175 ); 176 /* 177 * limit selection to inbox content (selected folder, not deleted or intended to be deleted and already parsed) 178 * 179 * if not can see all absolutely limit to only assigned emails 180 */ 181 $absolute_user_where_limit = $user_can_see_all ? '' : ( " AND inbox_defined_staff " . $wpdb->prepare ( " = %s ", $current_user_id ) ); 172 182 $other_where_terms = 173 183 "full_folder_string = '$folder' AND … … 175 185 to_be_moved_on_server = 0 AND 176 186 serialized_email_object > '' 187 $absolute_user_where_limit 177 188 "; 178 189 190 $sort_assigned_to_top = ( $data->tab == 'CATEGORY_ASSIGNED' || $data->tab == 'CATEGORY_READY' ) ? " if( inbox_defined_staff, 1, 0) DESC, " : ''; 179 191 // key implementing language for group options (note that higher parse_quality number is worse parse, up to 6 with no email address 180 $sort_assigned_to_top = ( $data->tab == 'CATEGORY_ASSIGNED' || $data->tab == 'CATEGORY_READY' ) ? " if( inbox_defined_staff, 1, 0) DESC, " : '';181 192 $group_lines = 182 193 "GROUP BY BINARY … … 185 196 IF( $sweep_definition, subject, folder_uid ) 186 197 ) 187 188 198 ORDER BY $sort_assigned_to_top min( if ( account_thread_latest > '', account_thread_latest, email_date_time ) ) " . $data->sort . ', min(email_date_time) ' . $data->sort . ''; 189 199 $ungroup_lines = … … 192 202 /* 193 203 * 194 * joins to support Assigned and Ready tabs 195 * 204 * join to support Assigned and Ready tabs 205 * 206 * $user_subject_where_limit does not limit the larger search, only the look up for the following subsidiary tables 207 * 208 * this join is only necessary when showing assigned and ready tabs for user with Email capability -- serves to move 209 * subjects that are identical to subjects of assigned emails into the ready and advocacy tabs 196 210 */ 197 // does the user have access to the whole inbox? 198 $current_user_id = get_current_user_id(); 199 $user_subject_where_limit = $user_can_see_all ? 200 ( 211 $user_subject_where_limit = 201 212 " WHERE inbox_defined_staff " . 202 213 ( … … 205 216 " > '' " 206 217 ) 207 ) : 208 "WHERE inbox_defined_staff = $current_user_id "; 218 ; 209 219 // join to identify assigned emails/subjects 210 $assigned_subject_join = 220 $assigned_subject_join = ! $user_can_see_all ? '' : 211 221 " 212 222 LEFT JOIN 213 223 ( 214 SELECT max( inbox_defined_reply_is_final) as subject_is_final, subject as assigned_subject224 SELECT max( inbox_defined_reply_is_final ) as subject_is_final, subject as assigned_subject 215 225 FROM $inbox_image_table 216 226 $user_subject_where_limit AND $other_where_terms … … 219 229 ON subject = assigned_subject 220 230 "; 221 // join to identify_assigned_constituents222 $constituent_table = $wpdb->prefix . 'wic_constituent';223 $user_constituent_where_limit = $user_can_see_all ? " WHERE case_assigned > '' " : "WHERE case_assigned = $current_user_id ";224 $assigned_constituent_join =225 "226 LEFT JOIN227 (228 SELECT c.id as constituent_id, case_assigned as constituent_assigned_staff FROM229 $inbox_image_table INNER JOIN $constituent_table c ON c.id = assigned_constituent230 $user_constituent_where_limit AND $other_where_terms231 GROUP BY c.id232 ) assigned_constituents233 ON assigned_constituent = constituent_id234 ";235 236 231 /* 237 232 * 238 233 * first check counts for all tabs with only basic where terms -- show straight message count, not grouped -- if all counts = 0 239 234 * 235 * if ! $user_can_see all, only seeing ready and assigned tabs and only for current user is inbox_defined_staff, only first two cases apply 240 236 */ 241 237 $tabs_array = WIC_Entity_Email_Account::get_tabs(); 242 238 $tabs_summary_sql = ''; 243 239 foreach ( $tabs_array as $tab ) { 244 $category = 'CATEGORY_' . strtoupper( $tab ); 240 $category = 'CATEGORY_' . strtoupper( $tab ); 241 if ( ! $user_can_see_all && ! in_array( $category, array( 'CATEGORY_READY', 'CATEGORY_ASSIGNED' ) ) ) { 242 continue; 243 } 244 // this logic, covers all four possible combinations for counts, the default covering all tabs other than the synthetic ready, advocacy and assigned 245 245 $tabs_summary_sql .= ", SUM(IF(" ; 246 246 switch ( $category) { 247 // in the first two cases, subject_is_final cannot be null because assigned_subject_is not null and inbox_defined_reply_is_final is not null field 247 248 case 'CATEGORY_READY': 248 $tabs_summary_sql .= 249 "( assigned_subject IS NOT NULL OR constituent_assigned_staff IS NOT NULL ) AND subject_is_final > 0, "; 249 $tabs_summary_sql .= ( 250 $user_can_see_all ? 251 " assigned_subject IS NOT NULL AND subject_is_final > 0, ": 252 " inbox_defined_reply_is_final > 0, " 253 ); 250 254 break; 251 255 case 'CATEGORY_ASSIGNED': 252 $tabs_summary_sql .= 253 "( assigned_subject IS NOT NULL OR constituent_assigned_staff IS NOT NULL ) AND subject_is_final = 0, "; 256 $tabs_summary_sql .= ( 257 $user_can_see_all ? 258 " assigned_subject IS NOT NULL AND subject_is_final = 0, ": 259 " inbox_defined_reply_is_final = 0, " 260 ); 254 261 break; 262 // in the latter two cases, mapped_issue cannot be null because it is a not null field 255 263 case 'CATEGORY_ADVOCACY': 256 264 $tabs_summary_sql .= 257 " ( assigned_subject IS NULL AND constituent_assigned_staff IS NULL )AND ( mapped_issue > 0 OR category = '$category' ), ";265 " assigned_subject IS NULL AND ( mapped_issue > 0 OR category = '$category' ), "; 258 266 break; 259 267 default: 260 268 $tabs_summary_sql .= 261 " ( assigned_subject IS NULL AND constituent_assigned_staff IS NULL )AND ( mapped_issue = 0 AND category = '$category' ), ";269 " assigned_subject IS NULL AND ( mapped_issue = 0 AND category = '$category' ), "; 262 270 } 263 271 $tabs_summary_sql .= "1, 0)) as $category"; … … 268 276 " 269 277 SELECT count(ID) as all_inbox_messages_count $tabs_summary_sql 270 FROM $inbox_image_table $assigned_subject_join $assigned_constituent_join278 FROM $inbox_image_table $assigned_subject_join 271 279 WHERE $other_where_terms 272 280 " … … 323 331 ) . 324 332 " 325 FROM $inbox_image_table $assigned_subject_join $assigned_constituent_join333 FROM $inbox_image_table $assigned_subject_join 326 334 WHERE 327 335 $filter_where
Note: See TracChangeset
for help on using the changeset viewer.