Skip to content

Commit

Permalink
Remove deprecated avatars and uploads implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Jul 4, 2024
1 parent dfc6e2b commit 9849cc2
Show file tree
Hide file tree
Showing 19 changed files with 8 additions and 347 deletions.
2 changes: 0 additions & 2 deletions app/controllers/v0/me_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ def user_params
:country_code,
:profile_picture,
:url,
:avatar,
:avatar_url
)
end

Expand Down
1 change: 0 additions & 1 deletion app/controllers/v0/static_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def search
h['url'] = v0_device_url(s.searchable_id)
elsif s.searchable_type == 'User'
h['username'] = s.searchable.username
h['avatar'] = s.searchable.avatar
h['profile_picture'] = profile_picture_url(s.searchable)
h['city'] = s.searchable.city
h['url'] = v0_user_url(s.searchable_id)
Expand Down
66 changes: 0 additions & 66 deletions app/controllers/v0/uploads_controller.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/controllers/v0/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ def user_params
:city,
:country_code,
:url,
:avatar,
:avatar_url
)
end

Expand Down
5 changes: 0 additions & 5 deletions app/models/avatar.rb

This file was deleted.

31 changes: 0 additions & 31 deletions app/models/upload.rb

This file was deleted.

15 changes: 1 addition & 14 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class User < ActiveRecord::Base

has_many :devices, foreign_key: 'owner_id', after_add: :update_cached_device_ids!, after_remove: :update_cached_device_ids!
has_many :sensors, through: :devices
has_many :uploads, dependent: :destroy
has_many :oauth_applications, class_name: 'Doorkeeper::Application', as: :owner
has_one_attached :profile_picture

Expand All @@ -49,7 +48,7 @@ def self.ransackable_attributes(auth_object = nil)
end

def self.ransackable_associations(auth_object = nil)
["devices", "sensors", "uploads"]
["devices", "sensors"]
end

def archive
Expand All @@ -68,10 +67,6 @@ def access_token
Doorkeeper::AccessToken.find_or_initialize_by(application_id: 4, resource_owner_id: id)
end

def avatar
avatar_url || "https://smartcitizen.s3.amazonaws.com/avatars/default.svg"
end

def access_token!
access_token.expires_in = 2.days.from_now
access_token.save
Expand Down Expand Up @@ -141,14 +136,6 @@ def update_all_device_ids!
update_column(:cached_device_ids, device_ids.try(:sort))
end

def self.check_bad_avatar_urls
User.where.not(avatar_url: nil).each do |user|
unless `curl -I #{user.avatar_url} 2>/dev/null | head -n 1`.split(' ')[1] == "200"
puts [user.id, user.avatar_url].join(' - ')
end
end
end

def forward_device_readings?
!!forwarding_token
end
Expand Down
1 change: 0 additions & 1 deletion app/views/v0/devices/_device.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ if local_assigns[:with_owner] && device.owner
json.url device.owner.url

unless local_assigns[:slim_owner]
json.avatar device.owner.avatar
json.profile_picture profile_picture_url(device.owner)
json.location device.owner.location
json.device_ids device.owner.cached_device_ids
Expand Down
1 change: 0 additions & 1 deletion app/views/v0/users/_user.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ json.(user,
:uuid,
:role,
:username,
:avatar,
:profile_picture,
:url,
:location,
Expand Down
6 changes: 0 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
resources :components, only: [:show, :index]
resources :sessions, only: :create

resources :uploads, path: 'avatars' do
post 'uploaded' => 'uploads#uploaded', on: :collection
end

resources :tag_sensors
resources :tags
resources :measurements
Expand All @@ -39,8 +35,6 @@
get :forward, to: "forwarding#authorize"

resources :me, only: [:index] do
patch 'avatar' => 'uploads#create', on: :collection
post 'avatar' => 'uploads#create', on: :collection
patch '/' => 'me#update', on: :collection
put '/' => 'me#update', on: :collection
delete '/' => 'me#destroy', on: :collection
Expand Down
4 changes: 4 additions & 0 deletions db/migrate/20240704062854_remove_avatars_and_uploads.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class RemoveAvatarsAndUploads < ActiveRecord::Migration[6.1]
def change
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_06_24_175242) do
ActiveRecord::Schema.define(version: 2024_07_04_062854) do

# These are extensions that must be enabled in order to support this database
enable_extension "adminpack"
Expand Down
108 changes: 0 additions & 108 deletions public/examples/image_uploads/form.html

This file was deleted.

2 changes: 1 addition & 1 deletion spec/controllers/v0/me_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rails_helper'

RSpec.describe V0::MeController do
skip { is_expected.to permit(:email,:username,:password,:city,:country_code,:url,:avatar,:avatar_url).for(:update) }
skip { is_expected.to permit(:email,:username,:password,:city,:country_code,:url).for(:update) }
end
2 changes: 1 addition & 1 deletion spec/controllers/v0/users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rails_helper'

RSpec.describe V0::UsersController do
it { is_expected.to permit(:email,:username,:password,:city,:country_code,:url,:avatar,:avatar_url).for(:create) }
it { is_expected.to permit(:email,:username,:password,:city,:country_code,:url).for(:create) }
end
9 changes: 0 additions & 9 deletions spec/factories/uploads.rb

This file was deleted.

32 changes: 0 additions & 32 deletions spec/models/upload_spec.rb

This file was deleted.

Loading

0 comments on commit 9849cc2

Please sign in to comment.