Merged in os-126-deploy (pull request )

Os 126 deploy
This commit is contained in:
Ivan Diaz 2016-12-13 21:37:56 -03:00
commit c0b3546e47
14 changed files with 209 additions and 54 deletions

@ -30,7 +30,7 @@ export default {
updateData() {
return {
type: 'UPDATE_DEPARTMENTS',
type: 'UPDATE_DATA',
payload: API.call({
path: '/system/get-settings',
data: {}

@ -76,7 +76,7 @@ class AddStaffModal extends React.Component {
email: form.email,
password: form.password,
level: form.level + 1,
department: JSON.stringify(departments)
departments: JSON.stringify(departments)
}
}).then(this.context.closeModal).catch((result) => {
this.setState({

@ -136,7 +136,7 @@ class AdminPanelDepartments extends React.Component {
if(this.state.selectedIndex !== -1) {
API.call({
path: '/staff/edit-department',
path: '/system/edit-department',
data: {
departmentId: this.getCurrentDepartment().id,
name: form.name
@ -147,9 +147,9 @@ class AdminPanelDepartments extends React.Component {
}).catch(this.onItemChange.bind(this, -1));
} else {
API.call({
path: '/staff/add-department',
path: '/system/add-department',
data: {
name: form.title
name: form.name
}
}).then(() => {
this.retrieveDepartments();
@ -172,7 +172,7 @@ class AdminPanelDepartments extends React.Component {
deleteDepartment() {
API.call({
path: '/staff/delete-department',
path: '/system/delete-department',
data: {
departmentId: this.getCurrentDepartment().id,
transferDepartmentId: this.getDropDownItemId()

@ -73,8 +73,8 @@ class StaffEditor extends React.Component {
</Form>
<span className="separator staff-editor__separator" />
<Form className="staff-editor__update-password" onSubmit={this.onSubmit.bind(this)}>
<FormField name="password" validation="PASSWORD" required label={i18n('PASSWORD')} fieldProps={{size: 'large'}}/>
<FormField name="rpassword" validation="REPEAT_PASSWORD" required label={i18n('REPEAT_PASSWORD')} fieldProps={{size: 'large'}}/>
<FormField name="password" validation="PASSWORD" required label={i18n('PASSWORD')} fieldProps={{size: 'large', password: true}}/>
<FormField name="rpassword" validation="REPEAT_PASSWORD" required label={i18n('REPEAT_PASSWORD')} fieldProps={{size: 'large', password: true}}/>
<SubmitButton size="medium" className="staff-editor__submit-button">{i18n('UPDATE_PASSWORD')}</SubmitButton>
</Form>
{(!this.props.myAccount) ? this.renderLevelForm() : null}
@ -86,10 +86,7 @@ class StaffEditor extends React.Component {
<div className="col-md-4">
<div className="staff-editor__departments">
<div className="staff-editor__departments-title">{i18n('Departments')}</div>
<Form values={{departments: this.state.departments}} onChange={form => this.setState({departments: form.departments})} onSubmit={this.onSubmit.bind(this)}>
<FormField name="departments" field="checkbox-group" fieldProps={{items: this.getDepartments()}} />
<SubmitButton size="medium">{i18n('UPDATE_DEPARTMENTS')}</SubmitButton>
</Form>
{(!this.props.myAccount) ? this.renderDepartmentsForm() : this.renderDepartmentsInfo()}
</div>
</div>
<div className="col-md-8">
@ -118,6 +115,24 @@ class StaffEditor extends React.Component {
);
}
renderDepartmentsForm() {
return (
<Form values={{departments: this.state.departments}} onChange={form => this.setState({departments: form.departments})} onSubmit={this.onSubmit.bind(this)}>
<FormField name="departments" field="checkbox-group" fieldProps={{items: this.getDepartments()}} />
<SubmitButton size="medium">{i18n('UPDATE_DEPARTMENTS')}</SubmitButton>
</Form>
);
}
renderDepartmentsInfo() {
return (
<Form values={{departments: this.state.departments}}>
<FormField name="departments" field="checkbox-group" fieldProps={{items: this.getDepartments()}} />
</Form>
);
}
renderTickets() {
return (
<div>

@ -1047,35 +1047,5 @@ module.exports = [
data: {}
};
}
},
{
path: '/staff/add-department',
time: 100,
response: function () {
return {
status: 'success',
data: {}
};
}
},
{
path: '/staff/edit-department',
time: 100,
response: function () {
return {
status: 'success',
data: {}
};
}
},
{
path: '/staff/delete-department',
time: 100,
response: function () {
return {
status: 'success',
data: {}
};
}
}
];

@ -16,5 +16,35 @@ module.exports = [
}
};
}
},
{
path: '/staff/add-department',
time: 100,
response: function () {
return {
status: 'success',
data: {}
};
}
},
{
path: '/staff/edit-department',
time: 100,
response: function () {
return {
status: 'success',
data: {}
};
}
},
{
path: '/staff/delete-department',
time: 100,
response: function () {
return {
status: 'success',
data: {}
};
}
}
];

@ -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();
}
}
}

@ -7,7 +7,7 @@ class GetUserByIdController extends Controller {
public function validations() {
return [
'permission' => 'staff_2',
'permission' => 'staff_1',
'requestData' => [
'userId' => [
'validation' => DataValidator::dataStoreId('user'),
@ -20,12 +20,21 @@ class GetUserByIdController extends Controller {
public function handler() {
$userId = Controller::request('userId');
$user = User::getDataStore($userId);
$staff = Controller::getLoggedUser();
$tickets = new DataStoreList();
foreach($user->sharedTicketList as $ticket) {
if($staff->sharedDepartmentList->includesId($ticket->department->id)) {
$tickets->add($ticket);
}
}
Response::respondSuccess([
'name' => $user->name,
'email' => $user->email,
'signupDate' => $user->signupDate,
'tickets' => $user->sharedTicketList->toArray()
'tickets' => $tickets->toArray()
]);
}
}

@ -6,7 +6,7 @@ class GetUsersController extends Controller {
public function validations() {
return[
'permission' => 'staff_2',
'permission' => 'staff_1',
'requestData' => [
'page' => [
'validation' => DataValidator::numeric(),

@ -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';
}

@ -33,6 +33,18 @@ class DataStoreList implements IteratorAggregate {
}
}
public function includesId($id) {
$includes = false;
foreach($this->list as $item) {
if($item->id == $id) {
$includes = true;
}
}
return $includes;
}
public function toBeanList() {
$beanList = [];

@ -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')