Skip to content

Commit

Permalink
Bump react-scripts from 3.4.1 to 4.0.3 + fix associated tech debt (#1102
Browse files Browse the repository at this point in the history
)

* npm install --save --save-exact react-scripts@4.0.3
* automatically added when running npm start
* move public/icons/ -> src/assets/icons/ + fix references + remove unused files
* move NavBar icons to src/assets/icons/ + fix references
* move various images/icons to src/assets/ + fix references
* add @debt comment to de-duplicate DEFAULT_PROFILE_IMAGE, DEFAULT_AVATAR_IMAGE, DEFAULT_PROFILE_PIC
* remove eslint-config-react-app from package.json as create-react-app already provides this
* remove additional eslint deps from package.json as create-react-app already provides them
* npm dedup
* ensure our eslint config extends from react-app as create-react-app suggests
* eslint: disable no-redeclare -> enable @typescript-eslint/no-redeclare": "warn",
* fix error  'T' is defined but never used  @typescript-eslint/no-unused-vars
* fix 'checkUserIsOwner' was used before it was defined  @typescript-eslint/no-use-before-define
* fix 'dataOrUpdateKey' was used before it was defined  @typescript-eslint/no-use-before-define
* fix error  'EditProfileFormValuesType' is defined but never used  @typescript-eslint/no-unused-vars
* fix warning  The 'menu' object makes the dependencies of useMemo Hook (at line 292) change on every render.
* fix  error  'useFirestoreConnect' import from 'react-redux-firebase' is restricted.
* fix error  'CSSProperties' is defined but never used  @typescript-eslint/no-unused-vars
* fix warning  'AdminVenuePreview' is already defined  @typescript-eslint/no-redeclare
* fix warning  'RoomInnerForm' is already defined  @typescript-eslint/no-redeclare
* fix warning  'TextReactionType' is already defined  @typescript-eslint/no-redeclare
* fix warning  'checkValidServiceWorker' / 'registerValidSW' was used before it was defined  @typescript-eslint/no-use-before-define
* refactor Audience to accept venue as a prop
* improve maybeSelector / maybeArraySelector / emptyArraySelector
* refactor useConnectRelatedVenues functions to make better use of maybeArraySelector / etc improvements
* fix warning  The 'venueEvents' logical expression could make the dependencies of useMemo Hook (at line 68) change on every render.
* refactor Audience to use usePartygoersbySeat hook
* refactor Auditorium to extract takeSeat / leaveSeat from main memo
* fix Jest Validation Error: Directory <rootDir> in the rootDir option was not found.
* npm install --save-dev source-map-explorer
* npm dedup
* add source-map-explorer analyze script to package.json
* remove @babel/preset-typescript@7.12.7 as it comes in react-scripts
* npm run browserslist:update-db
* add @debt comments for eslint rulesets to enable in future
  • Loading branch information
