Merge pull request #3097 from urbanrotnik/ur-sci-5422-valdiation-for-moving-folder

Add parent_folder validation [SCI-5422]
This commit is contained in:
Urban Rotnik 2021-01-19 10:46:50 +01:00 committed by GitHub
commit 4c4b315864
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View file

@ -105,9 +105,11 @@ class ProjectFolder < ApplicationRecord
end
def parent_folder_validation
return if parent_folder.id != id
errors.add(:parent_folder, I18n.t('activerecord.errors.models.project_folder.attributes.parent_folder'))
if parent_folder.id == id
errors.add(:parent_folder, I18n.t('activerecord.errors.models.project_folder.attributes.parent_folder'))
elsif ProjectFolder.inner_folders(team, self).where(id: parent_folder_id).exists?
errors.add(:parent_folder, I18n.t('activerecord.errors.models.project_folder.attributes.parent_folder_child'))
end
end
def ensure_uniqueness_name_on_moving

View file

@ -102,6 +102,7 @@ en:
attributes:
parent_folder_team: "Parent folder and folder should belongs to the same team"
parent_folder: "Folder cannot be parent to itself"
parent_folder_child: "Folder cannot be moved to it's child"
view_state:
attributes:
viewable_id: