-
+
@@ -61,7 +62,7 @@ class AdminPanelStaffMembers extends React.Component {
getDepartmentDropdownProps() {
return {
- items: this.getDepartments(),
+ departments: this.getDepartments(),
onChange: (event) => {
let departments = SessionStore.getDepartments();
this.setState({
@@ -97,12 +98,9 @@ class AdminPanelStaffMembers extends React.Component {
}
getDepartments() {
- let departments = SessionStore.getDepartments().map((department) => {
- return {content: department.name};
- });
-
+ let departments = _.clone(SessionStore.getDepartments())
departments.unshift({
- content: i18n('ALL_DEPARTMENTS')
+ name: i18n('ALL_DEPARTMENTS')
});
return departments;
diff --git a/client/src/app/admin/panel/staff/admin-panel-staff-members.scss b/client/src/app/admin/panel/staff/admin-panel-staff-members.scss
index 94e8b0da..974d2183 100644
--- a/client/src/app/admin/panel/staff/admin-panel-staff-members.scss
+++ b/client/src/app/admin/panel/staff/admin-panel-staff-members.scss
@@ -23,4 +23,7 @@
text-decoration: none;
}
}
-}
\ No newline at end of file
+ &__private {
+ margin-left: 5px;
+ }
+}
diff --git a/client/src/app/admin/panel/staff/staff-editor.js b/client/src/app/admin/panel/staff/staff-editor.js
index 8f2466bb..51d4e54b 100644
--- a/client/src/app/admin/panel/staff/staff-editor.js
+++ b/client/src/app/admin/panel/staff/staff-editor.js
@@ -256,7 +256,13 @@ class StaffEditor extends React.Component {
}
getDepartments() {
- return SessionStore.getDepartments().map(department => department.name);
+ return SessionStore.getDepartments().map(department => {
+ if(department.private*1){
+ return
{department.name}
+ }else {
+ return department.name;
+ }
+ });
}
getStaffLevelInfo() {
diff --git a/client/src/app/main/dashboard/dashboard-create-ticket/create-ticket-form.js b/client/src/app/main/dashboard/dashboard-create-ticket/create-ticket-form.js
index 4247f9a7..6d30bae1 100644
--- a/client/src/app/main/dashboard/dashboard-create-ticket/create-ticket-form.js
+++ b/client/src/app/main/dashboard/dashboard-create-ticket/create-ticket-form.js
@@ -8,6 +8,7 @@ import API from 'lib-app/api-call';
import SessionStore from 'lib-app/session-store';
import LanguageSelector from 'app-components/language-selector';
import Captcha from 'app/main/captcha';
+import DepartmentDropdown from 'app-components/department-dropdown';
import Header from 'core-components/header';
import TextEditor from 'core-components/text-editor';
@@ -48,8 +49,8 @@ class CreateTicketForm extends React.Component {
{(!this.props.userLogged) ? this.renderEmailAndName() : null}
- {return {content: department.name}}),
+
$department->id,
- 'name' => $department->name
+ 'name' => $department->name,
+ 'private' => $department->private
];
}
@@ -72,4 +73,4 @@ class GetStaffController extends Controller {
'sendEmailOnNewTicket' => $user->sendEmailOnNewTicket
]);
}
-}
\ No newline at end of file
+}
diff --git a/server/controllers/staff/un-assign-ticket.php b/server/controllers/staff/un-assign-ticket.php
index a162d4d4..e138dd80 100755
--- a/server/controllers/staff/un-assign-ticket.php
+++ b/server/controllers/staff/un-assign-ticket.php
@@ -27,6 +27,12 @@ class UnAssignStaffController extends Controller {
const PATH = '/un-assign-ticket';
const METHOD = 'POST';
+ private $user;
+
+ public function __construct($user=null) {
+ $this->user = $user;
+ }
+
public function validations() {
return [
'permission' => 'staff_1',
@@ -41,7 +47,7 @@ class UnAssignStaffController extends Controller {
public function handler() {
$ticketNumber = Controller::request('ticketNumber');
- $user = Controller::getLoggedUser();
+ $user = ($this->user? $this->user : Controller::getLoggedUser());
$ticket = Ticket::getByTicketNumber($ticketNumber);
$owner = $ticket->owner;
diff --git a/server/controllers/system/add-department.php b/server/controllers/system/add-department.php
index be0ed503..bef23f88 100755
--- a/server/controllers/system/add-department.php
+++ b/server/controllers/system/add-department.php
@@ -14,6 +14,7 @@ use Respect\Validation\Validator as DataValidator;
* @apiPermission staff3
*
* @apiParam {String} name Name of the new department.
+ * @apiParam {Boolean} private Indicates if the deparment is not shown to users.
*
* @apiUse NO_PERMISSION
*
@@ -28,17 +29,24 @@ class AddDepartmentController extends Controller {
public function validations() {
return [
'permission' => 'staff_3',
- 'requestData' => []
+ 'requestData' => [
+ 'name' => [
+ 'validation' => DataValidator::length(2, 100),
+ 'error' => ERRORS::INVALID_NAME
+ ]
+ ]
];
}
public function handler() {
$name = Controller::request('name');
+ $private = Controller::request('private');
$departmentInstance = new Department();
$departmentInstance->setProperties([
- 'name' => $name,
+ 'name' => $name ,
+ 'private' => $private ? 1 : 0
]);
$departmentInstance->store();
diff --git a/server/controllers/system/edit-department.php b/server/controllers/system/edit-department.php
index 19de4de8..9e18b8b7 100755
--- a/server/controllers/system/edit-department.php
+++ b/server/controllers/system/edit-department.php
@@ -16,6 +16,7 @@ DataValidator::with('CustomValidations', true);
*
* @apiParam {String} name The new name of the department.
* @apiParam {Number} departmentId The Id of the department.
+ * @apiParam {Boolean} private Indicates if the department is shown to users;
*
* @apiUse NO_PERMISSION
* @apiUse INVALID_NAME
@@ -33,10 +34,6 @@ class EditDepartmentController extends Controller {
return [
'permission' => 'staff_3',
'requestData' => [
- 'name' => [
- 'validation' => DataValidator::alnum(),
- 'error' => ERRORS::INVALID_NAME
- ],
'departmentId' => [
'validation' => DataValidator::dataStoreId('department'),
'error' => ERRORS::INVALID_DEPARTMENT
@@ -46,18 +43,20 @@ class EditDepartmentController extends Controller {
}
public function handler() {
+
$newname = Controller::request('name');
$departmentId = Controller::request('departmentId');
+ $private = Controller::request('private');
$departmentInstance = Department::getDataStore($departmentId);
- $departmentInstance->name = $newname ;
-
+ $newname ? $departmentInstance->name = $newname : null;
+ $departmentInstance->private = $private ? 1 : 0;
$departmentInstance->store();
Log::createLog('EDIT_DEPARTMENT', $departmentInstance->name);
-
+
Response::respondSuccess();
}
-}
\ No newline at end of file
+}
diff --git a/server/controllers/system/get-settings.php b/server/controllers/system/get-settings.php
index 5dcd636b..2d7fc2b7 100755
--- a/server/controllers/system/get-settings.php
+++ b/server/controllers/system/get-settings.php
@@ -50,7 +50,7 @@ class GetSettingsController extends Controller {
'smtp-host' => Setting::getSetting('smtp-host')->getValue(),
'smtp-user' => Setting::getSetting('smtp-user')->getValue(),
'registration' => Setting::getSetting('registration')->getValue(),
- 'departments' => Department::getDepartmentNames(),
+ 'departments' => Department::getAllDepartmentNames(),
'supportedLanguages' => Language::getSupportedLanguages(),
'allowedLanguages' => Language::getAllowedLanguages(),
'session-prefix' => Setting::getSetting('session-prefix')
@@ -66,7 +66,7 @@ class GetSettingsController extends Controller {
'max-size' => Setting::getSetting('max-size')->getValue(),
'title' => Setting::getSetting('title')->getValue(),
'registration' => Setting::getSetting('registration')->getValue(),
- 'departments' => Department::getDepartmentNames(),
+ 'departments' => Controller::isStaffLogged() ? Department::getAllDepartmentNames() : Department::getPublicDepartmentNames(),
'supportedLanguages' => Language::getSupportedLanguages(),
'allowedLanguages' => Language::getAllowedLanguages(),
'user-system-enabled' => intval(Setting::getSetting('user-system-enabled')->getValue()),
diff --git a/server/controllers/ticket/change-department.php b/server/controllers/ticket/change-department.php
index 47021b06..68092c0f 100755
--- a/server/controllers/ticket/change-department.php
+++ b/server/controllers/ticket/change-department.php
@@ -52,6 +52,10 @@ class ChangeDepartmentController extends Controller {
$department = Department::getDataStore($departmentId);
$user = Controller::getLoggedUser();
+ if(!$ticket->authorStaffId && $department->private){
+ throw new Exception(ERRORS::NO_PERMISSION);
+ }
+
if($ticket->owner && $ticket->owner->id !== $user->id && $user->level == 1){
throw new Exception(ERRORS::NO_PERMISSION);
}
@@ -67,8 +71,8 @@ class ChangeDepartmentController extends Controller {
$ticket->unread = !$ticket->isAuthor($user);
$ticket->store();
- if(!$user->sharedDepartmentList->includesId($department->id)) {
- $unAssignTicketController = new UnAssignStaffController();
+ if($ticket->owner && !$ticket->owner->sharedDepartmentList->includesId($department->id)) {
+ $unAssignTicketController = new UnAssignStaffController($ticket->owner);
$unAssignTicketController->validate();
$unAssignTicketController->handler();
}
diff --git a/server/controllers/ticket/create.php b/server/controllers/ticket/create.php
index 112f0391..709f2a9b 100755
--- a/server/controllers/ticket/create.php
+++ b/server/controllers/ticket/create.php
@@ -99,6 +99,9 @@ class CreateController extends Controller {
$this->email = Controller::request('email');
$this->name = Controller::request('name');
+ if(!Controller::isStaffLogged() && Department::getDataStore($this->departmentId)->private){
+ throw new Exception(ERRORS::INVALID_DEPARTMENT);
+ }
$this->storeTicket();
if(!Controller::isUserSystemEnabled()) {
diff --git a/server/models/Department.php b/server/models/Department.php
index d15a7e37..d856bb68 100755
--- a/server/models/Department.php
+++ b/server/models/Department.php
@@ -8,26 +8,28 @@ use RedBeanPHP\Facade as RedBean;
* @apiParam {Number} id Id of the department.
* @apiParam {String} name Name of the department.
* @apiParam {[Staff](#api-Data_Structures-ObjectStaff)[]} owners List of owners of the department.
+ * @apiParam {Boolean} private Indicates if the departmetn is not shown to users.
*/
class Department extends DataStore {
const TABLE = 'department';
-
+
public static function getProps() {
return [
'name',
'sharedTicketList',
- 'owners'
- ];
- }
-
- public function getDefaultProps() {
- return [
- 'owners' => 0
+ 'owners',
+ 'private'
];
}
- public static function getDepartmentNames() {
+ public function getDefaultProps() {
+ return [
+ 'owners' => 0
+ ];
+ }
+
+ public static function getAllDepartmentNames() {
$departmentsList = RedBean::findAll(Department::TABLE);
$departmentsNameList = [];
@@ -35,12 +37,32 @@ class Department extends DataStore {
$departmentsNameList[] = [
'id' => $department->id,
'name' => $department->name,
- 'owners' => $department->owners
+ 'owners' => $department->owners,
+ 'private' => $department->private
];
}
-
+
return $departmentsNameList;
}
+
+ public static function getPublicDepartmentNames() {
+ $departmentsList = RedBean::findAll(Department::TABLE);
+ $departmentsNameList = [];
+
+ foreach($departmentsList as $department) {
+ if(!$department->private) {
+ $departmentsNameList[] = [
+ 'id' => $department->id,
+ 'name' => $department->name,
+ 'owners' => $department->owners,
+ 'private' => $department->private
+ ];
+ }
+ }
+
+ return $departmentsNameList;
+ }
+
public function toArray() {
return [
'id' => $this->id,
@@ -48,4 +70,4 @@ class Department extends DataStore {
'owners' => $this->owners
];
}
-}
\ No newline at end of file
+}
diff --git a/tests/Makefile b/tests/Makefile
index b30f4e1c..1b0d3002 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -7,7 +7,7 @@ install:
@bundle install
run: export MYSQL_HOST=127.0.0.1
-run: export MYSQL_PORT=4040
+run: export MYSQL_PORT=3306
run:
./run-tests.sh