Skip to content
Snippets Groups Projects
Commit 05a5a771 authored by Jared Hancock's avatar Jared Hancock
Browse files

role: Assign clear role for primary department

parent 641199de
No related branches found
No related tags found
No related merge requests found
......@@ -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'];
......
......@@ -258,7 +258,20 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
}
?>
</select>
&nbsp;<span class="error">*&nbsp;<?php echo $errors['dept_id']; ?></span>&nbsp;<i class="help-tip icon-question-sign" href="#primary_department"></i>
&nbsp;
<select name="role_id">
<option value="0">&mdash; <?php echo __('Select Role');?> &mdash;</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>
&nbsp;<span class="error">*</span>
&nbsp;<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>
......
e9b05c1970a94c63220bdc6a3bee1c7d
36f6b32893c2b97c5104ab5302d2dd2e
/**
* @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';
......@@ -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();
}
}
}
......
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment