Class: TentD::API::Posts::Notify

Inherits:
Middleware show all
Defined in:
lib/tentd/api/posts.rb

Instance Method Summary collapse

Methods inherited from Middleware

#call, #initialize

Methods included from Authorizable

#authorize_env!, #authorize_env?

Constructor Details

This class inherits a constructor from TentD::API::Middleware

Instance Method Details

#action(env) ⇒ Object



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/tentd/api/posts.rb', line 260

def action(env)
  if deleted_post = env.notify_deleted_post
    post = Model::Post.create(
      :type => 'https://tent.io/types/post/delete/v0.1.0',
      :entity => env['tent.entity'],
      :original => true,
      :content => {
        :id => deleted_post.public_id
      }
    )
    Model::Permission.copy(deleted_post, post)
  else
    return env unless (post = env.response) && post.kind_of?(Model::Post)
  end
  Notifications.trigger(:type => post.type.uri, :post_id => post.id)
  env
end