27 Commits

Author SHA1 Message Date
Kabiru Mwenja fd9a5bea77 Merge pull request #23197 from opf/refactor/extract-semantic-project-identifier-format
Extract semantic project identifier regex into a composed constant
2026-05-13 17:49:56 +03:00
Kabiru Mwenja 47fe076905 Move validator into Projects namespace
- Validator moves to app/validators/projects/identifier_validator.rb
  as Projects::IdentifierValidator. The path-style symbol on the
  validates declaration ('projects/identifier') resolves to it.
  Distinguishes domain-specific validators from globally reusable
  ones (UrlValidator, JsonValidator, etc).

- Spec moves to spec/validators/projects/identifier_validator_spec.rb.

- Trim comments that explained framework conventions (validator
  lookup, declaration order). Keep comments only where the WHY is
  non-obvious to a Rails-fluent reader.
2026-04-29 11:30:50 +03:00
Kabiru Mwenja 452b416b7a Use excluding_project scope instead of raw where.not
The IdentifierSlugScopes module already exposes .excluding_project(project)
for exactly this — dropping the validator out of the scope vocabulary
into a raw where.not was a layering leak. Behavior is identical.
2026-04-29 09:14:15 +03:00
Kabiru Mwenja d7aadd3874 Use Project directly instead of record.class
Validator is named ProjectIdentifierValidator and YARD-documented
as Project-only. Project does not use STI, so the indirection
through record.class adds nothing and obscures the contract.
Calling Project.identifier_slugs and Project.classic_identifier_format?
directly reads cleaner and matches the explicit @param record [Project]
constraint.
2026-04-29 09:09:08 +03:00
Kabiru Mwenja 97a266273c Extract project identifier validation into dedicated validator
Move five private validation methods out of the Projects::Identifier
concern into a top-level ActiveModel::EachValidator. The concern goes
from carrying ~50 lines of validation logic to declaring:

    validates :identifier, project_identifier: true,
                           if: :identifier_changed?

Format rules, reserved-keyword check, and historical-reservation check
all live in ProjectIdentifierValidator. Mode dispatch (classic vs
semantic vs :semantic_conversion context) is internal to the validator
and easy to swap for a registry if a third format ever appears.

Picks up the follow-up suggested in #22931 (comment 4326208630).

Notes:

- Validator is top-level (ProjectIdentifierValidator) not namespaced,
  matching the existing convention of UrlValidator / JsonValidator /
  SecureContextUriValidator and so Rails' validator lookup for
  `validates :identifier, project_identifier: true` resolves directly.

- Format constants (RESERVED_IDENTIFIERS, *_MAX_LENGTH) stay on the
  concern since they're shared with acts_as_url's blacklist/limit, the
  routing constraint, and suggesters — moving them to the validator
  would couple unrelated subsystems to a validator namespace.

- Validator declaration order in the concern is significant: presence
  + uniqueness must run before `project_identifier: true` so the
  historical-reservation check can short-circuit when uniqueness has
  already flagged :taken.

Pure-validator behaviour (format checks, reserved keyword,
:semantic_conversion context, historical reservation) moves to
spec/validators/project_identifier_validator_spec.rb. Integration
tests (FriendlyId :history wiring, :saving_custom_fields,
.suggest_identifier, .identifier_slugs scopes) stay in the model spec.
2026-04-29 08:54:30 +03:00
Alexander Brandon Coles 80ae66ed8c Fix missing copyright notices in app/validators 2025-07-18 18:09:37 +01:00
Alexander Brandon Coles 8cd962348a Freeze string literals in app/validators
rubocop -A --only Style/FrozenStringLiteralComment,Layout/EmptyLineAfterMagicComment,Style/RedundantFreeze app/validators
2025-07-18 17:44:01 +01:00
Oliver Günther 7af51312fd Strip whitespace in URL validator 2024-09-26 11:35:46 +02:00
Ivan Kuchin bca7db9398 update copyrights 2024-07-31 15:02:50 +02:00
Ivan Kuchin 4911b8a149 remove years from copyrights (except for COPYRIGHT file) 2024-07-31 15:02:49 +02:00
ulferts 3b2121f733 Revert "Merge remote-tracking branch 'origin/release/13.4' into dev"
This reverts commit 40b2bbeb09, reversing
changes made to b4c6cb17cc.
2024-03-21 11:31:17 +01:00
Ivan Kuchin 7787e457a3 Revert "Merge branch 'dev' into release/13.4"
This reverts commit a901541269, reversing
changes made to e573ca00b7.
2024-03-20 20:19:08 +01:00
Ivan Kuchin 9e4934cd0a change quotes using rubocop --only Style/StringLiterals,Style/QuotedSymbols -a 2024-03-20 18:05:22 +01:00
Christophe Bliard c795874f7f Update copyright year for 2024
command used: `rg -l 'Copyright \(C\) 2012-202\d the OpenProject' | xargs -n 100 sed -i -r 's/Copyright \(C\) 2012-202. the OpenProject/Copyright (C) 2012-2024 the OpenProject/'`
2024-01-02 16:23:54 +01:00
Klaus Zanders 26cee2729e Fixes Performance/RegexpMatch offenses 2023-09-06 12:50:32 +02:00
Oliver Günther cb60af9055 Merge remote-tracking branch 'origin/upgrade-to-ruby-3.2' into dev 2023-01-03 14:15:03 +01:00
Christophe Bliard 21a696ef9b Update copyright information for 2023 2022-12-30 15:51:26 +01:00
Christophe Bliard d2658792c3 Handle URI.parse returning empty string in host instead of nil
See https://hackerone.com/reports/156615
and https://github.com/ruby/ruby/commit/dd5118f8524c425894d4716
to know more.
2022-12-30 11:49:20 +01:00
Wieland Lindenthal 8230707bcf Use same Secure Context validation for OAuth applications
Currently redirect_uri field of OAuth applications (Doorkeeper
Applications) did only check for 'localhost', which is not
complete. Other loopback URLs are also valid, such as
'http://127.0.0.1'.

Now, it is coherent with the allowed hosts of ::Storages::Storage
2022-07-27 18:29:28 +02:00
Frank Bergmann b20d4db965 Add validation for file storages: Host attribute needs to provide a secure context 2022-07-27 18:29:28 +02:00
Christophe Bliard 48a4f1b6ad lint with rubocop --autocorrect (safe cops only) 2022-06-02 10:40:10 +02:00
Christophe Bliard a33524ef6d remove ruby magic comment for utf-8
ruby interprets source encoding as utf-8 since 2.0.0, making magic comment redundant and useless
2022-03-10 19:36:58 +01:00
Christophe Bliard bc8d423ec2 update copyright information for 2022 2022-03-01 17:05:59 +01:00
ulferts cb989527fe move user preference validations to contract 2021-09-03 10:27:20 +02:00
ulferts 0cee545248 adapt the json_validator from activerecord_json_validator
The error messages need to be more fine grained than what can be achieved with the original gem
2021-09-02 22:31:40 +02:00
ulferts 1bdd2ab9ae safe automatic fixes by rubocop (#8994) 2021-02-11 16:02:18 +01:00
Oliver Günther c27b6d9fa6 Add URL validator (#6094)
[ci skip]
2017-12-19 19:38:06 +01:00