Class: Decidim::Posts::DestroyPost

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/posts/destroy_post.rb

Instance Method Summary collapse

Constructor Details

#initialize(post, current_user) ⇒ DestroyPost

Returns a new instance of DestroyPost.



6
7
8
9
# File 'app/commands/decidim/posts/destroy_post.rb', line 6

def initialize(post, current_user)
  @post = post
  @current_user = current_user
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
# File 'app/commands/decidim/posts/destroy_post.rb', line 11

def call
  return broadcast(:invalid) unless @post.authored_by?(@current_user) || @current_user.admin?

  @post.destroy!

  broadcast(:ok, @post)
end