Class: TentD::API::Posts::GetOne
- Inherits:
-
Middleware
- Object
- Middleware
- TentD::API::Posts::GetOne
- Defined in:
- lib/tentd/api/posts.rb
Instance Method Summary collapse
Methods inherited from Middleware
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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tentd/api/posts.rb', line 23 def action(env) if (env, :read_posts) conditions = { :id => env.params.post_id } unless env.current_auth.post_types.include?('all') conditions[:type_base] = env.current_auth.post_types.map { |t| TentType.new(t).base } end if env.params.version conditions[:fields] = [:id] end post = Model::Post.first(conditions) else post = Model::Post.(env.params.post_id, env.current_auth) end if post if env.params.version if post_version = post.versions.first(:version => env.params.version.to_i) post = post_version else post = nil end end env.response = post end env end |