Class: TentD::API::Followers::GetOne

Inherits:
Middleware show all
Defined in:
lib/tentd/api/followers.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



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/tentd/api/followers.rb', line 106

def action(env)
  if env.full_read_authorized || authorize_env?(env, :self)
    follower = Model::Follower.find(env.params.follower_id)
  else
    follower = Model::Follower.find_with_permissions(env.params.follower_id, env.current_auth)
  end

  if env.full_read_authorized || authorize_env?(env, :self) || (follower && follower.public?)
    env.response = follower
  else
    raise Unauthorized
  end

  env
end