1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 09:23:13 +01:00

Fix redirection of wallet owners

This also fixes a problem where newly created
users would be redirected to a 404 page.
This commit is contained in:
Tim Daubenschütz 2016-02-01 13:50:55 +01:00
parent f2542f99bd
commit e2a481a3f0
7 changed files with 95 additions and 21 deletions

View File

@ -36,7 +36,10 @@ let PieceList = React.createClass({
accordionListItemType: React.PropTypes.func, accordionListItemType: React.PropTypes.func,
bulkModalButtonListType: React.PropTypes.func, bulkModalButtonListType: React.PropTypes.func,
canLoadPieceList: React.PropTypes.bool, canLoadPieceList: React.PropTypes.bool,
redirectTo: React.PropTypes.string, redirectTo: React.PropTypes.shape({
pathname: React.PropTypes.string,
query: React.PropTypes.object
}),
shouldRedirect: React.PropTypes.func, shouldRedirect: React.PropTypes.func,
customSubmitButton: React.PropTypes.element, customSubmitButton: React.PropTypes.element,
customThumbnailPlaceholder: React.PropTypes.func, customThumbnailPlaceholder: React.PropTypes.func,
@ -62,7 +65,10 @@ let PieceList = React.createClass({
] ]
}], }],
orderParams: ['artist_name', 'title'], orderParams: ['artist_name', 'title'],
redirectTo: '/register_piece', redirectTo: {
pathname: '/register_piece',
query: {}
},
shouldRedirect: () => true shouldRedirect: () => true
}; };
}, },
@ -120,10 +126,16 @@ let PieceList = React.createClass({
const { location: { query }, redirectTo, shouldRedirect } = this.props; const { location: { query }, redirectTo, shouldRedirect } = this.props;
const { unfilteredPieceListCount } = this.state; const { unfilteredPieceListCount } = this.state;
if (redirectTo && unfilteredPieceListCount === 0 && if (redirectTo && redirectTo.pathname && unfilteredPieceListCount === 0 &&
(typeof shouldRedirect === 'function' && shouldRedirect(unfilteredPieceListCount))) { (typeof shouldRedirect === 'function' && shouldRedirect(unfilteredPieceListCount))) {
// FIXME: hack to redirect out of the dispatch cycle // FIXME: hack to redirect out of the dispatch cycle
window.setTimeout(() => this.history.push({ query, pathname: redirectTo }), 0); window.setTimeout(() => this.history.push({
// Occasionally, the back end also sets query parameters for Onion.
// We need to consider this by merging all passed query parameters, as we'll
// otherwise end up in a 404 screen
query: Object.assign(query, redirectTo.query),
pathname: redirectTo.pathname
}), 0);
} }
}, },

View File

