jbox-web/redmine_git_hosting

View on GitHub
lib/redmine_git_hosting/patches/group_patch.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

require_dependency 'group'

module RedmineGitHosting
  module Patches
    module GroupPatch
      def self.prepended(base)
        base.class_eval do
          # Relations
          has_many :protected_branches_members, dependent: :destroy, foreign_key: :principal_id
          has_many :protected_branches, through: :protected_branches_members
        end
      end

      def user_added(user)
        super
        protected_branches.each do |pb|
          RepositoryProtectedBranches::MemberManager.new(pb).add_user_from_group(user, id)
        end
      end

      def user_removed(user)
        super
        protected_branches.each do |pb|
          RepositoryProtectedBranches::MemberManager.new(pb).remove_user_from_group(user, id)
        end
      end
    end
  end
end

Group.prepend RedmineGitHosting::Patches::GroupPatch unless Group.included_modules.include? RedmineGitHosting::Patches::GroupPatch