app/models/openstax/accounts/group_nesting.rb in openstax_accounts-4.1.1 vs app/models/openstax/accounts/group_nesting.rb in openstax_accounts-5.0.0

- old
+ new

@@ -1,9 +1,9 @@ module OpenStax::Accounts class GroupNesting < ActiveRecord::Base - attr_accessor :requestor + delegate :requestor, :syncing, to: :container_group belongs_to :container_group, class_name: 'OpenStax::Accounts::Group', primary_key: :openstax_uid, inverse_of: :member_group_nestings belongs_to :member_group, class_name: 'OpenStax::Accounts::Group', primary_key: :openstax_uid, inverse_of: :container_group_nesting @@ -12,26 +12,22 @@ validates_uniqueness_of :member_group_id validates_presence_of :container_group, :member_group, :requestor, :unless => :syncing_or_stubbing validate :no_loops, :unless => :syncing_or_stubbing - before_create :update_group_caches, :unless => :syncing? - before_destroy :update_group_caches, :unless => :syncing? + before_create :update_group_caches, :unless => :syncing + before_destroy :update_group_caches, :unless => :syncing before_create :create_openstax_accounts_group_nesting, :unless => :syncing_or_stubbing - before_destroy :update_group_caches, :destroy_openstax_accounts_group_nesting, + before_destroy :destroy_openstax_accounts_group_nesting, :unless => :syncing_or_stubbing protected - def syncing? - OpenStax::Accounts.syncing - end - def syncing_or_stubbing - syncing? || OpenStax::Accounts.configuration.enable_stubbing? + syncing || OpenStax::Accounts.configuration.enable_stubbing? end def no_loops return if member_group.nil? ||\ !member_group.subtree_group_ids.include?(container_group_id) @@ -43,20 +39,18 @@ # Returns false if the update fails (aborting the save transaction) UpdateGroupCaches.call(self).errors.none? end def create_openstax_accounts_group_nesting - return if OpenStax::Accounts.syncing || OpenStax::Accounts.configuration.enable_stubbing? return false unless requestor - OpenStax::Accounts.create_group_nesting(requestor, self) + OpenStax::Accounts::Api.create_group_nesting(requestor, self) end def destroy_openstax_accounts_group_nesting - return if OpenStax::Accounts.syncing || OpenStax::Accounts.configuration.enable_stubbing? return false unless requestor - OpenStax::Accounts.destroy_group_nesting(requestor, self) + OpenStax::Accounts::Api.destroy_group_nesting(requestor, self) end end end