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

Simplify locking current user when voting #5036

Merged
merged 1 commit into from
Dec 12, 2022
Merged

Simplify locking current user when voting #5036

merged 1 commit into from
Dec 12, 2022

Conversation

javierm
Copy link
Member

@javierm javierm commented Nov 25, 2022

References

Objectives

  • Simplify code
  • Avoid unneeded changes in the current_user object

@javierm javierm self-assigned this Nov 25, 2022
@javierm javierm added the 2.0 label Nov 25, 2022
@javierm javierm added this to Reviewing in Consul Democracy Nov 25, 2022
Back in commit 36e4524, we wrote:

> The `reload` method added to max_votes validation is needed because
> the author gets here with some changes because of the around_action
> `switch_locale`, which adds some changes to the current user record
> and therefore, the lock method raises an exception when trying to lock
> it requiring us to save or discard those record changes.

This happened when `current_user` didn't have a locale stored in the
database and the `current_locale` method returned the default locale.
And the test "Poll Votation Type Multiple answers" would indeed fail if
we removed the `reload` method. However, we can remove the need to
reload the record by avoiding the mentioned changes on the current user
record.

So we're changing the `User#locale` method so it doesn't modify the user
record.
Copy link
Member

@Senen Senen left a comment

Choose a reason for hiding this comment

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

Much better 😌

Consul Democracy automation moved this from Reviewing to Testing Dec 5, 2022
@javierm javierm merged commit bc716f6 into master Dec 12, 2022
Consul Democracy automation moved this from Testing to Release 2.0.0 Dec 12, 2022
@javierm javierm deleted the author_lock branch December 12, 2022 10:47
@javierm javierm removed the 2.0 label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants