mirror of
https://github.com/ascribe/onion.git
synced 2024-12-23 01:39:36 +01:00
Avoid unauthorized attempts at fetching ratings if user isn't an admin, judge, or jury
This commit is contained in:
parent
dcca228669
commit
34153c2322
@ -176,8 +176,8 @@ let PieceContainer = React.createClass({
|
|||||||
|
|
||||||
let NavigationHeader = React.createClass({
|
let NavigationHeader = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
piece: React.PropTypes.object,
|
piece: React.PropTypes.object.isRequired,
|
||||||
currentUser: React.PropTypes.object
|
currentUser: React.PropTypes.object.isRequired
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -213,9 +213,9 @@ let NavigationHeader = React.createClass({
|
|||||||
|
|
||||||
let PrizePieceRatings = React.createClass({
|
let PrizePieceRatings = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
loadPiece: React.PropTypes.func,
|
loadPiece: React.PropTypes.func.isRequired,
|
||||||
piece: React.PropTypes.object,
|
piece: React.PropTypes.object.isRequired,
|
||||||
currentUser: React.PropTypes.object
|
currentUser: React.PropTypes.object.isRequired
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
@ -227,9 +227,15 @@ let PrizePieceRatings = React.createClass({
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
PrizeRatingStore.listen(this.onChange);
|
PrizeRatingStore.listen(this.onChange);
|
||||||
PrizeRatingActions.fetchOne(this.props.piece.id);
|
|
||||||
PrizeRatingActions.fetchAverage(this.props.piece.id);
|
|
||||||
PieceListStore.listen(this.onChange);
|
PieceListStore.listen(this.onChange);
|
||||||
|
|
||||||
|
this.fetchRatingsIfAuthorized();
|
||||||
|
},
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
if (nextProps.currentUser.email !== this.props.currentUser.email) {
|
||||||
|
this.fetchRatingsIfAuthorized();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
@ -258,6 +264,21 @@ let PrizePieceRatings = React.createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
fetchRatingsIfAuthorized() {
|
||||||
|
const {
|
||||||
|
currentUser: {
|
||||||
|
is_admin: isAdmin,
|
||||||
|
is_judge: isJudge,
|
||||||
|
is_jury: isJury
|
||||||
|
},
|
||||||
|
piece: { id: pieceId } } = this.props;
|
||||||
|
|
||||||
|
if (isAdmin || isJudge || isJury) {
|
||||||
|
PrizeRatingActions.fetchOne(pieceId);
|
||||||
|
PrizeRatingActions.fetchAverage(pieceId);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
onRatingClick(event, args) {
|
onRatingClick(event, args) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
PrizeRatingActions.createRating(this.props.piece.id, args.rating).then(
|
PrizeRatingActions.createRating(this.props.piece.id, args.rating).then(
|
||||||
@ -425,12 +446,11 @@ let PrizePieceRatings = React.createClass({
|
|||||||
|
|
||||||
let PrizePieceDetails = React.createClass({
|
let PrizePieceDetails = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
piece: React.PropTypes.object
|
piece: React.PropTypes.object.isRequired
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this.props.piece
|
if (this.props.piece.prize
|
||||||
&& this.props.piece.prize
|
|
||||||
&& this.props.piece.prize.name
|
&& this.props.piece.prize.name
|
||||||
&& Object.keys(this.props.piece.extra_data).length !== 0){
|
&& Object.keys(this.props.piece.extra_data).length !== 0){
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user