Sha256: 47fe117ba4542abe220f0d771d2ef9d2c77dd478356606a6f5905b7922dec87d

Contents?: true

Size: 1.45 KB

Versions: 15

Compression:

Stored size: 1.45 KB

Contents

class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loaders::Policy
  name "default-user-access"

  attr_reader   :session, :options, :job
  attr_accessor :account_removed_count

  def main(people, session, options, policy, job)
    @session = session; @options = options; @job = job

    self.account_removed_count = 0

    people.each do |person|
      remove_account_when_no_email!(person)    if person.email.to_s.empty?
      person.account.policy_group_ids = defid  if no_policy_group_ids?(person)
    end

    warn_account_removal!
  end

  private

  def warn_account_removal!
    if account_removed_count > 0
      msg = "(DefaultPolicy on job '#{job.name}') Removed account to #{account_removed_count} people"
      session.logger.info(msg)
    end
  end

  def remove_account_when_no_email!(person)
    if person.account
      self.account_removed_count += 1 if had_account?(person)
      person.account = nil
    end
  end

  def had_account?(person)
    return false if person.new?
    return false if person.account_added?
    return !!person.original_doc["account"]
  end

  def no_policy_group_ids?(person)
    (account = person.account) &&  account.policy_group_ids.empty?
  end

  def defid
    @defid ||= policy_groups.to_id([default_group]).compact
  end

  def default_group
    session.config.people.default_usergroup
  end

  def policy_groups
    session.policy_groups
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
eco-helpers-2.0.57 lib/eco/api/policies/default_policies/99_user_access_policy.rb
eco-helpers-2.0.56 lib/eco/api/policies/default_policies/99_user_access_policy.rb
eco-helpers-2.0.55 lib/eco/api/policies/default_policies/99_user_access_policy.rb
eco-helpers-2.0.54 lib/eco/api/policies/default_policies/99_user_access_policy.rb
eco-helpers-2.0.53 lib/eco/api/policies/default_policies/99_user_access_policy.rb
eco-helpers-2.0.52 lib/eco/api/policies/default_policies/99_user_access_policy.rb
eco-helpers-2.0.51 lib/eco/api/policies/default_policies/99_user_access_policy.rb
eco-helpers-2.0.50 lib/eco/api/policies/default_policies/99_user_access_policy.rb
eco-helpers-2.0.49 lib/eco/api/policies/default_policies/99_user_access_policy.rb
eco-helpers-2.0.48 lib/eco/api/policies/default_policies/99_user_access_policy.rb
eco-helpers-2.0.47 lib/eco/api/policies/default_policies/99_user_access_policy.rb
eco-helpers-2.0.46 lib/eco/api/policies/default_policies/99_user_access_policy.rb
eco-helpers-2.0.45 lib/eco/api/policies/default_policies/99_user_access_policy.rb
eco-helpers-2.0.44 lib/eco/api/policies/default_policies/99_user_access_policy.rb
eco-helpers-2.0.43 lib/eco/api/policies/default_policies/99_user_access_policy.rb