Class: Decidim::Kids::Permissions

Inherits:
DefaultPermissions
  • Object
show all
Defined in:
app/permissions/decidim/kids/permissions.rb

Instance Method Summary collapse

Instance Method Details

#authorizations_action?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
47
48
# File 'app/permissions/decidim/kids/permissions.rb', line 39

def authorizations_action?
  return unless permission_action.subject == :authorizations

  case permission_action.action
  when :all
    return allow! unless user.organization.minors_participation_enabled?

    toggle_allow(!user.minor?)
  end
end

#conversation_action?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
# File 'app/permissions/decidim/kids/permissions.rb', line 50

def conversation_action?
  return unless permission_action.subject == :conversation
  return unless user.organization.minors_participation_enabled?
  return unless [:create, :update].include?(permission_action.action)

  conversation = context.fetch(:conversation)
  interlocutor = context.fetch(:interlocutor, user)
  toggle_allow(conversation.participants.all? { |p| minor_conversation_participant?(interlocutor, p) })
end

#minor_accounts_action?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/permissions/decidim/kids/permissions.rb', line 18

def minor_accounts_action?
  return unless permission_action.subject == :minor_accounts

  if !user.organization.minors_participation_enabled? || user.minor? || !user.confirmed?
    disallow!
  else
    case permission_action.action
    when :index
      allow!
    when :create
      can_create_minor_account?
    when :edit
      can_edit_minor_account?
    when :delete
      can_destroy_minor_account?
    when :impersonate
      can_impersonate_minor_account?
    end
  end
end

#permissionsObject



6
7
8
9
10
11
12
13
14
15
16
# File 'app/permissions/decidim/kids/permissions.rb', line 6

def permissions
  # return Decidim::Kids::Admin::Permissions.new(user, permission_action, context).permissions if permission_action.scope == :admin
  return permission_action if permission_action.scope == :admin
  return permission_action unless user

  minor_accounts_action?
  authorizations_action?
  conversation_action?

  permission_action
end