Skip to content

Commit

Permalink
remove deprecated avatar and upload code
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Dec 21, 2023
1 parent d1e34ce commit 4194cfc
Show file tree
Hide file tree
Showing 19 changed files with 12 additions and 363 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.

4 changes: 1 addition & 3 deletions app/controllers/v0/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def user_params
:password,
:city,
:country_code,
:url,
:avatar,
:avatar_url
: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.

16 changes: 2 additions & 14 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ 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 @@ -44,7 +44,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 @@ -63,10 +63,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 @@ -136,14 +132,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

private

def check_if_users_have_valid_email
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 @@ -33,7 +33,6 @@ if with_owner && device.owner
json.id device.owner.id
json.uuid device.owner.uuid
json.username device.owner.username
json.avatar device.owner.avatar

json.profile_picture profile_picture_url(device.owner)

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 @@ -38,8 +34,6 @@
resources :oauth_applications, path: 'applications'

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
6 changes: 6 additions & 0 deletions db/migrate/20231221142429_remove_avatars_and_uploads.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RemoveAvatarsAndUploads < ActiveRecord::Migration[6.1]
def change
drop_table :uploads
remove_column :users, :avatar_url
end
end
17 changes: 1 addition & 16 deletions 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: 2023_10_06_064514) do
ActiveRecord::Schema.define(version: 2023_12_21_142429) do

# These are extensions that must be enabled in order to support this database
enable_extension "adminpack"
Expand Down Expand Up @@ -261,19 +261,6 @@
t.index ["name"], name: "index_tags_on_name", unique: true
end

create_table "uploads", id: :serial, force: :cascade do |t|
t.string "type"
t.string "original_filename"
t.jsonb "metadata"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.uuid "uuid", default: -> { "uuid_generate_v4()" }
t.integer "user_id"
t.string "key"
t.index ["type"], name: "index_uploads_on_type"
t.index ["user_id"], name: "index_uploads_on_user_id"
end

create_table "users", id: :serial, force: :cascade do |t|
t.string "username"
t.string "email"
Expand All @@ -284,7 +271,6 @@
t.string "city"
t.string "country_code"
t.string "url"
t.string "avatar_url"
t.integer "role_mask", default: 0, null: false
t.uuid "uuid", default: -> { "uuid_generate_v4()" }
t.string "legacy_api_key", null: false
Expand All @@ -304,5 +290,4 @@
add_foreign_key "devices_tags", "tags"
add_foreign_key "postprocessings", "devices"
add_foreign_key "sensors", "measurements"
add_foreign_key "uploads", "users"
end
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.

Loading

0 comments on commit 4194cfc

Please sign in to comment.