diff --git a/server/controllers/ticket/get.php b/server/controllers/ticket/get.php index 599bc242..22a48776 100644 --- a/server/controllers/ticket/get.php +++ b/server/controllers/ticket/get.php @@ -86,6 +86,6 @@ class TicketGetController extends Controller { $user = Controller::getLoggedUser(); return (!Controller::isStaffLogged() && (Controller::isUserSystemEnabled() && $this->ticket->author->id !== $user->id)) || - (Controller::isStaffLogged() && !$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))); } } \ No newline at end of file diff --git a/server/libs/DataStoreList.php b/server/libs/DataStoreList.php index 84a75bd7..da995595 100644 --- a/server/libs/DataStoreList.php +++ b/server/libs/DataStoreList.php @@ -46,7 +46,7 @@ class DataStoreList implements IteratorAggregate { } public function isEmpty() { - return empty($list); + return empty($this->list); } public function toBeanList() { diff --git a/tests/scripts.rb b/tests/scripts.rb index 9b5eb892..0e2d911e 100644 --- a/tests/scripts.rb +++ b/tests/scripts.rb @@ -10,7 +10,7 @@ class Scripts raise response['message'] end userRow = $database.getRow('user', email, 'email') - response = request('/user/verify', { + request('/user/verify', { :email => email, :token => userRow['verification_token'] }) @@ -32,9 +32,9 @@ class Scripts response['data'] end - def self.createTicket() + def self.createTicket(title = 'Winter is coming') result = request('/ticket/create', { - title: 'Winter is coming', + title: title, content: 'The north remembers', departmentId: 1, language: 'en', @@ -46,7 +46,7 @@ class Scripts end def self.createAPIKey(name) - result = request('/system/add-api-key', { + request('/system/add-api-key', { csrf_userid: $csrf_userid, csrf_token: $csrf_token, name: name diff --git a/tests/system/disable-user-system.rb b/tests/system/disable-user-system.rb index 076fdb23..82b1fa6a 100644 --- a/tests/system/disable-user-system.rb +++ b/tests/system/disable-user-system.rb @@ -9,7 +9,6 @@ describe'system/disable-user-system' do password:$staff[:password] }) - puts result['message'] (result['status']).should.equal('success') row = $database.getRow('setting', 'user-system-enabled', 'name') @@ -20,7 +19,7 @@ describe'system/disable-user-system' do 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) + (numberOftickets.num_rows).should.equal(36) request('/user/logout') @@ -63,7 +62,6 @@ describe'system/disable-user-system' do password:$staff[:password] }) - puts result['message'] (result['status']).should.equal('success') row = $database.getRow('setting', 'user-system-enabled', 'name') @@ -71,7 +69,7 @@ describe'system/disable-user-system' do 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) + (numberOftickets.num_rows).should.equal(36) end diff --git a/tests/user/delete.rb b/tests/user/delete.rb index 029a6ab4..8b2ab837 100644 --- a/tests/user/delete.rb +++ b/tests/user/delete.rb @@ -1,28 +1,30 @@ describe '/user/delete' do - request('/user/logout') - result = request('/user/login', { - email: 'staff@opensupports.com', - password: 'staff', - staff: true - }) - - $csrf_userid = result['data']['userId'] - $csrf_token = result['data']['token'] it 'should delete user' do + Scripts.createUser('deletable@opensupports.com', 'deletable') + Scripts.login('deletable@opensupports.com', 'deletable') + Scripts.createTicket('Ticket that will be deleted') + + request('/user/logout') + Scripts.login('staff@opensupports.com', 'staff', true) + ticket = $database.getLastRow('ticket') + deletable_user = $database.getLastRow('user') + result = request('/user/delete', { - userId: 4, + userId: deletable_user['id'], csrf_userid: $csrf_userid, csrf_token: $csrf_token }) (result['status']).should.equal('success') - user = $database.getRow('user', 4 , 'id') - (user).should.equal(nil) + last_ticket = $database.getLastRow('ticket') + last_log = $database.getLastRow('log') + user = $database.getRow('user', deletable_user['id'] , 'id') - lastLog = $database.getLastRow('log') - (lastLog['type']).should.equal('DELETE_USER') + (user).should.equal(nil) + (ticket['id']).should.not.equal(last_ticket['id']) + (last_log['type']).should.equal('DELETE_USER') end end