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

Fix Person trying to serialize non-existing methods in User #10575

Merged
merged 4 commits into from
Jan 13, 2025

Conversation

gregorbg
Copy link
Member

@gregorbg gregorbg commented Jan 9, 2025

For some reason, we have the following code snippet in the serializable_hash method of Person:

# If there's a user for this Person, merge in all their data,
# the Person's data takes priority, though.
(user || User.new).serializable_hash(user_override_options).merge(json)

The code comment explains what the intention is, but the implementation is problematic because it directly passes down the serialization options from Person down to User. But Person has plenty of methods and properties (which the developer might want to serialize) that don't exist on User at all.

The only reason why this didn't break so far is because nobody ever happened to request (i.e. try and serialize) a property of Person that isn't available from User.

The monkey-patched method is essentially a short-hand for:

{
  only: USER_PERSON_COMMON_OPTIONS[:only] & options[:only],
  methods: USER_PERSON_COMMON_OPTIONS[:methods] & options[:methods],
  includes: USER_PERSON_COMMON_OPTIONS[:includes] & options[:includes],
}

with a little bit of null-safety built in. The intention is to merge these two arrays together, but only keep the union (i.e. common values shared between two arrays) of the value params. That way, we can effectively restrict which params should be passed down to User.

Copy link
Member

@danieljames-dj danieljames-dj left a comment

Choose a reason for hiding this comment

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

I understood almost everything, the monkey_patches code is bit confusing for me, but I think I understood it.

@gregorbg gregorbg merged commit f59b6b8 into thewca:main Jan 13, 2025
2 checks passed
FinnIckler added a commit to FinnIckler/worldcubeassociation.org that referenced this pull request Jan 14, 2025
create seperate index for filters

implement backend loading and filters

remove segment

fix stylings in filters

fix gender and region not being filtered

added show filters

implement by regions table

add i18n to resultsfilter

Create can_user_access? for ticket (thewca#10570)

* Create can_user_access? for ticket

* Review changes

Update sv translation.

Check competition dates for upcoming comps while banning (thewca#10573)

Edit Person Requests page in WRT panel (thewca#10451)

* Edit Person Requests page in WRT panel

* Review changes

---------

Co-authored-by: Daniel M James <[email protected]>

Remove @@character_set_server latin1 check (thewca#10584)

* Remove @@character_set_server latin1 check

* change check for utf8mb4

Switch flag to disable Comp Overview React on demand (thewca#10577)

* Switch flag to disable Comp Overview React on demand

* Fix tests

Bump @cubing/icons from 1.1.3 to 2.0.2

Bumps [@cubing/icons](https://github.com/cubing/icons) from 1.1.3 to 2.0.2.
- [Release notes](https://github.com/cubing/icons/releases)
- [Commits](cubing/icons@v1.1.3...v2.0.2)

---
updated-dependencies:
- dependency-name: "@cubing/icons"
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

Only disable qualification button if qualifications are enforced (thewca#10598)

* only disable qualification button if qualifications are enforced

* removed logs

Date Range locale fixes (thewca#10599)

* export time_will_tell i18n

* translate date_range function from time will tell

* use dateRange function in my competitions and competition overview

* make luxon use the I18n locale in the i18n string

* just use luxon Interval

* fix rubocop

Update pt translation.

Added name argument to validators for ticket validations (thewca#10572)

* Added name argument to validators for ticket validations

* Review changes

Bump @stripe/stripe-js from 5.4.0 to 5.5.0

Bumps [@stripe/stripe-js](https://github.com/stripe/stripe-js) from 5.4.0 to 5.5.0.
- [Release notes](https://github.com/stripe/stripe-js/releases)
- [Commits](stripe/stripe-js@v5.4.0...v5.5.0)

---
updated-dependencies:
- dependency-name: "@stripe/stripe-js"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Bump stylelint from 16.12.0 to 16.13.0

Bumps [stylelint](https://github.com/stylelint/stylelint) from 16.12.0 to 16.13.0.
- [Release notes](https://github.com/stylelint/stylelint/releases)
- [Changelog](https://github.com/stylelint/stylelint/blob/main/CHANGELOG.md)
- [Commits](stylelint/stylelint@16.12.0...16.13.0)

---
updated-dependencies:
- dependency-name: stylelint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Bump glob from 11.0.0 to 11.0.1

Bumps [glob](https://github.com/isaacs/node-glob) from 11.0.0 to 11.0.1.
- [Changelog](https://github.com/isaacs/node-glob/blob/main/changelog.md)
- [Commits](isaacs/node-glob@v11.0.0...v11.0.1)

---
updated-dependencies:
- dependency-name: glob
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Bump eslint-plugin-react from 7.37.3 to 7.37.4

Bumps [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) from 7.37.3 to 7.37.4.
- [Release notes](https://github.com/jsx-eslint/eslint-plugin-react/releases)
- [Changelog](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/CHANGELOG.md)
- [Commits](jsx-eslint/eslint-plugin-react@v7.37.3...v7.37.4)

---
updated-dependencies:
- dependency-name: eslint-plugin-react
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Bump aws-sdk-rds from 1.264.0 to 1.265.0

Bumps [aws-sdk-rds](https://github.com/aws/aws-sdk-ruby) from 1.264.0 to 1.265.0.
- [Release notes](https://github.com/aws/aws-sdk-ruby/releases)
- [Changelog](https://github.com/aws/aws-sdk-ruby/blob/version-3/gems/aws-sdk-rds/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-ruby/commits)

---
updated-dependencies:
- dependency-name: aws-sdk-rds
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Fix typo (thewca#10606)

Remove side effect from const & simplify/rename (thewca#10597)

Move WFC panel to default panel (thewca#10583)

Fix Person trying to serialize non-existing methods in User (thewca#10575)

* Fix Person trying to serialize non-existing methods in User

* Stringify keys upon merge

* Allow serializing teams through Person (grrr)

* Refactor serialization defaults to respect tests

Circumvent cache in WIC->Ethics sync (thewca#10588)

Bump @tanstack/react-query from 5.62.15 to 5.64.0

Bumps [@tanstack/react-query](https://github.com/TanStack/query/tree/HEAD/packages/react-query) from 5.62.15 to 5.64.0.
- [Release notes](https://github.com/TanStack/query/releases)
- [Commits](https://github.com/TanStack/query/commits/v5.64.0/packages/react-query)

---
updated-dependencies:
- dependency-name: "@tanstack/react-query"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Bump rubocop from 1.69.2 to 1.70.0 (thewca#10608)

Replace redirect with panel-page (thewca#10585)

Migrate mysql to 8.4 in Docker compose (thewca#10548)

* update docker compose for mysql8.4

* remove deprecated command

Let dropdowns expand beyond Modal body in EditEvents (thewca#10544)

* Let dropdowns expand beyond Modal body in EditEvents

* Let each individual modal choose whether they want scrolling

Hotfix: Allow mysql_native plugin locally as grace period

Run yarn dedupe after dependency updates

fix competitions_by_id serialization

don't include organizers or delegates in competition serialization

fix indentation

fix country being imported in routes

Update app/webpacker/components/Results/resultsFilter.jsx

Co-authored-by: Kevin Matthews <[email protected]>

mobile changes

Update app/webpacker/components/Results/Rankings/RankingsTable.jsx

Co-authored-by: Kevin Matthews <[email protected]>

change useMemo to try and fix by region rendering

force Table Body to rerender when changing show modes

use reduce instead of map

use a reducer instead of state

add title prop

parse initial State from the URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants