From 9aceff4313f6d0bba62ad7250b395e9b9c9e5be1 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 20 Nov 2016 23:01:38 -0300 Subject: [PATCH] Ivan - Fixes for Deploy --- client/src/actions/admin-data-actions.js | 4 +-- client/src/app-components/ticket-list.js | 10 +++++-- client/src/app-components/ticket-list.scss | 4 +++ client/src/app-components/ticket-viewer.js | 28 +++++++++++-------- .../panel/tickets/admin-panel-all-tickets.js | 6 +++- .../tickets/admin-panel-custom-responses.js | 25 +++++++++++------ .../panel/tickets/admin-panel-view-ticket.js | 4 +-- .../dashboard-ticket/dashboard-ticket-page.js | 2 ++ server/controllers/ticket/get.php | 19 +++++++++---- server/models/CustomResponse.php | 1 + server/models/Department.php | 5 +++- server/models/Ticket.php | 4 ++- tests/system/get-settings.rb | 6 ++-- tests/ticket/get.rb | 2 +- tests/user/get.rb | 2 +- 15 files changed, 82 insertions(+), 40 deletions(-) diff --git a/client/src/actions/admin-data-actions.js b/client/src/actions/admin-data-actions.js index aea9550e..f4daa5ff 100644 --- a/client/src/actions/admin-data-actions.js +++ b/client/src/actions/admin-data-actions.js @@ -32,7 +32,7 @@ export default { }; }, - retrieveAllTickets(page) { + retrieveAllTickets(page = 1) { return { type: 'ALL_TICKETS', payload: API.call({ @@ -42,7 +42,7 @@ export default { }; }, - searchTickets(query, page) { + searchTickets(query, page = 1) { return { type: 'ALL_TICKETS', payload: API.call({ diff --git a/client/src/app-components/ticket-list.js b/client/src/app-components/ticket-list.js index fa6f8aac..6dfe68fc 100644 --- a/client/src/app-components/ticket-list.js +++ b/client/src/app-components/ticket-list.js @@ -161,7 +161,7 @@ class TicketList extends React.Component { } gerTicketTableObject(ticket) { - let titleText = (ticket.unread) ? ticket.title + ' (1)' : ticket.title; + let titleText = (this.isTicketUnread(ticket)) ? ticket.title + ' (1)' : ticket.title; return { number: ( @@ -178,8 +178,8 @@ class TicketList extends React.Component { department: ticket.department.name, author: ticket.author.name, date: DateTransformer.transformToString(ticket.date), - unread: ticket.unread, - highlighted: ticket.unread + unread: this.isTicketUnread(ticket), + highlighted: this.isTicketUnread(ticket) }; } @@ -231,6 +231,10 @@ class TicketList extends React.Component { } return row1.closed ? -1 : 1; } + + isTicketUnread(ticket) { + return (this.props.type === 'primary' && ticket.unread) || (this.props.type === 'secondary' && ticket.unreadStaff); + } } diff --git a/client/src/app-components/ticket-list.scss b/client/src/app-components/ticket-list.scss index 416d55c5..e0cb9ceb 100644 --- a/client/src/app-components/ticket-list.scss +++ b/client/src/app-components/ticket-list.scss @@ -18,6 +18,10 @@ text-align: right; } + &__author { + text-align: center; + } + &__date { text-align: right; } diff --git a/client/src/app-components/ticket-viewer.js b/client/src/app-components/ticket-viewer.js index 536730f3..fd5cb252 100644 --- a/client/src/app-components/ticket-viewer.js +++ b/client/src/app-components/ticket-viewer.js @@ -54,16 +54,7 @@ class TicketViewer extends React.Component {
{ticket.events && ticket.events.map(this.renderTicketEvent.bind(this))}
-
-
{i18n('RESPOND')}
- {this.renderCustomResponses()} -
-
- - {i18n('RESPOND_TICKET')} - -
-
+ {(!this.props.ticket.closed && (this.props.editable || !this.props.assignmentAllowed)) ? this.renderResponseField() : null} ); } @@ -173,7 +164,7 @@ class TicketViewer extends React.Component { ); } else { - ownerNode = i18n((this.props.closed) ? 'CLOSED' : 'OPENED'); + ownerNode = i18n((this.props.ticket.closed) ? 'CLOSED' : 'OPENED'); } return ownerNode; @@ -185,6 +176,21 @@ class TicketViewer extends React.Component { ); } + renderResponseField() { + return ( +
+
{i18n('RESPOND')}
+ {this.renderCustomResponses()} +
+
+ + {i18n('RESPOND_TICKET')} + +
+
+ ); + } + renderCustomResponses() { let customResponsesNode = null; diff --git a/client/src/app/admin/panel/tickets/admin-panel-all-tickets.js b/client/src/app/admin/panel/tickets/admin-panel-all-tickets.js index 00dbc3a4..b721f35f 100644 --- a/client/src/app/admin/panel/tickets/admin-panel-all-tickets.js +++ b/client/src/app/admin/panel/tickets/admin-panel-all-tickets.js @@ -52,7 +52,11 @@ class AdminPanelAllTickets extends React.Component { onSearch(query) { this.setState({query, page: 1}); - this.props.dispatch(AdminDataAction.searchTickets(query)); + if (query) { + this.props.dispatch(AdminDataAction.searchTickets(query)); + } else { + this.props.dispatch(AdminDataAction.retrieveAllTickets()); + } } onPageChange(event) { diff --git a/client/src/app/admin/panel/tickets/admin-panel-custom-responses.js b/client/src/app/admin/panel/tickets/admin-panel-custom-responses.js index 4e4f8bf8..9531652a 100644 --- a/client/src/app/admin/panel/tickets/admin-panel-custom-responses.js +++ b/client/src/app/admin/panel/tickets/admin-panel-custom-responses.js @@ -153,7 +153,7 @@ class AdminPanelCustomResponses extends React.Component { API.call({ path: '/ticket/edit-custom-response', data: { - id: this.state.selectedIndex, + id: this.props.items[this.state.selectedIndex].id, name: form.name, content: form.content, language: form.language @@ -161,7 +161,7 @@ class AdminPanelCustomResponses extends React.Component { }).then(() => { this.setState({formLoading: false}); this.retrieveCustomResponses(); - }); + }).catch(this.onItemChange.bind(this, -1)); } else { API.call({ path: '/ticket/add-custom-response', @@ -171,17 +171,19 @@ class AdminPanelCustomResponses extends React.Component { language: form.language } }).then(() => { - this.setState({formLoading: false}); this.retrieveCustomResponses(); - }); + this.onItemChange(-1); + }).catch(this.onItemChange.bind(this, -1)); } } - onDiscardChangesClick() { + onDiscardChangesClick(event) { + event.preventDefault(); this.onItemChange(this.state.selectedIndex); } - onDeleteClick() { + onDeleteClick(event) { + event.preventDefault(); AreYouSure.openModal(i18n('WILL_DELETE_CUSTOM_RESPONSE'), this.deleteCustomResponse.bind(this)); } @@ -189,9 +191,12 @@ class AdminPanelCustomResponses extends React.Component { API.call({ path: '/ticket/delete-custom-response', data: { - id: this.state.selectedIndex + id: this.props.items[this.state.selectedIndex].id } - }).then(this.retrieveCustomResponses.bind(this)); + }).then(() => { + this.retrieveCustomResponses(); + this.onItemChange(-1); + }); } updateForm(index) { @@ -204,6 +209,7 @@ class AdminPanelCustomResponses extends React.Component { this.setState({ selectedIndex: index, edited: false, + formLoading: false, form: form, errors: {} }); @@ -211,6 +217,9 @@ class AdminPanelCustomResponses extends React.Component { retrieveCustomResponses() { this.props.dispatch(AdminDataActions.retrieveCustomResponses()); + this.setState({ + edited: false + }); } } diff --git a/client/src/app/admin/panel/tickets/admin-panel-view-ticket.js b/client/src/app/admin/panel/tickets/admin-panel-view-ticket.js index 5d2583ec..b0002fdc 100644 --- a/client/src/app/admin/panel/tickets/admin-panel-view-ticket.js +++ b/client/src/app/admin/panel/tickets/admin-panel-view-ticket.js @@ -64,7 +64,7 @@ class AdminPanelViewTicket extends React.Component { onChange: this.retrieveTicket.bind(this), assignmentAllowed: true, customResponses: this.props.customResponses, - editable: _.get(this.state.ticket, 'owner.id') === SessionStore.getUserData().id + editable: this.state.ticket.owner && this.state.ticket.owner.id == SessionStore.getSessionData().userId }; } @@ -89,7 +89,7 @@ class AdminPanelViewTicket extends React.Component { data: { ticketNumber: this.props.params.ticketNumber } - }) + }); } } diff --git a/client/src/app/main/dashboard/dashboard-ticket/dashboard-ticket-page.js b/client/src/app/main/dashboard/dashboard-ticket/dashboard-ticket-page.js index 959fe32f..4f30814d 100644 --- a/client/src/app/main/dashboard/dashboard-ticket/dashboard-ticket-page.js +++ b/client/src/app/main/dashboard/dashboard-ticket/dashboard-ticket-page.js @@ -23,6 +23,8 @@ class DashboardTicketPage extends React.Component { data: { ticketNumber: ticket.ticketNumber } + }).then(() => { + this.retrieveUserData(); }); } } diff --git a/server/controllers/ticket/get.php b/server/controllers/ticket/get.php index 0acd26fe..36ef3f8b 100644 --- a/server/controllers/ticket/get.php +++ b/server/controllers/ticket/get.php @@ -5,6 +5,8 @@ DataValidator::with('CustomValidations', true); class TicketGetController extends Controller { const PATH = '/get'; + private $ticket; + public function validations() { return [ 'permission' => 'user', @@ -18,14 +20,19 @@ class TicketGetController extends Controller { } public function handler() { - $ticketNumber = Controller::request('ticketNumber'); + $this->ticket = Ticket::getByTicketNumber(Controller::request('ticketNumber')); - $ticket = Ticket::getByTicketNumber($ticketNumber); - - if ($ticket->author->id != Controller::getLoggedUser()->id) { - Response::respondError(ERRORS::INVALID_TICKET); + if ($this->shouldDenyPermission()) { + Response::respondError(ERRORS::NO_PERMISSION); } else { - Response::respondSuccess($ticket->toArray()); + Response::respondSuccess($this->ticket->toArray()); } } + + private function shouldDenyPermission() { + $user = Controller::getLoggedUser(); + + return (!Controller::isStaffLogged() && $this->ticket->author->id !== $user->id) || + (Controller::isStaffLogged() && $this->ticket->owner && $this->ticket->owner->id !== $user->id); + } } \ No newline at end of file diff --git a/server/models/CustomResponse.php b/server/models/CustomResponse.php index 5bcd8731..f3c4049c 100644 --- a/server/models/CustomResponse.php +++ b/server/models/CustomResponse.php @@ -13,6 +13,7 @@ class CustomResponse extends DataStore { public function toArray() { return [ + 'id' => $this->id, 'name' => $this->name, 'language' => $this->language, 'content' => $this->content, diff --git a/server/models/Department.php b/server/models/Department.php index 10628b65..a263d38e 100644 --- a/server/models/Department.php +++ b/server/models/Department.php @@ -16,7 +16,10 @@ class Department extends DataStore { $departmentsNameList = []; foreach($departmentsList as $department) { - $departmentsNameList[] = $department->name; + $departmentsNameList[] = [ + 'id' => $department->id, + 'name' => $department->name + ]; } return $departmentsNameList; diff --git a/server/models/Ticket.php b/server/models/Ticket.php index aa44c289..911b2f8f 100644 --- a/server/models/Ticket.php +++ b/server/models/Ticket.php @@ -74,6 +74,7 @@ class Ticket extends DataStore { 'file' => $this->file, 'language' => $this->language, 'unread' => !!$this->unread, + 'unreadStaff' => !!$this->unreadStaff, 'closed' => !!$this->closed, 'priority' => $this->priority, 'author' => $this->authorToArray(), @@ -106,7 +107,7 @@ class Ticket extends DataStore { 'email' => $owner->email ]; } else { - return []; + return null; } } @@ -128,6 +129,7 @@ class Ticket extends DataStore { 'id'=> $author->id, 'name' => $author->name, 'email' =>$author->email, + 'profilePic' => ($author instanceof Staff) ? $author->profilePic : null, 'staff' => $author instanceof Staff ]; } diff --git a/tests/system/get-settings.rb b/tests/system/get-settings.rb index 437d6ee6..2368c73f 100644 --- a/tests/system/get-settings.rb +++ b/tests/system/get-settings.rb @@ -4,8 +4,8 @@ describe '/system/get-settings' do (result['status']).should.equal('success') (result['data']['language']).should.equal('en') - (result['data']['departments'][0]).should.equal('Tech Support') - (result['data']['departments'][1]).should.equal('Suggestions') - (result['data']['departments'][2]).should.equal('Sales and Subscriptions') + (result['data']['departments'][0]['name']).should.equal('Tech Support') + (result['data']['departments'][1]['name']).should.equal('Suggestions') + (result['data']['departments'][2]['name']).should.equal('Sales and Subscriptions') end end \ No newline at end of file diff --git a/tests/ticket/get.rb b/tests/ticket/get.rb index 698192f7..29a26545 100644 --- a/tests/ticket/get.rb +++ b/tests/ticket/get.rb @@ -75,7 +75,7 @@ describe '/ticket/get/' do (result['data']['unread']).should.equal(false) (result['data']['author']['name']).should.equal('Cersei Lannister') (result['data']['author']['email']).should.equal('cersei@os4.com') - (result['data']['owner']).should.equal([]) + (result['data']['owner']).should.equal(nil) (result['data']['events'].size).should.equal(1) (result['data']['events'][0]['type']).should.equal('COMMENT') (result['data']['events'][0]['content']).should.equal('some valid comment made') diff --git a/tests/user/get.rb b/tests/user/get.rb index bf142ffe..e683ecbb 100644 --- a/tests/user/get.rb +++ b/tests/user/get.rb @@ -51,7 +51,7 @@ describe '/user/get' do (ticketFromUser['unread']).should.equal(false) (ticketFromUser['author']['name']).should.equal('User Get') (ticketFromUser['author']['email']).should.equal('user_get@os4.com') - (ticketFromUser['owner']).should.equal([]) + (ticketFromUser['owner']).should.equal(nil) (ticketFromUser['events']).should.equal([]) end end \ No newline at end of file