diff --git a/server/controllers/staff/edit.php b/server/controllers/staff/edit.php
index ac7ab89f..6b7e0262 100755
--- a/server/controllers/staff/edit.php
+++ b/server/controllers/staff/edit.php
@@ -18,6 +18,7 @@ use Respect\Validation\Validator as DataValidator;
* @apiParam {String} email The new email of the staff member. Optional.
* @apiParam {String} password The new password of the staff member. Optional.
* @apiParam {Number} level The new level of the staff member. Optional.
+ * @apiParam {Boolean} sendEmailOnNewTicket Indicates if it receives an email when a new ticket is created.
*
* @apiUse NO_PERMISSION
* @apiUse INVALID_STAFF
@@ -85,6 +86,10 @@ class EditStaffController extends Controller {
if($fileUploader = $this->uploadFile(true)) {
$this->staffInstance->profilePic = ($fileUploader instanceof FileUploader) ? $fileUploader->getFileName() : null;
}
+
+ if(Controller::request('sendEmailOnNewTicket') !== null && !Controller::request('staffId') ) {
+ $this->staffInstance->sendEmailOnNewTicket = Controller::request('sendEmailOnNewTicket');
+ }
$this->staffInstance->store();
}
diff --git a/server/controllers/system/init-admin.php b/server/controllers/system/init-admin.php
index 80f49609..1648fa0f 100755
--- a/server/controllers/system/init-admin.php
+++ b/server/controllers/system/init-admin.php
@@ -64,7 +64,8 @@ class InitAdminController extends Controller {
'profilePic' => '',
'level' => 3,
'sharedDepartmentList' => Department::getAll(),
- 'sharedTicketList' => []
+ 'sharedTicketList' => [],
+ 'sendEmailOnNewTicket' => 1
]);
foreach(Department::getAll() as $department) {
diff --git a/server/controllers/ticket/close.php b/server/controllers/ticket/close.php
index 55382d89..e3b86dc4 100755
--- a/server/controllers/ticket/close.php
+++ b/server/controllers/ticket/close.php
@@ -18,7 +18,7 @@ DataValidator::with('CustomValidations', true);
*
* @apiUse NO_PERMISSION
* @apiUse INVALID_TICKET
- *
+ *
* @apiSuccess {Object} data Empty object
*
*/
@@ -30,15 +30,33 @@ class CloseController extends Controller {
private $ticket;
public function validations() {
- return [
- 'permission' => 'user',
- 'requestData' => [
- 'ticketNumber' => [
- 'validation' => DataValidator::validTicketNumber(),
- 'error' => ERRORS::INVALID_TICKET
+ $session = Session::getInstance();
+
+ if (Controller::isUserSystemEnabled() || Controller::isStaffLogged()) {
+ return [
+ 'permission' => 'user',
+ 'requestData' => [
+ 'ticketNumber' => [
+ 'validation' => DataValidator::validTicketNumber(),
+ 'error' => ERRORS::INVALID_TICKET
+ ]
]
- ]
- ];
+ ];
+ } else {
+ return [
+ 'permission' => 'any',
+ 'requestData' => [
+ 'ticketNumber' => [
+ 'validation' => DataValidator::equals($session->getTicketNumber()),
+ 'error' => ERRORS::INVALID_TICKET
+ ],
+ 'csrf_token' => [
+ 'validation' => DataValidator::equals($session->getToken()),
+ 'error' => ERRORS::INVALID_TOKEN
+ ]
+ ]
+ ];
+ }
}
public function handler() {
@@ -57,15 +75,18 @@ class CloseController extends Controller {
$this->sendMail();
Log::createLog('CLOSE', $this->ticket->ticketNumber);
-
+
Response::respondSuccess();
}
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);
+ 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() {
@@ -95,8 +116,8 @@ class CloseController extends Controller {
$mailSender = MailSender::getInstance();
$mailSender->setTemplate(MailTemplate::TICKET_CLOSED, [
- 'to' => $this->ticket->author->email,
- 'name' => $this->ticket->author->name,
+ 'to' => ($this->ticket->author) ? $this->ticket->author->email : $this->ticket->authorEmail,
+ 'name' => ($this->ticket->author) ? $this->ticket->author->name : $this->ticket->authorName,
'ticketNumber' => $this->ticket->ticketNumber,
'title' => $this->ticket->title,
'url' => Setting::getSetting('url')->getValue()
@@ -104,4 +125,4 @@ class CloseController extends Controller {
$mailSender->send();
}
-}
\ No newline at end of file
+}
diff --git a/server/controllers/ticket/comment.php b/server/controllers/ticket/comment.php
index 8d08bdf1..96e9d3db 100755
--- a/server/controllers/ticket/comment.php
+++ b/server/controllers/ticket/comment.php
@@ -20,6 +20,7 @@ DataValidator::with('CustomValidations', true);
* @apiUse NO_PERMISSION
* @apiUse INVALID_CONTENT
* @apiUse INVALID_TICKET
+ * @apiUse INVALID_TOKEN
*
* @apiSuccess {Object} data Empty object
*
@@ -63,7 +64,7 @@ class CommentController extends Controller {
],
'csrf_token' => [
'validation' => DataValidator::equals($session->getToken()),
- 'error' => Controller::request('csrf_token') . ' ' . $session->getToken()
+ 'error' => ERRORS::INVALID_TOKEN
]
]
diff --git a/server/controllers/ticket/create.php b/server/controllers/ticket/create.php
index 9b6c36df..248f7bf4 100755
--- a/server/controllers/ticket/create.php
+++ b/server/controllers/ticket/create.php
@@ -97,6 +97,13 @@ class CreateController extends Controller {
if(!Controller::isUserSystemEnabled()) {
$this->sendMail();
}
+
+ $staffs = Staff::find('send_email_on_new_ticket = 1');
+ foreach ($staffs as $staff) {
+ if($staff->sharedDepartmentList->includesId(Controller::request('departmentId'))) {
+ $this->sendMailStaff($staff->email);
+ }
+ }
Log::createLog('CREATE_TICKET', $this->ticketNumber);
Response::respondSuccess([
@@ -154,4 +161,17 @@ class CreateController extends Controller {
$mailSender->send();
}
+
+ private function sendMailStaff($email) {
+ $mailSender = new MailSender();
+
+ $mailSender->setTemplate(MailTemplate::TICKET_CREATED_STAFF, [
+ 'to' => $email,
+ 'name' => $this->name,
+ 'ticketNumber' => $this->ticketNumber,
+ 'title' => $this->title
+ ]);
+
+ $mailSender->send();
+ }
}
diff --git a/server/controllers/ticket/get.php b/server/controllers/ticket/get.php
index ce953561..8b62bad1 100755
--- a/server/controllers/ticket/get.php
+++ b/server/controllers/ticket/get.php
@@ -16,6 +16,7 @@ DataValidator::with('CustomValidations', true);
* @apiParam {Number} ticketNumber The number of the ticket.
*
* @apiUse INVALID_TICKET
+ * @apiUse INVALID_TOKEN
* @apiUse NO_PERMISSION
*
* @apiSuccess {[Ticket](#api-Data_Structures-ObjectTicket)} data Information about the requested ticket.
@@ -52,7 +53,7 @@ class TicketGetController extends Controller {
],
'csrf_token' => [
'validation' => DataValidator::equals($session->getToken()),
- 'error' => $session->getToken() . ' != ' . Controller::request('csrf_token')
+ 'error' => ERRORS::INVALID_TOKEN
]
]
];
diff --git a/server/data/InitialMails.php b/server/data/InitialMails.php
index 2ef94d8f..cc64e735 100755
--- a/server/data/InitialMails.php
+++ b/server/data/InitialMails.php
@@ -380,7 +380,49 @@ class InitialMails {
'subject' => '#{{ticketNumber}} 票已关闭 - OpenSupports',
'body' => file_get_contents('data/mail-templates/ticket-closed-cn.html')
]
+ ],
+ 'TICKET_CREATED_STAFF' => [
+ 'en' => [
+ 'subject' => '#{{ticketNumber}} Ticket created - OpenSupports',
+ 'body' => file_get_contents('data/mail-templates/ticket-created-staff-en.html')
+ ],
+ 'es' => [
+ 'subject' => '#{{ticketNumber}} Ticket creado - OpenSupports',
+ 'body' => file_get_contents('data/mail-templates/ticket-created-staff-es.html')
+ ],
+ 'de' => [
+ 'subject' => '#{{ticketNumber}} Ticket erstellt - OpenSupports',
+ 'body' => file_get_contents('data/mail-templates/ticket-created-staff-de.html')
+ ],
+ 'fr' => [
+ 'subject' => '#{{ticketNumber}} Ticket créé - OpenSupports',
+ 'body' => file_get_contents('data/mail-templates/ticket-created-staff-fr.html')
+ ],
+ 'in' => [
+ 'subject' => '#{{ticketNumber}} tiket dibuat - OpenSupports',
+ 'body' => file_get_contents('data/mail-templates/ticket-created-staff-in.html')
+ ],
+ 'jp' => [
+ 'subject' => '#{{ticketNumber}} チケットが作成されました - OpenSupports',
+ 'body' => file_get_contents('data/mail-templates/ticket-created-staff-jp.html')
+ ],
+ 'pt' => [
+ 'subject' => '#{{ticketNumber}} Ticket criado - OpenSupports',
+ 'body' => file_get_contents('data/mail-templates/ticket-created-staff-pt.html')
+ ],
+ 'ru' => [
+ 'subject' => '#{{ticketNumber}} Создан билет - OpenSupports',
+ 'body' => file_get_contents('data/mail-templates/ticket-created-staff-ru.html')
+ ],
+ 'tr' => [
+ 'subject' => '#{{ticketNumber}} Bilet oluşturuldu - OpenSupports',
+ 'body' => file_get_contents('data/mail-templates/ticket-created-staff-tr.html')
+ ],
+ 'cn' => [
+ 'subject' => '#{{ticketNumber}} 已创建票证 - OpenSupports',
+ 'body' => file_get_contents('data/mail-templates/ticket-created-staff-cn.html')
]
+ ]
];
}
}
\ No newline at end of file
diff --git a/server/data/mail-templates/ticket-created-staff-cn.html b/server/data/mail-templates/ticket-created-staff-cn.html
new file mode 100644
index 00000000..a9ac1fde
--- /dev/null
+++ b/server/data/mail-templates/ticket-created-staff-cn.html
@@ -0,0 +1,378 @@
+
+
+
+
+
+ Support Center
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ 用戶 {{name}}。 他創造了一個題為新票 {{title}}。
+ |
+
+
+
+
+
+
+
+
+
+ 您可以通过其票号访问票证。
+ |
+
+
+
+ {{ticketNumber}}
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+ OpenSupports
+ Open source ticket system
+ www.opensupports.com
+ |
+
+
+
+ |
+
+
+
+
\ No newline at end of file
diff --git a/server/data/mail-templates/ticket-created-staff-de.html b/server/data/mail-templates/ticket-created-staff-de.html
new file mode 100644
index 00000000..697a050c
--- /dev/null
+++ b/server/data/mail-templates/ticket-created-staff-de.html
@@ -0,0 +1,378 @@
+
+
+
+
+
+ Support Center
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ Der Benutzer {{name}} hat ein neues Ticket erstellt berechtigt {{title}}.
+ |
+
+
+
+
+
+
+
+
+
+ Sie können das Ticket nach der Fahrkartennummer erreichen.
+ |
+
+
+
+ {{ticketNumber}}
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+ OpenSupports
+ Open source ticket system
+ www.opensupports.com
+ |
+
+
+
+ |
+
+
+
+
\ No newline at end of file
diff --git a/server/data/mail-templates/ticket-created-staff-en.html b/server/data/mail-templates/ticket-created-staff-en.html
new file mode 100644
index 00000000..01d13c76
--- /dev/null
+++ b/server/data/mail-templates/ticket-created-staff-en.html
@@ -0,0 +1,378 @@
+
+
+
+
+
+ Support Center
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ User {{name}} has created a new ticket titled {{title}}.
+ |
+
+
+
+
+
+
+
+
+
+ You can access to the ticket by its ticket number.
+ |
+
+
+
+ {{ticketNumber}}
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+ OpenSupports
+ Open source ticket system
+ www.opensupports.com
+ |
+
+
+
+ |
+
+
+
+
\ No newline at end of file
diff --git a/server/data/mail-templates/ticket-created-staff-es.html b/server/data/mail-templates/ticket-created-staff-es.html
new file mode 100644
index 00000000..b5a511eb
--- /dev/null
+++ b/server/data/mail-templates/ticket-created-staff-es.html
@@ -0,0 +1,378 @@
+
+
+
+
+
+ Support Center
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ El usuario {{name}} ha creado un nuevo ticket titulado {{title}}.
+ |
+
+
+
+
+
+
+
+
+
+ Puedes ver el ticket usando el numero de ticket prensentado abajo.
+ |
+
+
+
+ {{ticketNumber}}
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+ OpenSupports
+ Open source ticket system
+ www.opensupports.com
+ |
+
+
+
+ |
+
+
+
+
\ No newline at end of file
diff --git a/server/data/mail-templates/ticket-created-staff-fr.html b/server/data/mail-templates/ticket-created-staff-fr.html
new file mode 100644
index 00000000..f38dff7f
--- /dev/null
+++ b/server/data/mail-templates/ticket-created-staff-fr.html
@@ -0,0 +1,378 @@
+
+
+
+
+
+ Support Center
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ L'utilisateur {{name}}. a créé un nouveau poste intitulé {{title}}.
+ |
+
+
+
+
+
+
+
+
+
+ Vous pouvez accéder au billet par son numéro de ticket.
+ |
+
+
+
+ {{ticketNumber}}
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+ OpenSupports
+ Open source ticket system
+ www.opensupports.com
+ |
+
+
+
+ |
+
+
+
+
\ No newline at end of file
diff --git a/server/data/mail-templates/ticket-created-staff-in.html b/server/data/mail-templates/ticket-created-staff-in.html
new file mode 100644
index 00000000..89350bf2
--- /dev/null
+++ b/server/data/mail-templates/ticket-created-staff-in.html
@@ -0,0 +1,378 @@
+
+
+
+
+
+ Support Center
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ उपयोगकर्ता {{name}} हकदार एक नया पद बनाया गया है {{title}}.
+ |
+
+
+
+
+
+
+
+
+
+ आप अपने टिकट नंबर से टिकट तक पहुंच सकते हैं।
+ |
+
+
+
+ {{ticketNumber}}
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+ OpenSupports
+ Open source ticket system
+ www.opensupports.com
+ |
+
+
+
+ |
+
+
+
+
\ No newline at end of file
diff --git a/server/data/mail-templates/ticket-created-staff-jp.html b/server/data/mail-templates/ticket-created-staff-jp.html
new file mode 100644
index 00000000..9e0e50a3
--- /dev/null
+++ b/server/data/mail-templates/ticket-created-staff-jp.html
@@ -0,0 +1,378 @@
+
+
+
+
+
+ Support Center
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ ユーザーは {{name}} 彼は題した新しいチケットを作成しました {{title}}。
+ |
+
+
+
+
+
+
+
+
+
+ そのチケット番号でチケットにアクセスできます。
+ |
+
+
+
+ {{ticketNumber}}
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+ OpenSupports
+ Open source ticket system
+ www.opensupports.com
+ |
+
+
+
+ |
+
+
+
+
\ No newline at end of file
diff --git a/server/data/mail-templates/ticket-created-staff-pt.html b/server/data/mail-templates/ticket-created-staff-pt.html
new file mode 100644
index 00000000..9b8fa947
--- /dev/null
+++ b/server/data/mail-templates/ticket-created-staff-pt.html
@@ -0,0 +1,378 @@
+
+
+
+
+
+ Support Center
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ O usuário {{name}} criou um novo bilhete de direito {{title}}.
+ |
+
+
+
+
+
+
+
+
+
+ Você pode acessar o bilhete pelo seu número de bilhete.
+ |
+
+
+
+ {{ticketNumber}}
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+ OpenSupports
+ Open source ticket system
+ www.opensupports.com
+ |
+
+
+
+ |
+
+
+
+
\ No newline at end of file
diff --git a/server/data/mail-templates/ticket-created-staff-ru.html b/server/data/mail-templates/ticket-created-staff-ru.html
new file mode 100644
index 00000000..814a68e8
--- /dev/null
+++ b/server/data/mail-templates/ticket-created-staff-ru.html
@@ -0,0 +1,378 @@
+
+
+
+
+
+ Support Center
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ Пользователь {{name}} создал новый билет под названием {{title}}.
+ |
+
+
+
+
+
+
+
+
+
+ Вы можете получить доступ к билету по его номеру билета.
+ |
+
+
+
+ {{ticketNumber}}
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+ OpenSupports
+ Open source ticket system
+ www.opensupports.com
+ |
+
+
+
+ |
+
+
+
+
\ No newline at end of file
diff --git a/server/data/mail-templates/ticket-created-staff-tr.html b/server/data/mail-templates/ticket-created-staff-tr.html
new file mode 100644
index 00000000..5f29e64d
--- /dev/null
+++ b/server/data/mail-templates/ticket-created-staff-tr.html
@@ -0,0 +1,378 @@
+
+
+
+
+
+ Support Center
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ Kullanıcı {{name}} başlıklı yeni bir bilet yarattı {{title}} .
+ |
+
+
+
+
+
+
+
+
+
+ Bilete bilet numarasından erişebilirsiniz.
+ |
+
+
+
+ {{ticketNumber}}
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+ OpenSupports
+ Open source ticket system
+ www.opensupports.com
+ |
+
+
+
+ |
+
+
+
+
\ No newline at end of file
diff --git a/server/models/MailTemplate.php b/server/models/MailTemplate.php
index 436b4b3f..6f1bce1f 100755
--- a/server/models/MailTemplate.php
+++ b/server/models/MailTemplate.php
@@ -22,6 +22,7 @@ class MailTemplate extends DataStore {
const TICKET_CREATED = 'TICKET_CREATED';
const TICKET_RESPONDED = 'TICKET_RESPONDED';
const TICKET_CLOSED = 'TICKET_CLOSED';
+ const TICKET_CREATED_STAFF = 'TICKET_CREATED_STAFF';
public static function getTemplate($type) {
$globalLanguage = Setting::getSetting('language')->value;
diff --git a/server/models/Staff.php b/server/models/Staff.php
index 9681d6f5..dd448d35 100755
--- a/server/models/Staff.php
+++ b/server/models/Staff.php
@@ -31,14 +31,16 @@ class Staff extends DataStore {
'sharedDepartmentList',
'sharedTicketList',
'lastLogin',
- 'ownStatList'
+ 'ownStatList',
+ 'sendEmailOnNewTicket'
];
}
public function getDefaultProps() {
return [
'level' => 1,
- 'ownStatList' => new DataStoreList()
+ 'ownStatList' => new DataStoreList(),
+ 'sendEmailOnNewTicket' => 0
];
}
@@ -55,7 +57,8 @@ class Staff extends DataStore {
'level' => $this->level,
'departments' => $this->sharedDepartmentList->toArray(),
'tickets' => $this->sharedTicketList->toArray(),
- 'lastLogin' => $this->lastLogin
+ 'lastLogin' => $this->lastLogin ,
+ 'sendEmailOnNewTicket' => $this->sendEmailOnNewTicket
];
}
}
diff --git a/tests/staff/edit.rb b/tests/staff/edit.rb
index a42de635..117b7ee5 100644
--- a/tests/staff/edit.rb
+++ b/tests/staff/edit.rb
@@ -49,6 +49,7 @@ describe'/staff/edit' do
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
email: 'newwstaff@opensupports.com',
+ sendEmailOnNewTicket: '1'
})
(result['status']).should.equal('success')
@@ -57,6 +58,7 @@ describe'/staff/edit' do
(row['email']).should.equal('newwstaff@opensupports.com')
(row['level']).should.equal('2')
+ (row['send_email_on_new_ticket']).should.equal('1')
row = $database.getRow('department', 1, 'id')
(row['owners']).should.equal('3')
diff --git a/tests/system/get-mail-templates.rb b/tests/system/get-mail-templates.rb
index 34dd2600..97a63e65 100644
--- a/tests/system/get-mail-templates.rb
+++ b/tests/system/get-mail-templates.rb
@@ -10,6 +10,6 @@ describe'system/get-mail-templates' do
(result['status']).should.equal('success')
- (result['data'].size).should.equal(90)
+ (result['data'].size).should.equal(100)
end
end