Module: Decidim::ActionDelegator::Admin::DelegationHelper

Defined in:
app/helpers/decidim/action_delegator/admin/delegation_helper.rb

Instance Method Summary collapse

Instance Method Details

#consultations_for_selectObject



15
16
17
# File 'app/helpers/decidim/action_delegator/admin/delegation_helper.rb', line 15

def consultations_for_select
  organization_consultations.map { |consultation| [translated_attribute(consultation.title), consultation.id] }
end

#existing_authorizations(participants) ⇒ Object



50
51
52
53
54
55
56
# File 'app/helpers/decidim/action_delegator/admin/delegation_helper.rb', line 50

def existing_authorizations(participants)
  uniq_ids = participants_uniq_ids(participants)
  user_ids = current_organization.users.select(:id).where(email: participants.select(:email))
  Decidim::Authorization.select(:decidim_user_id).where(unique_id: uniq_ids).or(
    Decidim::Authorization.select(:decidim_user_id).where(decidim_user_id: user_ids)
  )
end

#grantees_for_selectObject



11
12
13
# File 'app/helpers/decidim/action_delegator/admin/delegation_helper.rb', line 11

def grantees_for_select
  current_organization.users
end

#granters_for_selectObject



7
8
9
# File 'app/helpers/decidim/action_delegator/admin/delegation_helper.rb', line 7

def granters_for_select
  current_organization.users
end

#missing_decidim_users(participants) ⇒ Object



33
34
35
# File 'app/helpers/decidim/action_delegator/admin/delegation_helper.rb', line 33

def missing_decidim_users(participants)
  participants.where(decidim_user: nil).or(participants.where.not(decidim_user: current_organization.users)).where.not(id: missing_registered_users(participants))
end

#missing_registered_users(participants) ⇒ Object



37
38
39
40
41
42
43
# File 'app/helpers/decidim/action_delegator/admin/delegation_helper.rb', line 37

def missing_registered_users(participants)
  participants.where.not(email: current_organization.users.select(:email))
              .where.not("MD5(CONCAT(phone,'-',?,'-',?)) IN (?)",
                         current_organization.id,
                         Digest::MD5.hexdigest(Rails.application.secret_key_base),
                         Authorization.select(:unique_id).where.not(unique_id: nil))
end

#missing_verifications_for(resources, action) ⇒ Object



27
28
29
30
31
# File 'app/helpers/decidim/action_delegator/admin/delegation_helper.rb', line 27

def missing_verifications_for(resources, action)
  resources.where.not(id: Decidim::ResourcePermission.select(:resource_id)
    .where(resource: resources)
    .where(Arel.sql("permissions->'#{action}'->'authorization_handlers'->>'delegations_verifier' IS NOT NULL")))
end

#organization_consultationsObject



23
24
25
# File 'app/helpers/decidim/action_delegator/admin/delegation_helper.rb', line 23

def organization_consultations
  Decidim::Consultations::OrganizationConsultations.new(current_organization).query
end

#participants_uniq_ids(participants) ⇒ Object



45
46
47
48
# File 'app/helpers/decidim/action_delegator/admin/delegation_helper.rb', line 45

def participants_uniq_ids(participants)
  phones = Participant.phone_combinations(participants.pluck(:phone))
  Participant.verifier_ids(Participant.phone_combinations(phones.map { |phone| "#{phone}-#{current_organization.id}" }))
end

#ponderations_for_select(setting) ⇒ Object



19
20
21
# File 'app/helpers/decidim/action_delegator/admin/delegation_helper.rb', line 19

def ponderations_for_select(setting)
  setting.ponderations.map { |ponderation| [ponderation.title, ponderation.id] }
end

#total_missing_authorizations(participants) ⇒ Object



58
59
60
# File 'app/helpers/decidim/action_delegator/admin/delegation_helper.rb', line 58

def total_missing_authorizations(participants)
  participants.count - existing_authorizations(participants).count
end