resolve merge conflict
This commit is contained in:
commit
ce58e064cf
client/src
app-components
app
admin/panel
staff
tickets
main/dashboard/dashboard-create-ticket
server
controllers
staff
ticket
models
tests
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ class TicketViewer extends React.Component {
|
|||
</div>
|
||||
<div className="ticket-viewer__info-row-header row">
|
||||
<div className="col-md-4">{i18n('PRIORITY')}</div>
|
||||
<div className="col-md-4">{i18n('OWNED')}</div>
|
||||
<div className="col-md-4">{i18n('OWNER')}</div>
|
||||
<div className="col-md-4">{i18n('STATUS')}</div>
|
||||
</div>
|
||||
<div className="ticket-viewer__info-row-values row">
|
||||
|
@ -107,9 +107,7 @@ class TicketViewer extends React.Component {
|
|||
<DropDown className="ticket-viewer__editable-dropdown" items={priorityList} selectedIndex={priorities[ticket.priority]} onChange={this.onPriorityDropdownChanged.bind(this)} />
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<Button type={(ticket.owner) ? 'primary' : 'secondary'} size="extra-small" onClick={this.onAssignClick.bind(this)}>
|
||||
{i18n(ticket.owner ? 'UN_ASSIGN' : 'ASSIGN_TO_ME')}
|
||||
</Button>
|
||||
{this.renderEditableOwnerNode()}
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
{ticket.closed ?
|
||||
|
@ -162,6 +160,23 @@ class TicketViewer extends React.Component {
|
|||
);
|
||||
}
|
||||
|
||||
renderEditableOwnerNode() {
|
||||
let ownerNode = null;
|
||||
let {ticket, userId} = this.props;
|
||||
|
||||
if (_.isEmpty(ticket.owner) || ticket.owner.id == userId) {
|
||||
ownerNode = (
|
||||
<Button type={(ticket.owner) ? 'primary' : 'secondary'} size="extra-small" onClick={this.onAssignClick.bind(this)}>
|
||||
{i18n(ticket.owner ? 'UN_ASSIGN' : 'ASSIGN_TO_ME')}
|
||||
</Button>
|
||||
);
|
||||
} else {
|
||||
ownerNode = (this.props.ticket.owner) ? this.props.ticket.owner.name : i18n('NONE')
|
||||
}
|
||||
|
||||
return ownerNode;
|
||||
}
|
||||
|
||||
renderOwnerNode() {
|
||||
let ownerNode = null;
|
||||
|
||||
|
@ -371,6 +386,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']
|
||||
};
|
||||
|
|
|
@ -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/'
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 (
|
||||
<div className="admin-panel-my-tickets">
|
||||
<Header title={i18n('MY_TICKETS')} description={i18n('MY_TICKETS_DESCRIPTION')} />
|
||||
{(this.props.error) ? <Message type="error">{i18n('ERROR_RETRIEVING_TICKETS')}</Message> : <TicketList {...this.getProps()}/>}
|
||||
<div style={{textAlign: 'right', marginTop: 10}}>
|
||||
<Button onClick={this.onCreateTicket.bind(this)} type="secondary" size="medium">
|
||||
<Icon size="sm" name="plus"/> Create ticket
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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(
|
||||
<div>
|
||||
<CreateTicketForm onSuccess={this.onCreateTicketSuccess.bind(this)} />
|
||||
<div style={{textAlign: 'center'}}>
|
||||
<Button onClick={ModalContainer.closeModal} type="link">Close</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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 (
|
||||
<div className={this.getClass()}>
|
||||
<Wrapper>
|
||||
<CreateTicketForm userLogged={(this.props.location.pathname !== '/create-ticket')} />
|
||||
<CreateTicketForm
|
||||
userLogged={(this.props.location.pathname !== '/create-ticket')}
|
||||
onSuccess={this.onCreateTicketSuccess.bind(this)}/>
|
||||
</Wrapper>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
@ -70,7 +70,7 @@ class AssignStaffController extends Controller {
|
|||
} else {
|
||||
$this->user->sharedTicketList->add($this->ticket);
|
||||
$this->ticket->owner = $this->user;
|
||||
$this->ticket->unread = true;
|
||||
$this->ticket->unread = !$this->ticket->isAuthor($this->user);
|
||||
$event = Ticketevent::getEvent(Ticketevent::ASSIGN);
|
||||
$event->setProperties(array(
|
||||
'authorStaff' => Controller::getLoggedUser(),
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -45,12 +45,14 @@ class UnAssignStaffController extends Controller {
|
|||
$ticket = Ticket::getByTicketNumber($ticketNumber);
|
||||
$owner = $ticket->owner;
|
||||
|
||||
if(($owner && $owner->id === $user->id) || $user->level > 2) {
|
||||
$owner->sharedTicketList->remove($ticket);
|
||||
$owner->store();
|
||||
if($ticket->isOwner($user) || $user->level > 2) {
|
||||
if(!$ticket->isAuthor($user)) {
|
||||
$owner->sharedTicketList->remove($ticket);
|
||||
$owner->store();
|
||||
}
|
||||
|
||||
$ticket->owner = null;
|
||||
$ticket->unread = true;
|
||||
$ticket->unread = !$ticket->isAuthor($user);
|
||||
|
||||
$event = Ticketevent::getEvent(Ticketevent::UN_ASSIGN);
|
||||
$event->setProperties(array(
|
||||
|
|
|
@ -64,7 +64,7 @@ class ChangeDepartmentController extends Controller {
|
|||
));
|
||||
$ticket->addEvent($event);
|
||||
$ticket->department = $department;
|
||||
$ticket->unread = true;
|
||||
$ticket->unread = !$ticket->isAuthor($user);
|
||||
$ticket->store();
|
||||
|
||||
if(!$user->sharedDepartmentList->includesId($department->id)) {
|
||||
|
|
|
@ -18,9 +18,9 @@ use Respect\Validation\Validator as DataValidator;
|
|||
*
|
||||
* @apiUse NO_PERMISSION
|
||||
* @apiUse INVALID_TICKET
|
||||
* @apiUse INVALID_PRIORITY
|
||||
* @apiUse INVALID_PRIORITY
|
||||
*
|
||||
* @apiSuccess {Object} data Empty object
|
||||
* @apiSuccess {Object} data Empty object
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -52,10 +52,10 @@ class ChangePriorityController extends Controller {
|
|||
|
||||
if($ticket->owner && $user->id === $ticket->owner->id) {
|
||||
$ticket->priority = $priority;
|
||||
$ticket->unread = true;
|
||||
$ticket->unread = !$ticket->isAuthor($user);
|
||||
$event = Ticketevent::getEvent(Ticketevent::PRIORITY_CHANGED);
|
||||
$event->setProperties(array(
|
||||
'authorStaff' => Controller::getLoggedUser(),
|
||||
'authorStaff' => Controller::getLoggedUser(),
|
||||
'content' => $ticket->priority,
|
||||
'date' => Date::getCurrentDate()
|
||||
));
|
||||
|
@ -70,5 +70,3 @@ class ChangePriorityController extends Controller {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -62,9 +62,12 @@ class CloseController extends Controller {
|
|||
public function handler() {
|
||||
$this->ticket = Ticket::getByTicketNumber(Controller::request('ticketNumber'));
|
||||
|
||||
if($this->shouldDenyPermission()) {
|
||||
Response::respondError(ERRORS::NO_PERMISSION);
|
||||
return;
|
||||
if(
|
||||
(Controller::isUserSystemEnabled() || Controller::isStaffLogged()) &&
|
||||
!$this->ticket->isOwner(Controller::getLoggedUser()) &&
|
||||
!$this->ticket->isAuthor(Controller::getLoggedUser())
|
||||
) {
|
||||
throw new Exception(ERRORS::NO_PERMISSION);
|
||||
}
|
||||
|
||||
$this->markAsUnread();
|
||||
|
@ -79,22 +82,9 @@ class CloseController extends Controller {
|
|||
Response::respondSuccess();
|
||||
}
|
||||
|
||||
private function shouldDenyPermission() {
|
||||
if(Controller::isStaffLogged()) {
|
||||
return $this->ticket->owner && $this->ticket->owner->id !== Controller::getLoggedUser()->id;
|
||||
} else if(Controller::isUserSystemEnabled()) {
|
||||
return $this->ticket->author->id !== Controller::getLoggedUser()->id;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function markAsUnread() {
|
||||
if(Controller::isStaffLogged()) {
|
||||
$this->ticket->unread = true;
|
||||
} else {
|
||||
$this->ticket->unreadStaff = true;
|
||||
}
|
||||
$this->ticket->unread = !$this->ticket->isAuthor(Controller::getLoggedUser());
|
||||
$this->ticket->unreadStaff = !$this->ticket->isOwner(Controller::getLoggedUser());
|
||||
}
|
||||
|
||||
private function addCloseEvent() {
|
||||
|
|
|
@ -65,7 +65,6 @@ class CommentController extends Controller {
|
|||
'csrf_token' => [
|
||||
'validation' => DataValidator::equals($session->getToken()),
|
||||
'error' => ERRORS::INVALID_TOKEN
|
||||
|
||||
]
|
||||
]
|
||||
];
|
||||
|
@ -73,24 +72,30 @@ class CommentController extends Controller {
|
|||
}
|
||||
|
||||
public function handler() {
|
||||
$session = Session::getInstance();
|
||||
$this->requestData();
|
||||
$ticketAuthor = $this->ticket->authorToArray();
|
||||
$isAuthor = $this->ticket->isAuthor(Controller::getLoggedUser());
|
||||
$isOwner = $this->ticket->isOwner(Controller::getLoggedUser());
|
||||
|
||||
if ((!Controller::isUserSystemEnabled() && !Controller::isStaffLogged()) ||
|
||||
(!Controller::isStaffLogged() && $session->isLoggedWithId(($this->ticket->author) ? $this->ticket->author->id : 0)) ||
|
||||
(Controller::isStaffLogged() && $session->isLoggedWithId(($this->ticket->owner) ? $this->ticket->owner->id : 0))) {
|
||||
$this->storeComment();
|
||||
|
||||
if(Controller::isStaffLogged() || $this->ticket->owner) {
|
||||
$this->sendMail();
|
||||
}
|
||||
|
||||
Log::createLog('COMMENT', $this->ticket->ticketNumber);
|
||||
|
||||
Response::respondSuccess();
|
||||
} else {
|
||||
Response::respondError(ERRORS::NO_PERMISSION);
|
||||
if((Controller::isUserSystemEnabled() || Controller::isStaffLogged()) && !$isOwner && !$isAuthor) {
|
||||
throw new Exception(ERRORS::NO_PERMISSION);
|
||||
}
|
||||
|
||||
$this->storeComment();
|
||||
|
||||
if($isAuthor && $this->ticket->owner) {
|
||||
$this->sendMail([
|
||||
'email' => $this->ticket->owner->email,
|
||||
'name' => $this->ticket->owner->name,
|
||||
'staff' => true
|
||||
]);
|
||||
} else {
|
||||
$this->sendMail($ticketAuthor);
|
||||
}
|
||||
|
||||
Log::createLog('COMMENT', $this->ticket->ticketNumber);
|
||||
|
||||
Response::respondSuccess();
|
||||
}
|
||||
|
||||
private function requestData() {
|
||||
|
@ -110,7 +115,8 @@ class CommentController extends Controller {
|
|||
));
|
||||
|
||||
if(Controller::isStaffLogged()) {
|
||||
$this->ticket->unread = true;
|
||||
$this->ticket->unread = !$this->ticket->isAuthor(Controller::getLoggedUser());
|
||||
$this->ticket->unreadStaff = !$this->ticket->isOwner(Controller::getLoggedUser());
|
||||
$comment->authorStaff = Controller::getLoggedUser();
|
||||
} else if(Controller::isUserSystemEnabled()) {
|
||||
$this->ticket->unreadStaff = true;
|
||||
|
@ -121,20 +127,16 @@ class CommentController extends Controller {
|
|||
$this->ticket->store();
|
||||
}
|
||||
|
||||
private function sendMail() {
|
||||
private function sendMail($recipient) {
|
||||
$mailSender = MailSender::getInstance();
|
||||
|
||||
$email = ($this->ticket->author) ? $this->ticket->author->email : $this->ticket->authorEmail;
|
||||
$name = ($this->ticket->author) ? $this->ticket->author->name : $this->ticket->authorName;
|
||||
|
||||
if(!Controller::isStaffLogged() && $this->ticket->owner) {
|
||||
$email = $this->ticket->owner->email;
|
||||
$name = $this->ticket->owner->name;
|
||||
}
|
||||
$email = $recipient['email'];
|
||||
$name = $recipient['name'];
|
||||
$isStaff = $recipient['staff'];
|
||||
|
||||
$url = Setting::getSetting('url')->getValue();
|
||||
|
||||
if(!Controller::isUserSystemEnabled()) {
|
||||
if(!Controller::isUserSystemEnabled() && !$isStaff) {
|
||||
$url .= '/check-ticket/' . $this->ticket->ticketNumber;
|
||||
$url .= '/' . $email;
|
||||
}
|
||||
|
|
|
@ -122,7 +122,6 @@ class CreateController extends Controller {
|
|||
'title' => $this->title,
|
||||
'content' => $this->content,
|
||||
'language' => $this->language,
|
||||
'author' => $author,
|
||||
'department' => $department,
|
||||
'file' => ($fileUploader instanceof FileUploader) ? $fileUploader->getFileName() : null,
|
||||
'date' => Date::getCurrentDate(),
|
||||
|
@ -130,19 +129,23 @@ class CreateController extends Controller {
|
|||
'unreadStaff' => true,
|
||||
'closed' => false,
|
||||
'authorName' => $this->name,
|
||||
'authorEmail' => $this->email
|
||||
'authorEmail' => $this->email,
|
||||
));
|
||||
|
||||
if(Controller::isUserSystemEnabled()) {
|
||||
$ticket->setAuthor($author);
|
||||
|
||||
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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ class Ticket extends DataStore {
|
|||
'closed',
|
||||
'priority',
|
||||
'author',
|
||||
'authorStaff',
|
||||
'owner',
|
||||
'ownTicketeventList',
|
||||
'unreadStaff',
|
||||
|
@ -60,6 +61,22 @@ class Ticket extends DataStore {
|
|||
return Ticket::getTicket($value, 'ticketNumber');
|
||||
}
|
||||
|
||||
public function setAuthor($author) {
|
||||
if($author instanceof User) {
|
||||
$this->author = $author;
|
||||
} else if($author instanceof Staff) {
|
||||
$this->authorStaff = $author;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAuthor() {
|
||||
if($this->author && !$this->author->isNull()) {
|
||||
return $this->author;
|
||||
} else {
|
||||
return $this->authorStaff;
|
||||
}
|
||||
}
|
||||
|
||||
public function getDefaultProps() {
|
||||
return array(
|
||||
'priority' => 'low',
|
||||
|
@ -112,18 +129,20 @@ class Ticket extends DataStore {
|
|||
}
|
||||
|
||||
public function authorToArray() {
|
||||
$author = $this->author;
|
||||
$author = $this->getAuthor();
|
||||
|
||||
if ($author && !$author->isNull()) {
|
||||
return [
|
||||
'id' => $author->id,
|
||||
'name' => $author->name,
|
||||
'staff' => $author instanceof Staff,
|
||||
'profilePic' => ($author instanceof Staff) ? $author->profilePic : null,
|
||||
'email' => $author->email
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'name' => $this->authorName,
|
||||
'email' => $this->authorEmail
|
||||
'name' => $this->authorName,
|
||||
'email' => $this->authorEmail
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +174,7 @@ class Ticket extends DataStore {
|
|||
];
|
||||
|
||||
$author = $ticketEvent->getAuthor();
|
||||
if(!$author->isNull()) {
|
||||
if($author && !$author->isNull()) {
|
||||
$event['author'] = [
|
||||
'id'=> $author->id,
|
||||
'name' => $author->name,
|
||||
|
@ -174,4 +193,13 @@ class Ticket extends DataStore {
|
|||
public function addEvent(Ticketevent $event) {
|
||||
$this->ownTicketeventList->add($event);
|
||||
}
|
||||
|
||||
public function isAuthor($user) {
|
||||
$ticketAuthor = $this->authorToArray();
|
||||
return $user->id == $ticketAuthor['id'] && ($user instanceof Staff) == $ticketAuthor['staff'];
|
||||
}
|
||||
|
||||
public function isOwner($user) {
|
||||
return $this->owner && $user->id == $this->owner->id && ($user instanceof Staff);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ describe'/staff/get-all' do
|
|||
(result['data'][0]['departments'][1]['name']).should.equal('Suggestions')
|
||||
(result['data'][0]['departments'][2]['id']).should.equal('3')
|
||||
(result['data'][0]['departments'][2]['name']).should.equal('Tech support')
|
||||
(result['data'][0]['assignedTickets']).should.equal(3)
|
||||
(result['data'][0]['assignedTickets']).should.equal(4)
|
||||
(result['data'][0]['closedTickets']).should.equal(0)
|
||||
|
||||
(result['data'][2]['name']).should.equal('Arya Stark')
|
||||
|
|
|
@ -10,6 +10,7 @@ describe '/staff/get-new-tickets' do
|
|||
})
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
(result['data'].size).should.equal(8)
|
||||
(result['data'].size).should.equal(9)
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,6 +22,6 @@ describe '/staff/get-tickets' do
|
|||
})
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
(result['data'].size).should.equal(2)
|
||||
(result['data'].size).should.equal(3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ describe '/staff/un-assign-ticket' do
|
|||
(ticket['owner_id']).should.equal(nil)
|
||||
(ticket['unread']).should.equal('1')
|
||||
|
||||
staff_ticket = $database.getRow('staff_ticket', 1 , 'id')
|
||||
staff_ticket = $database.getRow('staff_ticket', 1 , 'ticket_id')
|
||||
|
||||
(staff_ticket).should.equal(nil)
|
||||
end
|
||||
|
@ -75,7 +75,7 @@ describe '/staff/un-assign-ticket' do
|
|||
(ticket['owner_id']).should.equal(nil)
|
||||
(ticket['unread']).should.equal('1')
|
||||
|
||||
staff_ticket = $database.getRow('staff_ticket', 1 , 'id')
|
||||
staff_ticket = $database.getRow('staff_ticket', 1 , 'ticket_id')
|
||||
|
||||
(staff_ticket).should.equal(nil)
|
||||
end
|
||||
|
|
|
@ -92,7 +92,7 @@ describe'system/disable-user-system' do
|
|||
|
||||
numberOftickets= $database.query("SELECT * FROM ticket WHERE author_email IS NULL AND author_name IS NULL AND author_id IS NOT NULL" )
|
||||
|
||||
(numberOftickets.num_rows).should.equal(39)
|
||||
(numberOftickets.num_rows).should.equal(40)
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -2,9 +2,32 @@ describe '/ticket/close' do
|
|||
request('/user/logout')
|
||||
Scripts.login($staff[:email], $staff[:password], true)
|
||||
|
||||
it 'should close a ticket if everything is okey' do
|
||||
it 'should not close ticket if not assigned' do
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
request('/staff/un-assign-ticket', {
|
||||
ticketNumber: ticket['ticket_number'],
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
|
||||
result = request('/ticket/close', {
|
||||
ticketNumber: ticket['ticket_number'],
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
|
||||
(result['status']).should.equal('fail')
|
||||
end
|
||||
|
||||
it 'should close ticket if you have it assigned' do
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
|
||||
request('/staff/assign-ticket', {
|
||||
ticketNumber: ticket['ticket_number'],
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
|
||||
result = request('/ticket/close', {
|
||||
ticketNumber: ticket['ticket_number'],
|
||||
csrf_userid: $csrf_userid,
|
||||
|
@ -19,28 +42,34 @@ describe '/ticket/close' do
|
|||
|
||||
lastLog = $database.getLastRow('log')
|
||||
(lastLog['type']).should.equal('CLOSE')
|
||||
|
||||
request('/user/logout')
|
||||
Scripts.createUser('closer@os4.com','closer','Closer')
|
||||
Scripts.login('closer@os4.com','closer')
|
||||
Scripts.createTicket('tickettoclose')
|
||||
|
||||
ticket = $database.getRow('ticket', 'tickettoclose', 'title')
|
||||
|
||||
result = request('/ticket/close', {
|
||||
request('/staff/un-assign-ticket', {
|
||||
ticketNumber: ticket['ticket_number'],
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
|
||||
})
|
||||
end
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
it 'should close ticket if you are the author' do
|
||||
request('/user/logout')
|
||||
Scripts.createUser('closer@os4.com','closer','Closer')
|
||||
Scripts.login('closer@os4.com','closer')
|
||||
Scripts.createTicket('tickettoclose')
|
||||
|
||||
ticket = $database.getRow('ticket', 'tickettoclose', 'title')
|
||||
(ticket['closed']).should.equal('1')
|
||||
ticket = $database.getRow('ticket', 'tickettoclose', 'title')
|
||||
|
||||
lastLog = $database.getLastRow('log')
|
||||
(lastLog['type']).should.equal('CLOSE')
|
||||
result = request('/ticket/close', {
|
||||
ticketNumber: ticket['ticket_number'],
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
|
||||
})
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
|
||||
ticket = $database.getRow('ticket', 'tickettoclose', 'title')
|
||||
(ticket['closed']).should.equal('1')
|
||||
|
||||
lastLog = $database.getLastRow('log')
|
||||
(lastLog['type']).should.equal('CLOSE')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -78,6 +78,31 @@ describe '/ticket/comment/' do
|
|||
(lastLog['type']).should.equal('COMMENT')
|
||||
end
|
||||
|
||||
it 'should add comment to ticket created by staff' do
|
||||
request('/user/logout')
|
||||
Scripts.login($staff[:email], $staff[:password], true)
|
||||
result = request('/ticket/comment', {
|
||||
content: 'some comment content',
|
||||
ticketNumber: $ticketNumberByStaff,
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
|
||||
ticket = $database.getRow('ticket', $ticketNumberByStaff, 'ticket_number')
|
||||
comment = $database.getRow('ticketevent', ticket['id'], 'ticket_id')
|
||||
(comment['content']).should.equal('some comment content')
|
||||
(comment['type']).should.equal('COMMENT')
|
||||
(comment['author_staff_id']).should.equal($csrf_userid)
|
||||
(ticket['unread_staff']).should.equal('1')
|
||||
|
||||
lastLog = $database.getLastRow('log')
|
||||
(lastLog['type']).should.equal('COMMENT')
|
||||
|
||||
request('/user/logout')
|
||||
end
|
||||
|
||||
it 'should fail if user is not the author nor owner' do
|
||||
Scripts.createUser('no_commenter@comment.com', 'no_commenter', 'No Commenter')
|
||||
Scripts.login('no_commenter@comment.com', 'no_commenter')
|
||||
|
|
|
@ -144,4 +144,24 @@ describe '/ticket/create' do
|
|||
(ticket2).should.equal((ticket0 - 100000 + 2 * ticket_number_gap) % 900000 + 100000)
|
||||
(ticket3).should.equal((ticket0 - 100000 + 3 * ticket_number_gap) % 900000 + 100000)
|
||||
end
|
||||
|
||||
it 'should be able to create a ticket while being staff' do
|
||||
request('/user/logout')
|
||||
Scripts.login($staff[:email], $staff[:password], true)
|
||||
result = request('/ticket/create', {
|
||||
title: 'created by staff',
|
||||
content: 'The staff created it',
|
||||
departmentId: 1,
|
||||
language: 'en',
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
(result['status']).should.equal('success')
|
||||
ticket = $database.getRow('ticket', result['data']['ticketNumber'], 'ticket_number')
|
||||
(ticket['author_id']).should.equal(nil)
|
||||
(ticket['author_staff_id']).should.equal('1')
|
||||
|
||||
$ticketNumberByStaff = result['data']['ticketNumber']
|
||||
request('/user/logout')
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue