From 1cc7f4a45d9e9fdf1943eb92d3cd2071ba497337 Mon Sep 17 00:00:00 2001 From: Michael Kozono Date: Fri, 1 Sep 2017 16:49:09 -0700 Subject: Enable share_with_group_lock on subgroup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …when needed --- app/models/namespace.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'app/models') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index e7cbc5170e8..aeda829415a 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -44,6 +44,10 @@ class Namespace < ActiveRecord::Base after_commit :refresh_access_of_projects_invited_groups, on: :update, if: -> { previous_changes.key?('share_with_group_lock') } + before_create :sync_share_with_group_lock_with_parent + before_update :sync_share_with_group_lock_with_parent, if: :parent_changed? + after_commit :force_share_with_group_lock_on_descendants, on: :update, if: -> { previous_changes.key?('share_with_group_lock') && share_with_group_lock? } + # Legacy Storage specific hooks after_update :move_dir, if: :path_changed? @@ -219,4 +223,14 @@ class Namespace < ActiveRecord::Base errors.add(:parent_id, "has too deep level of nesting") end end + + def sync_share_with_group_lock_with_parent + if has_parent? && parent.share_with_group_lock? + self.share_with_group_lock = true + end + end + + def force_share_with_group_lock_on_descendants + descendants.update_all(share_with_group_lock: true) + end end -- cgit v1.2.1