Skip to content
This repository was archived by the owner on Sep 25, 2025. It is now read-only.

feat: restrict venue creation - #1212

Merged
gikf merged 22 commits into
freeCodeCamp:mainfrom
ojeytonwilliams:feat/restrict-venue-creation
Jul 14, 2022
Merged

gikf merged 22 commits into
freeCodeCamp:mainfrom
ojeytonwilliams:feat/restrict-venue-creation

Conversation

@ojeytonwilliams

@ojeytonwilliams ojeytonwilliams commented Jul 12, 2022 •

Copy link
Copy Markdown
Contributor
  • I have read Chapter's contributing guidelines.
  • My pull request has a descriptive title (not a vague title like Update README.md).
  • My pull request targets the main branch of Chapter.

Closes #1195

This is a little more extensive than most auth PRs, because of the reasons mentioned in the linked issue.

To ensure that the associated chapterId was available for the request, I put venue creation inside /dashboard/chapters/[chapterId]/ much like event creation. Similar story for editing events.

TODO:

  • Move event edit page inside /dashboard/chapters/[chapterId]/ (necessary, but nothing to do with this)
  • Make sure VenueForm gets passed chapter_id (it's fine, the onSubmit method is doing it)

@gitpod-io

gitpod-io Bot commented Jul 12, 2022

Copy link
Copy Markdown

@ojeytonwilliams ojeytonwilliams changed the title Feat/restrict venue creation feat: restrict venue creation Jul 12, 2022
@ghost

ghost commented Jul 12, 2022 •

Copy link
Copy Markdown
👇 Click on the image for a new way to code review
  • Make big changes easier — review code in small groups of related files

  • Know where to start — see the whole change at a glance

  • Take a code tour — explore the change with an interactive tour

  • Make comments and review — all fully sync’ed with github

    Try it now!

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

It should be enough to use the chapterId query param and the venue's
own id
@ojeytonwilliams
ojeytonwilliams marked this pull request as ready for review July 13, 2022 10:42
@ojeytonwilliams
ojeytonwilliams requested a review from a team July 13, 2022 10:42

@gikf gikf left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much of the chapter - venue relation (venues are per chapter, one venue can be used only in one chapter), is expected in this PR? Venues are referencing single chapter, but the constrain isn't really enforced in any way.

Suggestions are for two unrelated, minor, things spotted.

@ojeytonwilliams

Copy link
Copy Markdown
Contributor Author

How much of the chapter - venue relation (venues are per chapter, one venue can be used only in one chapter), is expected in this PR? Venues are referencing single chapter, but the constrain isn't really enforced in any way.

I'm not entirely happy with how I've done this, so I'd welcome your thoughts.

The idea is this: giving venues a foreign key referencing chapters enforces the requirement that each venue is associated with a single chapter.

Making the [id, chapter_id] pair unique was a hack to make use of the chapterId variable. It's too hacky, though, since id alone is already unique. It seems fine to send chapterId with the query, so that the authChecker accepts the request, and then just not use the variable inside the resolver. That's still kind of a hack, but less so.

One thing I was wondering is how else do think this should be enforced? Do we need further UI changes or did you have something else in mind?

id is already unique and chapterId was only required so that the
resolver 'needed' it, but this was an artificial need. Instead we can
send the variable so that the authChecker can work and discard it once
it reaches the resolver.
@gikf

gikf commented Jul 14, 2022

Copy link
Copy Markdown
Member

What I meant that it isn't enforced was that there were events in other chapters seeded with venues from chapter 1, or that in event creation form all venues can be been picked (and used).

I thought about adding to the venue field in events table another relation - to the chapter_id https://github.com/ojeytonwilliams/chapter/blob/2051af4ee3d0b89253afadad29b209b593d4a14b/server/prisma/schema.prisma#L113-L120
In my mind this takes care of setting constraint in the db. The @@unique([id, chapter_id]) still seems to be needed though, otherwise prisma complains.

@ojeytonwilliams

Copy link
Copy Markdown
Contributor Author

Got you. I was trying to do as little as possible in this PR, but thinking a little ahead would have been good... The approach you're suggesting sounds great; my hack stops being a hack if it's required by Prisma!

How about this approach: revert the last commit, merge this (assuming you're otherwise happy) and then constrain the db to ensure that the event's venue is from the right chapter?

@gikf gikf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me 👍

@gikf
gikf enabled auto-merge (squash) July 14, 2022 11:57
@gikf
gikf merged commit e459306 into freeCodeCamp:main Jul 14, 2022
@ojeytonwilliams
ojeytonwilliams deleted the feat/restrict-venue-creation branch July 14, 2022 13:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

API status: ready for review UI/UX This issue deals with UI/UX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Associate Venues with Chapters

2 participants