Skip to content

Commit

Permalink
fix: add token to secret and basic error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
yhru committed Oct 25, 2024
1 parent 710944b commit 8ad1ad3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 23 deletions.
1 change: 1 addition & 0 deletions app/controllers/users/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ def update
@to_show, @to_hide, @to_update = champs_to_turbo_update(champs_public_attributes_params, dossier.champs.filter(&:public?))
render :update, layout: false
end
format.html { redirect_to dossier_path(@dossier) }
end
end

Expand Down
13 changes: 0 additions & 13 deletions app/graphql/types/champs/referentiel_de_polynesie_champ_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,7 @@ module Types::Champs
class ReferentielDePolynesieChampType < Types::BaseObject
implements Types::ChampType

field :selected_value, String, null: true
field :table_id, ID, null: true
field :search_field, String, null: true

def selected_value
object.value
end

def table_id
object.table_id
end

def search_field
object.search_field
end
end
end
6 changes: 3 additions & 3 deletions app/lib/referentiel_de_polynesie/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
class ReferentielDePolynesie::API
class << self
def available_tables
engine&.available_tables
engine&.available_tables || []
end

def search(domain_id, term)
engine&.search(domain_id, term)
engine&.search(domain_id, term) || []
end

def fetch_row(external_id)
table, id = external_id.split(':')
engine.fetch_row(table, id)
engine&.fetch_row(table, id) || {}
end

def engine
Expand Down
21 changes: 15 additions & 6 deletions app/lib/referentiel_de_polynesie/baserow_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@ class << self

def search(domain_id, term)
config = config(domain_id)
return [] unless config
search_field = config['Champ de recherche']
params = { "filter__field_#{search_field}__contains" => term }
url = rows_url(config['Table'])
response = Typhoeus.get(url, headers: database_headers(config['Token']), params: params)
pp response
if response.success?
JSON.parse(response.body, symbolize_names: true)[:results].map do
{ name: _1[:"field_#{search_field}"], id: _1[:id], domain: domain_id }
end + [{ name: 'Autre', id: 0, domain: domain_id }]
begin
response = Typhoeus.get(url, headers: database_headers(config['Token']), params: params)
pp response
if response.success?
JSON.parse(response.body, symbolize_names: true)[:results].map do |result|
{ name: result[:"field_#{search_field}"], id: result[:id], domain: domain_id }
end + [{ name: 'Autre', id: 0, domain: domain_id }]
else
Rails.logger.error("Baserow API error: #{response.code} - #{response.body}")
[]
end
rescue Typhoeus::Errors::TyphoeusError => e
Rails.logger.error("Baserow API error: #{e.message}")
[]
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/dossiers/messages/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
= render NestedForms::FormOwnerComponent.new
= form_for(commentaire, url: form_url, html: { multipart: local_assigns.has_key?(:dossier), data: { controller: 'persisted-form', persisted_form_key_value: dom_id(local_assigns.fetch(:dossier, local_assigns.fetch(:last_commentaire, current_user))) } }) do |f|
= form_for(commentaire, url: form_url, html: { multipart: local_assigns.has_key?(:dossier), data: { controller: 'persisted-form', persisted_form_key_value: dom_id(local_assigns.fetch(:dossier, local_assigns.fetch(:last_commentaire, current_user))), turbo: true } }) do |f|
- placeholder = t('views.shared.dossiers.messages.form.write_message_to_administration_placeholder')
- if local_assigns.has_key?(:last_commentaire)
= f.hidden_field :last_commentaire, value: last_commentaire.id, name: :id
Expand Down
1 change: 1 addition & 0 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ defaults: &defaults
userpwd: <%= ENV['CERTIGNA_USERPWD'] %>
baserow:
url: <%= ENV['API_BASEROW_URL'] %>
token: <%= ENV['API_BASEROW_TOKEN'] %>
config_table: <%= ENV['API_BASEROW_CONFIG_TABLE'] %>
autocomplete:
api_geo_url: <%= ENV['API_GEO_URL'] %>
Expand Down

0 comments on commit 8ad1ad3

Please sign in to comment.