diff --git a/client/src/actions/session-actions.js b/client/src/actions/session-actions.js index 42ce50db..910d8ea1 100644 --- a/client/src/actions/session-actions.js +++ b/client/src/actions/session-actions.js @@ -58,7 +58,7 @@ export default { } }).then((result) => { store.dispatch(this.getUserData(result.data.userId, result.data.token)); - + return result; }) }; diff --git a/client/src/app-components/ticket-event.js b/client/src/app-components/ticket-event.js index 375f6391..5bc9fcf1 100644 --- a/client/src/app-components/ticket-event.js +++ b/client/src/app-components/ticket-event.js @@ -117,7 +117,7 @@ class TicketEvent extends React.Component { return (
- {((this.props.author.id === this.props.userId) || (this.props.userStaff)) ? this.renderEditIcon() : null} + {((this.props.author.id == this.props.userId && this.props.author.staff == this.props.userStaff) || this.props.userStaff) ? this.renderEditIcon() : null}
) } diff --git a/client/src/app-components/ticket-viewer.js b/client/src/app-components/ticket-viewer.js index 9f8db3d7..e965fe8e 100644 --- a/client/src/app-components/ticket-viewer.js +++ b/client/src/app-components/ticket-viewer.js @@ -69,7 +69,6 @@ class TicketViewer extends React.Component { render() { const ticket = this.props.ticket; - return (
@@ -605,6 +604,7 @@ class TicketViewer extends React.Component { } export default connect((store) => { + return { userId: store.session.userId, userStaff: store.session.staff, diff --git a/client/src/reducers/session-reducer.js b/client/src/reducers/session-reducer.js index 4f8104dd..08374ad1 100644 --- a/client/src/reducers/session-reducer.js +++ b/client/src/reducers/session-reducer.js @@ -77,7 +77,8 @@ class SessionReducer extends Reducer { logged: true, pending: false, failed: false, - userId: payload.data.userId + userId: payload.data.userId, + staff: payload.data.staff }); } @@ -94,6 +95,7 @@ class SessionReducer extends Reducer { sessionStore.storeRememberData({ token: resultData.rememberToken, userId: resultData.userId, + staff: resultData.staff, expiration: resultData.rememberExpiration }); } diff --git a/server/controllers/user/get.php b/server/controllers/user/get.php index 98f480be..8bd6d00a 100755 --- a/server/controllers/user/get.php +++ b/server/controllers/user/get.php @@ -54,6 +54,7 @@ class GetUserController extends Controller { Response::respondSuccess([ 'name' => $user->name, 'email' => $user->email, + 'staff' => false, 'verified' => !$user->verificationToken, 'tickets' => $parsedTicketList, 'customfields' => $user->xownCustomfieldvalueList->toArray(), diff --git a/server/controllers/user/login.php b/server/controllers/user/login.php index 05eee6f1..b0a2d4b4 100755 --- a/server/controllers/user/login.php +++ b/server/controllers/user/login.php @@ -108,7 +108,7 @@ class LoginController extends Controller { return array( 'userId' => $userInstance->id, 'userEmail' => $userInstance->email, - 'staff' => Controller::request('staff'), + 'staff' => !!Controller::request('staff'), 'token' => Session::getInstance()->getToken(), 'rememberToken' => $this->rememberToken, 'rememberExpiration' => $this->rememberExpiration diff --git a/server/models/Staff.php b/server/models/Staff.php index aed2296a..da28038a 100755 --- a/server/models/Staff.php +++ b/server/models/Staff.php @@ -50,7 +50,7 @@ class Staff extends DataStore { } public function canManageTicket(Ticket $ticket){ - return $this->sharedDepartmentList->includesId($ticket->departmentId) || $this->id === $ticket->author_staff_id; + return $this->sharedDepartmentList->includesId($ticket->departmentId) || $this->id === $ticket->authorStaffId; } public function toArray() { diff --git a/tests/ticket/seen.rb b/tests/ticket/seen.rb index b6675ad3..8240bb6b 100644 --- a/tests/ticket/seen.rb +++ b/tests/ticket/seen.rb @@ -21,6 +21,20 @@ describe '/ticket/seen' do end describe 'when an user is logged' do + + request('/user/logout') + Scripts.login() + it 'should fail if user is not author' do + ticket = $database.getRow('ticket', 1, 'id') + result = request('/ticket/seen', { + ticketNumber: ticket['ticket_number'], + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('fail') + (result['message']).should.equal('NO_PERMISSION') + end request('/user/logout') Scripts.login('user_get@os4.com', 'user_get') diff --git a/tests/user/login.rb b/tests/user/login.rb index e3d09c9e..373d7050 100644 --- a/tests/user/login.rb +++ b/tests/user/login.rb @@ -41,7 +41,7 @@ describe '/user/login' do }) (result['status']).should.equal('success') - (result['data']['staff']).should.equal('true') + (result['data']['staff']).should.equal(true) end it 'should work with remember token' do