diff --git a/client/src/app-components/ticket-list.js b/client/src/app-components/ticket-list.js index 18293252..c3d95be4 100644 --- a/client/src/app-components/ticket-list.js +++ b/client/src/app-components/ticket-list.js @@ -17,6 +17,7 @@ class TicketList extends React.Component { ticketPath: React.PropTypes.string, showDepartmentDropdown: React.PropTypes.bool, tickets: React.PropTypes.arrayOf(React.PropTypes.object), + userId: React.PropTypes.number, type: React.PropTypes.oneOf([ 'primary', 'secondary' @@ -233,7 +234,15 @@ class TicketList extends React.Component { } isTicketUnread(ticket) { - return (this.props.type === 'primary' && ticket.unread) || (this.props.type === 'secondary' && ticket.unreadStaff); + if(this.props.type === 'primary') { + return ticket.unread; + } else if(this.props.type === 'secondary') { + if(ticket.author.id == this.props.userId && ticket.author.staff) { + return ticket.unread; + } else { + return ticket.unreadStaff; + } + } } } diff --git a/client/src/app-components/ticket-viewer.js b/client/src/app-components/ticket-viewer.js index 14476b21..65cd7aa9 100644 --- a/client/src/app-components/ticket-viewer.js +++ b/client/src/app-components/ticket-viewer.js @@ -99,7 +99,7 @@ class TicketViewer extends React.Component {
{i18n('PRIORITY')}
-
{i18n('OWNED')}
+
{i18n('OWNER')}
{i18n('STATUS')}
@@ -107,9 +107,7 @@ class TicketViewer extends React.Component {
- + {this.renderEditableOwnerNode()}
+ ); + } else { + ownerNode = (this.props.ticket.owner) ? this.props.ticket.owner.name : i18n('NONE') + } + + return ownerNode; + } + renderOwnerNode() { let ownerNode = null; @@ -358,6 +373,7 @@ class TicketViewer extends React.Component { export default connect((store) => { return { + userId: store.session.userId, allowAttachments: store.config['allow-attachments'], userSystemEnabled: store.config['user-system-enabled'] }; diff --git a/client/src/app/admin/panel/staff/staff-editor.js b/client/src/app/admin/panel/staff/staff-editor.js index 4bcc171a..65b65d01 100644 --- a/client/src/app/admin/panel/staff/staff-editor.js +++ b/client/src/app/admin/panel/staff/staff-editor.js @@ -235,6 +235,7 @@ class StaffEditor extends React.Component { getTicketListProps() { return { type: 'secondary', + userId: this.props.staffId, tickets: this.props.tickets, departments: this.props.departments, ticketPath: '/admin/panel/tickets/view-ticket/' 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 1f7f6cc2..e6eec7d0 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 @@ -13,6 +13,7 @@ import Message from 'core-components/message'; class AdminPanelAllTickets extends React.Component { static defaultProps = { + userId: 0, departments: [], tickets: [] }; @@ -40,6 +41,7 @@ class AdminPanelAllTickets extends React.Component { getTicketListProps() { return { + userId: this.props.userId, showDepartmentDropdown: false, departments: this.props.departments, tickets: this.props.tickets, @@ -75,6 +77,7 @@ class AdminPanelAllTickets extends React.Component { export default connect((store) => { return { + userId: store.session.userId, departments: store.session.userDepartments, tickets: store.adminData.allTickets, pages: store.adminData.allTicketsPages, diff --git a/client/src/app/admin/panel/tickets/admin-panel-my-tickets.js b/client/src/app/admin/panel/tickets/admin-panel-my-tickets.js index e90847ec..caed8aaf 100644 --- a/client/src/app/admin/panel/tickets/admin-panel-my-tickets.js +++ b/client/src/app/admin/panel/tickets/admin-panel-my-tickets.js @@ -5,13 +5,18 @@ import i18n from 'lib-app/i18n'; import AdminDataAction from 'actions/admin-data-actions'; import TicketList from 'app-components/ticket-list'; +import ModalContainer from 'app-components/modal-container'; +import CreateTicketForm from 'app/main/dashboard/dashboard-create-ticket/create-ticket-form'; +import Button from 'core-components/button'; +import Icon from 'core-components/icon'; import Header from 'core-components/header'; import Message from 'core-components/message'; class AdminPanelMyTickets extends React.Component { static defaultProps = { + userId: 0, departments: [], tickets: [] }; @@ -19,18 +24,24 @@ class AdminPanelMyTickets extends React.Component { componentDidMount() { this.props.dispatch(AdminDataAction.retrieveMyTickets()); } - + render() { return (
{(this.props.error) ? {i18n('ERROR_RETRIEVING_TICKETS')} : } +
+ +
); } getProps() { return { + userId: this.props.userId, departments: this.props.departments, tickets: this.props.tickets, type: 'secondary', @@ -38,10 +49,27 @@ class AdminPanelMyTickets extends React.Component { ticketPath: '/admin/panel/tickets/view-ticket/' }; } + + onCreateTicket() { + ModalContainer.openModal( +
+ +
+ +
+
+ ); + } + + onCreateTicketSuccess() { + ModalContainer.closeModal(); + this.props.dispatch(AdminDataAction.retrieveMyTickets()); + } } export default connect((store) => { return { + userId: store.session.userId, departments: store.session.userDepartments, tickets: store.adminData.myTickets, loading: !store.adminData.myTicketsLoaded, diff --git a/client/src/app/admin/panel/tickets/admin-panel-new-tickets.js b/client/src/app/admin/panel/tickets/admin-panel-new-tickets.js index bb3240cb..185a3656 100644 --- a/client/src/app/admin/panel/tickets/admin-panel-new-tickets.js +++ b/client/src/app/admin/panel/tickets/admin-panel-new-tickets.js @@ -12,6 +12,7 @@ import Message from 'core-components/message'; class AdminPanelNewTickets extends React.Component { static defaultProps = { + userId: 0, departments: [], tickets: [] }; @@ -31,6 +32,7 @@ class AdminPanelNewTickets extends React.Component { getProps() { return { + userId: this.props.userId, departments: this.props.departments, tickets: this.props.tickets, type: 'secondary', @@ -42,6 +44,7 @@ class AdminPanelNewTickets extends React.Component { export default connect((store) => { return { + userId: store.session.userId, departments: store.session.userDepartments, tickets: store.adminData.newTickets, loading: !store.adminData.newTicketsLoaded, 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 320c1809..83566c0c 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 @@ -75,7 +75,10 @@ class AdminPanelViewTicket extends React.Component { onChange: this.retrieveTicket.bind(this), assignmentAllowed: this.props.assignmentAllowed, customResponses: this.props.customResponses, - editable: this.state.ticket.owner && this.state.ticket.owner.id == SessionStore.getSessionData().userId + editable: ( + (this.state.ticket.owner && this.state.ticket.owner.id == SessionStore.getSessionData().userId) || + (this.state.ticket.author && this.state.ticket.author.staff && this.state.ticket.author.id == SessionStore.getSessionData().userId) + ) }; } @@ -94,7 +97,7 @@ class AdminPanelViewTicket extends React.Component { ticket: result.data }); - if(!this.props.avoidSeen && result.data.unreadStaff) { + if(!this.props.avoidSeen) { API.call({ path: '/ticket/seen', data: { @@ -109,7 +112,7 @@ class AdminPanelViewTicket extends React.Component { loading: false, ticket: {} }); - + if(this.props.onRetrieveFail) { this.props.onRetrieveFail(); } 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 aa8f2d68..d4859a08 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 @@ -6,8 +6,6 @@ import history from 'lib-app/history'; import i18n from 'lib-app/i18n'; import API from 'lib-app/api-call'; import SessionStore from 'lib-app/session-store'; -import store from 'app/store'; -import SessionActions from 'actions/session-actions'; import LanguageSelector from 'app-components/language-selector'; import Captcha from 'app/main/captcha'; @@ -21,7 +19,8 @@ import Message from 'core-components/message'; class CreateTicketForm extends React.Component { static propTypes = { - userLogged: React.PropTypes.bool + userLogged: React.PropTypes.bool, + onSuccess: React.PropTypes.func, }; static defaultProps = { @@ -138,14 +137,11 @@ class CreateTicketForm extends React.Component { this.setState({ loading: false, message: 'success' + }, () => { + if(this.props.onSuccess) { + this.props.onSuccess(); + } }); - - if(this.props.userLogged) { - store.dispatch(SessionActions.getUserData()); - setTimeout(() => {history.push('/dashboard')}, 2000); - } else { - setTimeout(() => {history.push('/check-ticket/' + result.data.ticketNumber + '/' + email)}, 1000); - } } onTicketFail() { diff --git a/client/src/app/main/dashboard/dashboard-create-ticket/dashboard-create-ticket-page.js b/client/src/app/main/dashboard/dashboard-create-ticket/dashboard-create-ticket-page.js index 81c4d6e8..817ff25f 100644 --- a/client/src/app/main/dashboard/dashboard-create-ticket/dashboard-create-ticket-page.js +++ b/client/src/app/main/dashboard/dashboard-create-ticket/dashboard-create-ticket-page.js @@ -2,7 +2,9 @@ import React from 'react'; import classNames from 'classnames'; import {connect} from 'react-redux'; +import SessionActions from 'actions/session-actions'; import CreateTicketForm from 'app/main/dashboard/dashboard-create-ticket/create-ticket-form'; + import Widget from 'core-components/widget'; class DashboardCreateTicketPage extends React.Component { @@ -21,12 +23,23 @@ class DashboardCreateTicketPage extends React.Component { return (
- +
); } + onCreateTicketSuccess() { + if((this.props.location.pathname !== '/create-ticket')) { + this.props.dispatch(SessionActions.getUserData()); + setTimeout(() => {history.push('/dashboard')}, 2000); + } else { + setTimeout(() => {history.push('/check-ticket/' + result.data.ticketNumber + '/' + email)}, 1000); + } + } + getClass() { let classes = { 'dashboard-create-ticket-page': true, diff --git a/server/controllers/staff/get-new-tickets.php b/server/controllers/staff/get-new-tickets.php index b0e2e6e2..5289edd3 100755 --- a/server/controllers/staff/get-new-tickets.php +++ b/server/controllers/staff/get-new-tickets.php @@ -15,7 +15,7 @@ use Respect\Validation\Validator as DataValidator; * @apiPermission staff1 * * @apiUse NO_PERMISSION - * + * * @apiSuccess {[Ticket](#api-Data_Structures-ObjectTicket)[]} data Array of new tickets. * */ @@ -41,13 +41,13 @@ class GetNewTicketsStaffController extends Controller { foreach ($user->sharedDepartmentList as $department) { $query .= 'department_id=' . $department->id . ' OR '; } - $query = substr($query,0,-3); + $ownerExists = RedBean::exec('SHOW COLUMNS FROM ticket LIKE \'owner_id\''); if($ownerExists != 0) { - $query .= ') AND owner_id IS NULL'; + $query .= 'FALSE) AND owner_id IS NULL'; } else { - $query .= ')'; + $query .= 'FALSE)'; } $ticketList = Ticket::find($query); diff --git a/server/controllers/staff/un-assign-ticket.php b/server/controllers/staff/un-assign-ticket.php index 95a1b1e9..070c8db9 100755 --- a/server/controllers/staff/un-assign-ticket.php +++ b/server/controllers/staff/un-assign-ticket.php @@ -45,9 +45,11 @@ class UnAssignStaffController extends Controller { $ticket = Ticket::getByTicketNumber($ticketNumber); $owner = $ticket->owner; - if(($owner && $owner->id === $user->id) || $user->level > 1) { - $owner->sharedTicketList->remove($ticket); - $owner->store(); + if($ticket->isOwner($user) || $user->level > 1) { + if(!$ticket->isAuthor($user)) { + $owner->sharedTicketList->remove($ticket); + $owner->store(); + } $ticket->owner = null; $ticket->unread = !$ticket->isAuthor($user); diff --git a/server/controllers/ticket/create.php b/server/controllers/ticket/create.php index eda86b42..5e6e9600 100755 --- a/server/controllers/ticket/create.php +++ b/server/controllers/ticket/create.php @@ -134,16 +134,18 @@ class CreateController extends Controller { $ticket->setAuthor($author); - if(Controller::isUserSystemEnabled() && !Controller::isStaffLogged()) { + if(Controller::isUserSystemEnabled() || Controller::isStaffLogged()) { $author->sharedTicketList->add($ticket); + } + + if(Controller::isUserSystemEnabled() && !Controller::isStaffLogged()) { $author->tickets++; $this->email = $author->email; $this->name = $author->name; - - $author->store(); } + $author->store(); $ticket->store(); $this->ticketNumber = $ticket->ticketNumber; diff --git a/server/controllers/ticket/seen.php b/server/controllers/ticket/seen.php index c5693141..0f79d1c3 100755 --- a/server/controllers/ticket/seen.php +++ b/server/controllers/ticket/seen.php @@ -43,20 +43,20 @@ class SeenController extends Controller { $ticketnumber = Controller::request('ticketNumber'); $user = Controller::getLoggedUser(); $ticket = Ticket::getByTicketNumber($ticketnumber); - - if (Controller::isStaffLogged() && $ticket->owner && $ticket->owner->id === $user->id) { + + if(!$ticket->isOwner($user) && !$ticket->isAuthor($user)) { + throw new Exception(ERRORS::NO_PERMISSION); + } + + if ($ticket->isOwner($user)) { $ticket->unreadStaff = false; - $ticket->store(); - Response::respondSuccess(); - return; } - if (!Controller::isStaffLogged() && $ticket->author && $user->id === $ticket->author->id) { - $ticket->unread = false; - $ticket->store(); - Response::respondSuccess(); - return; + if ($ticket->isAuthor($user)) { + $ticket->unread = false; } - Response::respondError(ERRORS::NO_PERMISSION); - + + $ticket->store(); + + Response::respondSuccess(); } -} \ No newline at end of file +}