• Hi guys and thanks for your wonderful plugin.

    I developed a small customer area where I integrated SupportCandy among other functionalities.

    For each customer we can create several user accounts, which can access al out custom functionalities, but can’t access the support tickts (by normal SupportCandy design).

    Is there any way / hook / filter / API that allows me to show user A tickets from user B and also allow user B to interact on user A tickets? I prefer a aolution that does not obliges me to give permissions on a per-ticket level, I rather have a way to do it in the runtime, while listing the tickets and interacting with them. That way I’m going to define which users have access to other users ticktets will be my logic, I just want a way to tell that to SupportCandy via PHP.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’m also looking for something similar

    Thread Starter Marco Almeida | Webdados

    (@webdados)

    I’ve been able to list the several users of the same team (under my logic) by using the wpsc_tl_customer_restrict_rules filter and add email addresses to the query, but when getting into the ticket, we get the no permission message.

    The same filter should be used everywhere to check for permissions.

    Thread Starter Marco Almeida | Webdados

    (@webdados)

    In order to actually get access to the ticket, I had to use the wpsc_has_permission filter.

    I think this filter should control any access to the tickets, including listing them, without having to use the wpsc_tl_customer_restrict_rules filter. It would make the developer’s life so much easier.

    To wrap up, here’s my solution to give other team members (based on my customer’s plugin logic, which is not important for the broad scenario – all the remaining code was removed ):

    <?php
    
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    
    /**
     * Webdados_Clients class
     */
    class Webdados_Clients {
    
    	/* Constructor */
    	public function __construct() {
    		//Hooks
    		add_action( 'plugins_loaded', array( $this, 'call_global_hooks' ) );
    	}
    
    	/* Global Hooks */
    	public function call_global_hooks() {
    		//SupportCandy integration
    		add_filter( 'wpsc_tl_customer_restrict_rules', array( $this, 'wpsc_tl_customer_restrict_rules' ) );
    		add_filter( 'wpsc_has_permission', array( $this, 'wpsc_has_permission' ), 10, 3 );
    	}
    
    	/* Allow team members to access main account tickets and vice-versa */
    	public function wpsc_tl_customer_restrict_rules( $restrict_rules ) {
    		//Use your own logic to get other users that should have access to the tickets list
    		$users = get_users( array( ... ) );
    		//Add emails to the restric_rules array
    		foreach( $users as $user ) {
    			$restrict_rules[$i] = array(
    				'key'     => 'customer_email',
    				'value'   => $user->data->user_email,
    				'compare' => '=',
    			);
    			$i++;
    		}
    		return $restrict_rules;
    	}
    	private function get_team_members_emails_for_support( $client_id ) {
    		$users_email = array();
    		$users = get_users( array(
    			'meta_key'   => 'webdados_clients_client_id',
    			'meta_value' => $client_id
    		) );
    		foreach( $users as $user ) {
    			$users_email[] = $user->data->user_email;
    		}
    		return $users_email;
    	}
    	public function wpsc_has_permission( $response, $ticket_id, $permission ) {
    		//Only if the current user doesn't have access yet
    		if ( ! $response ) {
    			//Use your own logic to get other users that should have access to the tickets list (in this case, that might have created it in the first place)
    			$users = get_users( array( ... ) );
    			foreach( $users as $user ) {
    				$users_email[] = $user->data->user_email;
    			}
    			//Get the ticket and check if it was created by one of the team members
    			$ticket = $wpscfunction->get_ticket( $ticket_id );
    			if ( in_array( $ticket['customer_email'], $users_email ) ) {
    				switch( $permission ) {
    					//You could give other permissions - My goal is to let the current user interact with the ticket belonging to a felow team member, but not delete it, for example
    					case 'view_ticket':
    					case 'reply_ticket':
    					case 'change_status':
    						return true;
    						break;
    				}
    			}
    		}
    		return $response;
    	}
    
    }
    Thread Starter Marco Almeida | Webdados

    (@webdados)

    You completely killed my integration with version 3.

    I’ve been looking at the code and there are no filters whatsoever that replace wpsc_has_permission and wpsc_tl_customer_restrict_rules, so I can’t give users of the same team access to each other’s tickets like it was possible before using those hooks.

    As I mentioned on another ticket, killing all the previous hooks is a trainwreck.
    Saying: “do not upgrade” is not responsible.

    Can I expect to have filters that will allow giving users access to other users ticket’s like it was possible before?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Give access to some users to other users tickets’ is closed to new replies.