diff --git a/include/class.staff.php b/include/class.staff.php index 9fecd59ef4306fb2eb5cb467a544d167f3e287a9..4fa79eb6a9a62e83065c1c7b80d92cd9b6b1832a 100644 --- a/include/class.staff.php +++ b/include/class.staff.php @@ -34,6 +34,9 @@ implements AuthenticatedUser { 'dept' => array( 'constraint' => array('dept_id' => 'Dept.id'), ), + 'role' => array( + 'constraint' => array('role_id' => 'Role.id'), + ), 'group' => array( 'constraint' => array('group_id' => 'Group.id'), ), @@ -272,17 +275,16 @@ implements AuthenticatedUser { } function getRole($dept=null) { - - if ($dept) { - $deptId = is_object($dept) ? $dept->getId() : $dept; + $deptId = is_object($dept) ? $dept->getId() : $dept; + if ($deptId && $deptId != $this->dept_id) { if (isset($this->_roles[$deptId])) return $this->_roles[$deptId]; if (($role=$this->group->getRole($deptId))) return $this->_roles[$deptId] = $role; } - - return $this->group->getRole(); + // For the primary department, use the primary role + return $this->role; } function hasPermission($perm) { @@ -755,6 +757,8 @@ implements AuthenticatedUser { if(!$vars['dept_id']) $errors['dept_id']=__('Department is required'); + if(!$vars['role_id']) + $errors['role_id']=__('Role for primary department is required'); if(!$vars['group_id']) $errors['group_id']=__('Group is required'); @@ -768,6 +772,7 @@ implements AuthenticatedUser { $this->onvacation = isset($vars['onvacation'])?1:0; $this->assigned_only = isset($vars['assigned_only'])?1:0; $this->dept_id = $vars['dept_id']; + $this->role_id = $vars['role_id']; $this->group_id = $vars['group_id']; $this->timezone = $vars['timezone']; $this->username = $vars['username']; diff --git a/include/staff/staff.inc.php b/include/staff/staff.inc.php index 1bc7ca1d675f14a7be2c5346d14f173c9a1e3949..7a9c01eeedacff6d082453c7aeaf44fbe74c7fb7 100644 --- a/include/staff/staff.inc.php +++ b/include/staff/staff.inc.php @@ -258,7 +258,20 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); } ?> </select> - <span class="error">* <?php echo $errors['dept_id']; ?></span> <i class="help-tip icon-question-sign" href="#primary_department"></i> + + <select name="role_id"> + <option value="0">— <?php echo __('Select Role');?> —</option> + <?php + foreach (Role::getRoles() as $id=>$name) { + $sel=($info['role_id']==$id)?'selected="selected"':''; + echo sprintf('<option value="%d" %s>%s</option>',$id,$sel,$name); + } + ?> + </select> + <span class="error">*</span> + <i class="help-tip icon-question-sign" href="#primary_department"></i> + <div class="error"><?php echo $errors['dept_id']; ?></div> + <div class="error"><?php echo $errors['role_id']; ?></div> </td> </tr> <tr> diff --git a/include/upgrader/streams/core.sig b/include/upgrader/streams/core.sig index 1327f8f5c3b956d8e1080af97b4158cd73874482..ca8a3dae54ce2f95a30f3729ff58cffbde89ef0b 100644 --- a/include/upgrader/streams/core.sig +++ b/include/upgrader/streams/core.sig @@ -1 +1 @@ -e9b05c1970a94c63220bdc6a3bee1c7d +36f6b32893c2b97c5104ab5302d2dd2e diff --git a/include/upgrader/streams/core/1ee831c8-e9b05c19.cleanup.sql b/include/upgrader/streams/core/1ee831c8-36f6b328.cleanup.sql similarity index 100% rename from include/upgrader/streams/core/1ee831c8-e9b05c19.cleanup.sql rename to include/upgrader/streams/core/1ee831c8-36f6b328.cleanup.sql diff --git a/include/upgrader/streams/core/1ee831c8-e9b05c19.patch.sql b/include/upgrader/streams/core/1ee831c8-36f6b328.patch.sql similarity index 87% rename from include/upgrader/streams/core/1ee831c8-e9b05c19.patch.sql rename to include/upgrader/streams/core/1ee831c8-36f6b328.patch.sql index b949f52b25196c7b8d17829200b670fe6ffb842d..7ec72fbfdac2a66cbc7607e5b7c186f089cb1dc6 100644 --- a/include/upgrader/streams/core/1ee831c8-e9b05c19.patch.sql +++ b/include/upgrader/streams/core/1ee831c8-36f6b328.patch.sql @@ -1,5 +1,5 @@ /** - * @signature e9b05c1970a94c63220bdc6a3bee1c7d + * @signature 36f6b32893c2b97c5104ab5302d2dd2e * @version v1.9.6 * @title Add role-based access * @@ -22,6 +22,9 @@ CREATE TABLE `%TABLE_PREFIX%role` ( ALTER TABLE `%TABLE_PREFIX%group_dept_access` ADD `role_id` INT UNSIGNED NOT NULL DEFAULT '0'; +ALTER TABLE `%TABLE_PREFIX%staff` + ADD `role_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `dept_id`; + ALTER TABLE `%TABLE_PREFIX%groups` CHANGE `group_id` `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, CHANGE `group_name` `name` VARCHAR(120) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', @@ -39,5 +42,5 @@ ALTER TABLE `%TABLE_PREFIX%department` -- Finished with patch UPDATE `%TABLE_PREFIX%config` - SET `value`='e9b05c1970a94c63220bdc6a3bee1c7d' + SET `value`='36f6b32893c2b97c5104ab5302d2dd2e' WHERE `key` = 'schema_signature' AND `namespace` = 'core'; diff --git a/include/upgrader/streams/core/1ee831c8-e9b05c19.task.php b/include/upgrader/streams/core/1ee831c8-36f6b328.task.php similarity index 86% rename from include/upgrader/streams/core/1ee831c8-e9b05c19.task.php rename to include/upgrader/streams/core/1ee831c8-36f6b328.task.php index 3785980847f16fdf290ed2c8f5f805ef89478bca..3b8ff65b41343cff6852899844942b3ed63b04ce 100644 --- a/include/upgrader/streams/core/1ee831c8-e9b05c19.task.php +++ b/include/upgrader/streams/core/1ee831c8-36f6b328.task.php @@ -41,6 +41,13 @@ class GroupRoles extends MigrationTask { $group->role_id = $role->getId(); $group->save(); } + + // Copy group default role to the agent for the respective primary + // department role + foreach (Staff::objects()->select_related('group') as $staff) { + $staff->role_id = $staff->group->role_id; + $staff->save(); + } } } diff --git a/setup/inc/streams/core/install-mysql.sql b/setup/inc/streams/core/install-mysql.sql index 086b648fb4f4c9b6a85ec79edf610c1877469cc5..94492a21ade51447ee70c52fec850b15e253383d 100644 --- a/setup/inc/streams/core/install-mysql.sql +++ b/setup/inc/streams/core/install-mysql.sql @@ -521,6 +521,7 @@ CREATE TABLE `%TABLE_PREFIX%staff` ( `staff_id` int(11) unsigned NOT NULL auto_increment, `group_id` int(10) unsigned NOT NULL default '0', `dept_id` int(10) unsigned NOT NULL default '0', + `role_id` int(10) unsigned NOT NULL default '0', `username` varchar(32) NOT NULL default '', `firstname` varchar(32) default NULL, `lastname` varchar(32) default NULL,