commit
f052e7a568
|
@ -0,0 +1,91 @@
|
|||
const APICallMock = require('lib-app/__mocks__/api-call-mock');
|
||||
|
||||
const SubmitButton = ReactMock();
|
||||
const Button = ReactMock();
|
||||
const Input = ReactMock();
|
||||
const Form = ReactMock();
|
||||
const Checkbox = ReactMock();
|
||||
const Message = ReactMock();
|
||||
const FormField = ReactMock();
|
||||
const Widget = ReactMock();
|
||||
|
||||
const PasswordRecovery = requireUnit('app-components/password-recovery', {
|
||||
'lib-app/api-call': APICallMock,
|
||||
'core-components/submit-button': SubmitButton,
|
||||
'core-components/button': Button,
|
||||
'core-components/form-field': FormField,
|
||||
'core-components/': FormField,
|
||||
'core-components/form': Form,
|
||||
'core-components/checkbox': Checkbox,
|
||||
'core-components/message': Message,
|
||||
'core-components/widget': Widget,
|
||||
});
|
||||
|
||||
describe('PasswordRecovery component', function () {
|
||||
let recoverWidget, recoverForm, widgetTransition, emailInput, component,
|
||||
backToLoginButton, submitButton;
|
||||
|
||||
let dispatch = stub();
|
||||
|
||||
beforeEach(function () {
|
||||
component = TestUtils.renderIntoDocument(
|
||||
<PasswordRecovery />
|
||||
);
|
||||
recoverWidget = TestUtils.scryRenderedComponentsWithType(component, Widget)[0];
|
||||
recoverForm = TestUtils.scryRenderedComponentsWithType(component, Form)[0];
|
||||
emailInput = TestUtils.scryRenderedComponentsWithType(component, Input)[0];
|
||||
submitButton = TestUtils.scryRenderedComponentsWithType(component, SubmitButton)[0];
|
||||
backToLoginButton = TestUtils.scryRenderedComponentsWithType(component, Button)[0];
|
||||
});
|
||||
|
||||
it('should control form errors by prop', function () {
|
||||
expect(recoverForm.props.errors).to.deep.equal({});
|
||||
recoverForm.props.onValidateErrors({email: 'MOCK_ERROR'});
|
||||
expect(recoverForm.props.errors).to.deep.equal({email: 'MOCK_ERROR'});
|
||||
});
|
||||
|
||||
it('should call sendRecoverPassword when submitted', function () {
|
||||
let mockSubmitData = {email: 'MOCK_VALUE'};
|
||||
APICallMock.call.reset();
|
||||
|
||||
recoverForm.props.onSubmit(mockSubmitData);
|
||||
expect(APICallMock.call).to.have.been.calledWith({
|
||||
path: '/user/send-recover-password',
|
||||
data: mockSubmitData
|
||||
});
|
||||
});
|
||||
|
||||
it('should set loading true in the form when submitted', function () {
|
||||
let mockSubmitData = {email: 'MOCK_VALUE'};
|
||||
|
||||
recoverForm.props.onSubmit(mockSubmitData);
|
||||
expect(recoverForm.props.loading).to.equal(true);
|
||||
});
|
||||
|
||||
it('should add error and stop loading when send recover fails', function () {
|
||||
component.refs.recoverForm.refs.email.focus.reset();
|
||||
|
||||
component.onRecoverPasswordFail();
|
||||
expect(recoverForm.props.errors).to.deep.equal({email: 'EMAIL_NOT_EXIST'});
|
||||
expect(recoverForm.props.loading).to.equal(false);
|
||||
expect(component.refs.recoverForm.refs.email.focus).to.have.been.called;
|
||||
});
|
||||
|
||||
it('should show message when send recover success', function () {
|
||||
let message = TestUtils.scryRenderedComponentsWithType(component, Message)[0];
|
||||
expect(message).to.equal(undefined);
|
||||
|
||||
component.onRecoverPasswordSent();
|
||||
message = TestUtils.scryRenderedComponentsWithType(component, Message)[0];
|
||||
|
||||
expect(recoverForm.props.loading).to.equal(false);
|
||||
expect(message).to.not.equal(null);
|
||||
expect(message.props.type).to.equal('info');
|
||||
expect(message.props.children).to.equal('RECOVER_SENT');
|
||||
});
|
||||
|
||||
it('should show front side if \'Back to login form\' link is clicked', function () {
|
||||
backToLoginButton.props.onClick();
|
||||
expect(widgetTransition.props.sideToShow).to.equal('front');
|
||||
});
|
||||
});
|
|
@ -25,10 +25,11 @@ class PasswordRecovery extends React.Component {
|
|||
};
|
||||
|
||||
render() {
|
||||
const { renderLogo, formProps, onBackToLoginClick } = this.props;
|
||||
return (
|
||||
<Widget {...this.props} className="password-recovery__content">
|
||||
<Widget {...this.props} className={this.getClass()} title={!renderLogo && i18n('RECOVER_PASSWORD')}>
|
||||
{this.renderLogo()}
|
||||
<Form {...this.props.formProps}>
|
||||
<Form {...formProps}>
|
||||
<div className="password-recovery__inputs">
|
||||
<FormField placeholder={i18n('EMAIL_LOWERCASE')} name="email" className="password-recovery__input" validation="EMAIL" required/>
|
||||
</div>
|
||||
|
@ -36,7 +37,7 @@ class PasswordRecovery extends React.Component {
|
|||
<SubmitButton type="primary">{i18n('RECOVER_PASSWORD')}</SubmitButton>
|
||||
</div>
|
||||
</Form>
|
||||
<Button className="password-recovery__forgot-password" type="link" onClick={this.props.onBackToLoginClick} onMouseDown={(event) => {event.preventDefault()}}>
|
||||
<Button className="password-recovery__forgot-password" type="link" onClick={onBackToLoginClick} onMouseDown={(event) => {event.preventDefault()}}>
|
||||
{i18n('BACK_LOGIN_FORM')}
|
||||
</Button>
|
||||
{this.renderRecoverStatus()}
|
||||
|
@ -44,6 +45,13 @@ class PasswordRecovery extends React.Component {
|
|||
);
|
||||
}
|
||||
|
||||
getClass() {
|
||||
return classNames({
|
||||
'password-recovery__content': true,
|
||||
[this.props.className]: (this.props.className)
|
||||
});
|
||||
}
|
||||
|
||||
renderLogo() {
|
||||
let logo = null;
|
||||
|
||||
|
|
|
@ -120,11 +120,11 @@ class TicketViewer extends React.Component {
|
|||
<DropDown className="ticket-viewer__editable-dropdown" items={priorityList} selectedIndex={priorities[ticket.priority]} onChange={this.onPriorityDropdownChanged.bind(this)} />
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
{this.renderEditableOwnerNode()}
|
||||
{this.renderAssignStaffList()}
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
{ticket.closed ?
|
||||
<Button type='secondary' size="extra-small" onClick={this.onCloseClick.bind(this)}>
|
||||
<Button type='secondary' size="extra-small" onClick={this.onReopenClick.bind(this)}>
|
||||
{i18n('RE_OPEN')}
|
||||
</Button> : i18n('OPENED')}
|
||||
</div>
|
||||
|
@ -173,19 +173,6 @@ class TicketViewer extends React.Component {
|
|||
);
|
||||
}
|
||||
|
||||
renderEditableOwnerNode() {
|
||||
let ownerNode = null;
|
||||
let {ticket, userId} = this.props;
|
||||
|
||||
if (_.isEmpty(ticket.owner) || ticket.owner.id == userId) {
|
||||
ownerNode = this.renderAssignStaffList();
|
||||
} else {
|
||||
ownerNode = (this.props.ticket.owner) ? this.props.ticket.owner.name : i18n('NONE')
|
||||
}
|
||||
|
||||
return ownerNode;
|
||||
}
|
||||
|
||||
renderOwnerNode() {
|
||||
let ownerNode = null;
|
||||
|
||||
|
@ -205,8 +192,6 @@ class TicketViewer extends React.Component {
|
|||
let selectedIndex = _.findIndex(items, {id: ownerId});
|
||||
selectedIndex = (selectedIndex !== -1) ? selectedIndex : 0;
|
||||
|
||||
console.log(selectedIndex);
|
||||
|
||||
return (
|
||||
<DropDown
|
||||
className="ticket-viewer__editable-dropdown" items={items}
|
||||
|
@ -323,13 +308,27 @@ class TicketViewer extends React.Component {
|
|||
APICallPromise.then(this.onTicketModification.bind(this));
|
||||
}
|
||||
|
||||
onCloseClick() {
|
||||
AreYouSure.openModal(null, this.toggleClose.bind(this));
|
||||
onReopenClick() {
|
||||
AreYouSure.openModal(null, this.reopenTicket.bind(this));
|
||||
}
|
||||
|
||||
toggleClose() {
|
||||
onCloseTicketClick(event) {
|
||||
event.preventDefault();
|
||||
AreYouSure.openModal(null, this.closeTicket.bind(this));
|
||||
}
|
||||
|
||||
reopenTicket() {
|
||||
API.call({
|
||||
path: (this.props.ticket.closed) ? '/ticket/re-open' : '/ticket/close',
|
||||
path: '/ticket/re-open',
|
||||
data: {
|
||||
ticketNumber: this.props.ticket.ticketNumber
|
||||
}
|
||||
}).then(this.onTicketModification.bind(this));
|
||||
}
|
||||
|
||||
closeTicket() {
|
||||
API.call({
|
||||
path: '/ticket/close',
|
||||
data: {
|
||||
ticketNumber: this.props.ticket.ticketNumber
|
||||
}
|
||||
|
@ -414,15 +413,6 @@ class TicketViewer extends React.Component {
|
|||
this.props.onChange();
|
||||
}
|
||||
}
|
||||
onCloseTicketClick(event){
|
||||
event.preventDefault();
|
||||
API.call({
|
||||
path: '/ticket/close',
|
||||
data: {
|
||||
ticketNumber: this.props.ticket.ticketNumber
|
||||
}
|
||||
}).then(this.onTicketModification.bind(this));
|
||||
}
|
||||
|
||||
getStaffAssignmentItems() {
|
||||
const {staffMembers, userDepartments, userId, ticket} = this.props;
|
||||
|
|
|
@ -23,7 +23,7 @@ class AdminPanelStaffMembers extends React.Component {
|
|||
|
||||
static propTypes = {
|
||||
staffList: React.PropTypes.array,
|
||||
loading: React.PropTypes.boolean,
|
||||
loading: React.PropTypes.bool,
|
||||
}
|
||||
|
||||
static defaultProps = {
|
||||
|
@ -37,7 +37,7 @@ class AdminPanelStaffMembers extends React.Component {
|
|||
};
|
||||
|
||||
componentDidMount() {
|
||||
this.props.dispatch(AdminDataActions.retrieveStaffMembers());
|
||||
this.retrieveStaffMembers();
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@ -107,6 +107,10 @@ class AdminPanelStaffMembers extends React.Component {
|
|||
|
||||
return departments;
|
||||
}
|
||||
|
||||
retrieveStaffMembers() {
|
||||
this.props.dispatch(AdminDataActions.retrieveStaffMembers());
|
||||
}
|
||||
}
|
||||
|
||||
export default connect((store) => {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import {connect} from 'react-redux';
|
||||
import history from 'lib-app/history';
|
||||
|
||||
import SessionActions from 'actions/session-actions';
|
||||
import CreateTicketForm from 'app/main/dashboard/dashboard-create-ticket/create-ticket-form';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*const SessionActionsMock = require('actions/__mocks__/session-actions-mock');
|
||||
const SessionActionsMock = require('actions/__mocks__/session-actions-mock');
|
||||
const APICallMock = require('lib-app/__mocks__/api-call-mock');
|
||||
|
||||
const SubmitButton = ReactMock();
|
||||
|
@ -9,11 +9,13 @@ const Checkbox = ReactMock();
|
|||
const Message = ReactMock();
|
||||
const Widget = ReactMock();
|
||||
const WidgetTransition = ReactMock();
|
||||
const PasswordRecovery = ReactMock();
|
||||
|
||||
const MainHomePageLoginWidget = requireUnit('app/main/main-home/main-home-page-login-widget', {
|
||||
'react-redux': ReduxMock,
|
||||
'actions/session-actions': SessionActionsMock,
|
||||
'lib-app/api-call': APICallMock,
|
||||
'app-components/password-recovery': PasswordRecovery,
|
||||
'core-components/submit-button': SubmitButton,
|
||||
'core-components/button': Button,
|
||||
'core-components/input': Input,
|
||||
|
@ -107,8 +109,7 @@ describe('Login/Recover Widget', function () {
|
|||
});
|
||||
|
||||
describe('Recover Password form', function () {
|
||||
let recoverWidget, recoverForm, widgetTransition, emailInput, component,
|
||||
backToLoginButton, submitButton;
|
||||
let recoverPassword, widgetTransition, component;
|
||||
|
||||
let dispatch = stub();
|
||||
|
||||
|
@ -117,32 +118,20 @@ describe('Login/Recover Widget', function () {
|
|||
<MainHomePageLoginWidget dispatch={dispatch} session={{pending: false, failed: false}} />
|
||||
);
|
||||
widgetTransition = TestUtils.scryRenderedComponentsWithType(component, WidgetTransition)[0];
|
||||
recoverWidget = TestUtils.scryRenderedComponentsWithType(component, Widget)[1];
|
||||
recoverForm = TestUtils.scryRenderedComponentsWithType(component, Form)[1];
|
||||
emailInput = TestUtils.scryRenderedComponentsWithType(component, Input)[2];
|
||||
submitButton = TestUtils.scryRenderedComponentsWithType(component, SubmitButton)[1];
|
||||
backToLoginButton = TestUtils.scryRenderedComponentsWithType(component, Button)[1];
|
||||
|
||||
component.refs.recoverForm = {
|
||||
refs: {
|
||||
email: {
|
||||
focus: stub()
|
||||
}
|
||||
}
|
||||
};
|
||||
recoverPassword = TestUtils.scryRenderedComponentsWithType(component, PasswordRecovery)[0];
|
||||
});
|
||||
|
||||
it('should control form errors by prop', function () {
|
||||
expect(recoverForm.props.errors).to.deep.equal({});
|
||||
recoverForm.props.onValidateErrors({email: 'MOCK_ERROR'});
|
||||
expect(recoverForm.props.errors).to.deep.equal({email: 'MOCK_ERROR'});
|
||||
expect(recoverPassword.props.formProps.errors).to.deep.equal({});
|
||||
recoverPassword.props.formProps.onValidateErrors({email: 'MOCK_ERROR'});
|
||||
expect(recoverPassword.props.formProps.errors).to.deep.equal({email: 'MOCK_ERROR'});
|
||||
});
|
||||
|
||||
it('should call sendRecoverPassword when submitted', function () {
|
||||
let mockSubmitData = {email: 'MOCK_VALUE'};
|
||||
APICallMock.call.reset();
|
||||
|
||||
recoverForm.props.onSubmit(mockSubmitData);
|
||||
recoverPassword.props.formProps.onSubmit(mockSubmitData);
|
||||
expect(APICallMock.call).to.have.been.calledWith({
|
||||
path: '/user/send-recover-password',
|
||||
data: mockSubmitData
|
||||
|
@ -152,12 +141,12 @@ describe('Login/Recover Widget', function () {
|
|||
it('should set loading true in the form when submitted', function () {
|
||||
let mockSubmitData = {email: 'MOCK_VALUE'};
|
||||
|
||||
recoverForm.props.onSubmit(mockSubmitData);
|
||||
expect(recoverForm.props.loading).to.equal(true);
|
||||
recoverPassword.props.formProps.onSubmit(mockSubmitData);
|
||||
expect(recoverForm.props.formProps.loading).to.equal(true);
|
||||
});
|
||||
|
||||
it('should add error and stop loading when send recover fails', function () {
|
||||
component.refs.recoverForm.refs.email.focus.reset();
|
||||
component.refs.recoverPassword.refs.email.focus.reset();
|
||||
|
||||
component.onRecoverPasswordFail();
|
||||
expect(recoverForm.props.errors).to.deep.equal({email: 'EMAIL_NOT_EXIST'});
|
||||
|
@ -183,4 +172,4 @@ describe('Login/Recover Widget', function () {
|
|||
expect(widgetTransition.props.sideToShow).to.equal('front');
|
||||
});
|
||||
});
|
||||
});*/
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@ import API from 'lib-app/api-call';
|
|||
import focus from 'lib-core/focus';
|
||||
import i18n from 'lib-app/i18n';
|
||||
|
||||
import PasswordRecovery from 'app-components/password-recovery.js';
|
||||
import PasswordRecovery from 'app-components/password-recovery';
|
||||
import SubmitButton from 'core-components/submit-button';
|
||||
import Button from 'core-components/button';
|
||||
import Form from 'core-components/form';
|
||||
|
|
|
@ -35,6 +35,7 @@ global.reRenderIntoDocument = (function () {
|
|||
global.ReduxMock = {
|
||||
connect: stub().returns(stub().returnsArg(0))
|
||||
};
|
||||
global.globalIndexPath = '';
|
||||
|
||||
Array.prototype.swap = function (x,y) {
|
||||
var b = this[x];
|
||||
|
|
|
@ -28,7 +28,9 @@ 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
|
||||
@docker stop opensupports-srv || true
|
||||
@rm -rf .fakemail || true
|
||||
@mkdir .fakemail
|
||||
|
||||
db:
|
||||
@docker exec -it opensupports-db bash -c "mysql -u root" || echo "${red}Please execute 'make run' first${reset}"
|
||||
|
|
|
@ -80,7 +80,24 @@ class EditStaffController extends Controller {
|
|||
}
|
||||
|
||||
if(Controller::request('departments') && Controller::isStaffLogged(3)) {
|
||||
$this->staffInstance->sharedDepartmentList = $this->getDepartmentList();
|
||||
$departmentList = $this->getDepartmentList();
|
||||
$ticketList = $this->staffInstance->sharedTicketList;
|
||||
|
||||
$this->staffInstance->sharedDepartmentList = $departmentList;
|
||||
|
||||
foreach($ticketList as $ticket) {
|
||||
if(!$departmentList->includesId($ticket->department->id)) {
|
||||
if($ticket->isOwner($this->staffInstance) ) {
|
||||
$ticket->owner = null;
|
||||
}
|
||||
|
||||
if(!$ticket->isAuthor($this->staffInstance)) {
|
||||
$this->staffInstance->sharedTicketList->remove($ticket);
|
||||
}
|
||||
|
||||
$ticket->store();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($fileUploader = $this->uploadFile(true)) {
|
||||
|
|
|
@ -46,7 +46,7 @@ class UnAssignStaffController extends Controller {
|
|||
$owner = $ticket->owner;
|
||||
|
||||
if($ticket->isOwner($user) || $user->level > 2) {
|
||||
if(!$ticket->isAuthor($user)) {
|
||||
if(!$ticket->isAuthor($owner)) {
|
||||
$owner->sharedTicketList->remove($ticket);
|
||||
$owner->store();
|
||||
}
|
||||
|
|
|
@ -78,6 +78,6 @@ class TicketGetController extends Controller {
|
|||
$user = Controller::getLoggedUser();
|
||||
|
||||
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() && (!$user->sharedTicketList->includesId($this->ticket->id) && !$user->sharedDepartmentList->includesId($this->ticket->department->id)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,8 +63,13 @@ class ReOpenController extends Controller {
|
|||
private function shouldDenyPermission() {
|
||||
$user = Controller::getLoggedUser();
|
||||
|
||||
return (!Controller::isStaffLogged() && $this->ticket->author->id !== $user->id) ||
|
||||
(Controller::isStaffLogged() && $this->ticket->owner && $this->ticket->owner->id !== $user->id);
|
||||
return !(
|
||||
$this->ticket->isAuthor($user) ||
|
||||
(
|
||||
Controller::isStaffLogged() &&
|
||||
$user->sharedDepartmentList->includesId($this->ticket->department->id)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function markAsUnread() {
|
||||
|
|
|
@ -41,7 +41,10 @@ class RecoverPasswordController extends Controller {
|
|||
'permission' => 'any',
|
||||
'requestData' => [
|
||||
'email' => [
|
||||
'validation' => DataValidator::email()->userEmail(),
|
||||
'validation' => DataValidator::oneOf(
|
||||
DataValidator::email()->userEmail(),
|
||||
DataValidator::email()->staffEmail()
|
||||
),
|
||||
'error' => ERRORS::INVALID_EMAIL
|
||||
],
|
||||
'password' => [
|
||||
|
|
|
@ -38,7 +38,10 @@ class SendRecoverPasswordController extends Controller {
|
|||
'permission' => 'any',
|
||||
'requestData' => [
|
||||
'email' => [
|
||||
'validation' => DataValidator::email()->userEmail(),
|
||||
'validation' => DataValidator::oneOf(
|
||||
DataValidator::email()->userEmail(),
|
||||
DataValidator::email()->staffEmail()
|
||||
),
|
||||
'error' => ERRORS::INVALID_EMAIL
|
||||
]
|
||||
]
|
||||
|
@ -66,7 +69,7 @@ class SendRecoverPasswordController extends Controller {
|
|||
$recoverPassword->setProperties(array(
|
||||
'email' => $email,
|
||||
'token' => $this->token,
|
||||
'staff' => $this->staff
|
||||
'staff' => !!$this->staff
|
||||
));
|
||||
$recoverPassword->store();
|
||||
|
||||
|
|
|
@ -47,9 +47,10 @@ spl_autoload_register(function ($class) {
|
|||
}
|
||||
});
|
||||
|
||||
//Load custom validations
|
||||
// LOAD CUSTOM VALIDATIONS
|
||||
include_once 'libs/validations/dataStoreId.php';
|
||||
include_once 'libs/validations/userEmail.php';
|
||||
include_once 'libs/validations/staffEmail.php';
|
||||
include_once 'libs/validations/captcha.php';
|
||||
include_once 'libs/validations/validLanguage.php';
|
||||
include_once 'libs/validations/validTicketNumber.php';
|
||||
|
|
|
@ -55,6 +55,10 @@ abstract class Controller {
|
|||
public static function request($key, $secure = false) {
|
||||
$result = call_user_func(self::$dataRequester, $key);
|
||||
|
||||
if($key === 'email' || $key === 'newEmail') {
|
||||
return strtolower($result);
|
||||
}
|
||||
|
||||
if($secure) {
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$purifier = new HTMLPurifier($config);
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace CustomValidations;
|
||||
|
||||
use Respect\Validation\Rules\AbstractRule;
|
||||
|
||||
class StaffEmail extends AbstractRule {
|
||||
|
||||
public function validate($email) {
|
||||
$user = \Staff::getUser($email, 'email');
|
||||
|
||||
return !$user->isNull();
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ describe'/staff/edit' do
|
|||
|
||||
row = $database.getRow('staff', 3, 'id')
|
||||
|
||||
(row['email']).should.equal('LittleLannister@opensupports.com')
|
||||
(row['email']).should.equal('littlelannister@opensupports.com')
|
||||
(row['level']).should.equal('1')
|
||||
|
||||
rows = $database.getRow('department_staff', 3, 'staff_id')
|
||||
|
|
Loading…
Reference in New Issue