-
Notifications
You must be signed in to change notification settings - Fork 26
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
Validate course number #318
Open
simfeld
wants to merge
7
commits into
hitobito:master
Choose a base branch
from
simfeld:feature/validate-course-number
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4a7cc8f
Add validate_course_number column to event kinds
simfeld a90453e
Implement validation
simfeld 5b3ec9b
Add specs
simfeld fa7e971
Reuse constants
simfeld 5e2163a
Fix license text
simfeld 7201c7c
Attempt to correct fixtures in CI
simfeld 8e9d16c
Update db/migrate/20240309005706_add_validate_course_number_to_event_…
simfeld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,6 +13,8 @@ module Pbs::Event::Course | |||||||||||||
APPROVALS = %w(requires_approval_abteilung requires_approval_region | ||||||||||||||
requires_approval_kantonalverband requires_approval_bund).freeze | ||||||||||||||
|
||||||||||||||
COURSE_NUMBER_REGEX = /\APBS CH(?: [A-Z]{2})? [0-9]{3}-[0-9]{2}\z/.freeze | ||||||||||||||
|
||||||||||||||
included do | ||||||||||||||
include Pbs::Event::RestrictedRole | ||||||||||||||
|
||||||||||||||
|
@@ -42,6 +44,14 @@ module Pbs::Event::Course | |||||||||||||
validates :bsv_days, numericality: { greater_than_or_equal_to: 0, allow_blank: true } | ||||||||||||||
validate :assert_bsv_days_precision | ||||||||||||||
|
||||||||||||||
validates :number, format: { with: COURSE_NUMBER_REGEX, | ||||||||||||||
message: :must_adhere_to_format, | ||||||||||||||
if: :validate_number? } | ||||||||||||||
|
||||||||||||||
def validate_number? | ||||||||||||||
(new_record? || number_changed? || kind_id_changed?) && kind.validate_course_number | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be possible to update existing records as long as course number and event kind are left untouched There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Find ich persönlich leserlicher |
||||||||||||||
end | ||||||||||||||
|
||||||||||||||
### CALLBACKS | ||||||||||||||
after_initialize :become_campy | ||||||||||||||
before_save :set_requires_approval | ||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
db/migrate/20231215154134_set_block_warning_sent_at_for_people.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
db/migrate/20240309005706_add_validate_course_number_to_event_kinds.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright (c) 2024, Pfadibewegung Schweiz. This file is part of | ||
# hitobito_pbs and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito. | ||
|
||
class AddValidateCourseNumberToEventKinds < ActiveRecord::Migration[6.1] | ||
def change | ||
add_column :event_kinds, :validate_course_number, :boolean, default: false, null: false | ||
simfeld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following what's specified in https://pilot.scouts.ch (page 12 in the current version)