mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-28 16:24:42 +02:00
Merge pull request #183 from ivandiazwm/master
Add docker and make support
This commit is contained in:
commit
ce3d2a249b
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,6 +1,9 @@
|
|||||||
server/composer.lock
|
|
||||||
server/vendor
|
|
||||||
.idea
|
.idea
|
||||||
.jshintrc
|
.jshintrc
|
||||||
|
tests/Gemfile.lock
|
||||||
|
server/composer.lock
|
||||||
|
server/vendor
|
||||||
server/files/
|
server/files/
|
||||||
!server/files/.gitkeep
|
!server/files/.gitkeep
|
||||||
|
server/.dbdata
|
||||||
|
server/.fakemail
|
||||||
|
55
README.md
55
README.md
@ -45,48 +45,29 @@ Just as there is a `gulp dev` task for development, there is also a `gulp prod`
|
|||||||
3. Run `npm test` to run the tests.
|
3. Run `npm test` to run the tests.
|
||||||
|
|
||||||
### Getting up and running BACK-END (server folder)
|
### Getting up and running BACK-END (server folder)
|
||||||
|
1. Install [Docker CE](https://docs.docker.com/install/)
|
||||||
|
2. Go to the server folder: `cd opensupports/server`
|
||||||
|
3. Run `make build` to build the images
|
||||||
|
4. Run `make install` to install composer dependencies
|
||||||
|
|
||||||
1. Clone this repo: `git clone https://github.com/opensupports/opensupports.git`
|
- `make run` runs the backend and database
|
||||||
2. [Install PHP 5.6](https://www.dev-metal.com/install-setup-php-5-6-ubuntu-14-04-lts/)
|
- `make stop` stop backend and database server
|
||||||
3. [Create MySQL Database](#markdown-header-create-mysql-database)
|
- `make log` show live server logs
|
||||||
4. [Install composer](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-composer-on-ubuntu-14-04)
|
- `make db` access to mysql database console
|
||||||
5. Go to the server folder: `cd opensupports/server`
|
- `make sh` access to backend docker container bash
|
||||||
6. Run: `composer install`
|
- `make test` run phpunit tests
|
||||||
7. Run the server with: `php -S localhost:8080`
|
|
||||||
|
|
||||||
##### Create MySQL Database
|
Server api runs on `http://localhost:8080/`
|
||||||
|
Also, there's a *phpmyadmin* instance running on `http://localhost:6060/`,
|
||||||
1. Install mysql-server:
|
you can access with the username `root` and empty password
|
||||||
|
|
||||||
Ubuntu
|
|
||||||
|
|
||||||
`sudo apt-get install mysql-server`
|
|
||||||
|
|
||||||
Cent OS
|
|
||||||
|
|
||||||
`sudo yum install mysql-server`
|
|
||||||
`/etc/init.d/mysqld start`
|
|
||||||
|
|
||||||
2. Access the MySQL shell:
|
|
||||||
|
|
||||||
`mysql -u root`
|
|
||||||
|
|
||||||
3. Create a new database:
|
|
||||||
|
|
||||||
`CREATE DATABASE development;`
|
|
||||||
|
|
||||||
4. Run the MySQL server:
|
|
||||||
|
|
||||||
`sudo /etc/init.d/mysql start`
|
|
||||||
|
|
||||||
##### BACKEND API RUBY TESTING
|
##### BACKEND API RUBY TESTING
|
||||||
|
|
||||||
1. Install Ruby: `sudo apt-get install ruby-full`
|
1. Go to tests folder: `cd opensupports/tests`
|
||||||
2. Install MySQL dev dependencies: `sudo apt-get install libmysqlclient-dev libmysqlclient16 ruby-dev`
|
2. Run `make install` to install ruby and its the required dependencies
|
||||||
3. Install bundle: `sudo gem install bundler`
|
|
||||||
4. Go to tests folder: `cd opensupports/tests`
|
- `make run` for running tests (database will be cleared)
|
||||||
5. Install project dependencies: `bundle install`
|
- `make clear` for clearing database
|
||||||
Tests can run by using executing the `run-tests.sh` file.
|
|
||||||
|
|
||||||
##### BACKEND FAKE SMTP SERVER
|
##### BACKEND FAKE SMTP SERVER
|
||||||
If you're doing development, you can use a FakeSMTP server to see the mails that are being sent.
|
If you're doing development, you can use a FakeSMTP server to see the mails that are being sent.
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
import history from 'lib-app/history';
|
import history from 'lib-app/history';
|
||||||
import i18n from 'lib-app/i18n';
|
import i18n from 'lib-app/i18n';
|
||||||
@ -26,6 +27,7 @@ class InstallStep3Database extends React.Component {
|
|||||||
{this.renderMessage()}
|
{this.renderMessage()}
|
||||||
<Form loading={this.state.loading} onSubmit={this.onSubmit.bind(this)}>
|
<Form loading={this.state.loading} onSubmit={this.onSubmit.bind(this)}>
|
||||||
<FormField name="dbHost" label={i18n('DATABASE_HOST')} fieldProps={{size: 'large'}} required/>
|
<FormField name="dbHost" label={i18n('DATABASE_HOST')} fieldProps={{size: 'large'}} required/>
|
||||||
|
<FormField name="dbPort" label={i18n('DATABASE_PORT')} fieldProps={{size: 'large'}} infoMessage={i18n('DEFAULT_PORT')}/>
|
||||||
<FormField name="dbName" label={i18n('DATABASE_NAME')} fieldProps={{size: 'large'}} infoMessage={i18n('LEFT_EMPTY_DATABASE')}/>
|
<FormField name="dbName" label={i18n('DATABASE_NAME')} fieldProps={{size: 'large'}} infoMessage={i18n('LEFT_EMPTY_DATABASE')}/>
|
||||||
<FormField name="dbUser" label={i18n('DATABASE_USER')} fieldProps={{size: 'large'}} required/>
|
<FormField name="dbUser" label={i18n('DATABASE_USER')} fieldProps={{size: 'large'}} required/>
|
||||||
<FormField name="dbPassword" label={i18n('DATABASE_PASSWORD')} fieldProps={{size: 'large', password: true}}/>
|
<FormField name="dbPassword" label={i18n('DATABASE_PASSWORD')} fieldProps={{size: 'large', password: true}}/>
|
||||||
@ -63,7 +65,7 @@ class InstallStep3Database extends React.Component {
|
|||||||
}, () => {
|
}, () => {
|
||||||
API.call({
|
API.call({
|
||||||
path: '/system/init-database',
|
path: '/system/init-database',
|
||||||
data: form
|
data: _.extend({}, form, {dbPort: form.dbPort || 3306})
|
||||||
})
|
})
|
||||||
.then(() => history.push('/install/step-4'))
|
.then(() => history.push('/install/step-4'))
|
||||||
.catch(({message}) => this.setState({
|
.catch(({message}) => this.setState({
|
||||||
@ -75,4 +77,4 @@ class InstallStep3Database extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default InstallStep3Database;
|
export default InstallStep3Database;
|
||||||
|
@ -228,6 +228,7 @@ export default {
|
|||||||
'USER_SYSTEM': 'User System',
|
'USER_SYSTEM': 'User System',
|
||||||
'PREVIOUS': 'Previous',
|
'PREVIOUS': 'Previous',
|
||||||
'DATABASE_HOST': 'MySQL server',
|
'DATABASE_HOST': 'MySQL server',
|
||||||
|
'DATABASE_PORT': 'MySQL server port',
|
||||||
'DATABASE_NAME': 'MySQL database name',
|
'DATABASE_NAME': 'MySQL database name',
|
||||||
'DATABASE_USER': 'MySQL user',
|
'DATABASE_USER': 'MySQL user',
|
||||||
'DATABASE_PASSWORD': 'MySQL password',
|
'DATABASE_PASSWORD': 'MySQL password',
|
||||||
@ -359,6 +360,7 @@ export default {
|
|||||||
'ACTIVITY_PRIORITY_CHANGED_THIS': 'changed priority of this ticket to',
|
'ACTIVITY_PRIORITY_CHANGED_THIS': 'changed priority of this ticket to',
|
||||||
'DATE_PREFIX': 'on',
|
'DATE_PREFIX': 'on',
|
||||||
'LEFT_EMPTY_DATABASE': 'Leave empty for automatic database creation',
|
'LEFT_EMPTY_DATABASE': 'Leave empty for automatic database creation',
|
||||||
|
'DEFAULT_PORT': 'Leave empty for 3306 as default',
|
||||||
'REMEMBER_ME': 'Remember me',
|
'REMEMBER_ME': 'Remember me',
|
||||||
'EMAIL_LOWERCASE': 'email',
|
'EMAIL_LOWERCASE': 'email',
|
||||||
'PASSWORD_LOWERCASE': 'password',
|
'PASSWORD_LOWERCASE': 'password',
|
||||||
|
@ -4,7 +4,7 @@ const SessionStore = require('lib-app/session-store');
|
|||||||
|
|
||||||
function processData (data, dataAsForm = false) {
|
function processData (data, dataAsForm = false) {
|
||||||
let newData;
|
let newData;
|
||||||
|
|
||||||
if(dataAsForm) {
|
if(dataAsForm) {
|
||||||
newData = new FormData();
|
newData = new FormData();
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ function processData (data, dataAsForm = false) {
|
|||||||
csrf_userid: SessionStore.getSessionData().userId
|
csrf_userid: SessionStore.getSessionData().userId
|
||||||
}, data)
|
}, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
return newData;
|
return newData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,16 +48,16 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getFileLink(filePath) {
|
getFileLink(filePath) {
|
||||||
return apiRoot + '/system/download?file=' + filePath;
|
return apiRoot + '/system/download?file=' + filePath;
|
||||||
},
|
},
|
||||||
|
|
||||||
getAPIUrl() {
|
getAPIUrl() {
|
||||||
return apiRoot;
|
return apiRoot;
|
||||||
},
|
},
|
||||||
|
|
||||||
getURL() {
|
getURL() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
2
server/.dockerignore
Normal file
2
server/.dockerignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.dbdata
|
||||||
|
.fakemail
|
16
server/Dockerfile
Normal file
16
server/Dockerfile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
FROM fauria/lamp
|
||||||
|
MAINTAINER Ivan Diaz <ivan@opensupports.com>
|
||||||
|
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install zip unzip php7.0-zip php7.0-mbstring -y && \
|
||||||
|
apt-get remove --yes php7.0-snmp && \
|
||||||
|
(curl -s https://getcomposer.org/installer | php) && \
|
||||||
|
mv composer.phar /usr/local/bin/composer
|
||||||
|
|
||||||
|
RUN echo 'LISTEN 8080' >> /etc/apache2/apache2.conf
|
||||||
|
RUN sed -i "1s/.*/<VirtualHost *:8080>/" /etc/apache2/sites-enabled/000-default.conf
|
||||||
|
RUN sed -i "5s/.*/Listen 8080/" /etc/apache2/ports.conf
|
||||||
|
|
||||||
|
# ENVIRONMENT VARIABLES
|
||||||
|
ENV MYSQL_HOST 127.0.0.1
|
||||||
|
ENV MYSQL_PORT 4040
|
37
server/Makefile
Normal file
37
server/Makefile
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
red=`tput setaf 1`
|
||||||
|
yellow=`tput setaf 3`
|
||||||
|
reset=`tput sgr0`
|
||||||
|
|
||||||
|
build:
|
||||||
|
@docker pull mysql:5.6
|
||||||
|
@docker pull phpmyadmin/phpmyadmin
|
||||||
|
@docker pull munkyboy/fakesmtp
|
||||||
|
@docker build -t opensupports-srv . || echo "A${red}An error occurred${reset}"
|
||||||
|
|
||||||
|
install:
|
||||||
|
@docker exec -it opensupports-srv bash -c "cd /var/www/html && composer install" || echo "${red}Please execute 'make run' first${reset}" && chmod 777 -R vendor/
|
||||||
|
@docker exec -it opensupports-db bash -c "mysql -u root -e \"CREATE DATABASE IF NOT EXISTS development;\" " || echo "${red}Please execute 'make run' first${reset}"
|
||||||
|
|
||||||
|
run:
|
||||||
|
@docker run -d --name opensupports-db -p 4040:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -v $(PWD)/.dbdata/:/var/lib/mysql mysql:5.6
|
||||||
|
@docker run -d --name opensupports-myadmin --link opensupports-db:db -p 6060:80 phpmyadmin/phpmyadmin
|
||||||
|
@docker run -d --name opensupports-fakesmtp -p 7070:25 -v ${PWD}/.fakemail/:/var/mail munkyboy/fakesmtp
|
||||||
|
@docker run -d --name opensupports-srv --net=host --rm -e LOG_STDOUT=true -e LOG_STDERR=true -e LOG_LEVEL=debug -v ${PWD}:/var/www/html opensupports-srv
|
||||||
|
|
||||||
|
test:
|
||||||
|
@./run-tests.sh
|
||||||
|
|
||||||
|
log:
|
||||||
|
@docker attach opensupports-srv || echo "${red}Please execute 'make run' first${reset}"
|
||||||
|
|
||||||
|
stop:
|
||||||
|
@docker stop opensupports-db && docker rm opensupports-db || true
|
||||||
|
@docker stop opensupports-myadmin && docker rm opensupports-myadmin || true
|
||||||
|
@docker stop opensupports-fakesmtp && docker rm opensupports-fakesmtp || true
|
||||||
|
@docker stop opensupports-srv
|
||||||
|
|
||||||
|
db:
|
||||||
|
@docker exec -it opensupports-db bash -c "mysql -u root" || echo "${red}Please execute 'make run' first${reset}"
|
||||||
|
|
||||||
|
sh:
|
||||||
|
@docker exec -it opensupports-srv bash
|
@ -1,16 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
$env['MYSQL_SERVER'] = getenv('MYSQL_SERVER');
|
$env['MYSQL_HOST'] = getenv('MYSQL_HOST');
|
||||||
|
$env['MYSQL_PORT'] = getenv('MYSQL_PORT');
|
||||||
$env['MYSQL_USER'] = getenv('MYSQL_USER');
|
$env['MYSQL_USER'] = getenv('MYSQL_USER');
|
||||||
$env['MYSQL_PASSWORD'] = getenv('MYSQL_PASSWORD');
|
$env['MYSQL_PASSWORD'] = getenv('MYSQL_PASSWORD');
|
||||||
$env['MYSQL_DATABASE'] = getenv('MYSQL_DATABASE');
|
$env['MYSQL_DATABASE'] = getenv('MYSQL_DATABASE');
|
||||||
|
|
||||||
$mysql_host = ($env['MYSQL_SERVER']) ? $env['MYSQL_SERVER'] : 'localhost';
|
$mysql_host = ($env['MYSQL_HOST']) ? $env['MYSQL_HOST'] : 'localhost';
|
||||||
|
$mysql_port = ($env['MYSQL_PORT']) ? $env['MYSQL_PORT'] : '3306';
|
||||||
$mysql_user = ($env['MYSQL_USER']) ? $env['MYSQL_USER'] : 'root';
|
$mysql_user = ($env['MYSQL_USER']) ? $env['MYSQL_USER'] : 'root';
|
||||||
$mysql_password = ($env['MYSQL_PASSWORD']) ? $env['MYSQL_PASSWORD'] : '';
|
$mysql_password = ($env['MYSQL_PASSWORD']) ? $env['MYSQL_PASSWORD'] : '';
|
||||||
$mysql_database = ($env['MYSQL_DATABASE']) ? $env['MYSQL_DATABASE'] : 'development';
|
$mysql_database = ($env['MYSQL_DATABASE']) ? $env['MYSQL_DATABASE'] : 'development';
|
||||||
|
|
||||||
define('MYSQL_HOST', $mysql_host);
|
define('MYSQL_HOST', $mysql_host);
|
||||||
|
define('MYSQL_PORT', $mysql_port);
|
||||||
define('MYSQL_USER', $mysql_user);
|
define('MYSQL_USER', $mysql_user);
|
||||||
define('MYSQL_PASSWORD', $mysql_password);
|
define('MYSQL_PASSWORD', $mysql_password);
|
||||||
define('MYSQL_DATABASE', $mysql_database);
|
define('MYSQL_DATABASE', $mysql_database);
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ DataValidator::with('CustomValidations', true);
|
|||||||
* @apiUse INVALID_TICKET
|
* @apiUse INVALID_TICKET
|
||||||
* @apiUse TICKET_ALREADY_ASSIGNED
|
* @apiUse TICKET_ALREADY_ASSIGNED
|
||||||
* @apiUse INVALID_DEPARTMENT
|
* @apiUse INVALID_DEPARTMENT
|
||||||
*
|
*
|
||||||
* @apiSuccess {Object} data Empty object
|
* @apiSuccess {Object} data Empty object
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -50,12 +50,12 @@ class AssignStaffController extends Controller {
|
|||||||
$this->ticket = Ticket::getByTicketNumber($ticketNumber);
|
$this->ticket = Ticket::getByTicketNumber($ticketNumber);
|
||||||
|
|
||||||
if($this->ticket->owner) {
|
if($this->ticket->owner) {
|
||||||
Response::respondError(ERRORS::TICKET_ALREADY_ASSIGNED);
|
throw new Exception(ERRORS::TICKET_ALREADY_ASSIGNED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->ticketHasStaffDepartment()) {
|
if(!$this->ticketHasStaffDepartment()) {
|
||||||
Response::respondError(ERRORS::INVALID_DEPARTMENT);
|
throw new Exception(ERRORS::INVALID_DEPARTMENT);
|
||||||
} else {
|
} else {
|
||||||
$this->user->sharedTicketList->add($this->ticket);
|
$this->user->sharedTicketList->add($this->ticket);
|
||||||
$this->ticket->owner = $this->user;
|
$this->ticket->owner = $this->user;
|
||||||
|
@ -43,26 +43,26 @@ class UnAssignStaffController extends Controller {
|
|||||||
$ticketNumber = Controller::request('ticketNumber');
|
$ticketNumber = Controller::request('ticketNumber');
|
||||||
$user = Controller::getLoggedUser();
|
$user = Controller::getLoggedUser();
|
||||||
$ticket = Ticket::getByTicketNumber($ticketNumber);
|
$ticket = Ticket::getByTicketNumber($ticketNumber);
|
||||||
|
$owner = $ticket->owner;
|
||||||
|
|
||||||
|
if(($owner && $owner->id === $user->id) || $user->level > 1) {
|
||||||
|
$owner->sharedTicketList->remove($ticket);
|
||||||
|
$owner->store();
|
||||||
|
|
||||||
if($ticket->owner && $ticket->owner->id == $user->id) {
|
|
||||||
$user->sharedTicketList->remove($ticket);
|
|
||||||
$user->store();
|
|
||||||
|
|
||||||
$ticket->owner = null;
|
$ticket->owner = null;
|
||||||
$ticket->unread = true;
|
$ticket->unread = true;
|
||||||
|
|
||||||
$event = Ticketevent::getEvent(Ticketevent::UN_ASSIGN);
|
$event = Ticketevent::getEvent(Ticketevent::UN_ASSIGN);
|
||||||
$event->setProperties(array(
|
$event->setProperties(array(
|
||||||
'authorStaff' => $user,
|
'authorStaff' => $user,
|
||||||
'date' => Date::getCurrentDate()
|
'date' => Date::getCurrentDate()
|
||||||
));
|
));
|
||||||
|
|
||||||
$ticket->addEvent($event);
|
$ticket->addEvent($event);
|
||||||
$ticket->store();
|
$ticket->store();
|
||||||
Response::respondSuccess();
|
Response::respondSuccess();
|
||||||
} else {
|
} else {
|
||||||
Response::respondError(ERRORS::NO_PERMISSION);
|
throw new Exception(ERRORS::NO_PERMISSION);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,10 @@ class EditSettingsController extends Controller {
|
|||||||
$allowed = json_decode(Controller::request('allowedLanguages'));
|
$allowed = json_decode(Controller::request('allowedLanguages'));
|
||||||
$supported = json_decode(Controller::request('supportedLanguages'));
|
$supported = json_decode(Controller::request('supportedLanguages'));
|
||||||
|
|
||||||
|
if (array_diff($supported, $allowed)) {
|
||||||
|
throw new Exception(ERRORS::INVALID_SUPPORTED_LANGUAGES);
|
||||||
|
}
|
||||||
|
|
||||||
foreach(Language::LANGUAGES as $languageCode) {
|
foreach(Language::LANGUAGES as $languageCode) {
|
||||||
$language = Language::getDataStore($languageCode, 'code');
|
$language = Language::getDataStore($languageCode, 'code');
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ use RedBeanPHP\Facade as RedBean;
|
|||||||
*
|
*
|
||||||
* @apiPermission any
|
* @apiPermission any
|
||||||
*
|
*
|
||||||
* @apiParam {String} dbHost Url of the database server.
|
* @apiParam {String} dbHost Location of the database server.
|
||||||
|
* @apiParam {String} dbPort Port of the database server.
|
||||||
* @apiParam {String} dbName Name of the database. If not given, the system will try to create one.
|
* @apiParam {String} dbName Name of the database. If not given, the system will try to create one.
|
||||||
* @apiParam {String} dbUser User of the database server.
|
* @apiParam {String} dbUser User of the database server.
|
||||||
* @apiParam {String} dbPassword Password of the database server.
|
* @apiParam {String} dbPassword Password of the database server.
|
||||||
@ -44,14 +45,15 @@ class InitDatabaseController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$dbHost = Controller::request('dbHost');
|
$dbHost = Controller::request('dbHost');
|
||||||
|
$dbPort = Controller::request('dbPort');
|
||||||
$dbName = Controller::request('dbName');
|
$dbName = Controller::request('dbName');
|
||||||
$dbUser = Controller::request('dbUser');
|
$dbUser = Controller::request('dbUser');
|
||||||
$dbPass = Controller::request('dbPassword');
|
$dbPass = Controller::request('dbPassword');
|
||||||
|
|
||||||
RedBean::setup('mysql:host=' . $dbHost, $dbUser, $dbPass);
|
RedBean::setup("mysql:host=$dbHost;port=$dbPort", $dbUser, $dbPass);
|
||||||
|
|
||||||
if($dbName) {
|
if($dbName) {
|
||||||
RedBean::addDatabase($dbName, 'mysql:host='. $dbHost . ';dbname=' . $dbName, $dbUser, $dbPass);
|
RedBean::addDatabase($dbName, "mysql:host=$dbHost;port=$dbPort;dbname=$dbName", $dbUser, $dbPass);
|
||||||
RedBean::selectDatabase($dbName);
|
RedBean::selectDatabase($dbName);
|
||||||
|
|
||||||
if(!RedBean::testConnection()) {
|
if(!RedBean::testConnection()) {
|
||||||
@ -60,7 +62,7 @@ class InitDatabaseController extends Controller {
|
|||||||
} else {
|
} else {
|
||||||
$dbName = 'opensupports_' . Hashing::generateRandomNumber(100, 999);
|
$dbName = 'opensupports_' . Hashing::generateRandomNumber(100, 999);
|
||||||
RedBean::exec('CREATE DATABASE ' . $dbName);
|
RedBean::exec('CREATE DATABASE ' . $dbName);
|
||||||
RedBean::addDatabase($dbName, 'mysql:host='. $dbHost . ';dbname=' . $dbName, $dbUser, $dbPass);
|
RedBean::addDatabase($dbName, "mysql:host=$dbHost;port=$dbPort;dbname=$dbName", $dbUser, $dbPass);
|
||||||
RedBean::selectDatabase($dbName);
|
RedBean::selectDatabase($dbName);
|
||||||
|
|
||||||
if(!RedBean::testConnection()) {
|
if(!RedBean::testConnection()) {
|
||||||
@ -71,6 +73,7 @@ class InitDatabaseController extends Controller {
|
|||||||
$configFile = fopen('config.php', 'w+') or die(ERRORS::INVALID_FILE);
|
$configFile = fopen('config.php', 'w+') or die(ERRORS::INVALID_FILE);
|
||||||
$content = '<?php' . PHP_EOL;
|
$content = '<?php' . PHP_EOL;
|
||||||
$content .= 'define(\'MYSQL_HOST\', \'' . $dbHost . '\');' . PHP_EOL;
|
$content .= 'define(\'MYSQL_HOST\', \'' . $dbHost . '\');' . PHP_EOL;
|
||||||
|
$content .= 'define(\'MYSQL_PORT\', \'' . $dbPort . '\');' . PHP_EOL;
|
||||||
$content .= 'define(\'MYSQL_USER\', \'' . $dbUser . '\');' . PHP_EOL;
|
$content .= 'define(\'MYSQL_USER\', \'' . $dbUser . '\');' . PHP_EOL;
|
||||||
$content .= 'define(\'MYSQL_PASSWORD\', \'' . $dbPass . '\');' . PHP_EOL;
|
$content .= 'define(\'MYSQL_PASSWORD\', \'' . $dbPass . '\');' . PHP_EOL;
|
||||||
$content .= 'define(\'MYSQL_DATABASE\', \'' . $dbName . '\');' . PHP_EOL;
|
$content .= 'define(\'MYSQL_DATABASE\', \'' . $dbName . '\');' . PHP_EOL;
|
||||||
|
@ -52,25 +52,27 @@ class ChangeDepartmentController extends Controller {
|
|||||||
$department = Department::getDataStore($departmentId);
|
$department = Department::getDataStore($departmentId);
|
||||||
$user = Controller::getLoggedUser();
|
$user = Controller::getLoggedUser();
|
||||||
|
|
||||||
if($ticket->owner && $ticket->owner->id !== $user->id){
|
if($ticket->owner && $ticket->owner->id !== $user->id && $user->level == 1){
|
||||||
Response::respondError(ERRORS::NO_PERMISSION);
|
throw new Exception(ERRORS::NO_PERMISSION);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$event = Ticketevent::getEvent(Ticketevent::DEPARTMENT_CHANGED);
|
$event = Ticketevent::getEvent(Ticketevent::DEPARTMENT_CHANGED);
|
||||||
$event->setProperties(array(
|
$event->setProperties(array(
|
||||||
'authorStaff' => Controller::getLoggedUser(),
|
'authorStaff' => $user,
|
||||||
'content' => $department->name,
|
'content' => $department->name,
|
||||||
'date' => Date::getCurrentDate()
|
'date' => Date::getCurrentDate()
|
||||||
));
|
));
|
||||||
$ticket->addEvent($event);
|
$ticket->addEvent($event);
|
||||||
$ticket->department = $department;
|
$ticket->department = $department;
|
||||||
$ticket->unread = true;
|
$ticket->unread = true;
|
||||||
if(!Controller::getLoggedUser()->sharedDepartmentList->includesId($department->id)) {
|
|
||||||
$ticket->owner = null;
|
|
||||||
}
|
|
||||||
$ticket->store();
|
$ticket->store();
|
||||||
|
|
||||||
|
if(!$user->sharedDepartmentList->includesId($department->id)) {
|
||||||
|
$unAssignTicketController = new UnAssignStaffController();
|
||||||
|
$unAssignTicketController->validate();
|
||||||
|
$unAssignTicketController->handler();
|
||||||
|
}
|
||||||
|
|
||||||
Log::createLog('DEPARTMENT_CHANGED', $ticket->ticketNumber);
|
Log::createLog('DEPARTMENT_CHANGED', $ticket->ticketNumber);
|
||||||
|
|
||||||
Response::respondSuccess();
|
Response::respondSuccess();
|
||||||
|
@ -18,9 +18,9 @@ DataValidator::with('CustomValidations', true);
|
|||||||
* @apiUse INVALID_TICKET
|
* @apiUse INVALID_TICKET
|
||||||
* @apiUse INVALID_TOKEN
|
* @apiUse INVALID_TOKEN
|
||||||
* @apiUse NO_PERMISSION
|
* @apiUse NO_PERMISSION
|
||||||
*
|
*
|
||||||
* @apiSuccess {[Ticket](#api-Data_Structures-ObjectTicket)} data Information about the requested ticket.
|
* @apiSuccess {[Ticket](#api-Data_Structures-ObjectTicket)} data Information about the requested ticket.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -78,6 +78,6 @@ class TicketGetController extends Controller {
|
|||||||
$user = Controller::getLoggedUser();
|
$user = Controller::getLoggedUser();
|
||||||
|
|
||||||
return (!Controller::isStaffLogged() && (Controller::isUserSystemEnabled() && $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) || !$user->sharedDepartmentList->includesId($this->ticket->department->id)));
|
(Controller::isStaffLogged() && (($this->ticket->owner && $this->ticket->owner->id !== $user->id) && !$user->sharedDepartmentList->includesId($this->ticket->department->id)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,6 +194,7 @@ class ERRORS {
|
|||||||
const INVALID_CAPTCHA = 'INVALID_CAPTCHA';
|
const INVALID_CAPTCHA = 'INVALID_CAPTCHA';
|
||||||
const INVALID_TICKET_EVENT = 'INVALID_TICKET_EVENT';
|
const INVALID_TICKET_EVENT = 'INVALID_TICKET_EVENT';
|
||||||
const INVALID_LANGUAGE = 'INVALID_LANGUAGE';
|
const INVALID_LANGUAGE = 'INVALID_LANGUAGE';
|
||||||
|
const INVALID_SUPPORTED_LANGUAGES = 'INVALID_SUPPORTED_LANGUAGES';
|
||||||
const TICKET_ALREADY_ASSIGNED = 'TICKET_ALREADY_ASSIGNED';
|
const TICKET_ALREADY_ASSIGNED = 'TICKET_ALREADY_ASSIGNED';
|
||||||
const INVALID_PRIORITY = 'INVALID_PRIORITY';
|
const INVALID_PRIORITY = 'INVALID_PRIORITY';
|
||||||
const INVALID_PAGE = 'INVALID_PAGE';
|
const INVALID_PAGE = 'INVALID_PAGE';
|
||||||
|
@ -6,7 +6,8 @@ require_once 'vendor/autoload.php';
|
|||||||
use RedBeanPHP\Facade as RedBean;
|
use RedBeanPHP\Facade as RedBean;
|
||||||
|
|
||||||
if(defined('MYSQL_HOST') && defined('MYSQL_DATABASE') && defined('MYSQL_USER') && defined('MYSQL_PASSWORD')) {
|
if(defined('MYSQL_HOST') && defined('MYSQL_DATABASE') && defined('MYSQL_USER') && defined('MYSQL_PASSWORD')) {
|
||||||
RedBean::setup('mysql:host='. MYSQL_HOST .';dbname=' . MYSQL_DATABASE , MYSQL_USER, MYSQL_PASSWORD);
|
if(!defined('MYSQL_PORT')) define('MYSQL_PORT', '3306');
|
||||||
|
RedBean::setup('mysql:host='. MYSQL_HOST . ';port=' . MYSQL_PORT . ';dbname=' . MYSQL_DATABASE , MYSQL_USER, MYSQL_PASSWORD);
|
||||||
RedBean::setAutoResolve(true);
|
RedBean::setAutoResolve(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,15 +31,15 @@ class Validator {
|
|||||||
$requestDataValue = Controller::request($requestDataKey);
|
$requestDataValue = Controller::request($requestDataKey);
|
||||||
$requestDataValidator = $requestDataValidationConfig['validation'];
|
$requestDataValidator = $requestDataValidationConfig['validation'];
|
||||||
$requestDataValidationErrorMessage = $requestDataValidationConfig['error'];
|
$requestDataValidationErrorMessage = $requestDataValidationConfig['error'];
|
||||||
|
|
||||||
$this->validateData($requestDataValue, $requestDataValidator, $requestDataValidationErrorMessage);
|
$this->validateData($requestDataValue, $requestDataValidator, $requestDataValidationErrorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validateData($value, DataValidator $dataValidator, $error) {
|
private function validateData($value, DataValidator $dataValidator, $error) {
|
||||||
if (!$dataValidator->validate($value)) {
|
if (!$dataValidator->validate($value)) {
|
||||||
throw new ValidationException($error);
|
throw new ValidationException($error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
20
tests/Makefile
Normal file
20
tests/Makefile
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
DB_HOST ?= `docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' opensupports-db`
|
||||||
|
|
||||||
|
install:
|
||||||
|
@apt-get install ruby-full
|
||||||
|
@apt-get install libmysqlclient-dev ruby-dev
|
||||||
|
@gem install bundler
|
||||||
|
@bundle install
|
||||||
|
|
||||||
|
run: export MYSQL_HOST=127.0.0.1
|
||||||
|
run: export MYSQL_PORT=4040
|
||||||
|
run:
|
||||||
|
./run-tests.sh
|
||||||
|
|
||||||
|
|
||||||
|
clear: export MYSQL_HOST=127.0.0.1
|
||||||
|
clear: export MYSQL_PORT=4040
|
||||||
|
clear:
|
||||||
|
./clean_db.sh && \
|
||||||
|
./clean_db.sh && \
|
||||||
|
./clean_db.sh
|
@ -1,9 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# DELETE ALL TABLES
|
# DELETE ALL TABLES
|
||||||
TABLES=$(mysql -u root development -e "SHOW TABLES IN development;" | awk '{ print $1}' | grep -v '^Tables')
|
TABLES=$(mysql --host ${MYSQL_HOST} --port ${MYSQL_PORT} -u root development -e "SHOW TABLES IN development;" | awk '{ print $1}' | grep -v '^Tables')
|
||||||
|
|
||||||
for t in $TABLES
|
for t in $TABLES
|
||||||
do
|
do
|
||||||
mysql -u root development -e "DROP TABLE $t"
|
mysql --host ${MYSQL_HOST} --port ${MYSQL_PORT} -u root development -e "DROP TABLE $t"
|
||||||
done
|
done
|
||||||
|
@ -21,9 +21,11 @@ end
|
|||||||
|
|
||||||
class Database
|
class Database
|
||||||
def initialize()
|
def initialize()
|
||||||
|
mysqlHost = ENV['MYSQL_HOST'] || 'localhost'
|
||||||
|
mysqlPort = ENV['MYSQL_PORT'] || '3306'
|
||||||
mysqlUser = ENV['MYSQL_USER'] || 'root'
|
mysqlUser = ENV['MYSQL_USER'] || 'root'
|
||||||
mysqlPass = ENV['MYSQL_PASSWORD'] || ''
|
mysqlPass = ENV['MYSQL_PASSWORD'] || ''
|
||||||
@connection = Mysql.new('localhost', mysqlUser , mysqlPass, 'development')
|
@connection = Mysql.new(mysqlHost, mysqlUser, mysqlPass, 'development', mysqlPort.to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
def close()
|
def close()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
./clean_db.sh
|
./clean_db.sh
|
||||||
./clean_db.sh
|
./clean_db.sh
|
||||||
./clean_db.sh
|
./clean_db.sh
|
||||||
bacon init.rb
|
bacon init.rb
|
||||||
|
@ -16,6 +16,26 @@ class Scripts
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.createStaff(email, password, name, level='1')
|
||||||
|
departments = request('/system/get-settings', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token
|
||||||
|
})['departments']
|
||||||
|
departments = departments.collect { |x| x.id }
|
||||||
|
|
||||||
|
response = request('/staff/add', {
|
||||||
|
:name => name,
|
||||||
|
:email => email,
|
||||||
|
:password => password,
|
||||||
|
:level => level,
|
||||||
|
:departments => departments.to_string
|
||||||
|
})
|
||||||
|
|
||||||
|
if response['status'] === 'fail'
|
||||||
|
raise response['message']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.login(email = 'steve@jobs.com', password = 'custompassword', staff = false)
|
def self.login(email = 'steve@jobs.com', password = 'custompassword', staff = false)
|
||||||
request('/user/logout')
|
request('/user/logout')
|
||||||
response = request('/user/login', {
|
response = request('/user/login', {
|
||||||
@ -32,6 +52,10 @@ class Scripts
|
|||||||
response['data']
|
response['data']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.logout()
|
||||||
|
request('/user/logout')
|
||||||
|
end
|
||||||
|
|
||||||
def self.createTicket(title = 'Winter is coming')
|
def self.createTicket(title = 'Winter is coming')
|
||||||
result = request('/ticket/create', {
|
result = request('/ticket/create', {
|
||||||
title: title,
|
title: title,
|
||||||
|
@ -24,7 +24,7 @@ describe '/staff/assign-ticket' do
|
|||||||
|
|
||||||
(ticket['unread']).should.equal('1')
|
(ticket['unread']).should.equal('1')
|
||||||
|
|
||||||
staff_ticket = $database.getRow('staff_ticket', 1 , 'id')
|
staff_ticket = $database.getRow('staff_ticket', 1 , 'ticket_id')
|
||||||
|
|
||||||
(staff_ticket['staff_id']).should.equal('1')
|
(staff_ticket['staff_id']).should.equal('1')
|
||||||
|
|
||||||
@ -44,4 +44,4 @@ describe '/staff/assign-ticket' do
|
|||||||
(result['message']).should.equal('TICKET_ALREADY_ASSIGNED')
|
(result['message']).should.equal('TICKET_ALREADY_ASSIGNED')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -42,26 +42,44 @@ describe'/staff/edit' do
|
|||||||
profilePic: '',
|
profilePic: '',
|
||||||
departments: '[1]'
|
departments: '[1]'
|
||||||
})
|
})
|
||||||
request('/user/logout')
|
|
||||||
Scripts.login('arya@opensupports.com', 'starkpassword', true)
|
row = $database.getRow('staff', 'Arya Stark', 'name')
|
||||||
|
|
||||||
result = request('/staff/edit', {
|
result = request('/staff/edit', {
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token,
|
csrf_token: $csrf_token,
|
||||||
email: 'newwstaff@opensupports.com',
|
staffId: row['id'],
|
||||||
|
email: 'ayra2@opensupports.com',
|
||||||
|
departments: '[1, 2, 3]',
|
||||||
sendEmailOnNewTicket: 1
|
sendEmailOnNewTicket: 1
|
||||||
})
|
})
|
||||||
|
|
||||||
(result['status']).should.equal('success')
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
row = $database.getRow('staff', $csrf_userid, 'id')
|
row = $database.getRow('staff', 'Arya Stark', 'name')
|
||||||
|
|
||||||
(row['email']).should.equal('newwstaff@opensupports.com')
|
(row['email']).should.equal('ayra2@opensupports.com')
|
||||||
(row['level']).should.equal('2')
|
(row['level']).should.equal('2')
|
||||||
(row['send_email_on_new_ticket']).should.equal('1')
|
(row['send_email_on_new_ticket']).should.equal('0')
|
||||||
|
|
||||||
row = $database.getRow('department', 1, 'id')
|
row = $database.getRow('department', 1, 'id')
|
||||||
(row['owners']).should.equal('4')
|
(row['owners']).should.equal('4')
|
||||||
|
|
||||||
|
row = $database.getRow('department', 2, 'id')
|
||||||
|
(row['owners']).should.equal('3')
|
||||||
|
|
||||||
|
row = $database.getRow('department', 3, 'id')
|
||||||
|
(row['owners']).should.equal('2')
|
||||||
|
|
||||||
|
Scripts.logout()
|
||||||
|
Scripts.login('ayra2@opensupports.com', 'starkpassword', true)
|
||||||
|
result = request('/staff/edit', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
sendEmailOnNewTicket: 1
|
||||||
|
})
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
row = $database.getRow('staff', 'Arya Stark', 'name')
|
||||||
|
(row['send_email_on_new_ticket']).should.equal('1')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -24,7 +24,7 @@ describe'/staff/get-all' do
|
|||||||
(result['data'][0]['closedTickets']).should.equal(0)
|
(result['data'][0]['closedTickets']).should.equal(0)
|
||||||
|
|
||||||
(result['data'][2]['name']).should.equal('Arya Stark')
|
(result['data'][2]['name']).should.equal('Arya Stark')
|
||||||
(result['data'][2]['email']).should.equal('newwstaff@opensupports.com')
|
(result['data'][2]['email']).should.equal('ayra2@opensupports.com')
|
||||||
(result['data'][2]['profilePic']).should.equal('')
|
(result['data'][2]['profilePic']).should.equal('')
|
||||||
(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')
|
||||||
@ -32,4 +32,4 @@ describe'/staff/get-all' do
|
|||||||
(result['data'][2]['assignedTickets']).should.equal(0)
|
(result['data'][2]['assignedTickets']).should.equal(0)
|
||||||
(result['data'][2]['closedTickets']).should.equal(0)
|
(result['data'][2]['closedTickets']).should.equal(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
describe '/staff/un-assign-ticket' do
|
describe '/staff/un-assign-ticket' do
|
||||||
request('/user/logout')
|
Scripts.logout()
|
||||||
Scripts.login($staff[:email], $staff[:password], true)
|
Scripts.login($staff[:email], $staff[:password], true)
|
||||||
|
|
||||||
#TODO: Create a staff without the ticket
|
#TODO: Create a staff without the ticket
|
||||||
@ -8,7 +8,7 @@ describe '/staff/un-assign-ticket' do
|
|||||||
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
it 'should un assign ticket if everything is okey' do
|
it 'should unassign ticket if it is the current owner' do
|
||||||
ticket = $database.getRow('ticket', 1 , 'id')
|
ticket = $database.getRow('ticket', 1 , 'id')
|
||||||
result = request('/staff/un-assign-ticket', {
|
result = request('/staff/un-assign-ticket', {
|
||||||
ticketNumber: ticket['ticket_number'],
|
ticketNumber: ticket['ticket_number'],
|
||||||
@ -28,8 +28,25 @@ describe '/staff/un-assign-ticket' do
|
|||||||
(staff_ticket).should.equal(nil)
|
(staff_ticket).should.equal(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should fail if ticket is not yours' do
|
it 'should fail if ticket is not yours and you are a staff level 1' do
|
||||||
|
$database.query('update staff set level="1" where id="1";')
|
||||||
ticket = $database.getRow('ticket', 1 , 'id')
|
ticket = $database.getRow('ticket', 1 , 'id')
|
||||||
|
|
||||||
|
Scripts.logout()
|
||||||
|
Scripts.login('ayra2@opensupports.com', 'starkpassword', true)
|
||||||
|
|
||||||
|
result = request('/staff/assign-ticket', {
|
||||||
|
ticketNumber: ticket['ticket_number'],
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token
|
||||||
|
})
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
|
ticket = $database.getRow('ticket', 1 , 'id')
|
||||||
|
|
||||||
|
Scripts.logout()
|
||||||
|
Scripts.login($staff[:email], $staff[:password], true)
|
||||||
|
|
||||||
result = request('/staff/un-assign-ticket', {
|
result = request('/staff/un-assign-ticket', {
|
||||||
ticketNumber: ticket['ticket_number'],
|
ticketNumber: ticket['ticket_number'],
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
@ -38,5 +55,29 @@ describe '/staff/un-assign-ticket' do
|
|||||||
|
|
||||||
(result['status']).should.equal('fail')
|
(result['status']).should.equal('fail')
|
||||||
(result['message']).should.equal('NO_PERMISSION')
|
(result['message']).should.equal('NO_PERMISSION')
|
||||||
|
$database.query('update staff set level="3" where id="1";')
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
it 'should unassign ticket if you are a staff level 3' do
|
||||||
|
ticket = $database.getRow('ticket', 1 , 'id')
|
||||||
|
Scripts.logout()
|
||||||
|
Scripts.login($staff[:email], $staff[:password], true)
|
||||||
|
result = request('/staff/un-assign-ticket', {
|
||||||
|
ticketNumber: ticket['ticket_number'],
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
|
ticket = $database.getRow('ticket', 1 , 'id')
|
||||||
|
|
||||||
|
(ticket['owner_id']).should.equal(nil)
|
||||||
|
(ticket['unread']).should.equal('1')
|
||||||
|
|
||||||
|
staff_ticket = $database.getRow('staff_ticket', 1 , 'id')
|
||||||
|
|
||||||
|
(staff_ticket).should.equal(nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
@ -37,6 +37,20 @@ describe'system/edit-settings' do
|
|||||||
|
|
||||||
request('/user/logout')
|
request('/user/logout')
|
||||||
end
|
end
|
||||||
|
it 'should fail if supported languages are invalid' do
|
||||||
|
request('/user/logout')
|
||||||
|
Scripts.login($staff[:email], $staff[:password], true)
|
||||||
|
|
||||||
|
result= request('/system/edit-settings', {
|
||||||
|
"csrf_userid" => $csrf_userid,
|
||||||
|
"csrf_token" => $csrf_token,
|
||||||
|
"supportedLanguages" => '["en", "pt", "jp", "ru", "de"]',
|
||||||
|
"allowedLanguages" => '["en", "pt", "jp", "ru"]'
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('fail')
|
||||||
|
(result['message']).should.equal('INVALID_SUPPORTED_LANGUAGES')
|
||||||
|
end
|
||||||
it 'should change allowed and supported languages' do
|
it 'should change allowed and supported languages' do
|
||||||
request('/user/logout')
|
request('/user/logout')
|
||||||
Scripts.login($staff[:email], $staff[:password], true)
|
Scripts.login($staff[:email], $staff[:password], true)
|
||||||
@ -45,7 +59,7 @@ describe'system/edit-settings' do
|
|||||||
"csrf_userid" => $csrf_userid,
|
"csrf_userid" => $csrf_userid,
|
||||||
"csrf_token" => $csrf_token,
|
"csrf_token" => $csrf_token,
|
||||||
"supportedLanguages" => '["en", "pt", "jp", "ru"]',
|
"supportedLanguages" => '["en", "pt", "jp", "ru"]',
|
||||||
"allowedLanguages" => '["en","pt", "jp", "ru", "de"]'
|
"allowedLanguages" => '["en", "pt", "jp", "ru", "de"]'
|
||||||
})
|
})
|
||||||
|
|
||||||
(result['status']).should.equal('success')
|
(result['status']).should.equal('success')
|
||||||
|
@ -13,62 +13,62 @@ describe'/system/get-stats' do
|
|||||||
|
|
||||||
#day 1
|
#day 1
|
||||||
for i in 0..5
|
for i in 0..5
|
||||||
$database.query("INSERT INTO log VALUES('', 'SIGNUP', NULL, " + yesterday3 + ", NULL, NULL, NULL);")
|
$database.query("INSERT INTO log VALUES(NULL, 'SIGNUP', NULL, " + yesterday3 + ", NULL, NULL, NULL);")
|
||||||
end
|
end
|
||||||
for i in 0..0
|
for i in 0..0
|
||||||
$database.query("INSERT INTO log VALUES('', 'CREATE_TICKET', NULL, " + yesterday3 + ", NULL, NULL, NULL);")
|
$database.query("INSERT INTO log VALUES(NULL, 'CREATE_TICKET', NULL, " + yesterday3 + ", NULL, NULL, NULL);")
|
||||||
end
|
end
|
||||||
for i in 0..1
|
for i in 0..1
|
||||||
$database.query("INSERT INTO log VALUES('', 'CLOSE', NULL, " + yesterday3 + ", NULL, NULL, NULL);")
|
$database.query("INSERT INTO log VALUES(NULL, 'CLOSE', NULL, " + yesterday3 + ", NULL, NULL, NULL);")
|
||||||
end
|
end
|
||||||
for i in 0..2
|
for i in 0..2
|
||||||
$database.query("INSERT INTO log VALUES('', 'COMMENT', NULL, " + yesterday3 + ", NULL, NULL, NULL);")
|
$database.query("INSERT INTO log VALUES(NULL, 'COMMENT', NULL, " + yesterday3 + ", NULL, NULL, NULL);")
|
||||||
end
|
end
|
||||||
for i in 0..8
|
for i in 0..8
|
||||||
$database.query("INSERT INTO ticketevent VALUES('', 'CLOSE', NULL, NULL, " + yesterday3 + ", NULL, NULL, 1);")
|
$database.query("INSERT INTO ticketevent VALUES(NULL, 'CLOSE', NULL, NULL, " + yesterday3 + ", NULL, NULL, 1);")
|
||||||
end
|
end
|
||||||
for i in 0..4
|
for i in 0..4
|
||||||
$database.query("INSERT INTO ticketevent VALUES('', 'ASSIGN', NULL, NULL, " + yesterday3 + ", NULL, NULL, 1);")
|
$database.query("INSERT INTO ticketevent VALUES(NULL, 'ASSIGN', NULL, NULL, " + yesterday3 + ", NULL, NULL, 1);")
|
||||||
end
|
end
|
||||||
|
|
||||||
#day 2
|
#day 2
|
||||||
for i in 0..7
|
for i in 0..7
|
||||||
$database.query("INSERT INTO log VALUES('', 'SIGNUP', NULL, " + yesterday2 + ", NULL, NULL, NULL);")
|
$database.query("INSERT INTO log VALUES(NULL, 'SIGNUP', NULL, " + yesterday2 + ", NULL, NULL, NULL);")
|
||||||
end
|
end
|
||||||
for i in 0..2
|
for i in 0..2
|
||||||
$database.query("INSERT INTO log VALUES('', 'CREATE_TICKET', NULL, " + yesterday2 + ", NULL, NULL, NULL);")
|
$database.query("INSERT INTO log VALUES(NULL, 'CREATE_TICKET', NULL, " + yesterday2 + ", NULL, NULL, NULL);")
|
||||||
end
|
end
|
||||||
for i in 0..9
|
for i in 0..9
|
||||||
$database.query("INSERT INTO log VALUES('', 'CLOSE', NULL, " + yesterday2 + ", NULL, NULL, NULL);")
|
$database.query("INSERT INTO log VALUES(NULL, 'CLOSE', NULL, " + yesterday2 + ", NULL, NULL, NULL);")
|
||||||
end
|
end
|
||||||
for i in 0..2
|
for i in 0..2
|
||||||
$database.query("INSERT INTO log VALUES('', 'COMMENT', NULL, " + yesterday2 + ", NULL, NULL, NULL);")
|
$database.query("INSERT INTO log VALUES(NULL, 'COMMENT', NULL, " + yesterday2 + ", NULL, NULL, NULL);")
|
||||||
end
|
end
|
||||||
for i in 0..10
|
for i in 0..10
|
||||||
$database.query("INSERT INTO ticketevent VALUES('', 'CLOSE', NULL, NULL, " + yesterday2 + ", NULL, NULL, 1);")
|
$database.query("INSERT INTO ticketevent VALUES(NULL, 'CLOSE', NULL, NULL, " + yesterday2 + ", NULL, NULL, 1);")
|
||||||
end
|
end
|
||||||
for i in 0..2
|
for i in 0..2
|
||||||
$database.query("INSERT INTO ticketevent VALUES('', 'ASSIGN', NULL, NULL, " + yesterday2 + ", NULL, NULL, 1);")
|
$database.query("INSERT INTO ticketevent VALUES(NULL, 'ASSIGN', NULL, NULL, " + yesterday2 + ", NULL, NULL, 1);")
|
||||||
end
|
end
|
||||||
|
|
||||||
#day 3
|
#day 3
|
||||||
for i in 0..0
|
for i in 0..0
|
||||||
$database.query("INSERT INTO log VALUES('', 'SIGNUP', NULL, " + yesterday + ", NULL, NULL, NULL);")
|
$database.query("INSERT INTO log VALUES(NULL, 'SIGNUP', NULL, " + yesterday + ", NULL, NULL, NULL);")
|
||||||
end
|
end
|
||||||
for i in 0..1
|
for i in 0..1
|
||||||
$database.query("INSERT INTO log VALUES('', 'CREATE_TICKET', NULL, " + yesterday + ", NULL, NULL, NULL);")
|
$database.query("INSERT INTO log VALUES(NULL, 'CREATE_TICKET', NULL, " + yesterday + ", NULL, NULL, NULL);")
|
||||||
end
|
end
|
||||||
for i in 0..4
|
for i in 0..4
|
||||||
$database.query("INSERT INTO log VALUES('', 'CLOSE', NULL, " + yesterday + ", NULL, NULL, NULL);")
|
$database.query("INSERT INTO log VALUES(NULL, 'CLOSE', NULL, " + yesterday + ", NULL, NULL, NULL);")
|
||||||
end
|
end
|
||||||
for i in 0..7
|
for i in 0..7
|
||||||
$database.query("INSERT INTO log VALUES('', 'COMMENT', NULL, " + yesterday + ", NULL, NULL, NULL);")
|
$database.query("INSERT INTO log VALUES(NULL, 'COMMENT', NULL, " + yesterday + ", NULL, NULL, NULL);")
|
||||||
end
|
end
|
||||||
for i in 0..3
|
for i in 0..3
|
||||||
$database.query("INSERT INTO ticketevent VALUES('', 'CLOSE', NULL, NULL, " + yesterday + ", NULL, NULL, 1);")
|
$database.query("INSERT INTO ticketevent VALUES(NULL, 'CLOSE', NULL, NULL, " + yesterday + ", NULL, NULL, 1);")
|
||||||
end
|
end
|
||||||
for i in 0..7
|
for i in 0..7
|
||||||
$database.query("INSERT INTO ticketevent VALUES('', 'ASSIGN', NULL, NULL, " + yesterday + ", NULL, NULL, 1);")
|
$database.query("INSERT INTO ticketevent VALUES(NULL, 'ASSIGN', NULL, NULL, " + yesterday + ", NULL, NULL, 1);")
|
||||||
end
|
end
|
||||||
|
|
||||||
@result = request('/system/get-stats', {
|
@result = request('/system/get-stats', {
|
||||||
|
@ -25,9 +25,9 @@ describe '/system/init-settings' do
|
|||||||
'language' => 'en'
|
'language' => 'en'
|
||||||
})
|
})
|
||||||
|
|
||||||
lang = $database.getRow('setting', 'language', 'name')
|
|
||||||
|
|
||||||
(result['status']).should.equal('success')
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
|
lang = $database.getRow('setting', 'language', 'name')
|
||||||
(lang['value']).should.equal('en')
|
(lang['value']).should.equal('en')
|
||||||
|
|
||||||
result = request('/system/init-admin', {
|
result = request('/system/init-admin', {
|
||||||
|
@ -21,6 +21,11 @@ describe '/ticket/change-department' do
|
|||||||
|
|
||||||
it 'should change department if everything is okey' do
|
it 'should change department if everything is okey' do
|
||||||
ticket = $database.getRow('ticket', 1 , 'id')
|
ticket = $database.getRow('ticket', 1 , 'id')
|
||||||
|
request('/staff/assign-ticket', {
|
||||||
|
ticketNumber: ticket['ticket_number'],
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token
|
||||||
|
})
|
||||||
|
|
||||||
result = request('/ticket/change-department', {
|
result = request('/ticket/change-department', {
|
||||||
ticketNumber: ticket['ticket_number'],
|
ticketNumber: ticket['ticket_number'],
|
||||||
@ -34,8 +39,43 @@ describe '/ticket/change-department' do
|
|||||||
ticket = $database.getRow('ticket', 1 , 'id')
|
ticket = $database.getRow('ticket', 1 , 'id')
|
||||||
(ticket['unread']).should.equal('1')
|
(ticket['unread']).should.equal('1')
|
||||||
(ticket['department_id']).should.equal('2')
|
(ticket['department_id']).should.equal('2')
|
||||||
|
(ticket['owner_id']).should.equal('1')
|
||||||
|
|
||||||
lastLog = $database.getLastRow('log')
|
lastLog = $database.getLastRow('log')
|
||||||
(lastLog['type']).should.equal('DEPARTMENT_CHANGED')
|
(lastLog['type']).should.equal('DEPARTMENT_CHANGED')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should unassing ticket if staff does not server new department' do
|
||||||
|
ticket = $database.getRow('ticket', 1 , 'id')
|
||||||
|
request('/staff/edit', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
departments: '[1, 2]',
|
||||||
|
staffId: 1
|
||||||
|
})
|
||||||
|
|
||||||
|
result = request('/ticket/change-department', {
|
||||||
|
ticketNumber: ticket['ticket_number'],
|
||||||
|
departmentId: 3,
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
|
ticket = $database.getRow('ticket', 1 , 'id')
|
||||||
|
(ticket['unread']).should.equal('1')
|
||||||
|
(ticket['department_id']).should.equal('3')
|
||||||
|
(ticket['owner_id']).should.equal(nil)
|
||||||
|
|
||||||
|
lastLog = $database.getLastRow('log')
|
||||||
|
(lastLog['type']).should.equal('DEPARTMENT_CHANGED')
|
||||||
|
|
||||||
|
request('/staff/edit', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
departments: '[1, 2, 3]',
|
||||||
|
staffId: 1
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user