Plugin Directory

Changeset 2147085


Ignore:
Timestamp:
08/28/2019 12:33:26 PM (7 years ago)
Author:
Will Brownsberger
Message:

version 4.5 work in progress

Location:
wp-issues-crm/trunk/php
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-issues-crm/trunk/php/admin/class-wic-admin-access.php

    r2146005 r2147085  
    108108                //'get_issue_options'           //not taking ajax calls
    109109                //'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',
    111111                'load_sent'                     => 'view_edit_unassigned',
    112112                'load_outbox'                   => 'view_edit_unassigned',
     
    352352    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 )
    353353        switch ( $action ) {
     354            case 'load_inbox':
     355                return self::can_user_access_this_inbox_page ( $data );
    354356            case 'load_message_detail': // from inbox, loading for reply
    355357                return self::can_user_access_this_folder_message ( $data->fullFolderString, $id );
     
    363365    }
    364366   
     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   
    365375
    366376    private static function can_user_access_this_folder_message( $folder, $uid ) {
     
    399409                return true;
    400410            } 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 ) ) );
    402412            }
    403413        // if outbox, check only assigned constituent
    404414        } 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 ) ) );               
    406416        }
    407417
  • wp-issues-crm/trunk/php/entity/class-wic-entity-email-inbox.php

    r2146005 r2147085  
    6868
    6969    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
    8074        $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 limits
    8775        $form_variables_object =  WIC_Entity_Email_Process::get_processing_options()['output'];
    8876        $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)
     
    10694        *   (2) They all have content mapped to the same issue/pro-con, which agrees with the subject mapped result
    10795        *   (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)
    10997        *   NOTE: There may or may not be a reply already assigned to the issue -- could be just recording
    11098        *
    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
    115100        *       * "have_trained_issue" (which determines, by adding a class below, whether a line is grouped and so eligible for sweeps per above strict criterion)
    116101        *       *  and the folder_uid list (which is the basis of all line processing)
     
    140125        * sweep_definition is critical concept that enforces strictness of automated reply processing per notes above
    141126        *
    142         * added inbox_defined terms exclude items that have had individual attention from the inbox in any grouping
     127        * added 4 inbox_defined terms exclude items that have had individual attention from the inbox in any grouping
    143128        */
    144129        $inbox_image_table = $wpdb->prefix . 'wic_inbox_image';
     
    156141            ";
    157142
     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
    158145        $filter = sanitize_text_field ( $data->filter );
    159146        $filter_where = self::filter_where ( $filter );
    160147
    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 ) );
    172182        $other_where_terms =
    173183            "full_folder_string = '$folder' AND
     
    175185                to_be_moved_on_server = 0 AND
    176186                serialized_email_object > ''
     187                $absolute_user_where_limit
    177188            "; 
    178189
     190        $sort_assigned_to_top = ( $data->tab == 'CATEGORY_ASSIGNED' || $data->tab == 'CATEGORY_READY' ) ? " if( inbox_defined_staff, 1, 0) DESC, " : '';
    179191        // 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, " : '';
    181192        $group_lines =
    182193            "GROUP BY BINARY
     
    185196                    IF( $sweep_definition, subject, folder_uid )
    186197                )
    187 
    188198            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 . '';
    189199        $ungroup_lines =
     
    192202        /*
    193203        *
    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
    196210        */
    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 = 
    201212                " WHERE inbox_defined_staff " .
    202213                    (
     
    205216                            " > '' "
    206217                    )   
    207             ) :
    208             "WHERE inbox_defined_staff = $current_user_id ";
     218            ;
    209219        // join to identify assigned emails/subjects
    210         $assigned_subject_join =
     220        $assigned_subject_join = ! $user_can_see_all ? '' :
    211221            "
    212222            LEFT JOIN
    213223                ( 
    214                   SELECT max(inbox_defined_reply_is_final) as subject_is_final, subject as assigned_subject
     224                  SELECT max( inbox_defined_reply_is_final ) as subject_is_final, subject as assigned_subject
    215225                  FROM $inbox_image_table
    216226                  $user_subject_where_limit AND $other_where_terms
     
    219229            ON subject = assigned_subject
    220230            ";
    221         // join to identify_assigned_constituents
    222         $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 JOIN
    227                 (
    228                 SELECT c.id as constituent_id, case_assigned as constituent_assigned_staff FROM
    229                 $inbox_image_table INNER JOIN $constituent_table c ON c.id = assigned_constituent
    230                 $user_constituent_where_limit AND $other_where_terms
    231                 GROUP BY c.id
    232                 ) assigned_constituents
    233             ON assigned_constituent = constituent_id
    234             ";
    235 
    236231        /*
    237232        *
    238233        * first check counts for all tabs with only basic where terms -- show straight message count, not grouped -- if all counts = 0
    239234        *
     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
    240236        */
    241237        $tabs_array = WIC_Entity_Email_Account::get_tabs();
    242238        $tabs_summary_sql = '';
    243239        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
    245245            $tabs_summary_sql .= ", SUM(IF(" ;
    246246            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
    247248                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                    );
    250254                    break;
    251255                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                    );
    254261                    break;
     262                // in the latter two cases, mapped_issue cannot be null because it is a not null field
    255263                case 'CATEGORY_ADVOCACY':
    256264                    $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' ), ";
    258266                    break;
    259267                default:
    260268                    $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' ), ";             
    262270            }
    263271            $tabs_summary_sql .= "1, 0)) as $category";
     
    268276            "
    269277            SELECT count(ID) as all_inbox_messages_count $tabs_summary_sql
    270             FROM $inbox_image_table $assigned_subject_join $assigned_constituent_join
     278            FROM $inbox_image_table $assigned_subject_join
    271279            WHERE $other_where_terms           
    272280            "
     
    323331            ) .
    324332            "
    325             FROM $inbox_image_table $assigned_subject_join $assigned_constituent_join
     333            FROM $inbox_image_table $assigned_subject_join
    326334            WHERE
    327335                $filter_where
Note: See TracChangeset for help on using the changeset viewer.