Merge pull request #254 from guillegiu/master

back-end structure and tests of feature #161 #80
This commit is contained in:
Ivan Diaz 2018-07-27 21:39:43 +02:00 committed by GitHub
commit 2cfa455087
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 18 deletions

View File

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

View File

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

View File

@ -10,11 +10,12 @@ DataValidator::with('CustomValidations', true);
* *
* @apiGroup User * @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 * @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 INVALID_EMAIL
* @apiUse USER_SYSTEM_DISABLED * @apiUse USER_SYSTEM_DISABLED
@ -30,6 +31,7 @@ class SendRecoverPasswordController extends Controller {
private $token; private $token;
private $user; private $user;
private $staff;
public function validations() { public function validations() {
return [ return [
@ -48,8 +50,14 @@ class SendRecoverPasswordController extends Controller {
throw new Exception(ERRORS::USER_SYSTEM_DISABLED); throw new Exception(ERRORS::USER_SYSTEM_DISABLED);
} }
$this->staff = Controller::request('staff');
$email = Controller::request('email'); $email = Controller::request('email');
if($this->staff){
$this->user = Staff::getUser($email,'email');
}else {
$this->user = User::getUser($email,'email'); $this->user = User::getUser($email,'email');
}
if(!$this->user->isNull()) { if(!$this->user->isNull()) {
$this->token = Hashing::generateRandomToken(); $this->token = Hashing::generateRandomToken();
@ -57,7 +65,8 @@ class SendRecoverPasswordController extends Controller {
$recoverPassword = new RecoverPassword(); $recoverPassword = new RecoverPassword();
$recoverPassword->setProperties(array( $recoverPassword->setProperties(array(
'email' => $email, 'email' => $email,
'token' => $this->token 'token' => $this->token,
'staff' => $this->staff
)); ));
$recoverPassword->store(); $recoverPassword->store();
@ -67,7 +76,6 @@ class SendRecoverPasswordController extends Controller {
} else { } else {
Response::respondError(ERRORS::INVALID_EMAIL); Response::respondError(ERRORS::INVALID_EMAIL);
} }
} }
public function sendEmail() { public function sendEmail() {

View File

@ -5,7 +5,8 @@ class RecoverPassword extends DataStore {
public static function getProps() { public static function getProps() {
return array ( return array (
'email', 'email',
'token' 'token',
'staff'
); );
} }

View File

@ -30,6 +30,23 @@ describe '/staff/assign-ticket' do
(staff_ticket['ticket_id']).should.equal('1') (staff_ticket['ticket_id']).should.equal('1')
end 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 it 'should fail if ticket is already owned' do
ticket = $database.getRow('ticket', 1 , 'id') 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]['level']).should.equal('2')
(result['data'][2]['departments'][0]['id']).should.equal('1') (result['data'][2]['departments'][0]['id']).should.equal('1')
(result['data'][2]['departments'][0]['name']).should.equal('Help and Support') (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) (result['data'][2]['closedTickets']).should.equal(0)
end end
end end

View File

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