Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ReCodEx/web-app into stri…
Browse files Browse the repository at this point in the history
…ng-sorting-locales
  • Loading branch information
Martin Krulis committed Oct 22, 2017
2 parents 378f34b + 1195074 commit 278f443
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,10 @@ const validate = ({

if (pointsPercentualThreshold) {
const numericThreshold = Number(pointsPercentualThreshold);
if (pointsPercentualThreshold !== Math.round(numericThreshold).toString()) {
if (
pointsPercentualThreshold.toString() !==
Math.round(numericThreshold).toString()
) {
errors['pointsPercentualThreshold'] = (
<FormattedMessage
id="app.editAssignmentForm.validation.pointsPercentualThresholdMustBeInteger"
Expand Down
1 change: 0 additions & 1 deletion src/components/forms/Fields/DatetimeField.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class DatetimeField extends Component {
{...input}
{...props}
locale={lang}
utc={true}
onFocus={() => this.onFocus()}
inputProps={{ disabled }}
/>{' '}
Expand Down
26 changes: 9 additions & 17 deletions src/pages/EditAssignment/EditAssignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import PageContent from '../../components/layout/PageContent';

import ResourceRenderer from '../../components/helpers/ResourceRenderer';
import EditAssignmentForm from '../../components/forms/EditAssignmentForm';
import DeleteAssignmentButtonContainer
from '../../containers/DeleteAssignmentButtonContainer';
import DeleteAssignmentButtonContainer from '../../containers/DeleteAssignmentButtonContainer';
import Box from '../../components/widgets/Box';
import { LoadingIcon, WarningIcon } from '../../components/icons';

Expand All @@ -21,14 +20,10 @@ import {
} from '../../redux/modules/assignments';
import { getAssignment } from '../../redux/selectors/assignments';
import { canSubmitSolution } from '../../redux/selectors/canSubmit';
import {
runtimeEnvironmentsSelector
} from '../../redux/selectors/runtimeEnvironments';
import { runtimeEnvironmentsSelector } from '../../redux/selectors/runtimeEnvironments';
import { isSubmitting } from '../../redux/selectors/submission';
import { loggedInUserIdSelector } from '../../redux/selectors/auth';
import {
fetchRuntimeEnvironments
} from '../../redux/modules/runtimeEnvironments';
import { fetchRuntimeEnvironments } from '../../redux/modules/runtimeEnvironments';
import { isReady, getJsData } from '../../redux/helpers/resourceManager';

import withLinks from '../../hoc/withLinks';
Expand Down Expand Up @@ -58,8 +53,8 @@ class EditAssignment extends Component {
pointsPercentualThreshold,
...rest
}) => ({
firstDeadline: moment(firstDeadline * 1000),
secondDeadline: moment(secondDeadline * 1000),
firstDeadline: moment.unix(firstDeadline),
secondDeadline: moment.unix(secondDeadline),
pointsPercentualThreshold: pointsPercentualThreshold * 100,
...rest
});
Expand Down Expand Up @@ -112,8 +107,7 @@ class EditAssignment extends Component {
}
>
<p>
<LoadingIcon />
{' '}
<LoadingIcon />{' '}
<FormattedMessage
id="app.editAssignment.loadingDescription"
defaultMessage="Loading latest assignment settings ..."
Expand All @@ -131,8 +125,7 @@ class EditAssignment extends Component {
}
>
<p>
<WarningIcon />
{' '}
<WarningIcon />{' '}
<FormattedMessage
id="app.editAssignment.failedDescription"
defaultMessage="Assignment settings could not have been loaded."
Expand All @@ -142,16 +135,15 @@ class EditAssignment extends Component {
}
resource={assignment}
>
{data => (
{data =>
<div>
<EditAssignmentForm
assignment={data}
initialValues={data ? this.getInitialValues(data) : {}}
onSubmit={formData => editAssignment(data.version, formData)}
formValues={formValues}
/>
</div>
)}
</div>}
</ResourceRenderer>
<br />
<Box
Expand Down
2 changes: 1 addition & 1 deletion src/pages/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const createRoutes = getState => {
<IndexRoute component={ResetPassword} />
<Route path="change" component={ChangePassword} />
</Route>
<Route path="admin">
<Route path="admin" onEnter={requireAuth}>
<Route path="instances">
<IndexRoute component={Instances} />
<Route path=":instanceId">
Expand Down
27 changes: 24 additions & 3 deletions src/redux/helpers/api/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import statusCode from 'statuscode';
import { addNotification } from '../../modules/notifications';
import flatten from 'flat';

import { logout } from '../../modules/auth';
import { isTokenValid, decode } from '../../helpers/token';

export const isTwoHundredCode = status => statusCode.accept(status, '2xx');
export const isServerError = status => statusCode.accept(status, '5xx');
export const isUnauthorized = status => status === 403;
Expand Down Expand Up @@ -73,15 +76,33 @@ export const createApiCallPromise = (
query = {},
method = 'GET',
headers = {},
accessToken = '',
body = undefined,
wasSuccessful = () => true,
doNotProcess = false
},
dispatch = undefined
) => {
let call = createRequest(endpoint, query, method, headers, body).catch(err =>
detectUnreachableServer(err, dispatch)
);
let call = createRequest(endpoint, query, method, headers, body)
.catch(err => detectUnreachableServer(err, dispatch))
.then(res => {
if (
res.status === 401 &&
!isTokenValid(decode(accessToken)) &&
dispatch
) {
dispatch(logout('/'));
dispatch(
addNotification(
'Your session expired and you were automatically logged out of the ReCodEx system.',
false
)
);
return Promise.reject(res);
}

return res;
});

// this processing can be manually skipped
return doNotProcess === true ? call : processResponse(call, dispatch);
Expand Down
7 changes: 5 additions & 2 deletions src/redux/selectors/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createSelector } from 'reselect';
import { statusTypes } from '../modules/auth';
import { isTokenValid } from '../helpers/token';

const getAuth = state => state.auth;
const getAccessToken = auth => auth.get('accessToken');
Expand Down Expand Up @@ -43,8 +44,10 @@ export const hasSucceeded = service =>
status => status === statusTypes.LOGGED_IN
);

export const isLoggedIn = createSelector(getAuth, auth =>
Boolean(auth.get('userId'))
export const isLoggedIn = createSelector(
getAuth,
auth =>
Boolean(auth.get('userId')) && isTokenValid(auth.get('accessToken').toJS())
);

export const isChanging = createSelector(
Expand Down
11 changes: 8 additions & 3 deletions test/redux/modules/auth-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ describe('Authentication', () => {
it('must return LOGGED OUT initial state when an expired access token is given', () => {
// the token
const exp = 1491903618 * 1000;
const expiredToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTE5MDM2MTh9.3iH9ZXaaACF0Jugajfv4TggeUcqJzPQYqGveh16WHkU';
const expiredToken =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTE5MDM2MTh9.3iH9ZXaaACF0Jugajfv4TggeUcqJzPQYqGveh16WHkU';

const reducer = reducerFactory(expiredToken, exp + 1000); // +1 second
const state = reducer(undefined, {});
Expand All @@ -114,7 +115,8 @@ describe('Authentication', () => {

it('must return LOGGED IN initial state when a valid access token is given', () => {
const exp = 1491903618 * 1000;
const validToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTE5MDM2MTgsInN1YiI6MTIzfQ._Er1LBGLVnD3bdg439fgL7E1YcnMgTDYtzfgjQrQrXQ';
const validToken =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTE5MDM2MTgsInN1YiI6MTIzfQ._Er1LBGLVnD3bdg439fgL7E1YcnMgTDYtzfgjQrQrXQ';
const reducer = reducerFactory(validToken, exp - 1000); // -1 second
const state = reducer(undefined, {});
const expectedState = fromJS({
Expand Down Expand Up @@ -142,7 +144,10 @@ describe('Authentication', () => {
it('must detect that the user is logged in', () => {
const state = {
auth: fromJS({
userId: 123
userId: 123,
accessToken: {
exp: Date.now() / 1000 + 100
}
})
};

Expand Down

0 comments on commit 278f443

Please sign in to comment.