mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-31 01:35:15 +02:00
Ivan - Add transfer to department [skip ci]
This commit is contained in:
parent
8b69934d36
commit
05380fdfda
@ -25,11 +25,13 @@ class UnAssignStaffController extends Controller {
|
||||
if($ticket->owner && $ticket->owner->id == $user->id) {
|
||||
$user->sharedTicketList->remove($ticket);
|
||||
$user->store();
|
||||
|
||||
$ticket->owner = null;
|
||||
$ticket->unread = true;
|
||||
|
||||
$event = Ticketevent::getEvent(Ticketevent::UN_ASSIGN);
|
||||
$event->setProperties(array(
|
||||
'authorStaff' => Controller::getLoggedUser(),
|
||||
'authorStaff' => $user,
|
||||
'date' => Date::getCurrentDate()
|
||||
));
|
||||
|
||||
|
@ -4,6 +4,9 @@ DataValidator::with('CustomValidations', true);
|
||||
|
||||
class DeleteDepartmentController extends Controller {
|
||||
const PATH = '/delete-department';
|
||||
|
||||
private $departmentId;
|
||||
private $transferDepartmentId;
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
@ -13,15 +16,65 @@ class DeleteDepartmentController extends Controller {
|
||||
'validation' => DataValidator::dataStoreId('department'),
|
||||
'error' => ERRORS::INVALID_DEPARTMENT
|
||||
],
|
||||
'transferDepartmentId' => [
|
||||
'validation' => DataValidator::dataStoreId('department'),
|
||||
'error' => ERRORS::INVALID_DEPARTMENT
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$this->departmentId = Controller::request('departmentId');
|
||||
$this->transferDepartmentId = Controller::request('transferDepartmentId');
|
||||
|
||||
$departmentId = Controller::request('departmentId');
|
||||
$departmentInstance = Department::getDataStore($departmentId);
|
||||
if ($this->departmentId === $this->transferDepartmentId) {
|
||||
Response::respondError(ERRORS::SAME_DEPARTMENT);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->transferDepartmentTickets();
|
||||
$departmentInstance = Department::getDataStore($this->departmentId);
|
||||
$departmentInstance->delete();
|
||||
|
||||
Response::respondSuccess();
|
||||
}
|
||||
|
||||
public function transferDepartmentTickets() {
|
||||
$tickets = Ticket::find('department_id = ?', [$this->departmentId]);
|
||||
$newDepartment = Department::getDataStore($this->transferDepartmentId);;
|
||||
|
||||
foreach($tickets as $ticket) {
|
||||
$staffOwner = $ticket->owner;
|
||||
|
||||
if($staffOwner) {
|
||||
$hasDepartment = false;
|
||||
|
||||
foreach($staffOwner->sharedDepartmentList as $department) {
|
||||
if($department->id === $newDepartment->id) {
|
||||
$hasDepartment = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$hasDepartment) {
|
||||
$staffOwner->sharedTicketList->remove($ticket);
|
||||
$staffOwner->store();
|
||||
|
||||
$ticket->owner = null;
|
||||
$ticket->unread = true;
|
||||
|
||||
$event = Ticketevent::getEvent(Ticketevent::UN_ASSIGN);
|
||||
$event->setProperties(array(
|
||||
'authorStaff' => $staffOwner,
|
||||
'date' => Date::getCurrentDate()
|
||||
));
|
||||
|
||||
$ticket->addEvent($event);
|
||||
}
|
||||
}
|
||||
|
||||
$ticket->department = $newDepartment;
|
||||
$ticket->store();
|
||||
}
|
||||
}
|
||||
}
|
@ -29,4 +29,5 @@ class ERRORS {
|
||||
const INVALID_LEVEL = 'INVALID_LEVEL';
|
||||
const ALREADY_A_STAFF = 'ALREADY_A_STAFF';
|
||||
const INVALID_STAFF = 'INVALID_STAFF';
|
||||
const SAME_DEPARTMENT = 'SAME_DEPARTMENT';
|
||||
}
|
||||
|
@ -1,18 +1,82 @@
|
||||
describe'system/delete-department' do
|
||||
describe 'system/delete-department' do
|
||||
request('/user/logout')
|
||||
Scripts.createUser('tranferguy@opensupports.com', 'transfer', 'Transfer Guy')
|
||||
Scripts.login('tranferguy@opensupports.com', 'transfer')
|
||||
|
||||
ticket1 = request('/ticket/create',{
|
||||
title: 'Transferible ticket 1',
|
||||
content: 'The north remembers',
|
||||
departmentId: 4,
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
ticket2 =request('/ticket/create',{
|
||||
title: 'Transferible ticket 2',
|
||||
content: 'The north remembers',
|
||||
departmentId: 4,
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
ticket3 = request('/ticket/create',{
|
||||
title: 'Transferible ticket 3',
|
||||
content: 'The north remembers',
|
||||
departmentId: 4,
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
ticket1 = ticket1['data']['ticketNumber']
|
||||
ticket2 = ticket2['data']['ticketNumber']
|
||||
ticket3 = ticket3['data']['ticketNumber']
|
||||
|
||||
request('/user/logout')
|
||||
Scripts.login($staff[:email], $staff[:password], true)
|
||||
request('/staff/edit', {
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token,
|
||||
departments: '[1, 2, 3, 4]'
|
||||
})
|
||||
request('/staff/assign-ticket', {
|
||||
ticketNumber: ticket3,
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
|
||||
it 'should delete department' do
|
||||
result= request('/system/delete-department', {
|
||||
it 'should fail if departments are the same' do
|
||||
result = request('/system/delete-department', {
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token,
|
||||
departmentId: 4
|
||||
departmentId: 4,
|
||||
transferDepartmentId: 4
|
||||
})
|
||||
|
||||
(result['status']).should.equal('fail')
|
||||
(result['message']).should.equal('SAME_DEPARTMENT')
|
||||
end
|
||||
|
||||
it 'should delete department' do
|
||||
result = request('/system/delete-department', {
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token,
|
||||
departmentId: 4,
|
||||
transferDepartmentId: 2
|
||||
})
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
|
||||
row = $database.getRow('department', 4, 'id')
|
||||
|
||||
(row).should.equal(nil)
|
||||
|
||||
ticket1 = $database.getRow('ticket', ticket1, 'ticket_number')
|
||||
ticket2 = $database.getRow('ticket', ticket2, 'ticket_number')
|
||||
ticket3 = $database.getRow('ticket', ticket3, 'ticket_number')
|
||||
|
||||
(ticket1['department_id']).should.equal('2')
|
||||
(ticket1['owner_id']).should.equal(nil)
|
||||
|
||||
(ticket2['department_id']).should.equal('2')
|
||||
(ticket2['owner_id']).should.equal(nil)
|
||||
|
||||
(ticket3['department_id']).should.equal('2')
|
||||
(ticket3['owner_id']).should.equal($csrf_userid)
|
||||
end
|
||||
end
|
@ -96,7 +96,6 @@ describe '/ticket/create' do
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
|
||||
puts result['message']
|
||||
(result['status']).should.equal('success')
|
||||
|
||||
ticket = $database.getRow('ticket','Winter is coming','title')
|
||||
|
Loading…
x
Reference in New Issue
Block a user