@ -62,13 +62,15 @@ let PrizePieceList = React.createClass({
}, },
render() { render() {
const { is_judge: isJudge, is_jury: isJury, is_admin: isAdmin } = this.state.currentUser;
setDocumentTitle(getLangText('Collection')); setDocumentTitle(getLangText('Collection'));
let orderParams = ['artist_name', 'title']; let orderParams = ['artist_name', 'title'];
if (this.state.currentUser.is_jury) { if (isJury) {
orderParams = ['rating', 'title']; orderParams = ['rating', 'title'];
} }
if (this.state.currentUser.is_judge) { if (isJudge) {
orderParams = ['rating', 'title', 'selected']; orderParams = ['rating', 'title', 'selected'];
} }
return ( return (
@ -80,7 +82,8 @@ let PrizePieceList = React.createClass({
orderBy={this.state.currentUser.is_jury ? 'rating' : null} orderBy={this.state.currentUser.is_jury ? 'rating' : null}
filterParams={[]} filterParams={[]}
customSubmitButton={this.getButtonSubmit()} customSubmitButton={this.getButtonSubmit()}
location={this.props.location}/> location={this.props.location}
shouldRedirect={() => !(isJury || isJudge || isAdmin)} />
</div> </div>
); );
} }

View File

@ -1,4 +1,4 @@
'use strict' 'use strict';
import React from 'react'; import React from 'react';

View File

@ -6,11 +6,14 @@ import PieceList from '../../../../piece_list';
import UserActions from '../../../../../actions/user_actions'; import UserActions from '../../../../../actions/user_actions';
import UserStore from '../../../../../stores/user_store'; import UserStore from '../../../../../stores/user_store';
import WhitelabelActions from '../../../../../actions/whitelabel_actions';
import WhitelabelStore from '../../../../../stores/whitelabel_store';
import CylandAccordionListItem from './cyland_accordion_list/cyland_accordion_list_item'; import CylandAccordionListItem from './cyland_accordion_list/cyland_accordion_list_item';
import { getLangText } from '../../../../../utils/lang_utils'; import { getLangText } from '../../../../../utils/lang_utils';
import { setDocumentTitle } from '../../../../../utils/dom_utils'; import { setDocumentTitle } from '../../../../../utils/dom_utils';
import { mergeOptions } from '../../../../../utils/general_utils';
let CylandPieceList = React.createClass({ let CylandPieceList = React.createClass({
propTypes: { propTypes: {
@ -18,15 +21,22 @@ let CylandPieceList = React.createClass({
}, },
getInitialState() { getInitialState() {
return UserStore.getState(); return mergeOptions(
UserStore.getState(),
WhitelabelStore.getState()
);
}, },
componentDidMount() { componentDidMount() {
UserStore.listen(this.onChange); UserStore.listen(this.onChange);
WhitelabelStore.listen(this.onChange);
WhitelabelActions.fetchWhitelabel();
UserActions.fetchCurrentUser(); UserActions.fetchCurrentUser();
}, },
componentWillUnmount() { componentWillUnmount() {
WhitelabelStore.unlisten(this.onChange);
UserStore.unlisten(this.onChange); UserStore.unlisten(this.onChange);
}, },
@ -34,13 +44,30 @@ let CylandPieceList = React.createClass({
this.setState(state); this.setState(state);
}, },
shouldRedirect(pieceCount) {
const {
currentUser: { email: userEmail },
whitelabel: {
user: whitelabelAdminEmail
}
} = this.state;
return userEmail !== whitelabelAdminEmail && !pieceCount;
},
render() { render() {
setDocumentTitle(getLangText('Collection')); setDocumentTitle(getLangText('Collection'));
return ( return (
<div> <div>
<PieceList <PieceList
redirectTo="/register_piece?slide_num=0" redirectTo={{
pathname: '/register_piece',
query: {
'slide_num': 0
}
}}
shouldRedirect={this.shouldRedirect}
accordionListItemType={CylandAccordionListItem} accordionListItemType={CylandAccordionListItem}
filterParams={[{ filterParams={[{
label: getLangText('Show works I have'), label: getLangText('Show works I have'),

View File

@ -6,8 +6,12 @@ import PieceList from '../../../../piece_list';
import UserActions from '../../../../../actions/user_actions'; import UserActions from '../../../../../actions/user_actions';
import UserStore from '../../../../../stores/user_store'; import UserStore from '../../../../../stores/user_store';
import NotificationStore from '../../../../../stores/notification_store'; import NotificationStore from '../../../../../stores/notification_store';
import WhitelabelActions from '../../../../../actions/whitelabel_actions';
import WhitelabelStore from '../../../../../stores/whitelabel_store';
import IkonotvAccordionListItem from './ikonotv_accordion_list/ikonotv_accordion_list_item'; import IkonotvAccordionListItem from './ikonotv_accordion_list/ikonotv_accordion_list_item';
import { setDocumentTitle } from '../../../../../utils/dom_utils'; import { setDocumentTitle } from '../../../../../utils/dom_utils';
@ -23,31 +27,43 @@ let IkonotvPieceList = React.createClass({
getInitialState() { getInitialState() {
return mergeOptions( return mergeOptions(
NotificationStore.getState(), NotificationStore.getState(),
UserStore.getState() UserStore.getState(),
WhitelabelStore.getState()
); );
}, },
componentDidMount() { componentDidMount() {
NotificationStore.listen(this.onChange); NotificationStore.listen(this.onChange);
WhitelabelStore.listen(this.onChange);
UserStore.listen(this.onChange); UserStore.listen(this.onChange);
WhitelabelActions.fetchWhitelabel();
UserActions.fetchCurrentUser(); UserActions.fetchCurrentUser();
}, },
componentWillUnmount() { componentWillUnmount() {
NotificationStore.unlisten(this.onChange); NotificationStore.unlisten(this.onChange);
WhitelabelStore.unlisten(this.onChange);
UserStore.unlisten(this.onChange); UserStore.unlisten(this.onChange);
}, },
onChange(state) { onChange(state) {
this.setState(state); this.setState(state);
}, },
redirectIfNoContractNotifications() { shouldRedirect(pieceCount) {
const { contractAgreementListNotifications } = this.state; const {
contractAgreementListNotifications,
currentUser: { email: userEmail },
whitelabel: {
user: whitelabelAdminEmail
}
} = this.state;
return contractAgreementListNotifications && !contractAgreementListNotifications.length; return contractAgreementListNotifications &&
!contractAgreementListNotifications.length &&
userEmail !== whitelabelAdminEmail &&
!pieceCount;
}, },
render() { render() {
@ -56,8 +72,13 @@ let IkonotvPieceList = React.createClass({
return ( return (
<div> <div>
<PieceList <PieceList
redirectTo="/register_piece?slide_num=0" redirectTo={{
shouldRedirect={this.redirectIfNoContractNotifications} pathname: '/register_piece',
query: {
'slide_num': 0
}
}}
shouldRedirect={this.shouldRedirect}
accordionListItemType={IkonotvAccordionListItem} accordionListItemType={IkonotvAccordionListItem}
filterParams={[{ filterParams={[{
label: getLangText('Show works I have'), label: getLangText('Show works I have'),

View File

@ -49,6 +49,10 @@ let MarketPieceList = React.createClass({
this.setState(state); this.setState(state);
}, },
shouldRedirect(isUserAdmin) {
return (pieceCount) => !isUserAdmin && !pieceCount;
},
render() { render() {
const { customThumbnailPlaceholder, location } = this.props; const { customThumbnailPlaceholder, location } = this.props;
const { const {
@ -59,11 +63,12 @@ let MarketPieceList = React.createClass({
} } = this.state; } } = this.state;
let filterParams = null; let filterParams = null;
let isUserAdmin = null;
let canLoadPieceList = false; let canLoadPieceList = false;
if (userEmail && whitelabelAdminEmail) { if (userEmail && whitelabelAdminEmail) {
canLoadPieceList = true; canLoadPieceList = true;
const isUserAdmin = userEmail === whitelabelAdminEmail; isUserAdmin = userEmail === whitelabelAdminEmail;
filterParams = [{ filterParams = [{
label: getLangText('Show works I can'), label: getLangText('Show works I can'),
@ -78,7 +83,13 @@ let MarketPieceList = React.createClass({
return ( return (
<PieceList <PieceList
canLoadPieceList={canLoadPieceList} canLoadPieceList={canLoadPieceList}
redirectTo="/register_piece?slide_num=0" redirectTo={{
pathname: '/register_piece',
query: {
'slide_num': 0
}
}}
shouldRedirect={this.shouldRedirect(isUserAdmin)}
bulkModalButtonListType={MarketAclButtonList} bulkModalButtonListType={MarketAclButtonList}
customThumbnailPlaceholder={customThumbnailPlaceholder} customThumbnailPlaceholder={customThumbnailPlaceholder}
filterParams={filterParams} filterParams={filterParams}

View File

@ -117,7 +117,7 @@ let MarketRegisterPiece = React.createClass({
step, step,
whitelabel: { whitelabel: {
name: whitelabelName = 'Market' name: whitelabelName = 'Market'
} } = this.state; } } = this.state;
setDocumentTitle(getLangText('Register a new piece')); setDocumentTitle(getLangText('Register a new piece'));