Adds `parent_organization_match` validation
What does this MR do and why?
While working on Adds validation on project's organization (!155833 - merged), we found out that we're not validating that project or group belongs to the same organization as its parent.
In this MR we're adding validation on the application level, where we're checking if project.organization
is the same as parent.organization_id
.
We're doing the same for namespaces.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
- Checkout the
marjanovic/add-organization-validation-on-projects-parent
branch - Open Rails console
rails c
- Try to create a project with organization different from its parent organization
- Verify that record is invalid
🎉 - Repeat the same for groups.
user = User.last
organization = FactoryBot.create(:organization, path: 'new-org1', name: 'new-org1')
project = Project.new(namespace: user.namespace, path: 'project-path', name: 'project-name', creator: user, organization: organization)
project.valid?
=> false
project.errors
=> #<ActiveModel::Errors [#<ActiveModel::NestedError attribute=project_namespace.organization_id, type=must match the parent organization's ID, options={}>, #<ActiveModel::Error attribute=organization_id, type=must match the parent organization's ID, options={}>]>
Related #480497 (closed)
Edited by Abdul Wadood