Class: Decidim::Admin::UnhideResource

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/admin/unhide_resource.rb

Overview

A command with all the business logic when a user hides a resource.

Instance Method Summary collapse

Constructor Details

#initialize(reportable, current_user, with_admin_log: true) ⇒ UnhideResource

Public: Initializes the command.

reportable - A Decidim::Reportable current_user - the user that performs the action with_admin_log Boolean - determines whether to log the action of unhide a resource in the admin log



12
13
14
15
16
# File 'app/commands/decidim/admin/unhide_resource.rb', line 12

def initialize(reportable, current_user, with_admin_log: true)
  @reportable = reportable
  @current_user = current_user
  @with_admin_log = with_admin_log
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid, together with the resource.

  • :invalid if the resource is already hidden

Returns nothing.



24
25
26
27
28
29
30
# File 'app/commands/decidim/admin/unhide_resource.rb', line 24

def call
  return broadcast(:parent_invalid) if @reportable.respond_to?(:commentable) && @reportable.commentable.try(:hidden?)
  return broadcast(:invalid) unless unhideable?

  @with_admin_log ? unhide_with_admin_log! : unhide!
  broadcast(:ok, @reportable)
end