1. Kayako Download customers: we will continue to develop and support Kayako Download beyond July 2017, alongside the new Kayako for existing customers.

    Find out more.

  2. The forum you are viewing relates to Kayako Classic. If you signed up or upgraded to the new Kayako (after the 4th July 2016), the information in this thread may not apply to you. You can visit the forums for the new Kayako here.

Prevent staff from taking ownership from other staff

Discussion in 'Developing, APIs and extending' started by Dylan Stafford, Jan 22, 2014.

  1. Hello everyone,

    Does anyone know of a way to prevent staff from taking ownership from another staff?

    I have a Sales department that works off commission - I have all the leads coming into Kayako. They jump on the leads and take ownership as fast as they can so they can follow through on the lead and make their bonus. The problem is that there is nothing stopping a second staff from taking ownership if Staff A has taken ownership, but Staff B has clicked on it within that 30 second window where his browser has not refreshed then tries to take ownership. I have a view forced on that department that will only allow them to see the tickets that are "Unassigned" or "Assigned to Me", but that will only refresh the browser every 30 seconds.

    I guess this could be fixed a couple of different ways - refreshing every 5 seconds, or throwing an error when someone tries to take ownership of a ticket that is assigned to another staff. Does anyone know of a way to do either of these? Or a better solution?

    Thanks in advance!
     
  2. Gary McGrath

    Gary McGrath Staff Member

    Hi there Dylan,

    If you're self hosted, you could make a change to force that system.

    file: class.SWIFT_Ticket.php
    location: __apps\tickets\models\Ticket
    Near line: 2623 is the SetOwner function

    You could add a simple check in here, something like the below, just after the current owner matches the one provided check.

    Code:
     
    // Bail out if the ticket already has someone assigned
    if ($this->GetProperty('ownerstaffid') != 0) {
    return true;
    }
     
    
    Gary
     
  3. Thanks so much Gary!

    I am definitely horrible when it comes to anything php, so I was wondering if I could bother you to help me just a little bit more.

    What occurs when they do try and take ownership with this modification? Does it throw an error or alert them in any way? Also, is there a way to add another check in here so this only applies to one department?

    When I do make this change, do I need to reload anything or clear a cache - or will the changes take place as soon as I save the file?

    Thanks so much for helping out!

    P.S. - Kayako is an amazing product!
     
  4. Gary McGrath

    Gary McGrath Staff Member

    Hi Dylan,

    It currently would just silently fail, it is possible to alter it to display a warning, and also lock it to only apply to a certain department.

    Do you know the departmentid in question? ( if you goto the admin cp, departments, and hover over every department, you will see in the status bar it has a link which ends in /# where the # is the id of the department.

    Gary
     
  5. Hello again Gary,

    Throwing a pop up error of some sort would be great! That way they know they did not get the ticket and that it is already assigned to someone else. I of course have no idea how to do that, and would be forever appreciative of any advice as to how to accomplish this :)

    The department ID for our Sales department is 11.

    Thanks again!

    -Dylan
     
  6. Gary McGrath

    Gary McGrath Staff Member

    Hi there Dylan,

    file: class.Controller_Ticket.php
    location:__apps\tickets\staff

    Near line 742 find the following code:

    Code:
     
      // Check permission
      if (!$_SWIFT_TicketObject->CanAccess($_SWIFT->Staff) || $_SWIFT->Staff->GetPermission('staff_tcanupateticket') == '0') {
       $this->UserInterface->Header($this->Language->Get('tickets') . ' > ' . $this->Language->Get('viewticket'), self::MENU_ID,
         self::NAVIGATION_ID);
       $this->UserInterface->DisplayError($this->Language->Get('titlenoperm'), $this->Language->Get('msgnoperm'));
       $this->UserInterface->Footer();
       return false;
      }
     
    
    just under that, add the following code:

    Code:
     
                    //Stop Ticket Owner Change if Already Assigned
            if ($_SWIFT_TicketObject->GetProperty('departmentid') == 11){
            if ($_SWIFT_TicketObject->GetProperty('ownerstaffid') != 0) {
       $this->UserInterface->DisplayError("Ticket Already Assigned", "You cannot change the owner of this ticket, someone else already owns it.");
       $this->UserInterface->Footer();
                return false;
            }}
     
    
    Then further down, Near line 4769 find the following code:

    Code:
     
      // Check permission
      if (!$_SWIFT_TicketObject->CanAccess($_SWIFT->Staff)) {
       echo $this->Language->Get('msgnoperm');
       return false;
      }
     
    
    just under that, add the following code:

    Code:
     
                    //Stop Ticket Owner Change if Already Assigned
            if ($_SWIFT_TicketObject->GetProperty('departmentid') == 11){
            if ($_SWIFT_TicketObject->GetProperty('ownerstaffid') != 0) {
       $this->UserInterface->DisplayError("Ticket Already Assigned", "You cannot change the owner of this ticket, someone else already owns it.");
       $this->UserInterface->Footer();
                return false;
            }}
     
    
    That should do it :)

    Gary
     
  7. This works perfectly!

    You just saved me a world of trouble Gary - Thanks you so much!
    -Dylan
     
  8. Actually, I found some issues :)

    When someone tries to reply to a ticket they own or change the status, they receive the error as soon as they hit "Update" even if they are not changing the owner field.

    Also, a user can click on someone else's ticket and hit the "Take" button which bypasses the code you gave me and allows them to take ownership of the ticket from someone else.

    I hate to keep bothering you after you have helped me so much already, but is there a way to fix this?

    Thanks in advance!
    -Dylan
     
  9. Scratch that Gary - I took what you taught me and figured out how to make it work!

    I changed the code you gave me to :

    PHP:
    if ($_SWIFT_TicketObject->GetProperty('departmentid') == 11){
            if (
    $_SWIFT_TicketObject->GetProperty('ownerstaffid') != || $_SWIFT->Staff->GetStaffID()) {
                
    $this->UserInterface->DisplayError("Ticket Already Assigned""You cannot change the owner of this ticket, someone else already owns it.");
                
    $this->UserInterface->Footer();
                return 
    false;
    Then added that same code in the section for the "Take a Ticket" section.

    Thanks again for all your help!
    -Dylan
     
  10. Gary McGrath

    Gary McGrath Staff Member

    Hi Dylan,

    No problem.

    same file, near line 1102, find

    Code:
     
      // Check permission
      if (!$_SWIFT_TicketObject->CanAccess($_SWIFT->Staff) || $_SWIFT->Staff->GetPermission('staff_tcanupateticket') == '0') {
      $this->UserInterface->Header($this->Language->Get('tickets') . ' > ' . $this->Language->Get('viewticket'), self::MENU_ID,
        self::NAVIGATION_ID);
      $this->UserInterface->DisplayError($this->Language->Get('titlenoperm'), $this->Language->Get('msgnoperm'));
      $this->UserInterface->Footer();
      return false;
      }
     
    
    and after that, add the following ( this fixes the take button ):

    Code:
     
                            //Stop Ticket Owner Change if Already Assigned
            if ($_SWIFT_TicketObject->GetProperty('departmentid') == 11){
            if ($_SWIFT_TicketObject->GetProperty('ownerstaffid') != 0) {
      $this->UserInterface->DisplayError("Ticket Already Assigned", "You cannot change the owner of this ticket, someone else already owns it.");
      $this->UserInterface->Footer();
                return false;
            }}
     
    
    then change the first code block to this (the code near line 74 )

    Code:
                    //Stop Ticket Owner Change if Already Assigned
            if ($_SWIFT_TicketObject->GetProperty('departmentid') == 11){
            if ($_SWIFT_TicketObject->GetProperty('ownerstaffid') != 0 && $_POST['genownerstaffid'] != $_SWIFT_TicketObject->GetProperty('ownerstaffid')) {
      $this->UserInterface->DisplayError("Ticket Already Assigned", "You cannot change the owner of this ticket, someone else already owns it.");
      $this->UserInterface->Footer();
                return false;
            }}
    
    That should stop the reply update issues.

    Gary
     
  11. Gary McGrath

    Gary McGrath Staff Member

    Whoops,

    only just noticed you posted here aswell, glad you got it working :)

    Gary
     
  12. Hello again Gary!

    I am once again stuck :)

    This question involves the same piece of code, but now they want it to where once specific user can be immune from the ticket owner check that prevents people form taking ownership. Basically, I made the department managers an admin account whose username is "salesadmin" so they can log in and move stuff around as needed. The problem of course is that the code we put in place prevents anyone (even admins) from making changes in the Sales department. Is there any way to only apply this to a certain team that the sales staff is in? or just exclude one account from the code we put in place?

    Thanks in advance!
     
  13. Also, if someone clicks on the "Assign" button after they open a ticket, they are still able to take ownership from other staff. Unfortunately some agents figured this out and are are stealing sales leads from other agents :mad:
     
  14. Gary McGrath

    Gary McGrath Staff Member

    Hi Dylan,

    Did you make sure to put the code in all 3 locations, 1 stops the general submit, one stops the take button, and the other stops the assign button.

    The new code you will need is:

    Code:
     
                    //Stop Ticket Owner Change if Already Assigned
            if ($_SWIFT_TicketObject->GetProperty('departmentid') == 11){
            $_SWIFT_StaffObject = new SWIFT_Staff(new SWIFT_DataID($_SWIFT->Staff->GetStaffID()));
            if ($_SWIFT_StaffObject->IsAdmin() != 1 && $_SWIFT_TicketObject->GetProperty('ownerstaffid') != 0 && $_POST['genownerstaffid'] != $_SWIFT_TicketObject->GetProperty('ownerstaffid')) {
      $this->UserInterface->DisplayError("Ticket Already Assigned", "You cannot change the owner of this ticket, someone else already owns it." . $_SWIFT_StaffObject->IsAdmin());
      $this->UserInterface->Footer();
                return false;
            }}
     
    
    This codes makes it so if your logged in as an admin user, you bypass the check.

    Kind regards,

    Gary
     
  15. Thanks Gary,

    I was looking for the third location, but cannot seem to find it. I do see the one that addresses the take button, and the General tab - but I do not see where to put the one that handles the assign button. I am most likely looking right at it...
     
  16. Gary McGrath

    Gary McGrath Staff Member

    Hi Dylan,

    Despatch = assign

    near 742
    1102
    4769

    Gary
     
  17. Perfect. You are a lifesaver!

    Thanks!
     
  18. Gary McGrath

    Gary McGrath Staff Member

    no worries, glad I was able to help :)

    Gary
     
  19. So I am back with another request for help.... Management has just asked me to make one more change, so I am hoping for you assistance one more time :)

    Basically, everything is working flawlessly that you helped me with before, but they want a slight change to it. Some agents have been assigning tickets to other agents when they don't know about it, which causes us to miss sales leads. I don't know if the agents can do this directly, or if they have to assign the ticket to "Unassigned" first, then assign it to another agent.
    Any way to make the sales agents only able to assign tickets to themselves, then never assign it to anyone else or set it to the unassigned status?

    Sorry for being so difficult, but thanks for the help!!
    -Dylan
     
  20. Gary McGrath

    Gary McGrath Staff Member

    Hi Dylan,

    The code changes should already be doing that, once the ticket is assigned, you cannot change its assignment. I think maybe the issue is they are pressing the surrender button to make it unassigned again?

    Give this a try, same file, near line 1159,

    You will see this function:

    Code:
    
     public function Surrender($_ticketID, $_listType = 'inbox', $_departmentID = -1, $_ticketStatusID = -1, $_ticketTypeID = -1,
     $_ticketLimitOffset = 0) {
    
    
    Just under that, add the line

    Code:
    
      $this->UserInterface->DisplayError("Ticket Already Assigned", "You cannot Surrender this ticket.");
      $this->UserInterface->Footer();
      return false;
    
    
    Gary
     

Share This Page