Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F906971
base_controller.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 30, 12:09 PM
Size
829 B
Mime Type
text/x-ruby
Expires
Mon, Sep 1, 12:09 PM (1 d, 6 h)
Engine
blob
Format
Raw Data
Handle
253740
Attached To
rARCHIVING archiving
base_controller.rb
View Options
class
Api
::
BaseController
<
ApplicationController
skip_before_action
:verify_authenticity_token
respond_to
:json
helper_method
:current_api_user
,
:api_render
rescue_from
ActiveRecord
::
RecordNotFound
do
render
json
:
{
msg
:
'resource not found'
},
status
:
:not_found
end
# Returns a 403 forbidden header if there is no associated user with the provided token
def
require_api_login
unless
current_api_user
head
:forbidden
end
end
protected
# Fetches the current user based on the provided token
def
current_api_user
@current_api_user
||=
if
token
=
request
.
env
[
'HTTP_API_TOKEN'
].
presence
User
.
find_by
(
token
:
token
)
end
end
# Wrapper method to simplify object rendering for api
def
api_render
(
object
)
render
json
:
object
.
to_json
(
for_api
:
true
)
end
end
Event Timeline
Log In to Comment