Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy staging -> master #1365

Merged
merged 1 commit into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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