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

#5698 Fix a bug when editing a 1 week ban, duration resetting to 1 day #5702

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

DCrow
Copy link
Contributor

@DCrow DCrow commented May 6, 2024

When editing a ban and ban duration was different from selectable durations it would reset to the first selection(which was 1 day).

Judging from the comment, there are some bans that don't conform to current restrictions, which breaks duration selector in ban edit page.

# In production, the oldest bans have negative duration because in 2013 the database was migrated and the
# created_at field was reset to 2013, which made their creation date come after their expiration date.

…ctable durations it would reset to the first selection(which was 1 day)
@DCrow DCrow changed the title #5698 Fix #5698 May 6, 2024
@DCrow DCrow changed the title Fix #5698 #5698 Fix a bug when editing a ban, duration resetting to 1 day May 6, 2024
@nottalulah
Copy link
Contributor

This doesn't actually fix the problem with one-week bans, see #5698 (comment). There are also a lot of random formatting changes here that don't relate to the issue.

I don't think anyone is editing 11-year-old bans to warrant such a bandaid for them.

DCrow added 2 commits May 6, 2024 17:45
…rom selectable durations it would reset to the first selection(which was 1 day)"

This reverts commit c0be35b.
…ostgres silently transforms week intervals into day intervals, so when we save a P1W interval we get a P7D, which then gets reset(since it doesn't exist in selectable duration list) to the default value in ban edit page
@DCrow
Copy link
Contributor Author

DCrow commented May 6, 2024

It seems postgres doesn't support saving week intervals.
Under the hood it changes weeks to days.
So when we save 1 week duration we get 7 days in return.
Changed so that we save 7 days and expect 7 days interval in dropdown.

Also on a side note.
Maybe rename 1 week to 7 days?
Since this also incorrectly shows 1 week as 7 days.

elsif duration < 1.month
duration.in_days.round.days.inspect

@DCrow DCrow changed the title #5698 Fix a bug when editing a ban, duration resetting to 1 day #5698 Fix a bug when editing a 1 week ban, duration resetting to 1 day May 6, 2024
@nottalulah
Copy link
Contributor

Prior to f878ed9 it showed as 1 week (see here). Given that change I think renaming it to 7 days makes sense, unless changing the formatting like that was just an oversight.

@DCrow
Copy link
Contributor Author

DCrow commented May 6, 2024

For now changed to 7 days for consistency's sake.
Since the next page right after saving(or updating) displays 7 days.

If it was an oversight, I think it's best to change label and humanized_duration in a separate commit/PR.

@nottalulah
Copy link
Contributor

If the label is 7 days why are you doing 1.week.in_days.round.days instead of just 7.days?

@DCrow
Copy link
Contributor Author

DCrow commented May 7, 2024

I thought about that, but then it would differ from

validates :duration, inclusion: { in: [1.day, 3.days, 1.week, 1.month, 3.months, 6.months, 1.year, 100.years], message: "%{value} is not a valid ban duration" }, if: :duration_changed?

And would raise questions down the line.
Like why its 7.days in one place and 1.week in the other.

This way at least its more consistent.

@nottalulah
Copy link
Contributor

Well right now there's the inconsistency of it being 1.week in the duration validator, but 7.days in the UI. It should just be 7 days everywhere.

@DCrow
Copy link
Contributor Author

DCrow commented May 7, 2024

Changed in ban model and simplified value in view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants