Sha256: 73c908d8260892a4c5f13f89ef59406bd896913b62af8ff4e91f9db6e3433320
Contents?: true
Size: 1.37 KB
Versions: 3
Compression:
Stored size: 1.37 KB
Contents
# frozen_string_literal: true module Decidim module Admin # This command gets called when permissions for a component are updated # in the admin panel. class UpdateComponentPermissions < Rectify::Command attr_reader :form, :component # Public: Initializes the command. # # form - The form from which the data in this component comes from. # component - The component to update. def initialize(form, component) @form = form @component = component end # Public: Sets the permissions for a component. # # Broadcasts :ok if created, :invalid otherwise. def call return broadcast(:invalid) unless @form.valid? transaction do update_permissions run_hooks end broadcast(:ok) end private def update_permissions permissions = @form.permissions.inject({}) do |result, (key, value)| serialized = { "authorization_handler_name" => value.authorization_handler_name } serialized["options"] = JSON.parse(value.options) if value.options result.update(key => serialized) end @component.update!( permissions: permissions ) end def run_hooks @component.manifest.run_hooks(:permission_update, @component) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems