Merge branch 'master' of github.com:opensupports/opensupports

This commit is contained in:
Ivan Diaz 2018-07-27 20:36:56 -03:00
commit 6383b52fd0
7 changed files with 61 additions and 18 deletions

View File

@ -15,6 +15,7 @@ DataValidator::with('CustomValidations', true);
* @apiPermission staff1
*
* @apiParam {Number} ticketNumber The number of the ticket to assign.
* @apiParam {Number} staffId The id of the staff.
*
* @apiUse NO_PERMISSION
* @apiUse INVALID_TICKET
@ -46,12 +47,22 @@ class AssignStaffController extends Controller {
public function handler() {
$ticketNumber = Controller::request('ticketNumber');
$this->user = Controller::getLoggedUser();
$staffId = Controller::request('staffId');
$this->ticket = Ticket::getByTicketNumber($ticketNumber);
if($staffId) {
$this->user = Staff::getDataStore($staffId, 'id');
if($this->user->isNull()) {
throw new Exception(ERRORS::INVALID_STAFF);
}
if(!$this->user->sharedDepartmentList->includesId($this->ticket->department->id)) {
throw new Exception(ERRORS::INVALID_DEPARTMENT);
}
} else {
$this->user = Controller::getLoggedUser();
}
if($this->ticket->owner) {
throw new Exception(ERRORS::TICKET_ALREADY_ASSIGNED);
return;
}
if(!$this->ticketHasStaffDepartment()) {

View File

@ -56,7 +56,7 @@ class RecoverPasswordController extends Controller {
if(!Controller::isUserSystemEnabled()) {
throw new Exception(ERRORS::USER_SYSTEM_DISABLED);
}
$this->requestData();
$this->changePassword();
}
@ -68,7 +68,12 @@ class RecoverPasswordController extends Controller {
}
public function changePassword() {
$recoverPassword = RecoverPassword::getDataStore($this->token, 'token');
$this->user = User::getDataStore($this->email, 'email');
if($recoverPassword->staff) {
$this->user = Staff::getDataStore($this->email, 'email');
}else {
$this->user = User::getDataStore($this->email, 'email');
}
if (!$recoverPassword->isNull() && !$this->user->isNull()) {
$recoverPassword->delete();
@ -80,7 +85,7 @@ class RecoverPasswordController extends Controller {
$this->user->store();
$this->sendMail();
Response::respondSuccess();
Response::respondSuccess(['staff' => $recoverPassword->staff]);
} else {
Response::respondError(ERRORS::NO_PERMISSION);
}

View File

@ -10,11 +10,12 @@ DataValidator::with('CustomValidations', true);
*
* @apiGroup User
*
* @apiDescription This path sends a token to the email of the user to change his password.
* @apiDescription This path sends a token to the email of the user/staff to change his password.
*
* @apiPermission any
*
* @apiParam {String} email The email of the user who forgot the password.
* @apiParam {String} email The email of the user/staff who forgot the password.
* @apiParam {Boolean} staff Indicates if the user is a staff member.
*
* @apiUse INVALID_EMAIL
* @apiUse USER_SYSTEM_DISABLED
@ -30,6 +31,7 @@ class SendRecoverPasswordController extends Controller {
private $token;
private $user;
private $staff;
public function validations() {
return [
@ -47,17 +49,24 @@ class SendRecoverPasswordController extends Controller {
if(!Controller::isUserSystemEnabled()) {
throw new Exception(ERRORS::USER_SYSTEM_DISABLED);
}
$this->staff = Controller::request('staff');
$email = Controller::request('email');
$this->user = User::getUser($email,'email');
if($this->staff){
$this->user = Staff::getUser($email,'email');
}else {
$this->user = User::getUser($email,'email');
}
if(!$this->user->isNull()) {
$this->token = Hashing::generateRandomToken();
$recoverPassword = new RecoverPassword();
$recoverPassword->setProperties(array(
'email' => $email,
'token' => $this->token
'token' => $this->token,
'staff' => $this->staff
));
$recoverPassword->store();
@ -67,7 +76,6 @@ class SendRecoverPasswordController extends Controller {
} else {
Response::respondError(ERRORS::INVALID_EMAIL);
}
}
public function sendEmail() {

View File

@ -1,15 +1,16 @@
<?php
class RecoverPassword extends DataStore {
const TABLE = 'recoverpassword';
public static function getProps() {
return array (
'email',
'token'
'token',
'staff'
);
}
public function getDefaultProps() {
return array();
}
}
}

View File

@ -30,6 +30,23 @@ describe '/staff/assign-ticket' do
(staff_ticket['ticket_id']).should.equal('1')
end
it 'should assign ticket if a staff choose another to assing a ticket ' do
ticket = $database.getRow('ticket', 3 , 'id')
result = request('/staff/assign-ticket', {
ticketNumber: ticket['ticket_number'],
staffId:4,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('success')
ticket = $database.getRow('ticket', 3 , 'id')
(ticket['owner_id']).should.equal('4')
(ticket['unread']).should.equal('1')
end
it 'should fail if ticket is already owned' do
ticket = $database.getRow('ticket', 1 , 'id')

View File

@ -29,7 +29,7 @@ describe'/staff/get-all' do
(result['data'][2]['level']).should.equal('2')
(result['data'][2]['departments'][0]['id']).should.equal('1')
(result['data'][2]['departments'][0]['name']).should.equal('Help and Support')
(result['data'][2]['assignedTickets']).should.equal(0)
(result['data'][2]['assignedTickets']).should.equal(1)
(result['data'][2]['closedTickets']).should.equal(0)
end
end

View File

@ -10,6 +10,7 @@ describe '/staff/get-new-tickets' do
})
(result['status']).should.equal('success')
(result['data'].size).should.equal(10)
(result['data'].size).should.equal(9)
end
end