Skip to content

Commit a2f545b

Browse files
committed
removed some console logs as they are not needed anymore. added a test to see if a user could update another users profile afer updating firebase security rules this is functional also a user cannot update an event they are not the host of. users can still view events and other profiles. added await to the setMainPhoto function and a few other functions so that we get a toast if it fails instead of a error on the screen or a blank page for the user. Also adjusted firestore rules to allow the user to change their photo
1 parent 95aa7d4 commit a2f545b

7 files changed

Lines changed: 24 additions & 18 deletions

File tree

‎client/src/Components/TestComponent.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
22
import { connect } from 'react-redux';
33
import {Button } from 'semantic-ui-react'
4-
import {incrementAsync, decrementAsync} from '../Components/testarea/testActions';
4+
import {incrementAsync, decrementAsync, testPermission} from '../Components/testarea/testActions';
55
import Script from 'react-load-script';
66
import PlacesAutocomplete, { geocodeByAddress, getLatLng } from 'react-places-autocomplete'
77
import { openModal} from "../Components/modals/modalActions";
@@ -16,6 +16,7 @@ const actions = {
1616
incrementAsync,
1717
decrementAsync,
1818
openModal,
19+
testPermission,
1920
}
2021

2122

@@ -52,7 +53,7 @@ class TestComponent extends Component {
5253
value: this.state.address,
5354
onChange: this.onChange,
5455
}
55-
const {incrementAsync, decrementAsync, data, openModal, loading} = this.props;
56+
const {incrementAsync, decrementAsync, data, openModal, loading, testPermission} = this.props;
5657
return (
5758
<div>
5859
<Script
@@ -64,6 +65,7 @@ class TestComponent extends Component {
6465
<Button loading = {loading} onClick={incrementAsync} color='green' content= 'Increment'/>
6566
<Button loading = {loading} onClick={decrementAsync} color='red' content= 'Decrement'/>
6667
<Button onClick ={() => openModal('TestModal', {data: 43})} color = "teal" content = "Open Modal" />
68+
<Button onClick ={testPermission} color = "teal" content = "Test Permission" />
6769
<form onSubmit={this.handleFormSubmit}>
6870
{this.state.scriptLoaded &&
6971
<PlacesAutocomplete inputProps={inputProps} />}

‎client/src/Components/events/EventDetailed/EventDetailedHeader.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const EventDetailedHeader = ({ event, isHost, isGoing, goingToEvent, cancelGoing
7676
Manage Event
7777
</Button>
7878
)}
79+
7980
</Segment>
8081
</Segment.Group>
8182
</div>

‎client/src/Components/testarea/testActions.js‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
COUNTER_ACTION_STARTED,
55
COUNTER_ACTION_FINISHED
66
} from "./testConstants";
7+
import firebase from '../../config/firebase';
8+
79

810
export const incrementCounter = () => {
911
return {
@@ -49,4 +51,18 @@ export const decrementAsync = () => {
4951
dispatch({type: DECREMENT_COUNTER})
5052
dispatch(finishCounterAction())
5153
}
52-
};
54+
};
55+
56+
/*Should make sure that a user cannot update another users profile */
57+
export const testPermission = () =>
58+
async (dispatch, getState) => {
59+
const firestore = firebase.firestore();
60+
try {
61+
let userDocRef = await firestore.collection('users').doc('dMmLUV1CQpXvrKAivrQ27gCdgYg2');
62+
userDocRef.update({
63+
displayName: 'testing'
64+
})
65+
} catch (error){
66+
console.log(error)
67+
}
68+
}

‎client/src/Components/user/Settings/PhotosPage.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class PhotosPage extends Component {
102102

103103
handleSetMainPhoto = photo => async () => {
104104
try {
105-
this.props.setMainPhoto(photo);
105+
await this.props.setMainPhoto(photo);
106106
toastr.success("Success", "Main Photo updated!");
107107
} catch (error) {
108108
toastr.error("Oops", error.message);

‎client/src/Components/user/UserDetailed/UserDetailedPage.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ const actions = {
4747

4848
class UserDetailedPage extends Component {
4949
async componentDidMount() {
50-
// console.log(this.props.userUid) // received
5150
await this.props.getUserEvents(this.props.userUid);
5251
}
5352

@@ -69,8 +68,7 @@ class UserDetailedPage extends Component {
6968
} = this.props; //requesting
7069
const isCurrentUser = auth.uid === match.params.id;
7170
const isFollowing = !isEmpty(following);
72-
console.log(following)
73-
console.log(this.props.match.params.id)
71+
7472
// console.log(requesting);
7573
// const loading = Object.values(requesting).some(a => a === true);
7674

‎client/src/Components/user/UserDetailed/UserDetailedSidebar.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import { Link } from "react-router-dom";
44

55

66
const UserDetailedSidebar = ({ isCurrentUser, followUser, profile, isFollowing, unfollowUser}) => {
7-
console.log(isCurrentUser, isFollowing)
8-
const buttonDisplayed = isCurrentUser || isFollowing; // if its not the current user then thats false if not folowing thats false result is false returns false
9-
//if we are following buttonDisplayed will equal true
10-
console.log(buttonDisplayed)
117
return (
128
<Grid.Column width={4}>
139
<Segment>

‎client/src/Components/user/userActions.js‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ export const setMainPhoto = photo => async (
115115
dispatch(asyncActionStart());
116116
const firestore = firebase.firestore();
117117
const user = firebase.auth().currentUser;
118-
console.log("show user object from auth");
119-
console.log(user);
120118
const today = new Date(Date.now());
121119
let userDocRef = firestore.collection("users").doc(user.uid);
122120
let eventAttendeeRef = firestore.collection("event_attendee");
@@ -150,7 +148,6 @@ export const setMainPhoto = photo => async (
150148
}
151149
}
152150

153-
console.log(batch);
154151
await batch.commit();
155152
dispatch(asyncActionFinish());
156153
} catch (error) {
@@ -164,8 +161,6 @@ export const goingToEvent = event => async (dispatch, getState) => {
164161
dispatch(asyncActionStart());
165162
const firestore = firebase.firestore();
166163
const user = firebase.auth().currentUser;
167-
console.log("check out user");
168-
console.log(user);
169164
const photoURL = getState().firebase.profile.photoURL;
170165
const displayName = getState().firebase.profile.displayName;
171166
const attendee = {
@@ -308,11 +303,9 @@ export const followUser = userToFollow => async (
308303
};
309304

310305
export const unfollowUser = userToUnfollow =>
311-
// console.log(userToUnfollow)
312306
async (dispatch, getState, { getFirestore }) => {
313307
const firestore = getFirestore();
314308
const user = firestore.auth().currentUser;
315-
console.log(user);
316309
try {
317310
await firestore.delete({
318311
collection: "users",

0 commit comments

Comments
 (0)