From 485aa0d541b6de7fcf126dcd82cc95451b005df2 Mon Sep 17 00:00:00 2001 From: Urban Rotnik Date: Tue, 12 Jan 2021 13:04:36 +0100 Subject: [PATCH] Remove project_folder in callback --- app/controllers/projects_controller.rb | 1 - app/models/project.rb | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 70660053e..dc7546f82 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index 9e5d003fc..6a6e8ebd9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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