0xdevalias authored May 6, 2021
1 parent 0210045 commit 5b6d4a0
Show file tree
Hide file tree
Showing 49 changed files with 11,999 additions and 6,698 deletions.
9 changes: 8 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@
"plugins": ["@typescript-eslint"],
"extends": [
"react-app",
// "eslint:recommended", // @debt enable this + fix the issues in a standalone PR
// "plugin:@typescript-eslint/recommended", // @debt enable this + fix the issues in a standalone PR
// "plugin:@typescript-eslint/recommended-requiring-type-checking", // @debt enable this + fix the issues in a standalone PR
"plugin:react/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:react-hooks/recommended"
],
"rules": {
"@typescript-eslint/no-redeclare": "warn",
"@typescript-eslint/no-use-before-define": "warn",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-vars": "error",
// these base rules can report incorrect errors when using TypeScript, see the corresponding @typescript-eslint versions
"no-redeclare": "off",
"no-use-before-define": "off",
"no-restricted-imports": [
"error",
{
Expand Down
110 changes: 55 additions & 55 deletions functions/venue.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const admin = require("firebase-admin");
const functions = require("firebase-functions");
const { checkAuth } = require("./auth");
const { HttpsError } = require("firebase-functions/lib/providers/https");
const PLAYA_VENUE_ID = "jamonline";

const PLAYA_VENUE_ID = "jamonline";
const MAX_TRANSIENT_EVENT_DURATION_HOURS = 6;

// These represent all of our venue templates (they should remain alphabetically sorted, deprecated should be separate from the rest)
Expand Down Expand Up @@ -71,6 +71,54 @@ const PlacementState = {
Hidden: "HIDDEN",
};

const checkUserIsOwner = async (venueId, uid) => {
await admin
.firestore()
.collection("venues")
.doc(venueId)
.get()
.then(async (doc) => {
if (!doc.exists) {
throw new HttpsError("not-found", `Venue ${venueId} does not exist`);
}
const venue = doc.data();
if (venue.owners && venue.owners.includes(uid)) return;

if (venue.parentId) {
const doc = await admin
.firestore()
.collection("venues")
.doc(venue.parentId)
.get();

if (!doc.exists) {
throw new HttpsError(
"not-found",
`Venue ${venueId} references missing parent ${venue.parentId}`
);
}
const parentVenue = doc.data();
if (!(parentVenue.owners && parentVenue.owners.includes(uid))) {
throw new HttpsError(
"permission-denied",
`User is not an owner of ${venueId} nor parent ${venue.parentId}`
);
}
}

throw new HttpsError(
"permission-denied",
`User is not an owner of ${venueId}`
);
})
.catch((err) => {
throw new HttpsError(
"internal",
`Error occurred obtaining venue ${venueId}: ${err.toString()}`
);
});
};

const checkUserIsAdminOrOwner = async (venueId, uid) => {
try {
return await checkUserIsOwner(venueId, uid);
Expand Down Expand Up @@ -197,53 +245,12 @@ const getVenueId = (name) => {

const checkIfValidVenueId = (venueId) => /[a-z0-9_]{1,250}/.test(venueId);

const checkUserIsOwner = async (venueId, uid) => {
await admin
.firestore()
.collection("venues")
.doc(venueId)
.get()
.then(async (doc) => {
if (!doc.exists) {
throw new HttpsError("not-found", `Venue ${venueId} does not exist`);
}
const venue = doc.data();
if (venue.owners && venue.owners.includes(uid)) return;

if (venue.parentId) {
const doc = await admin
.firestore()
.collection("venues")
.doc(venue.parentId)
.get();

if (!doc.exists) {
throw new HttpsError(
"not-found",
`Venue ${venueId} references missing parent ${venue.parentId}`
);
}
const parentVenue = doc.data();
if (!(parentVenue.owners && parentVenue.owners.includes(uid))) {
throw new HttpsError(
"permission-denied",
`User is not an owner of ${venueId} nor parent ${venue.parentId}`
);
}
}

throw new HttpsError(
"permission-denied",
`User is not an owner of ${venueId}`
);
})
.catch((err) => {
throw new HttpsError(
"internal",
`Error occurred obtaining venue ${venueId}: ${err.toString()}`
);
});
};
const dataOrUpdateKey = (data, updated, key) =>
(data && data[key] && typeof data[key] !== "undefined" && data[key]) ||
(updated &&
updated[key] &&
typeof updated[key] !== "undefined" &&
updated[key]);

/** Add a user to the list of admins
*
Expand Down Expand Up @@ -850,10 +857,3 @@ exports.setVenueLiveStatus = functions.https.onCall(async (data, context) => {

await admin.firestore().collection("venues").doc(data.venueId).update(update);
});

const dataOrUpdateKey = (data, updated, key) =>
(data && data[key] && typeof data[key] !== "undefined" && data[key]) ||
(updated &&
updated[key] &&
typeof updated[key] !== "undefined" &&
updated[key]);
7 changes: 4 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
// export default async (): Promise<Config.InitialOptions> => {
module.exports = async () => {
return {
rootDir: "<rootDir>",
rootDir: ".",
roots: ["<rootDir>", "<rootDir>/src"],
verbose: true,
maxWorkers: "50%",

testMatch: [
"{.,src}/**/__tests__/**/*.+(ts|tsx|js)",
"{.,src}/**/?(*.)+(spec|test).+(ts|tsx|js)",
"**/__tests__/**/*.+(ts|tsx|js)",
"**/?(*.)+(spec|test).+(ts|tsx|js)",
],

// @debt make these work to actually ignore the paths we want
Expand Down
Loading

0 comments on commit 5b6d4a0

Please sign in to comment.