diff --git a/server/controllers/ticket/change-department.php b/server/controllers/ticket/change-department.php index 2891482b..2cfe0f25 100644 --- a/server/controllers/ticket/change-department.php +++ b/server/controllers/ticket/change-department.php @@ -43,6 +43,9 @@ class ChangeDepartmentController extends Controller { $ticket->department = $department; $ticket->unread = true; $ticket->store(); + + Log::createLog('CHANGE_DEPARTMENT', $department); + Response::respondSuccess(); } } \ No newline at end of file diff --git a/server/controllers/ticket/change-priority.php b/server/controllers/ticket/change-priority.php index 24f9271e..989fa5ec 100644 --- a/server/controllers/ticket/change-priority.php +++ b/server/controllers/ticket/change-priority.php @@ -37,6 +37,8 @@ class ChangePriorityController extends Controller { )); $ticket->addEvent($event); $ticket->store(); + + Log::createLog('CHANGE_PRIORITY', $priority); Response::respondSuccess(); } else { Response::respondError(ERRORS::NO_PERMISSION); diff --git a/server/controllers/ticket/close.php b/server/controllers/ticket/close.php index d62d4d5f..3080c7b2 100644 --- a/server/controllers/ticket/close.php +++ b/server/controllers/ticket/close.php @@ -32,6 +32,9 @@ class CloseController extends Controller { $this->ticket->closed = true; $this->ticket->store(); + + Log::createLog('CLOSE_TICKET', $this->ticket); + Response::respondSuccess(); } diff --git a/server/controllers/ticket/comment.php b/server/controllers/ticket/comment.php index d9db4566..96e4202e 100644 --- a/server/controllers/ticket/comment.php +++ b/server/controllers/ticket/comment.php @@ -30,6 +30,9 @@ class CommentController extends Controller { if ($session->isLoggedWithId($this->ticket->author->id) || Controller::isStaffLogged()) { $this->storeComment(); + + Log::createLog('COMMENT_TICKET', $this->ticket); + Response::respondSuccess(); } else { Response::respondError(ERRORS::NO_PERMISSION); diff --git a/server/controllers/ticket/create.php b/server/controllers/ticket/create.php index 501b8896..d34d3e9b 100644 --- a/server/controllers/ticket/create.php +++ b/server/controllers/ticket/create.php @@ -43,6 +43,7 @@ class CreateController extends Controller { $this->storeTicket(); + Log::createLog('CREATE_TICKET', $this->title); Response::respondSuccess([ 'ticketNumber' => $this->ticketNumber ]); diff --git a/server/controllers/ticket/edit-custom-response.php b/server/controllers/ticket/edit-custom-response.php index c030f2de..12b170a7 100644 --- a/server/controllers/ticket/edit-custom-response.php +++ b/server/controllers/ticket/edit-custom-response.php @@ -34,6 +34,7 @@ class EditCustomResponseController extends Controller { $customResponse->store(); + Log::createLog('EDIT_CUSTOM_RESPONSE', null); Response::respondSuccess(); } } \ No newline at end of file diff --git a/server/controllers/ticket/re-open.php b/server/controllers/ticket/re-open.php index 0a1d4896..b5f97713 100644 --- a/server/controllers/ticket/re-open.php +++ b/server/controllers/ticket/re-open.php @@ -31,6 +31,9 @@ class ReOpenController extends Controller { $this->ticket->closed = false; $this->ticket->store(); + + Log::createLog('RE_OPEN_TICKET', $this->ticket); + Response::respondSuccess(); } diff --git a/tests/article/article.rb b/tests/article/article.rb index 606fc11f..c353d662 100644 --- a/tests/article/article.rb +++ b/tests/article/article.rb @@ -27,6 +27,9 @@ describe 'Article path' do (article['content']).should.equal('This is an article about server management.') (article['topic_id']).should.equal(@topic_id.to_s) (article['position']).should.equal('1') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('ADD_ARTICLE') end it 'should edit article' do @@ -43,6 +46,9 @@ describe 'Article path' do (article['content']).should.equal('This is an article about server management2.') (article['topic_id']).should.equal(@topic_id.to_s) (article['position']).should.equal('1') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('EDIT_ARTICLE') end it 'should edit article topic' do @@ -76,6 +82,9 @@ describe 'Article path' do csrf_token: $csrf_token }) (result['status']).should.equal('success') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('DELETE_ARTICLE') end it 'should retrieve all articles' do @@ -103,5 +112,6 @@ describe 'Article path' do (result['data'][0]['articles'][0]['title']).should.equal('Some article') (result['data'][0]['articles'][0]['content']).should.equal('This is an article about server management.') (result['data'][0]['articles'][0]['position']).should.equal('1') + end -end \ No newline at end of file +end diff --git a/tests/article/topic.rb b/tests/article/topic.rb index 9da373c1..ddaa6ab7 100644 --- a/tests/article/topic.rb +++ b/tests/article/topic.rb @@ -17,6 +17,9 @@ describe 'Topic paths' do (topic['name']).should.equal('Server management') (topic['icon_color']).should.equal('red') (topic['icon']).should.equal('cogs') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('ADD_TOPIC') end it 'should edit topic correctly' do @@ -44,6 +47,9 @@ describe 'Topic paths' do }) (result['status']).should.equal('success') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('DELETE_TOPIC') end it 'should deny permission if it is not logged as staff' do @@ -78,4 +84,4 @@ describe 'Topic paths' do (result['status']).should.equal('fail') (result['message']).should.equal('NO_PERMISSION') end -end \ No newline at end of file +end diff --git a/tests/libs.rb b/tests/libs.rb index b8431702..f5496d48 100644 --- a/tests/libs.rb +++ b/tests/libs.rb @@ -23,6 +23,12 @@ class Database return queryResponse.fetch_hash end + + def getLastRow(table) + queryResponse = @connection.query("select * from #{table} order by id desc limit 1") + + return queryResponse.fetch_hash + end end $database = Database.new diff --git a/tests/staff/add.rb b/tests/staff/add.rb index baf42c35..1f557034 100644 --- a/tests/staff/add.rb +++ b/tests/staff/add.rb @@ -26,6 +26,9 @@ describe'/staff/add' do row = $database.getRow('department', 1, 'id') (row['owners']).should.equal('2') + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('ADD_STAFF') + end it 'should fail if staff member is alrady a staff' do result= request('/staff/add', { diff --git a/tests/system/add-department.rb b/tests/system/add-department.rb index 5da0e1ad..c4cbf96c 100644 --- a/tests/system/add-department.rb +++ b/tests/system/add-department.rb @@ -14,5 +14,8 @@ describe'system/add-department' do row = $database.getRow('department', 4, 'id') (row['name']).should.equal('new department') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('ADD_DEPARTMENT') end -end \ No newline at end of file +end diff --git a/tests/system/delete-department.rb b/tests/system/delete-department.rb index ee9ded50..0c841b95 100644 --- a/tests/system/delete-department.rb +++ b/tests/system/delete-department.rb @@ -81,5 +81,8 @@ describe 'system/delete-department' do (ticket3['department_id']).should.equal('2') (ticket3['owner_id']).should.equal($csrf_userid) + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('DELETE_DEPARTMENT') end -end \ No newline at end of file +end diff --git a/tests/system/edit-department.rb b/tests/system/edit-department.rb index e7620b6d..0f09ecb2 100644 --- a/tests/system/edit-department.rb +++ b/tests/system/edit-department.rb @@ -15,5 +15,8 @@ describe'system/edit-department' do row = $database.getRow('department', 4, 'id') (row['name']).should.equal('second name') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('EDIT_DEPARTMENT') end -end \ No newline at end of file +end diff --git a/tests/system/edit-settings.rb b/tests/system/edit-settings.rb index ca57a4b5..b7eaf26b 100644 --- a/tests/system/edit-settings.rb +++ b/tests/system/edit-settings.rb @@ -52,6 +52,9 @@ describe'system/edit-settings' do (row['value']).should.equal('pass1234') request('/user/logout') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('EDIT_SETTINGS') end it 'should change allowed and supported languages' do request('/user/logout') @@ -93,49 +96,9 @@ describe'system/edit-settings' do row = $database.getRow('language', 'de', 'code') (row['allowed']).should.equal('1') + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('EDIT_SETTINGS') + request('/user/logout') end - - it 'should change allowed and supported languages' 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", "pr", "jp", "ru"]', - "allowedLanguages" => '["en","pr", "jp", "ru", "de"]' - }) - - (result['status']).should.equal('success') - - row = $database.getRow('language', 'en', 'code') - (row['supported']).should.equal('1') - - row = $database.getRow('language', 'pr', 'code') - (row['supported']).should.equal('1') - - row = $database.getRow('language', 'jp', 'code') - (row['supported']).should.equal('1') - - row = $database.getRow('language', 'ru', 'code') - (row['supported']).should.equal('1') - - row = $database.getRow('language', 'en', 'code') - (row['allowed']).should.equal('1') - - row = $database.getRow('language', 'pr', 'code') - (row['allowed']).should.equal('1') - - row = $database.getRow('language', 'jp', 'code') - (row['allowed']).should.equal('1') - - row = $database.getRow('language', 'ru', 'code') - (row['allowed']).should.equal('1') - - row = $database.getRow('language', 'de', 'code') - (row['allowed']).should.equal('1') - - request('/user/logout') - end -end \ No newline at end of file +end diff --git a/tests/ticket/change-department.rb b/tests/ticket/change-department.rb index 0775d999..112f6c3a 100644 --- a/tests/ticket/change-department.rb +++ b/tests/ticket/change-department.rb @@ -19,5 +19,8 @@ describe '/ticket/change-department' do ticket = $database.getRow('ticket', 1 , 'id') (ticket['unread']).should.equal('1') (ticket['department_id']).should.equal('2') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('CHANGE_DEPARTMENT') end -end \ No newline at end of file +end diff --git a/tests/ticket/change-priority.rb b/tests/ticket/change-priority.rb index 37ff474c..50669cbc 100644 --- a/tests/ticket/change-priority.rb +++ b/tests/ticket/change-priority.rb @@ -19,6 +19,9 @@ describe '/ticket/change-priority' do ticket = $database.getRow('ticket', 1 , 'id') (ticket['priority']).should.equal('high') (ticket['unread']).should.equal('1') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('CHANGE_PRIORITY') end it 'should change priority to medium if everything is okey' do @@ -36,6 +39,9 @@ describe '/ticket/change-priority' do ticket = $database.getRow('ticket', 1 , 'id') (ticket['priority']).should.equal('medium') (ticket['unread']).should.equal('1') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('CHANGE_PRIORITY') end it 'should change priority to low if everything is okey' do @@ -53,6 +59,9 @@ describe '/ticket/change-priority' do ticket = $database.getRow('ticket', 1 , 'id') (ticket['priority']).should.equal('low') (ticket['unread']).should.equal('1') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('CHANGE_PRIORITY') end -end \ No newline at end of file +end diff --git a/tests/ticket/close.rb b/tests/ticket/close.rb index a13b3c5d..f2a2930f 100644 --- a/tests/ticket/close.rb +++ b/tests/ticket/close.rb @@ -19,5 +19,7 @@ describe '/ticket/close' do (ticket['closed']).should.equal('1') (ticket['unread']).should.equal('1') + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('CLOSE_TICKET') end -end \ No newline at end of file +end diff --git a/tests/ticket/comment.rb b/tests/ticket/comment.rb index 27222b87..4117fe8d 100644 --- a/tests/ticket/comment.rb +++ b/tests/ticket/comment.rb @@ -73,6 +73,9 @@ describe '/ticket/comment/' do (comment['type']).should.equal('COMMENT') (comment['author_user_id']).should.equal($csrf_userid) (ticket['unread_staff']).should.equal('1') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('COMMENT_TICKET') end it 'should fail if user is not the author nor owner' do diff --git a/tests/ticket/create.rb b/tests/ticket/create.rb index 5789b53d..63aaa13b 100644 --- a/tests/ticket/create.rb +++ b/tests/ticket/create.rb @@ -116,6 +116,9 @@ describe '/ticket/create' do ticket_user_relation = $database.getRow('ticket_user', ticket['id'],'ticket_id') (ticket_user_relation['user_id']).should.equal($csrf_userid) + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('CREATE_TICKET') end it 'should set correct ticket number' do diff --git a/tests/ticket/custom-response.rb b/tests/ticket/custom-response.rb index 9321565e..74abcf57 100644 --- a/tests/ticket/custom-response.rb +++ b/tests/ticket/custom-response.rb @@ -18,6 +18,9 @@ describe 'CustomResponses' do (customResponse['name']).should.equal('Some common problem') (customResponse['content']).should.equal('this is the content of a custom response for a common problem') (customResponse['language']).should.equal('en') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('ADD_CUSTOM_RESPONSE') end end @@ -36,6 +39,9 @@ describe 'CustomResponses' do (customResponse['name']).should.equal('Some common problem') (customResponse['content']).should.equal('this is the content of a custom response for a common problem 2') (customResponse['language']).should.equal('en') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('EDIT_CUSTOM_RESPONSE') end end @@ -65,6 +71,9 @@ describe 'CustomResponses' do (result['status']).should.equal('success') customResponse = $database.getRow('customresponse', 1) (customResponse).should.equal(nil) + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('DELETE_CUSTOM_RESPONSE') end end -end \ No newline at end of file +end diff --git a/tests/ticket/re-open.rb b/tests/ticket/re-open.rb index 43bd3867..25774a44 100644 --- a/tests/ticket/re-open.rb +++ b/tests/ticket/re-open.rb @@ -19,5 +19,7 @@ describe '/ticket/re-open' do (ticket['closed']).should.equal('0') (ticket['unread']).should.equal('1') + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('RE_OPEN_TICKET') end -end \ No newline at end of file +end diff --git a/tests/user/ban.rb b/tests/user/ban.rb index 86d03e2d..6e971006 100644 --- a/tests/user/ban.rb +++ b/tests/user/ban.rb @@ -22,6 +22,8 @@ describe '/user/ban' do user = $database.getRow('ban', 1 , 'id') (user['email']).should.equal('nothing@hotmail.com') + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('BAN_USER') end it 'should get ban list' do @@ -58,6 +60,8 @@ describe '/user/ban' do user = $database.getRow('ban', 1 , 'id') (user).should.equal(nil) + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('UN_BAN_USER') end it 'should not un-ban user if it is not banned' do @@ -72,4 +76,4 @@ describe '/user/ban' do end -end \ No newline at end of file +end diff --git a/tests/user/delete.rb b/tests/user/delete.rb index 8b411d14..029a6ab4 100644 --- a/tests/user/delete.rb +++ b/tests/user/delete.rb @@ -22,7 +22,7 @@ describe '/user/delete' do user = $database.getRow('user', 4 , 'id') (user).should.equal(nil) + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('DELETE_USER') end end - - diff --git a/tests/user/signup.rb b/tests/user/signup.rb index b3e0978b..ac2b69b5 100644 --- a/tests/user/signup.rb +++ b/tests/user/signup.rb @@ -10,6 +10,9 @@ describe '/user/signup' do (userRow['email']).should.equal('steve@jobs.com') (userRow['name']).should.equal('Steve Jobs') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('SIGNUP') end it 'should fail if name is invalid' do