From ff0a3ee9122c63191de6654c2cb11ba5f03552f1 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 10 Dec 2014 14:29:11 -0600
Subject: [PATCH] role: Forbid removing agent primary role

---
 include/class.role.php      | 5 ++++-
 include/staff/group.inc.php | 6 ++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/class.role.php b/include/class.role.php
index f934cadd9..ef424a917 100644
--- a/include/class.role.php
+++ b/include/class.role.php
@@ -24,6 +24,9 @@ class RoleModel extends VerySimpleModel {
                 'list' => true,
                 'reverse' => 'Group.role',
             ),
+            'agents' => array(
+                'reverse' => 'Staff.role',
+            ),
         ),
     );
 
@@ -67,7 +70,7 @@ class RoleModel extends VerySimpleModel {
     }
 
     function isDeleteable() {
-        return ($this->groups->count() == 0);
+        return $this->groups->count() + $this->agents->count() == 0;
     }
 
 }
diff --git a/include/staff/group.inc.php b/include/staff/group.inc.php
index d471b791d..2a3a63807 100644
--- a/include/staff/group.inc.php
+++ b/include/staff/group.inc.php
@@ -75,7 +75,7 @@ $roles = Role::getActiveRoles();
             </td>
             <td>
                 <select name="role_id">
-                    <option value="0">Select One</option>
+                    <option value="0"><?php echo __('Select One'); ?></option>
                     <?php
                     foreach ($roles as $id => $role) {
                         $sel = ($info['role_id'] == $id) ? 'selected="selected"' : '';
@@ -140,7 +140,9 @@ $roles = Role::getActiveRoles();
                 ?>
                 <select name="<?php echo $_name; ?>">
                     <option value="0">&mdash; <?php
-                        echo __('Group Default'); ?> &mdash;</option>
+                    echo __('Group Default'); ?><?php
+                    if (isset($group)) echo ' ('.$group->role->getName().')';
+                    ?> &mdash;</option>
                     <?php
                     foreach ($roles as $rid => $role) {
                         $sel = '';
-- 
GitLab