mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-31 01:35:15 +02:00
Merged in OS-83-(Backend)-Ticket-events-architecture (pull request #54)
OS-83 (backend) ticket events architecture
This commit is contained in:
commit
9fba1562ea
@ -44,14 +44,19 @@ class CommentController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function storeComment() {
|
private function storeComment() {
|
||||||
$comment = new Comment();
|
$comment = Ticketevent::getEvent(Ticketevent::COMMENT);
|
||||||
$comment->setProperties(array(
|
$comment->setProperties(array(
|
||||||
'content' => $this->content,
|
'content' => $this->content,
|
||||||
'author' => Controller::getLoggedUser(),
|
|
||||||
'date' => Date::getCurrentDate()
|
'date' => Date::getCurrentDate()
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->ticket->ownCommentList->add($comment);
|
if(Controller::isStaffLogged()) {
|
||||||
|
$comment->authorUser = Controller::getLoggedUser();
|
||||||
|
} else {
|
||||||
|
$comment->authorUser = Controller::getLoggedUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->ticket->addEvent($comment);
|
||||||
$this->ticket->store();
|
$this->ticket->store();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,4 +15,5 @@ class ERRORS {
|
|||||||
const INIT_SETTINGS_DONE = 'Settings already initialized';
|
const INIT_SETTINGS_DONE = 'Settings already initialized';
|
||||||
const INVALID_OLD_PASSWORD = 'Invalid old password';
|
const INVALID_OLD_PASSWORD = 'Invalid old password';
|
||||||
const INVALID_CAPTCHA = 'Invalid captcha';
|
const INVALID_CAPTCHA = 'Invalid captcha';
|
||||||
|
const INVALID_TICKET_EVENT = 'INVALID_TICKET_EVENT';
|
||||||
}
|
}
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class Comment extends DataStore {
|
|
||||||
const TABLE = 'comment';
|
|
||||||
|
|
||||||
public static function getProps() {
|
|
||||||
return array(
|
|
||||||
'content',
|
|
||||||
'file',
|
|
||||||
'author',
|
|
||||||
'date'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,7 +17,7 @@ class Ticket extends DataStore {
|
|||||||
'closed',
|
'closed',
|
||||||
'author',
|
'author',
|
||||||
'owner',
|
'owner',
|
||||||
'ownCommentList'
|
'ownTicketeventList'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,6 +39,7 @@ class Ticket extends DataStore {
|
|||||||
public function store() {
|
public function store() {
|
||||||
parent::store();
|
parent::store();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateUniqueTicketNumber() {
|
public function generateUniqueTicketNumber() {
|
||||||
$ticketQuantity = Ticket::count('ticket');
|
$ticketQuantity = Ticket::count('ticket');
|
||||||
$minValue = 100000;
|
$minValue = 100000;
|
||||||
@ -57,8 +58,6 @@ class Ticket extends DataStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function toArray() {
|
public function toArray() {
|
||||||
$author = $this->author;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'ticketNumber' => $this->ticketNumber,
|
'ticketNumber' => $this->ticketNumber,
|
||||||
'title' => $this->title,
|
'title' => $this->title,
|
||||||
@ -74,7 +73,7 @@ class Ticket extends DataStore {
|
|||||||
'closed' => !!$this->closed,
|
'closed' => !!$this->closed,
|
||||||
'author' => $this->authorToArray(),
|
'author' => $this->authorToArray(),
|
||||||
'owner' => $this->ownerToArray(),
|
'owner' => $this->ownerToArray(),
|
||||||
'comments' => $this->commentsToArray()
|
'events' => $this->eventsToArray()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,23 +105,35 @@ class Ticket extends DataStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function commentsToArray() {
|
public function eventsToArray() {
|
||||||
$comments = [];
|
$events = [];
|
||||||
|
|
||||||
foreach ($this->ownCommentList as $comment) {
|
foreach ($this->ownTicketeventList as $ticketEvent) {
|
||||||
$comments[] = [
|
$event = [
|
||||||
'content'=> $comment->content,
|
'type' => $ticketEvent->type,
|
||||||
'author' => [
|
'content'=> $ticketEvent->content,
|
||||||
'id'=> 15,
|
'author' => [],
|
||||||
'name' => $comment->author->name,
|
'date'=> $ticketEvent->date,
|
||||||
'email' => $comment->author->email,
|
'file'=> $ticketEvent->file
|
||||||
'staff' => $comment->author->staff
|
|
||||||
],
|
|
||||||
'date'=> $comment->date,
|
|
||||||
'file'=> $comment->file
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$author = $ticketEvent->getAuthor();
|
||||||
|
if(!$author->isNull()) {
|
||||||
|
$event['author'] = [
|
||||||
|
'id'=> $author->id,
|
||||||
|
'name' => $author->name,
|
||||||
|
'email' =>$author->email,
|
||||||
|
'staff' => $author instanceof Staff
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$events[] = $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $comments;
|
return $events;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addEvent(Ticketevent $event) {
|
||||||
|
$this->ownTicketeventList->add($event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
60
server/models/Ticketevent.php
Normal file
60
server/models/Ticketevent.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Ticketevent extends DataStore {
|
||||||
|
const TABLE = 'ticketevent';
|
||||||
|
|
||||||
|
const COMMENT = 'COMMENT';
|
||||||
|
const ASSIGN = 'ASSIGN';
|
||||||
|
const UNASSIGN = 'UNASSIGN';
|
||||||
|
const CLOSE = 'CLOSE';
|
||||||
|
const REOPEN = 'REOPEN';
|
||||||
|
const DEPARTMENT_CHANGED = 'DEPARTMENT_CHANGED';
|
||||||
|
const PRIORITY_CHANGED = 'PRIORITY_CHANGED';
|
||||||
|
|
||||||
|
private static function getEventTypes() {
|
||||||
|
return [
|
||||||
|
'COMMENT',
|
||||||
|
'UNASSIGN',
|
||||||
|
'CLOSE',
|
||||||
|
'REOPEN',
|
||||||
|
'DEPARTMENT_CHANGED',
|
||||||
|
'PRIORITY_CHANGED',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getEvent($type) {
|
||||||
|
if (!in_array($type, Ticketevent::getEventTypes())) {
|
||||||
|
return new NullDataStore();
|
||||||
|
}
|
||||||
|
|
||||||
|
$ticketEvent = new Ticketevent();
|
||||||
|
$ticketEvent->setProperties([
|
||||||
|
'type' => $type
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $ticketEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProps() {
|
||||||
|
return [
|
||||||
|
'type',
|
||||||
|
'content',
|
||||||
|
'file',
|
||||||
|
'authorUser',
|
||||||
|
'authorStaff',
|
||||||
|
'date'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAuthor() {
|
||||||
|
if($this->authorUser) {
|
||||||
|
return $this->authorUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->authorStaff) {
|
||||||
|
return $this->authorStaff;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new NullDataStore();
|
||||||
|
}
|
||||||
|
}
|
@ -68,9 +68,10 @@ describe '/ticket/comment/' do
|
|||||||
(result['status']).should.equal('success')
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
ticket = $database.getRow('ticket', @ticketNumber, 'ticket_number')
|
ticket = $database.getRow('ticket', @ticketNumber, 'ticket_number')
|
||||||
comment = $database.getRow('comment', ticket['id'], 'ticket_id')
|
comment = $database.getRow('ticketevent', ticket['id'], 'ticket_id')
|
||||||
(comment['content']).should.equal('some comment content')
|
(comment['content']).should.equal('some comment content')
|
||||||
(comment['author_id']).should.equal($csrf_userid)
|
(comment['type']).should.equal('COMMENT')
|
||||||
|
(comment['author_user_id']).should.equal($csrf_userid)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should fail if user is not the author nor owner' do
|
it 'should fail if user is not the author nor owner' do
|
||||||
|
@ -15,6 +15,13 @@ describe '/ticket/get/' do
|
|||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
@ticketNumber = result['data']['ticketNumber']
|
@ticketNumber = result['data']['ticketNumber']
|
||||||
|
|
||||||
|
request('/ticket/comment', {
|
||||||
|
ticketNumber: @ticketNumber,
|
||||||
|
content: 'some valid comment made',
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should fail if ticketNumber is invalid' do
|
it 'should fail if ticketNumber is invalid' do
|
||||||
@ -46,6 +53,7 @@ describe '/ticket/get/' do
|
|||||||
result = Scripts.login('cersei@os4.com', 'cersei')
|
result = Scripts.login('cersei@os4.com', 'cersei')
|
||||||
$csrf_userid = result['userId']
|
$csrf_userid = result['userId']
|
||||||
$csrf_token = result['token']
|
$csrf_token = result['token']
|
||||||
|
|
||||||
result = request('/ticket/get', {
|
result = request('/ticket/get', {
|
||||||
ticketNumber: @ticketNumber,
|
ticketNumber: @ticketNumber,
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
@ -68,6 +76,8 @@ describe '/ticket/get/' do
|
|||||||
(result['data']['author']['name']).should.equal('Cersei Lannister')
|
(result['data']['author']['name']).should.equal('Cersei Lannister')
|
||||||
(result['data']['author']['email']).should.equal('cersei@os4.com')
|
(result['data']['author']['email']).should.equal('cersei@os4.com')
|
||||||
(result['data']['owner']).should.equal([])
|
(result['data']['owner']).should.equal([])
|
||||||
(result['data']['comments']).should.equal([])
|
(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')
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -52,6 +52,6 @@ describe '/user/get' do
|
|||||||
(ticketFromUser['author']['name']).should.equal('User Get')
|
(ticketFromUser['author']['name']).should.equal('User Get')
|
||||||
(ticketFromUser['author']['email']).should.equal('user_get@os4.com')
|
(ticketFromUser['author']['email']).should.equal('user_get@os4.com')
|
||||||
(ticketFromUser['owner']).should.equal([])
|
(ticketFromUser['owner']).should.equal([])
|
||||||
(ticketFromUser['comments']).should.equal([])
|
(ticketFromUser['events']).should.equal([])
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
x
Reference in New Issue
Block a user