Skip to content

Commit

Permalink
Remove support for "adults" category in firestore rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ikusteu committed Jul 9, 2023
1 parent ee9545b commit 31d921e
Showing 1 changed file with 3 additions and 39 deletions.
42 changes: 3 additions & 39 deletions packages/firestore/firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ service cloud.firestore {
function getCategories() {
return ["course-adults", "pre-competitive-adults", "course-minors", "pre-competitive-minors", "competitive"]
}
function getAllCategories() {
return ["course-adults", "pre-competitive-adults", "course-minors", "pre-competitive-minors", "competitive", "adults"]
}
function getSlotTypes() {
return ["ice", "off-ice"]
}
Expand Down Expand Up @@ -93,18 +90,12 @@ service cloud.firestore {
// Only admins can read/delete slots
allow read, delete: if isAdmin(organization)
// Validate data integrity for create/update
allow update: if isAdmin(organization) &&
allow create, update: if isAdmin(organization) &&
// check date
checkValidDate(request.resource.data.date) &&
// check valid type
request.resource.data.type in getSlotTypes() &&
// check valid categories (on update, "adults" is still supported, even though deprecated)
request.resource.data.categories.hasOnly(getAllCategories())
// @TODO check valid intervals
allow create: if isAdmin(organization) &&
checkValidDate(request.resource.data.date) &&
request.resource.data.type in getSlotTypes() &&
// allow slot creation only with currently supported categories
// contains only supported categories
request.resource.data.categories.hasOnly(getCategories())
}
// #endregion slot-checks
Expand Down Expand Up @@ -165,33 +156,7 @@ service cloud.firestore {
// Only admins can access customer collection
allow read, delete: if isAdmin(organization)
// Check data integrity
allow update: if (
isAdmin(organization) &&
// Check required fields
checkRequiredString(request.resource.data.name) &&
checkRequiredString(request.resource.data.surname) &&
// Check optional dates
checkOptionalValidDate(request.resource.data, "birthday") &&
checkOptionalValidDate(request.resource.data, "certificateExpiration") &&
checkOptionalValidDate(request.resource.data, "covidCertificateReleaseDate") &&
// Check category (allows updates even if "adults")
request.resource.data.categories.hasOnly(getAllCategories()) &&
// Check valid email
(
!("email" in request.resource.data) ||
request.resource.data.email == "" ||
checkValidEmail(request.resource.data.email)
) &&
// Check valid phone number
(
!("phone" in request.resource.data) ||
request.resource.data.phone == "" ||
checkValidPhoneNumber(request.resource.data.phone)
) &&
// Check release date suspended type
checkOptionalBoolean(request.resource.data, "covidCertificateSuspended")
)
allow create: if (
allow create, update: if (
isAdmin(organization) &&
// Check required fields
checkRequiredString(request.resource.data.name) &&
Expand All @@ -200,7 +165,6 @@ service cloud.firestore {
checkOptionalValidDate(request.resource.data, "birthday") &&
checkOptionalValidDate(request.resource.data, "certificateExpiration") &&
checkOptionalValidDate(request.resource.data, "covidCertificateReleaseDate") &&
// Check category (shouldn't allow creation with "adults" category)
request.resource.data.categories.hasOnly(getCategories()) &&
// Check valid email
(
Expand Down

0 comments on commit 31d921e

Please sign in to comment.