From e2a481a3f0a35c94e7f3e661e13e24e3bbde2909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Mon, 1 Feb 2016 13:50:55 +0100 Subject: [PATCH 1/2] Fix redirection of wallet owners This also fixes a problem where newly created users would be redirected to a 404 page. --- js/components/piece_list.js | 20 ++++++++--- .../components/prize_piece_list.js | 9 +++-- .../components/23vivi/23vivi_piece_list.js | 2 +- .../components/cyland/cyland_piece_list.js | 33 +++++++++++++++-- .../components/ikonotv/ikonotv_piece_list.js | 35 +++++++++++++++---- .../components/market/market_piece_list.js | 15 ++++++-- .../market/market_register_piece.js | 2 +- 7 files changed, 95 insertions(+), 21 deletions(-) diff --git a/js/components/piece_list.js b/js/components/piece_list.js index 567a53e9..82fc2df3 100644 --- a/js/components/piece_list.js +++ b/js/components/piece_list.js @@ -36,7 +36,10 @@ let PieceList = React.createClass({ accordionListItemType: React.PropTypes.func, bulkModalButtonListType: React.PropTypes.func, canLoadPieceList: React.PropTypes.bool, - redirectTo: React.PropTypes.string, + redirectTo: React.PropTypes.shape({ + pathname: React.PropTypes.string, + query: React.PropTypes.object + }), shouldRedirect: React.PropTypes.func, customSubmitButton: React.PropTypes.element, customThumbnailPlaceholder: React.PropTypes.func, @@ -62,7 +65,10 @@ let PieceList = React.createClass({ ] }], orderParams: ['artist_name', 'title'], - redirectTo: '/register_piece', + redirectTo: { + pathname: '/register_piece', + query: {} + }, shouldRedirect: () => true }; }, @@ -120,10 +126,16 @@ let PieceList = React.createClass({ const { location: { query }, redirectTo, shouldRedirect } = this.props; const { unfilteredPieceListCount } = this.state; - if (redirectTo && unfilteredPieceListCount === 0 && + if (redirectTo && redirectTo.pathname && unfilteredPieceListCount === 0 && (typeof shouldRedirect === 'function' && shouldRedirect(unfilteredPieceListCount))) { // 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); } }, diff --git a/js/components/whitelabel/prize/simple_prize/components/prize_piece_list.js b/js/components/whitelabel/prize/simple_prize/components/prize_piece_list.js index bd2b9f06..ec0def22 100644 --- a/js/components/whitelabel/prize/simple_prize/components/prize_piece_list.js +++ b/js/components/whitelabel/prize/simple_prize/components/prize_piece_list.js @@ -62,13 +62,15 @@ let PrizePieceList = React.createClass({ }, render() { + const { is_judge: isJudge, is_jury: isJury, is_admin: isAdmin } = this.state.currentUser; + setDocumentTitle(getLangText('Collection')); let orderParams = ['artist_name', 'title']; - if (this.state.currentUser.is_jury) { + if (isJury) { orderParams = ['rating', 'title']; } - if (this.state.currentUser.is_judge) { + if (isJudge) { orderParams = ['rating', 'title', 'selected']; } return ( @@ -80,7 +82,8 @@ let PrizePieceList = React.createClass({ orderBy={this.state.currentUser.is_jury ? 'rating' : null} filterParams={[]} customSubmitButton={this.getButtonSubmit()} - location={this.props.location}/> + location={this.props.location} + shouldRedirect={() => !(isJury || isJudge || isAdmin)} /> ); } diff --git a/js/components/whitelabel/wallet/components/23vivi/23vivi_piece_list.js b/js/components/whitelabel/wallet/components/23vivi/23vivi_piece_list.js index 0bfb8aa0..fa2bf5f0 100644 --- a/js/components/whitelabel/wallet/components/23vivi/23vivi_piece_list.js +++ b/js/components/whitelabel/wallet/components/23vivi/23vivi_piece_list.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; import React from 'react'; diff --git a/js/components/whitelabel/wallet/components/cyland/cyland_piece_list.js b/js/components/whitelabel/wallet/components/cyland/cyland_piece_list.js index c40b455a..288b7eb8 100644 --- a/js/components/whitelabel/wallet/components/cyland/cyland_piece_list.js +++ b/js/components/whitelabel/wallet/components/cyland/cyland_piece_list.js @@ -6,11 +6,14 @@ import PieceList from '../../../../piece_list'; import UserActions from '../../../../../actions/user_actions'; 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 { getLangText } from '../../../../../utils/lang_utils'; import { setDocumentTitle } from '../../../../../utils/dom_utils'; - +import { mergeOptions } from '../../../../../utils/general_utils'; let CylandPieceList = React.createClass({ propTypes: { @@ -18,15 +21,22 @@ let CylandPieceList = React.createClass({ }, getInitialState() { - return UserStore.getState(); + return mergeOptions( + UserStore.getState(), + WhitelabelStore.getState() + ); }, componentDidMount() { UserStore.listen(this.onChange); + WhitelabelStore.listen(this.onChange); + + WhitelabelActions.fetchWhitelabel(); UserActions.fetchCurrentUser(); }, componentWillUnmount() { + WhitelabelStore.unlisten(this.onChange); UserStore.unlisten(this.onChange); }, @@ -34,13 +44,30 @@ let CylandPieceList = React.createClass({ this.setState(state); }, + shouldRedirect(pieceCount) { + const { + currentUser: { email: userEmail }, + whitelabel: { + user: whitelabelAdminEmail + } + } = this.state; + + return userEmail !== whitelabelAdminEmail && !pieceCount; + }, + render() { setDocumentTitle(getLangText('Collection')); return (
!isUserAdmin && !pieceCount; + }, + render() { const { customThumbnailPlaceholder, location } = this.props; const { @@ -59,11 +63,12 @@ let MarketPieceList = React.createClass({ } } = this.state; let filterParams = null; + let isUserAdmin = null; let canLoadPieceList = false; if (userEmail && whitelabelAdminEmail) { canLoadPieceList = true; - const isUserAdmin = userEmail === whitelabelAdminEmail; + isUserAdmin = userEmail === whitelabelAdminEmail; filterParams = [{ label: getLangText('Show works I can'), @@ -78,7 +83,13 @@ let MarketPieceList = React.createClass({ return ( Date: Mon, 1 Feb 2016 14:47:51 +0100 Subject: [PATCH 2/2] Fix PR feedback --- .../accordion_list_item_thumbnail_placeholder.js | 2 +- js/components/piece_list.js | 8 ++++---- .../sluice_selected_prize_action_button.js | 2 +- ...3vivi_accordion_list_item_thumbnail_placeholder.js | 2 +- .../wallet/components/cyland/cyland_piece_list.js | 6 ++---- .../wallet/components/ikonotv/ikonotv_piece_list.js | 8 +++----- .../wallet/components/market/market_piece_list.js | 6 +----- .../wallet/components/market/market_register_piece.js | 11 +++++------ js/utils/regex_utils.js | 2 +- js/utils/url_utils.js | 2 +- 10 files changed, 20 insertions(+), 29 deletions(-) diff --git a/js/components/ascribe_accordion_list/accordion_list_item_thumbnail_placeholder.js b/js/components/ascribe_accordion_list/accordion_list_item_thumbnail_placeholder.js index 37c98371..8000affd 100644 --- a/js/components/ascribe_accordion_list/accordion_list_item_thumbnail_placeholder.js +++ b/js/components/ascribe_accordion_list/accordion_list_item_thumbnail_placeholder.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; import React from 'react'; diff --git a/js/components/piece_list.js b/js/components/piece_list.js index 82fc2df3..caf48aae 100644 --- a/js/components/piece_list.js +++ b/js/components/piece_list.js @@ -67,9 +67,9 @@ let PieceList = React.createClass({ orderParams: ['artist_name', 'title'], redirectTo: { pathname: '/register_piece', - query: {} + query: null }, - shouldRedirect: () => true + shouldRedirect: (pieceCount) => !pieceCount }; }, @@ -126,14 +126,14 @@ let PieceList = React.createClass({ const { location: { query }, redirectTo, shouldRedirect } = this.props; const { unfilteredPieceListCount } = this.state; - if (redirectTo && redirectTo.pathname && unfilteredPieceListCount === 0 && + if (redirectTo && redirectTo.pathname && (typeof shouldRedirect === 'function' && shouldRedirect(unfilteredPieceListCount))) { // FIXME: hack to redirect out of the dispatch cycle 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), + query: Object.assign({}, query, redirectTo.query), pathname: redirectTo.pathname }), 0); } diff --git a/js/components/whitelabel/prize/sluice/components/sluice_buttons/sluice_selected_prize_action_button.js b/js/components/whitelabel/prize/sluice/components/sluice_buttons/sluice_selected_prize_action_button.js index 7778a8de..7d013d5d 100644 --- a/js/components/whitelabel/prize/sluice/components/sluice_buttons/sluice_selected_prize_action_button.js +++ b/js/components/whitelabel/prize/sluice/components/sluice_buttons/sluice_selected_prize_action_button.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; import React from 'react'; import Moment from 'moment'; diff --git a/js/components/whitelabel/wallet/components/23vivi/23vivi_accordion_list/23vivi_accordion_list_item_thumbnail_placeholder.js b/js/components/whitelabel/wallet/components/23vivi/23vivi_accordion_list/23vivi_accordion_list_item_thumbnail_placeholder.js index f360c932..3a9b3943 100644 --- a/js/components/whitelabel/wallet/components/23vivi/23vivi_accordion_list/23vivi_accordion_list_item_thumbnail_placeholder.js +++ b/js/components/whitelabel/wallet/components/23vivi/23vivi_accordion_list/23vivi_accordion_list_item_thumbnail_placeholder.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; import React from 'react'; diff --git a/js/components/whitelabel/wallet/components/cyland/cyland_piece_list.js b/js/components/whitelabel/wallet/components/cyland/cyland_piece_list.js index 288b7eb8..29c7d46f 100644 --- a/js/components/whitelabel/wallet/components/cyland/cyland_piece_list.js +++ b/js/components/whitelabel/wallet/components/cyland/cyland_piece_list.js @@ -45,12 +45,10 @@ let CylandPieceList = React.createClass({ }, shouldRedirect(pieceCount) { - const { - currentUser: { email: userEmail }, + const { currentUser: { email: userEmail }, whitelabel: { user: whitelabelAdminEmail - } - } = this.state; + } } = this.state; return userEmail !== whitelabelAdminEmail && !pieceCount; }, diff --git a/js/components/whitelabel/wallet/components/ikonotv/ikonotv_piece_list.js b/js/components/whitelabel/wallet/components/ikonotv/ikonotv_piece_list.js index 1189992b..eccfd89c 100644 --- a/js/components/whitelabel/wallet/components/ikonotv/ikonotv_piece_list.js +++ b/js/components/whitelabel/wallet/components/ikonotv/ikonotv_piece_list.js @@ -52,13 +52,11 @@ let IkonotvPieceList = React.createClass({ }, shouldRedirect(pieceCount) { - const { - contractAgreementListNotifications, - currentUser: { email: userEmail }, + const { contractAgreementListNotifications, + currentUser: { email: userEmail }, whitelabel: { user: whitelabelAdminEmail - } - } = this.state; + } } = this.state; return contractAgreementListNotifications && !contractAgreementListNotifications.length && diff --git a/js/components/whitelabel/wallet/components/market/market_piece_list.js b/js/components/whitelabel/wallet/components/market/market_piece_list.js index ce8ca42b..ab9b31b2 100644 --- a/js/components/whitelabel/wallet/components/market/market_piece_list.js +++ b/js/components/whitelabel/wallet/components/market/market_piece_list.js @@ -49,10 +49,6 @@ let MarketPieceList = React.createClass({ this.setState(state); }, - shouldRedirect(isUserAdmin) { - return (pieceCount) => !isUserAdmin && !pieceCount; - }, - render() { const { customThumbnailPlaceholder, location } = this.props; const { @@ -89,7 +85,7 @@ let MarketPieceList = React.createClass({ 'slide_num': 0 } }} - shouldRedirect={this.shouldRedirect(isUserAdmin)} + shouldRedirect={(pieceCount) => !isUserAdmin && !pieceCount} bulkModalButtonListType={MarketAclButtonList} customThumbnailPlaceholder={customThumbnailPlaceholder} filterParams={filterParams} diff --git a/js/components/whitelabel/wallet/components/market/market_register_piece.js b/js/components/whitelabel/wallet/components/market/market_register_piece.js index c227722b..aa71c207 100644 --- a/js/components/whitelabel/wallet/components/market/market_register_piece.js +++ b/js/components/whitelabel/wallet/components/market/market_register_piece.js @@ -112,12 +112,11 @@ let MarketRegisterPiece = React.createClass({ render() { const { location } = this.props; - const { - piece, - step, - whitelabel: { - name: whitelabelName = 'Market' - } } = this.state; + const { piece, + step, + whitelabel: { + name: whitelabelName = 'Market' + } } = this.state; setDocumentTitle(getLangText('Register a new piece')); diff --git a/js/utils/regex_utils.js b/js/utils/regex_utils.js index 49412d07..13c14ecd 100644 --- a/js/utils/regex_utils.js +++ b/js/utils/regex_utils.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; // TODO: Create Unittests that test all functions diff --git a/js/utils/url_utils.js b/js/utils/url_utils.js index 94584026..41306498 100644 --- a/js/utils/url_utils.js +++ b/js/utils/url_utils.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; import camelCase from 'camelcase'; import decamelize from 'decamelize';