Remove project_folder in callback

This commit is contained in:
Urban Rotnik 2021-01-12 13:04:36 +01:00
parent 3ad14e06b2
commit 485aa0d541
2 changed files with 5 additions and 1 deletions

View file

@ -213,7 +213,6 @@ class ProjectsController < ApplicationController
next unless can_archive_project?(project)
project.transaction do
project.project_folder = nil
project.archive!(current_user)
log_activity(:archive_project, project)
counter += 1

View file

@ -13,6 +13,7 @@ class Project < ApplicationRecord
validates :visibility, presence: true
validates :team, presence: true
validate :project_folder_team, if: -> { project_folder.present? }
before_validation :remove_project_folder, on: :update, if: :archived_changed?
belongs_to :created_by,
foreign_key: 'created_by_id',
@ -330,4 +331,8 @@ class Project < ApplicationRecord
errors.add(:project_folder, I18n.t('activerecord.errors.models.project.attributes.project_folder.team'))
end
def remove_project_folder
self.project_folder = nil if archived?
end
end