Skip to content

Commit

Permalink
remove logo from observer
Browse files Browse the repository at this point in the history
  • Loading branch information
tsubik committed Sep 18, 2024
1 parent 976afdf commit abe2531
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 40 deletions.
16 changes: 2 additions & 14 deletions app/admin/observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def scoped_collection
end
end

permit_params :observer_type, :is_active, :logo, :name, :organization_type, :delete_logo,
permit_params :observer_type, :is_active, :name, :organization_type,
:responsible_qc1_id, :responsible_qc2_id, country_ids: []

csv do
Expand Down Expand Up @@ -46,10 +46,7 @@ def scoped_collection
end
# rubocop:enable Rails/OutputSafety
column :observer_type, sortable: true
column :logo do |o|
link_to o.logo&.identifier, o.logo&.url if o.logo&.url
end
column :name
lcolumn :name
column :responsible_qc1
column :responsible_qc2
column :created_at
Expand Down Expand Up @@ -96,9 +93,6 @@ def scoped_collection
links.join(" ").html_safe
end
# rubocop:enable Rails/OutputSafety
row :logo do |o|
link_to o.logo&.identifier, o.logo&.url
end
row :address
row :information_name
row :information_email
Expand All @@ -120,12 +114,6 @@ def scoped_collection
f.input :countries, collection: Country.with_translations(I18n.locale).order("country_translations.name asc")
f.input :observer_type, as: :select, collection: %w[Mandated SemiMandated External Government]
f.input :organization_type, as: :select, collection: ["NGO", "Academic", "Research Institute", "Private Company", "Other"]
if f.object.logo.present?
f.input :logo, as: :file, hint: image_tag(f.object.logo.url(:thumbnail))
f.input :delete_logo, as: :boolean, required: false, label: "Remove logo"
else
f.input :logo, as: :file
end
end
unless f.object.new_record?
f.inputs "Quality Control" do
Expand Down
8 changes: 0 additions & 8 deletions app/controllers/v1/observers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,5 @@ class ObserversController < APIController

skip_before_action :authenticate, only: [:index, :show]
load_and_authorize_resource class: "Observer"

def update
# When sending the logo empty, it deletes it
if params.dig("data", "attributes", "logo") == ""
params["data"]["attributes"]["delete-logo"] = "1"
end
super
end
end
end
5 changes: 0 additions & 5 deletions app/models/observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# created_at :datetime not null
# updated_at :datetime not null
# is_active :boolean default(TRUE), not null
# logo :string
# address :string
# information_name :string
# information_email :string
Expand All @@ -27,9 +26,6 @@
class Observer < ApplicationRecord
has_paper_trail

mount_base64_uploader :logo, LogoUploader
attr_accessor :delete_logo

normalizes :name, :address, :information_name, :data_name, :information_phone, :data_phone, with: -> { _1.strip }
normalizes :information_email, :data_email, with: -> { _1.strip.downcase }

Expand All @@ -50,7 +46,6 @@ class Observer < ApplicationRecord

EMAIL_VALIDATOR = /\A([\w+-].?)+@[a-z\d-]+(\.[a-z]+)*\.[a-z]+\z/i

before_validation { remove_logo! if delete_logo == "1" }
validates :name, presence: true
validates :observer_type, presence: true, inclusion: {in: %w[Mandated SemiMandated External Government],
message: "%{value} is not a valid observer type"}
Expand Down
8 changes: 4 additions & 4 deletions app/resources/v1/observer_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class ObserverResource < BaseResource
include CacheableByLocale
# caching

attributes :observer_type, :name, :is_active, :logo, :address,
attributes :observer_type, :name, :is_active, :address,
:information_name, :information_email, :information_phone, :data_name,
:data_email, :data_phone, :organization_type, :delete_logo, :public_info
:data_email, :data_phone, :organization_type, :public_info

has_many :countries
has_many :observations
Expand All @@ -34,9 +34,9 @@ def self.records(options = {})

def fetchable_fields
if (context[:app] == "observations-tool") || @model.public_info
super - [:delete_logo]
super
else
super - [:delete_logo, :address, :information_name, :information_email, :information_phone, :data_email, :data_phone, :data_name]
super - [:address, :information_name, :information_email, :information_phone, :data_email, :data_phone, :data_name]
end
end
end
Expand Down
1 change: 0 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,6 @@ en:
information_name: Information name #g
information_phone: Information phone #g
is_active: Is active #g
logo: Logo #g
observation_report_observers: Observation report observers #g
observation_reports: Observation reports #g
observations: Observations #g
Expand Down
1 change: 0 additions & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,6 @@ fr:
information_name: Nom de l'information #g
information_phone: Téléphone d'information #g
is_active: Actif ? #g
logo: Logo #g
observation_report_observers: Rapport d'observation observateurs #g
observation_reports: Rapports d'observation #g
observations: Observations #g
Expand Down
3 changes: 0 additions & 3 deletions db/fixtures/observers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Observer_5:
created_at: 2017-09-25 15:06:42 UTC
updated_at: 2023-12-06 09:36:08 UTC
is_active: true
logo: FODER.jpg
address: Derrière usine Bastos, face Restaurant Chinois Village, PO BOX 11417, Yaoundé,
Cameroon
information_name: JUSTIN CHRISTOPHE KAMGA
Expand All @@ -32,7 +31,6 @@ Observer_10:
created_at: 2017-09-25 15:06:42 UTC
updated_at: 2023-11-14 13:13:04 UTC
is_active: true
logo: CAGDF.jpg
address: 43, rue Nkounkou August, Makélékélé
information_name: Lambert Mabiala
information_email: lambertmabiala@yahoo.fr
Expand All @@ -47,7 +45,6 @@ Observer_16:
created_at: 2017-09-25 15:06:42 UTC
updated_at: 2024-01-25 12:53:53 UTC
is_active: true
logo: OGF.jpg
address: 6, avenue Marinel, Kinshasa/Gombe, référence Immeuble Sofide
information_name: Serge Bondo
information_email: skayembeb@gmail.com
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240918130301_remove_logo_from_observers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveLogoFromObservers < ActiveRecord::Migration[7.1]
def change
remove_column :observers, :logo, :string
end
end
3 changes: 1 addition & 2 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[7.1].define(version: 2024_08_09_153734) do
ActiveRecord::Schema[7.1].define(version: 2024_09_18_130301) do
create_schema "tiger"
create_schema "tiger_data"
create_schema "topology"
Expand Down Expand Up @@ -627,7 +627,6 @@
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.boolean "is_active", default: true, null: false
t.string "logo"
t.string "address"
t.string "information_name"
t.string "information_email"
Expand Down
2 changes: 0 additions & 2 deletions spec/factories/observers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# created_at :datetime not null
# updated_at :datetime not null
# is_active :boolean default(TRUE), not null
# logo :string
# address :string
# information_name :string
# information_email :string
Expand All @@ -26,7 +25,6 @@
factory :observer do
sequence(:name) { |n| "Observer #{n}" }
observer_type { "External" }
logo { Rack::Test::UploadedFile.new(File.join(Rails.root, "spec", "support", "files", "image.png")) }
sequence(:information_name) { |n| "Information name #{n}" }
sequence(:information_email) { |n| "info_email#{n}@mail.com" }
sequence(:information_phone) { |n| (n.to_s * 9).first(9) }
Expand Down

0 comments on commit abe2531

Please sign in to comment.