Sha256: 7a3fd46e8dee3a9c46cf65a4f0ba6a7e989916eed5bb737c9738922afd07e6ff

Contents?: true

Size: 1.27 KB

Versions: 16

Compression:

Stored size: 1.27 KB

Contents

module OpenStax::Accounts
  class GroupOwner < ActiveRecord::Base

    delegate :requestor, :syncing, to: :group

    belongs_to :group, class_name: 'OpenStax::Accounts::Group',
               primary_key: :openstax_uid, inverse_of: :group_owners
    belongs_to :user, class_name: 'OpenStax::Accounts::Account',
               primary_key: :openstax_uid, inverse_of: :group_owners

    validates :group, presence: true
    validates :user, presence: true, uniqueness: { scope: :group }
    validates :requestor, presence: true, unless: :syncing_or_stubbing?

    before_create :create_openstax_accounts_group_owner, unless: :syncing_or_stubbing?
    before_destroy :destroy_openstax_accounts_group_owner, unless: :syncing_or_stubbing?

    protected

    def syncing_or_stubbing?
      syncing || OpenStax::Accounts.configuration.enable_stubbing?
    end

    def create_openstax_accounts_group_owner
      return false if requestor.nil? || requestor.is_anonymous?

      OpenStax::Accounts::Api.create_group_owner(requestor, self) if requestor.has_authenticated?
    end

    def destroy_openstax_accounts_group_owner
      return false if requestor.nil? || requestor.is_anonymous?

      OpenStax::Accounts::Api.destroy_group_owner(requestor, self) if requestor.has_authenticated?
    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
openstax_accounts-8.1.1 app/models/openstax/accounts/group_owner.rb
openstax_accounts-8.1.0 app/models/openstax/accounts/group_owner.rb
openstax_accounts-8.0.1 app/models/openstax/accounts/group_owner.rb
openstax_accounts-8.0.0 app/models/openstax/accounts/group_owner.rb
openstax_accounts-7.13.1 app/models/openstax/accounts/group_owner.rb
openstax_accounts-7.13.0 app/models/openstax/accounts/group_owner.rb
openstax_accounts-7.12.0 app/models/openstax/accounts/group_owner.rb
openstax_accounts-7.11.0 app/models/openstax/accounts/group_owner.rb
openstax_accounts-7.10.0 app/models/openstax/accounts/group_owner.rb
openstax_accounts-7.9.0 app/models/openstax/accounts/group_owner.rb
openstax_accounts-7.8.0 app/models/openstax/accounts/group_owner.rb
openstax_accounts-7.7.0 app/models/openstax/accounts/group_owner.rb
openstax_accounts-7.6.0 app/models/openstax/accounts/group_owner.rb
openstax_accounts-7.5.0 app/models/openstax/accounts/group_owner.rb
openstax_accounts-7.4.0 app/models/openstax/accounts/group_owner.rb
openstax_accounts-7.3.0 app/models/openstax/accounts/group_owner.rb