Skip to content

Commit

Permalink
ensure that the profile_picture is sent in all responses with a user …
Browse files Browse the repository at this point in the history
…object
  • Loading branch information
timcowlishaw committed Oct 26, 2023
1 parent e4721f0 commit cacd017
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 22 deletions.
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# this file is required for errbit notifier
class ApplicationController < ActionController::API
include ActionController::ImplicitRender
include ActionController::Helpers
end
3 changes: 3 additions & 0 deletions app/controllers/v0/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require_relative '../../helpers/user_helper'
module V0
class ApplicationController < ActionController::API

Expand All @@ -10,6 +11,8 @@ class ApplicationController < ActionController::API
include PrettyJSON
include ErrorHandlers

helper ::UserHelper

respond_to :json

before_action :prepend_view_paths
Expand Down
3 changes: 3 additions & 0 deletions app/views/v0/devices/_device.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ if device.owner
json.uuid device.owner.uuid
json.username device.owner.username
json.avatar device.owner.avatar

json.profile_picture profile_picture_url(device.owner)

json.url device.owner.url
json.joined_at device.owner.joined_at
json.location device.owner.location
Expand Down
16 changes: 1 addition & 15 deletions app/views/v0/devices/index.jbuilder
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
json.array! @devices, partial: 'device', as: :device

# json.array! @devices do |device|
# json.id device.id
# json.name device.name
# json.description device.description
# json.status device.status
# json.added_at device.added_at
# json.last_reading_at device.last_reading_at
# json.updated_at device.updated_at

# json.kit_id device.kit_id

# json.owner device.owner, :id, :username, :avatar, :url, :joined_at, :location, :device_ids
# end
json.array! @devices, partial: 'device', as: :device
8 changes: 1 addition & 7 deletions app/views/v0/users/_user.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ json.(user,
:updated_at
)

if user.profile_picture.attached?
json.profile_picture polymorphic_url(user.profile_picture, only_path: false)

else
json.profile_picture ''
end

json.profile_picture profile_picture_url(user)

if current_user and (current_user.is_admin? or current_user == user)
json.merge! email: user.email
Expand Down

0 comments on commit cacd017

Please sign in to comment.