Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect query param #2527

Merged
merged 8 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added documentation on how to mount cloud starage(AWS S3 bucket, Azure container, Google Drive) as FUSE (<https://github.com/openvinotoolkit/cvat/pull/2377>)
- Added ability to work with share files without copying inside (<https://github.com/openvinotoolkit/cvat/pull/2377>)
- Tooltips in label selectors (<https://github.com/openvinotoolkit/cvat/pull/2509>)
- Page redirect after login using `next` query parameter (<https://github.com/openvinotoolkit/cvat/pull/2527>)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion cvat-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.11.6",
"version": "1.12.0",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
17 changes: 14 additions & 3 deletions cvat-ui/src/components/cvat-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,22 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
aboutInitialized,
pluginsInitialized,
formatsInitialized,
modelsInitialized,
switchShortcutsDialog,
switchSettingsDialog,
user,
keyMap,
location,
isModelPluginActive,
} = this.props;

const readyForRender =
(userInitialized && (user == null || !user.isVerified)) ||
(userInitialized && formatsInitialized && pluginsInitialized && aboutInitialized);
(userInitialized &&
formatsInitialized &&
pluginsInitialized &&
aboutInitialized &&
(!isModelPluginActive || modelsInitialized));

const subKeyMap = {
SWITCH_SHORTCUTS: keyMap.SWITCH_SHORTCUTS,
Expand Down Expand Up @@ -312,7 +318,10 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
{isModelPluginActive && (
<Route exact path='/models' component={ModelsPageContainer} />
)}
<Redirect push to='/tasks' />
<Redirect
push
to={new URLSearchParams(location.search).get('next') || '/tasks'}
/>
</Switch>
</GlobalHotKeys>
{/* eslint-disable-next-line */}
Expand All @@ -339,7 +348,9 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
path='/auth/password/reset/confirm'
component={ResetPasswordPageConfirmComponent}
/>
<Redirect to='/auth/login' />
<Redirect
to={location.pathname.length > 1 ? `/auth/login/?next=${location.pathname}` : '/auth/login'}
/>
</Switch>
</GlobalErrorBoundary>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
// SPDX-License-Identifier: MIT

import React, { useEffect } from 'react';
import { Redirect, useParams } from 'react-router';
import { Redirect, useParams, useLocation } from 'react-router';
import { useCookies } from 'react-cookie';

export default function LoginWithTokenComponent(): JSX.Element {
const { sessionId, token } = useParams();
const location = useLocation();
const { sessionId, token } = useParams<{ sessionId: string; token: string }>();
const [cookies, setCookie] = useCookies(['sessionid', 'csrftoken']);

const expires1y = new Date(new Date().setFullYear(new Date().getFullYear() + 1));
const expires2w = new Date(new Date().setDate(new Date().getDate() + 13));
const search = new URLSearchParams(location.search);

setCookie('sessionid', sessionId, { path: '/', expires: expires2w });
setCookie('csrftoken', token, { path: '/', expires: expires1y });
Expand All @@ -24,7 +26,7 @@ export default function LoginWithTokenComponent(): JSX.Element {
);

if (cookies.sessionid && cookies.csrftoken) {
return <Redirect to='/tasks' />;
return <Redirect to={search.get('next') || '/tasks'} />;
}
return <></>;
}
6 changes: 3 additions & 3 deletions cvat-ui/src/reducers/auth-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ export default function (state = defaultState, action: AuthActions | BoundariesA
return {
...state,
showChangePasswordDialog:
typeof action.payload.showChangePasswordDialog === 'undefined'
? !state.showChangePasswordDialog
: action.payload.showChangePasswordDialog,
typeof action.payload.showChangePasswordDialog === 'undefined' ?
!state.showChangePasswordDialog :
action.payload.showChangePasswordDialog,
};
case AuthActionTypes.REQUEST_PASSWORD_RESET:
return {
Expand Down
1 change: 1 addition & 0 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Cypress.Commands.add('logout', (username = Cypress.env('user')) => {
});
cy.get('.anticon-logout').click();
cy.url().should('include', '/auth/login');
cy.visit('/auth/login'); // clear query parameter "next"
});

Cypress.Commands.add('userRegistration', (firstName, lastName, userName, emailAddr, password) => {
Expand Down