diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/api/v1/internals/application_controller.rb | 19 | ||||
| -rw-r--r-- | app/controllers/api/v1/internals/compliance_check_sets_controller.rb | 13 | ||||
| -rw-r--r-- | app/controllers/api/v1/internals/netex_imports_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/compliance_check_set.rb | 2 | ||||
| -rw-r--r-- | app/models/netex_import.rb | 2 | ||||
| -rw-r--r-- | app/models/referential.rb | 1 | ||||
| -rw-r--r-- | app/views/compliance_control_sets/show.html.slim | 2 |
7 files changed, 32 insertions, 9 deletions
diff --git a/app/controllers/api/v1/internals/application_controller.rb b/app/controllers/api/v1/internals/application_controller.rb index 77b74f5f6..ab9daf4f7 100644 --- a/app/controllers/api/v1/internals/application_controller.rb +++ b/app/controllers/api/v1/internals/application_controller.rb @@ -4,11 +4,24 @@ module Api class ApplicationController < ActionController::Base respond_to :json layout false - before_action :authenticate + before_action :require_token + + def require_token + authenticate_token || render_unauthorized("Access denied") + end + + protected + + def render_unauthorized(message) + errors = { errors: [ { detail: message } ] } + render json: errors, status: :unauthorized + end private - def authenticate - authenticate_with_http_token { |token| Rails.application.secrets.api_token == token } + def authenticate_token + authenticate_with_http_token do |token| + return true if Rails.application.secrets.api_token == token + end end end end diff --git a/app/controllers/api/v1/internals/compliance_check_sets_controller.rb b/app/controllers/api/v1/internals/compliance_check_sets_controller.rb index db92c3fad..ccf1bcd2f 100644 --- a/app/controllers/api/v1/internals/compliance_check_sets_controller.rb +++ b/app/controllers/api/v1/internals/compliance_check_sets_controller.rb @@ -1,7 +1,7 @@ module Api module V1 module Internals - class ComplianceCheckSetsController < ApplicationController + class ComplianceCheckSetsController < Api::V1::Internals::ApplicationController include ControlFlow def validated @@ -19,7 +19,9 @@ module Api def notify_parent find_compliance_check_set - if @compliance_check_set.notify_parent && @compliance_check_set.parent + check_parent + + if @compliance_check_set.notify_parent render json: { status: "ok", message:"#{@compliance_check_set.parent_type} (id: #{@compliance_check_set.parent_id}) successfully notified at #{l(@compliance_check_set.notified_parent_at)}" @@ -31,6 +33,13 @@ module Api private + def check_parent + unless @compliance_check_set.parent + render json: {status: "error", message: I18n.t('compliance_check_sets.errors.no_parent') } + finish_action! + end + end + def find_compliance_check_set @compliance_check_set = ComplianceCheckSet.find(params[:id]) rescue ActiveRecord::RecordNotFound diff --git a/app/controllers/api/v1/internals/netex_imports_controller.rb b/app/controllers/api/v1/internals/netex_imports_controller.rb index 89bc1b81d..c8e33f7b8 100644 --- a/app/controllers/api/v1/internals/netex_imports_controller.rb +++ b/app/controllers/api/v1/internals/netex_imports_controller.rb @@ -1,7 +1,7 @@ module Api module V1 module Internals - class NetexImportsController < ApplicationController + class NetexImportsController < Api::V1::Internals::ApplicationController include ControlFlow def create diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb index 7c55561af..020100f4a 100644 --- a/app/models/compliance_check_set.rb +++ b/app/models/compliance_check_set.rb @@ -23,8 +23,6 @@ class ComplianceCheckSet < ActiveRecord::Base if parent # parent.child_change update(notified_parent_at: DateTime.now) - else - errors.add(:base, I18n.t('compliance_check_sets.errors.no_parent')) end end diff --git a/app/models/netex_import.rb b/app/models/netex_import.rb index a7a5bb9b8..b21af3408 100644 --- a/app/models/netex_import.rb +++ b/app/models/netex_import.rb @@ -27,7 +27,9 @@ class NetexImport < Import end def call_boiv_iev + Rails.logger.error("Begin IEV call for import") Net::HTTP.get(URI("#{Rails.configuration.iev_url}/boiv_iev/referentials/importer/new?id=#{id}")) + Rails.logger.error("End IEV call for import") rescue Exception => e logger.error "IEV server error : #{e.message}" logger.error e.backtrace.inspect diff --git a/app/models/referential.rb b/app/models/referential.rb index d090a3f7c..7aeb946c5 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -294,6 +294,7 @@ class Referential < ActiveRecord::Base def create_schema unless created_from Apartment::Tenant.create slug + Rails.logger.error( "Schema migrations count for Referential #{slug} " + Referential.connection.select_value("select count(*) from #{slug}.schema_migrations;").to_s ) end end diff --git a/app/views/compliance_control_sets/show.html.slim b/app/views/compliance_control_sets/show.html.slim index 2291eda06..e6416fda4 100644 --- a/app/views/compliance_control_sets/show.html.slim +++ b/app/views/compliance_control_sets/show.html.slim @@ -104,4 +104,4 @@ cls: 'table has-filter has-search', model: ComplianceControl - = flotted_links @compliance_control_set.id + = flotted_links @compliance_control_set.id |
