Merged in OS156-Disable-user-system (pull request #126)
Os156 disable user system
This commit is contained in:
commit
585159e84c
|
@ -7,7 +7,7 @@ class GetAllArticlesController extends Controller {
|
||||||
|
|
||||||
public function validations() {
|
public function validations() {
|
||||||
return [
|
return [
|
||||||
'permission' => 'user',
|
'permission' => (Controller::isUserSystemEnabled()) ? 'user' : 'any',
|
||||||
'requestData' => []
|
'requestData' => []
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,14 @@ require_once 'system/get-logs.php';
|
||||||
require_once 'system/get-mail-templates.php';
|
require_once 'system/get-mail-templates.php';
|
||||||
require_once 'system/edit-mail-template.php';
|
require_once 'system/edit-mail-template.php';
|
||||||
require_once 'system/recover-mail-template.php';
|
require_once 'system/recover-mail-template.php';
|
||||||
require_once 'system/get-stats.php';
|
|
||||||
require_once 'system/disable-registration.php';
|
require_once 'system/disable-registration.php';
|
||||||
require_once 'system/enable-registration.php';
|
require_once 'system/enable-registration.php';
|
||||||
|
require_once 'system/disable-user-system.php';
|
||||||
|
require_once 'system/enabled-user-system.php';
|
||||||
require_once 'system/add-api-key.php';
|
require_once 'system/add-api-key.php';
|
||||||
require_once 'system/delete-api-key.php';
|
require_once 'system/delete-api-key.php';
|
||||||
require_once 'system/get-all-keys.php';
|
require_once 'system/get-all-keys.php';
|
||||||
|
require_once 'system/get-stats.php';
|
||||||
require_once 'system/delete-all-users.php';
|
require_once 'system/delete-all-users.php';
|
||||||
require_once 'system/csv-import.php';
|
require_once 'system/csv-import.php';
|
||||||
require_once 'system/backup-database.php';
|
require_once 'system/backup-database.php';
|
||||||
|
@ -43,5 +45,7 @@ $systemControllerGroup->addController(new DeleteAllUsersController);
|
||||||
$systemControllerGroup->addController(new BackupDatabaseController);
|
$systemControllerGroup->addController(new BackupDatabaseController);
|
||||||
$systemControllerGroup->addController(new DownloadController);
|
$systemControllerGroup->addController(new DownloadController);
|
||||||
$systemControllerGroup->addController(new CSVImportController);
|
$systemControllerGroup->addController(new CSVImportController);
|
||||||
|
$systemControllerGroup->addController(new DisableUserSystemController);
|
||||||
|
$systemControllerGroup->addController(new EnabledUserSystemController);
|
||||||
|
|
||||||
$systemControllerGroup->finalize();
|
$systemControllerGroup->finalize();
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class DisableUserSystemController extends Controller {
|
||||||
|
const PATH = '/disable-user-system';
|
||||||
|
|
||||||
|
public function validations() {
|
||||||
|
return [
|
||||||
|
'permission' => 'staff_3',
|
||||||
|
'requestData' => []
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handler() {
|
||||||
|
$password = Controller::request('password');
|
||||||
|
|
||||||
|
if(!Hashing::verifyPassword($password, Controller::getLoggedUser()->password)) {
|
||||||
|
throw new Exception(ERRORS::INVALID_PASSWORD);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Controller::isUserSystemEnabled()) {
|
||||||
|
throw new Exception(ERRORS::SYSTEM_USER_IS_ALREADY_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
$userSystemEnabled = Setting::getSetting('user-system-enabled');
|
||||||
|
$userSystemEnabled->value = 0 ;
|
||||||
|
$userSystemEnabled->store();
|
||||||
|
|
||||||
|
$userList = User::getAll();
|
||||||
|
|
||||||
|
foreach($userList as $user) {
|
||||||
|
$ticketNumberList = [];
|
||||||
|
|
||||||
|
foreach($user->sharedTicketList as $ticket) {
|
||||||
|
$ticket->authorEmail = $user->email;
|
||||||
|
$ticket->authorName = $user->name;
|
||||||
|
$ticket->author = null;
|
||||||
|
|
||||||
|
$ticketNumberList[] = $ticket->ticketNumber;
|
||||||
|
$ticket->store();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mailSender = new MailSender();
|
||||||
|
|
||||||
|
$mailSender->setTemplate(MailTemplate::USER_SYSTEM_DISABLED, [
|
||||||
|
'to' => $user->email,
|
||||||
|
'name' => $user->name,
|
||||||
|
'tickets' => json_encode($ticketNumberList)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$mailSender->send();
|
||||||
|
|
||||||
|
$user->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
Response::respondSuccess();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class EnabledUserSystemController extends Controller {
|
||||||
|
const PATH = '/enabled-user-system';
|
||||||
|
|
||||||
|
public function validations() {
|
||||||
|
return [
|
||||||
|
'permission' => 'staff_3',
|
||||||
|
'requestData' => []
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handler() {
|
||||||
|
$password = Controller::request('password');
|
||||||
|
|
||||||
|
if(!Hashing::verifyPassword($password, Controller::getLoggedUser()->password)) {
|
||||||
|
throw new Exception(ERRORS::INVALID_PASSWORD);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Controller::isUserSystemEnabled()) {
|
||||||
|
throw new Exception(ERRORS::SYSTEM_USER_IS_ALREADY_ENABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
$userSystemEnabled = Setting::getSetting('user-system-enabled');
|
||||||
|
$userSystemEnabled->value = 1 ;
|
||||||
|
$userSystemEnabled->store();
|
||||||
|
|
||||||
|
$ticketList = Ticket::getAll();
|
||||||
|
|
||||||
|
foreach($ticketList as $ticket) {
|
||||||
|
|
||||||
|
$userRow = User::getDataStore($ticket->authorEmail, 'email');
|
||||||
|
|
||||||
|
if($userRow->isNull()) {
|
||||||
|
$this->createUser($ticket->authorEmail,$ticket->authorName);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$userRow->tickets = $userRow->tickets + 1;
|
||||||
|
$userRow->sharedTicketList->add($ticket);
|
||||||
|
$userRow->store();
|
||||||
|
}
|
||||||
|
|
||||||
|
$actualUserRow = User::getDataStore($ticket->authorEmail,'email');
|
||||||
|
$ticket->author = $actualUserRow;
|
||||||
|
$ticket->authorName = null;
|
||||||
|
$ticket->authorEmail = null;
|
||||||
|
$ticket->store();
|
||||||
|
}
|
||||||
|
|
||||||
|
Response::respondSuccess();
|
||||||
|
}
|
||||||
|
public function createUser($email,$name) {
|
||||||
|
$userInstance = new User();
|
||||||
|
|
||||||
|
$password = Hashing::generateRandomToken();
|
||||||
|
|
||||||
|
$userInstance->setProperties([
|
||||||
|
'name' => $name,
|
||||||
|
'signupDate' => Date::getCurrentDate(),
|
||||||
|
'tickets' => 1,
|
||||||
|
'email' => $email,
|
||||||
|
'password' => Hashing::hashPassword($password),
|
||||||
|
'verificationToken' => null
|
||||||
|
]);
|
||||||
|
|
||||||
|
$userInstance->store();
|
||||||
|
|
||||||
|
$mailSender = new MailSender();
|
||||||
|
$mailSender->setTemplate(MailTemplate::USER_SYSTEM_ENABLED, [
|
||||||
|
'to' => $email,
|
||||||
|
'name' => $name,
|
||||||
|
'password' => $password
|
||||||
|
]);
|
||||||
|
$mailSender->send();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,7 +46,8 @@ class GetSettingsController extends Controller {
|
||||||
'registration' => Setting::getSetting('registration')->getValue(),
|
'registration' => Setting::getSetting('registration')->getValue(),
|
||||||
'departments' => Department::getDepartmentNames(),
|
'departments' => Department::getDepartmentNames(),
|
||||||
'supportedLanguages' => Language::getSupportedLanguages(),
|
'supportedLanguages' => Language::getSupportedLanguages(),
|
||||||
'allowedLanguages' => Language::getAllowedLanguages()
|
'allowedLanguages' => Language::getAllowedLanguages(),
|
||||||
|
'user-system-enabled' => Setting::getSetting('user-system-enabled')->getValue()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ class InitSettingsController extends Controller {
|
||||||
'title' => 'Support Center',
|
'title' => 'Support Center',
|
||||||
'url' => 'http://www.opensupports.com/support',
|
'url' => 'http://www.opensupports.com/support',
|
||||||
'registration' => true,
|
'registration' => true,
|
||||||
|
'user-system-enabled' => true,
|
||||||
'last-stat-day' => '20170101', //TODO: get current date
|
'last-stat-day' => '20170101', //TODO: get current date
|
||||||
'ticket-gap' => Hashing::generateRandomPrime(100000, 999999),
|
'ticket-gap' => Hashing::generateRandomPrime(100000, 999999),
|
||||||
'file-gap' => Hashing::generateRandomPrime(100000, 999999),
|
'file-gap' => Hashing::generateRandomPrime(100000, 999999),
|
||||||
|
|
|
@ -9,7 +9,7 @@ class CommentController extends Controller {
|
||||||
private $content;
|
private $content;
|
||||||
|
|
||||||
public function validations() {
|
public function validations() {
|
||||||
return [
|
$validations = [
|
||||||
'permission' => 'user',
|
'permission' => 'user',
|
||||||
'requestData' => [
|
'requestData' => [
|
||||||
'content' => [
|
'content' => [
|
||||||
|
@ -22,13 +22,23 @@ class CommentController extends Controller {
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if(!Controller::isUserSystemEnabled()) {
|
||||||
|
$validations['permission'] = 'any';
|
||||||
|
$validations['requestData']['email'] = [
|
||||||
|
'validation' => DataValidator::email(),
|
||||||
|
'error' => ERRORS::INVALID_EMAIL
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $validations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handler() {
|
public function handler() {
|
||||||
$session = Session::getInstance();
|
$session = Session::getInstance();
|
||||||
$this->requestData();
|
$this->requestData();
|
||||||
|
|
||||||
if ($session->isLoggedWithId($this->ticket->author->id) || Controller::isStaffLogged()) {
|
if (!Controller::isUserSystemEnabled() || $session->isLoggedWithId($this->ticket->author->id) || Controller::isStaffLogged()) {
|
||||||
$this->storeComment();
|
$this->storeComment();
|
||||||
|
|
||||||
Log::createLog('COMMENT', $this->ticket->ticketNumber);
|
Log::createLog('COMMENT', $this->ticket->ticketNumber);
|
||||||
|
@ -41,9 +51,13 @@ class CommentController extends Controller {
|
||||||
|
|
||||||
private function requestData() {
|
private function requestData() {
|
||||||
$ticketNumber = Controller::request('ticketNumber');
|
$ticketNumber = Controller::request('ticketNumber');
|
||||||
|
$email = Controller::request('email');
|
||||||
$this->ticket = Ticket::getByTicketNumber($ticketNumber);
|
$this->ticket = Ticket::getByTicketNumber($ticketNumber);
|
||||||
$this->content = Controller::request('content');
|
$this->content = Controller::request('content');
|
||||||
|
|
||||||
|
if(!Controller::isUserSystemEnabled() && $this->ticket->authorEmail !== $email && !Controller::isStaffLogged()) {
|
||||||
|
throw new Exception(ERRORS::NO_PERMISSION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function storeComment() {
|
private function storeComment() {
|
||||||
|
@ -59,7 +73,7 @@ class CommentController extends Controller {
|
||||||
if(Controller::isStaffLogged()) {
|
if(Controller::isStaffLogged()) {
|
||||||
$this->ticket->unread = true;
|
$this->ticket->unread = true;
|
||||||
$comment->authorStaff = Controller::getLoggedUser();
|
$comment->authorStaff = Controller::getLoggedUser();
|
||||||
} else {
|
} else if(Controller::isUserSystemEnabled()) {
|
||||||
$this->ticket->unreadStaff = true;
|
$this->ticket->unreadStaff = true;
|
||||||
$comment->authorUser = Controller::getLoggedUser();
|
$comment->authorUser = Controller::getLoggedUser();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,11 @@ class CreateController extends Controller {
|
||||||
private $departmentId;
|
private $departmentId;
|
||||||
private $language;
|
private $language;
|
||||||
private $ticketNumber;
|
private $ticketNumber;
|
||||||
|
private $email;
|
||||||
|
private $name;
|
||||||
|
|
||||||
public function validations() {
|
public function validations() {
|
||||||
return [
|
$validations = [
|
||||||
'permission' => 'user',
|
'permission' => 'user',
|
||||||
'requestData' => [
|
'requestData' => [
|
||||||
'title' => [
|
'title' => [
|
||||||
|
@ -33,6 +35,16 @@ class CreateController extends Controller {
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if(!Controller::isUserSystemEnabled()) {
|
||||||
|
$validations['permission'] = 'any';
|
||||||
|
$validations['requestData']['captcha'] = [
|
||||||
|
'validation' => DataValidator::captcha(),
|
||||||
|
'error' => ERRORS::INVALID_CAPTCHA
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $validations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handler() {
|
public function handler() {
|
||||||
|
@ -40,6 +52,8 @@ class CreateController extends Controller {
|
||||||
$this->content = Controller::request('content');
|
$this->content = Controller::request('content');
|
||||||
$this->departmentId = Controller::request('departmentId');
|
$this->departmentId = Controller::request('departmentId');
|
||||||
$this->language = Controller::request('language');
|
$this->language = Controller::request('language');
|
||||||
|
$this->email = Controller::request('email');
|
||||||
|
$this->name = Controller::request('name');
|
||||||
|
|
||||||
$this->storeTicket();
|
$this->storeTicket();
|
||||||
|
|
||||||
|
@ -67,12 +81,17 @@ class CreateController extends Controller {
|
||||||
'unread' => false,
|
'unread' => false,
|
||||||
'unreadStaff' => true,
|
'unreadStaff' => true,
|
||||||
'closed' => false,
|
'closed' => false,
|
||||||
|
'authorName' => $this->name,
|
||||||
|
'authorEmail' => $this->email
|
||||||
));
|
));
|
||||||
|
|
||||||
$author->sharedTicketList->add($ticket);
|
if(Controller::isUserSystemEnabled()) {
|
||||||
$author->tickets++;
|
$author->sharedTicketList->add($ticket);
|
||||||
|
$author->tickets++;
|
||||||
|
|
||||||
|
$author->store();
|
||||||
|
}
|
||||||
|
|
||||||
$author->store();
|
|
||||||
$ticket->store();
|
$ticket->store();
|
||||||
|
|
||||||
$this->ticketNumber = $ticket->ticketNumber;
|
$this->ticketNumber = $ticket->ticketNumber;
|
||||||
|
|
|
@ -8,7 +8,7 @@ class TicketGetController extends Controller {
|
||||||
private $ticket;
|
private $ticket;
|
||||||
|
|
||||||
public function validations() {
|
public function validations() {
|
||||||
return [
|
$validations = [
|
||||||
'permission' => 'user',
|
'permission' => 'user',
|
||||||
'requestData' => [
|
'requestData' => [
|
||||||
'ticketNumber' => [
|
'ticketNumber' => [
|
||||||
|
@ -17,13 +17,38 @@ class TicketGetController extends Controller {
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if(!Controller::isUserSystemEnabled() && !Controller::isStaffLogged()) {
|
||||||
|
$validations['permission'] = 'any';
|
||||||
|
$validations['requestData']['email'] = [
|
||||||
|
'validation' => DataValidator::email(),
|
||||||
|
'error' => ERRORS::INVALID_EMAIL
|
||||||
|
];
|
||||||
|
$validations['requestData']['captcha'] = [
|
||||||
|
'validation' => DataValidator::captcha(),
|
||||||
|
'error' => ERRORS::INVALID_CAPTCHA
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $validations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handler() {
|
public function handler() {
|
||||||
|
$email = Controller::request('email');
|
||||||
|
|
||||||
$this->ticket = Ticket::getByTicketNumber(Controller::request('ticketNumber'));
|
$this->ticket = Ticket::getByTicketNumber(Controller::request('ticketNumber'));
|
||||||
|
|
||||||
|
if(!Controller::isUserSystemEnabled() && !Controller::isStaffLogged()) {
|
||||||
|
if($this->ticket->authorEmail === $email) {
|
||||||
|
Response::respondSuccess($this->ticket->toArray());
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
throw new Exception(ERRORS::NO_PERMISSION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->shouldDenyPermission()) {
|
if ($this->shouldDenyPermission()) {
|
||||||
Response::respondError(ERRORS::NO_PERMISSION);
|
throw new Exception(ERRORS::NO_PERMISSION);
|
||||||
} else {
|
} else {
|
||||||
Response::respondSuccess($this->ticket->toArray());
|
Response::respondSuccess($this->ticket->toArray());
|
||||||
}
|
}
|
||||||
|
@ -32,7 +57,7 @@ class TicketGetController extends Controller {
|
||||||
private function shouldDenyPermission() {
|
private function shouldDenyPermission() {
|
||||||
$user = Controller::getLoggedUser();
|
$user = Controller::getLoggedUser();
|
||||||
|
|
||||||
return (!Controller::isStaffLogged() && $this->ticket->author->id !== $user->id) ||
|
return (!Controller::isStaffLogged() && (Controller::isUserSystemEnabled() && $this->ticket->author->id !== $user->id)) ||
|
||||||
(Controller::isStaffLogged() && $this->ticket->owner && $this->ticket->owner->id !== $user->id);
|
(Controller::isStaffLogged() && $this->ticket->owner && $this->ticket->owner->id !== $user->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,6 +20,10 @@ class DeleteUserController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handler() {
|
public function handler() {
|
||||||
|
if(!Controller::isUserSystemEnabled()) {
|
||||||
|
throw new Exception(ERRORS::USER_SYSTEM_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
$userId = Controller::request('userId');
|
$userId = Controller::request('userId');
|
||||||
$user = User::getDataStore($userId);
|
$user = User::getDataStore($userId);
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,11 @@ class GetUserByIdController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handler() {
|
public function handler() {
|
||||||
|
|
||||||
|
if(!Controller::isUserSystemEnabled()) {
|
||||||
|
throw new Exception(ERRORS::USER_SYSTEM_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
$userId = Controller::request('userId');
|
$userId = Controller::request('userId');
|
||||||
$user = User::getDataStore($userId);
|
$user = User::getDataStore($userId);
|
||||||
$staff = Controller::getLoggedUser();
|
$staff = Controller::getLoggedUser();
|
||||||
|
|
|
@ -21,6 +21,10 @@ class GetUsersController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handler() {
|
public function handler() {
|
||||||
|
if(!Controller::isUserSystemEnabled()) {
|
||||||
|
throw new Exception(ERRORS::USER_SYSTEM_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
$userList = $this->getUserList();
|
$userList = $this->getUserList();
|
||||||
$userListArray = [];
|
$userListArray = [];
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,12 @@ class LoginController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handler() {
|
public function handler() {
|
||||||
|
if(!Controller::isUserSystemEnabled() && !Controller::request('staff')) {
|
||||||
|
throw new Exception(ERRORS::USER_SYSTEM_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->isAlreadyLoggedIn()) {
|
if ($this->isAlreadyLoggedIn()) {
|
||||||
Response::respondError(ERRORS::SESSION_EXISTS);
|
throw new Exception(ERRORS::SESSION_EXISTS);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->checkInputCredentials() || $this->checkRememberToken()) {
|
if ($this->checkInputCredentials() || $this->checkRememberToken()) {
|
||||||
|
|
|
@ -27,6 +27,10 @@ class RecoverPasswordController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handler() {
|
public function handler() {
|
||||||
|
if(!Controller::isUserSystemEnabled()) {
|
||||||
|
throw new Exception(ERRORS::USER_SYSTEM_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
$this->requestData();
|
$this->requestData();
|
||||||
$this->changePassword();
|
$this->changePassword();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,10 @@ class SendRecoverPasswordController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handler() {
|
public function handler() {
|
||||||
|
if(!Controller::isUserSystemEnabled()) {
|
||||||
|
throw new Exception(ERRORS::USER_SYSTEM_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
$email = Controller::request('email');
|
$email = Controller::request('email');
|
||||||
$this->user = User::getUser($email,'email');
|
$this->user = User::getUser($email,'email');
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,10 @@ class SignUpController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handler() {
|
public function handler() {
|
||||||
|
if(!Controller::isUserSystemEnabled()) {
|
||||||
|
throw new Exception(ERRORS::USER_SYSTEM_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
$this->storeRequestData();
|
$this->storeRequestData();
|
||||||
$apiKey = APIKey::getDataStore(Controller::request('apiKey'), 'token');
|
$apiKey = APIKey::getDataStore(Controller::request('apiKey'), 'token');
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,10 @@ class VerifyController extends Controller{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handler() {
|
public function handler() {
|
||||||
|
if(!Controller::isUserSystemEnabled()) {
|
||||||
|
throw new Exception(ERRORS::USER_SYSTEM_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
$email = Controller::request('email');
|
$email = Controller::request('email');
|
||||||
$token = Controller::request('token');
|
$token = Controller::request('token');
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,9 @@ class ERRORS {
|
||||||
const INVALID_TEMPLATE = 'INVALID_TEMPLATE';
|
const INVALID_TEMPLATE = 'INVALID_TEMPLATE';
|
||||||
const INVALID_SUBJECT = 'INVALID_SUBJECT';
|
const INVALID_SUBJECT = 'INVALID_SUBJECT';
|
||||||
const INVALID_BODY = 'INVALID_BODY';
|
const INVALID_BODY = 'INVALID_BODY';
|
||||||
|
const USER_SYSTEM_DISABLED = 'USER_SYSTEM_DISABLED';
|
||||||
|
const SYSTEM_USER_IS_ALREADY_DISABLED = 'SYSTEM_USER_IS_ALREADY_DISABLED';
|
||||||
|
const SYSTEM_USER_IS_ALREADY_ENABLED = 'SYSTEM_USER_IS_ALREADY_ENABLED';
|
||||||
const INVALID_PERIOD = 'INVALID_PERIOD';
|
const INVALID_PERIOD = 'INVALID_PERIOD';
|
||||||
const NAME_ALREADY_USED = 'NAME_ALREADY_USED';
|
const NAME_ALREADY_USED = 'NAME_ALREADY_USED';
|
||||||
const INVALID_FILE = 'INVALID_FILE';
|
const INVALID_FILE = 'INVALID_FILE';
|
||||||
|
|
|
@ -53,6 +53,26 @@ class InitialMails {
|
||||||
'body' => file_get_contents('data/mail-templates/user-recovered-password-es.html')
|
'body' => file_get_contents('data/mail-templates/user-recovered-password-es.html')
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
'USER_SYSTEM_DISABLED' => [
|
||||||
|
'en' => [
|
||||||
|
'subject' => 'Account has been deleted - OpenSupports',
|
||||||
|
'body' => file_get_contents('data/mail-templates/user-system-disabled-en.html')
|
||||||
|
],
|
||||||
|
'es' => [
|
||||||
|
'subject' => 'cuanta borrada - OpenSupports',
|
||||||
|
'body' => file_get_contents('data/mail-templates/user-system-disabled-es.html')
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'USER_SYSTEM_ENABLED' => [
|
||||||
|
'en' => [
|
||||||
|
'subject' => 'account has been created - OpenSupports',
|
||||||
|
'body' => file_get_contents('data/mail-templates/user-system-enabled-en.html')
|
||||||
|
],
|
||||||
|
'es' => [
|
||||||
|
'subject' => 'se te ha creado una cuenta - OpenSupports',
|
||||||
|
'body' => file_get_contents('data/mail-templates/user-system-enabled-es.html')
|
||||||
|
]
|
||||||
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
<div>
|
||||||
|
Hi {{name}} the system user has been deleted this is the list of your tickets {{tickets}}
|
||||||
|
</div>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<div>
|
||||||
|
hoola {{name}} the system user has been deleted this is the list of your tickets {{tickets}}
|
||||||
|
</div>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<div>
|
||||||
|
hi {{name}} the system user has been Created this is your new password {{password}} , you can change it if you want
|
||||||
|
maxi puto
|
||||||
|
</div>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<div>
|
||||||
|
hoola {{name}} el sistema de usuarios se ha creado este es tu contra {{password}} , puedes cambairla si quieres
|
||||||
|
</div>
|
|
@ -93,4 +93,8 @@ abstract class Controller {
|
||||||
throw new Exception(ERRORS::INVALID_FILE);
|
throw new Exception(ERRORS::INVALID_FILE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function isUserSystemEnabled() {
|
||||||
|
return Setting::getSetting('user-system-enabled')->getValue();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -8,6 +8,8 @@ class MailTemplate extends DataStore {
|
||||||
const USER_PASSWORD = 'USER_PASSWORD';
|
const USER_PASSWORD = 'USER_PASSWORD';
|
||||||
const PASSWORD_FORGOT = 'PASSWORD_FORGOT';
|
const PASSWORD_FORGOT = 'PASSWORD_FORGOT';
|
||||||
const PASSWORD_RECOVERED = 'PASSWORD_RECOVERED';
|
const PASSWORD_RECOVERED = 'PASSWORD_RECOVERED';
|
||||||
|
const USER_SYSTEM_DISABLED = 'USER_SYSTEM_DISABLED';
|
||||||
|
const USER_SYSTEM_ENABLED = 'USER_SYSTEM_ENABLED';
|
||||||
|
|
||||||
public static function getTemplate($type) {
|
public static function getTemplate($type) {
|
||||||
$globalLanguage = Setting::getSetting('language')->value;
|
$globalLanguage = Setting::getSetting('language')->value;
|
||||||
|
|
|
@ -20,7 +20,9 @@ class Ticket extends DataStore {
|
||||||
'owner',
|
'owner',
|
||||||
'ownTicketeventList',
|
'ownTicketeventList',
|
||||||
'unreadStaff',
|
'unreadStaff',
|
||||||
'language'
|
'language',
|
||||||
|
'authorEmail',
|
||||||
|
'authorName'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +81,9 @@ class Ticket extends DataStore {
|
||||||
'priority' => $this->priority,
|
'priority' => $this->priority,
|
||||||
'author' => $this->authorToArray(),
|
'author' => $this->authorToArray(),
|
||||||
'owner' => $this->ownerToArray(),
|
'owner' => $this->ownerToArray(),
|
||||||
'events' => $this->eventsToArray()
|
'events' => $this->eventsToArray(),
|
||||||
|
'authorEmail' => $this->authorEmail,
|
||||||
|
'authorName' => $this->authorName
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ require 'uri'
|
||||||
require 'mysql'
|
require 'mysql'
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'mechanize'
|
require 'mechanize'
|
||||||
require 'date'
|
|
||||||
require './libs.rb'
|
require './libs.rb'
|
||||||
require './scripts.rb'
|
require './scripts.rb'
|
||||||
|
|
||||||
|
@ -60,3 +59,4 @@ require './system/delete-api-key.rb'
|
||||||
require './system/get-all-keys.rb'
|
require './system/get-all-keys.rb'
|
||||||
require './system/file-upload-download.rb'
|
require './system/file-upload-download.rb'
|
||||||
require './system/csv-import.rb'
|
require './system/csv-import.rb'
|
||||||
|
require './system/disable-user-system.rb'
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
describe'system/disable-user-system' do
|
||||||
|
request('/user/logout')
|
||||||
|
Scripts.login($staff[:email], $staff[:password], true)
|
||||||
|
|
||||||
|
it 'should disable the user system' do
|
||||||
|
result = request('/system/disable-user-system', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
password:$staff[:password]
|
||||||
|
})
|
||||||
|
|
||||||
|
puts result['message']
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
|
row = $database.getRow('setting', 'user-system-enabled', 'name')
|
||||||
|
|
||||||
|
(row['value']).should.equal('0')
|
||||||
|
row = $database.getRow('user', 1, 'id')
|
||||||
|
(row).should.equal(nil)
|
||||||
|
|
||||||
|
numberOftickets= $database.query("SELECT * FROM ticket WHERE author_id IS NULL AND author_email IS NOT NULL AND author_name IS NOT NULL")
|
||||||
|
|
||||||
|
(numberOftickets.num_rows).should.equal(35)
|
||||||
|
|
||||||
|
request('/user/logout')
|
||||||
|
|
||||||
|
result = request('/user/signup', {
|
||||||
|
:name => 'test name',
|
||||||
|
:email => 'steve@mail.com',
|
||||||
|
:password => 'customm'
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('fail')
|
||||||
|
(result['message']).should.equal('USER_SYSTEM_DISABLED')
|
||||||
|
|
||||||
|
result = request('/user/login', {
|
||||||
|
email: @loginEmail,
|
||||||
|
password: @loginPass
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('fail')
|
||||||
|
(result['message']).should.equal('USER_SYSTEM_DISABLED')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not disable the user system if it is already disabled 'do
|
||||||
|
request('/user/logout')
|
||||||
|
Scripts.login($staff[:email], $staff[:password], true)
|
||||||
|
|
||||||
|
result = request('/system/disable-user-system', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
password:$staff[:password]
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('fail')
|
||||||
|
(result['message']).should.equal('SYSTEM_USER_IS_ALREADY_DISABLED')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should enabled the user system' do
|
||||||
|
result = request('/system/enabled-user-system', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
password:$staff[:password]
|
||||||
|
})
|
||||||
|
|
||||||
|
puts result['message']
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
|
row = $database.getRow('setting', 'user-system-enabled', 'name')
|
||||||
|
(row['value']).should.equal('1')
|
||||||
|
|
||||||
|
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(35)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not enabled the user system' do
|
||||||
|
result = request('/system/enabled-user-system', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
password:$staff[:password]
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('fail')
|
||||||
|
(result['message']).should.equal('SYSTEM_USER_IS_ALREADY_ENABLED')
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,6 +10,6 @@ describe'system/get-mail-templates' do
|
||||||
|
|
||||||
(result['status']).should.equal('success')
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
(result['data'].size).should.equal(10)
|
(result['data'].size).should.equal(14)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue