Sha256: 51601cd27e232ff0c3bd10f93b7ebab6a512b04bb2b0bdaa9e5c91b79cf24bed

Contents?: true

Size: 1.28 KB

Versions: 16

Compression:

Stored size: 1.28 KB

Contents

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

    delegate :requestor, :syncing, to: :group

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

    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_member, unless: :syncing_or_stubbing?
    before_destroy :destroy_openstax_accounts_group_member, unless: :syncing_or_stubbing?

    protected

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

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

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

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

      OpenStax::Accounts::Api.destroy_group_member(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_member.rb
openstax_accounts-8.1.0 app/models/openstax/accounts/group_member.rb
openstax_accounts-8.0.1 app/models/openstax/accounts/group_member.rb
openstax_accounts-8.0.0 app/models/openstax/accounts/group_member.rb
openstax_accounts-7.13.1 app/models/openstax/accounts/group_member.rb
openstax_accounts-7.13.0 app/models/openstax/accounts/group_member.rb
openstax_accounts-7.12.0 app/models/openstax/accounts/group_member.rb
openstax_accounts-7.11.0 app/models/openstax/accounts/group_member.rb
openstax_accounts-7.10.0 app/models/openstax/accounts/group_member.rb
openstax_accounts-7.9.0 app/models/openstax/accounts/group_member.rb
openstax_accounts-7.8.0 app/models/openstax/accounts/group_member.rb
openstax_accounts-7.7.0 app/models/openstax/accounts/group_member.rb
openstax_accounts-7.6.0 app/models/openstax/accounts/group_member.rb
openstax_accounts-7.5.0 app/models/openstax/accounts/group_member.rb
openstax_accounts-7.4.0 app/models/openstax/accounts/group_member.rb
openstax_accounts-7.3.0 app/models/openstax/accounts/group_member.rb