aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcedricnjanga2017-12-04 17:06:18 +0100
committercedricnjanga2017-12-04 17:06:18 +0100
commit1d5a19ce9f4f63fdb82cc1c985c9433495fd4920 (patch)
treea3edf490941cdc4f92583f7a49fff3d46b5378cf
parent198a715518079358c970a11e7116e30a3ccf5400 (diff)
downloadchouette-core-1d5a19ce9f4f63fdb82cc1c985c9433495fd4920.tar.bz2
Small refacto to handle no_parent error for ComplianceCheckSet
-rw-r--r--app/controllers/api/v1/internals/application_controller.rb5
-rw-r--r--app/controllers/api/v1/internals/compliance_check_sets_controller.rb4
-rw-r--r--app/controllers/api/v1/internals/netex_imports_controller.rb2
-rw-r--r--app/models/compliance_check_set.rb2
-rw-r--r--config/locales/compliance_check_sets.en.yml2
-rw-r--r--config/locales/compliance_check_sets.fr.yml2
-rw-r--r--config/routes.rb2
-rw-r--r--config/secrets.yml3
8 files changed, 14 insertions, 8 deletions
diff --git a/app/controllers/api/v1/internals/application_controller.rb b/app/controllers/api/v1/internals/application_controller.rb
index 2a9f2558a..77b74f5f6 100644
--- a/app/controllers/api/v1/internals/application_controller.rb
+++ b/app/controllers/api/v1/internals/application_controller.rb
@@ -2,16 +2,13 @@ module Api
module V1
module Internals
class ApplicationController < ActionController::Base
- inherit_resources
respond_to :json
layout false
before_action :authenticate
private
def authenticate
- authenticate_with_http_token do |token, options|
- @current_organisation = Api::V1::ApiKey.find_by_token(token).try(:organisation)
- end
+ authenticate_with_http_token { |token| Rails.application.secrets.api_token == token }
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 5e9137cb5..db92c3fad 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 < Api::V1::Internals::ApplicationController
+ class ComplianceCheckSetsController < ApplicationController
include ControlFlow
def validated
@@ -19,7 +19,7 @@ module Api
def notify_parent
find_compliance_check_set
- if @compliance_check_set.notify_parent
+ if @compliance_check_set.notify_parent && @compliance_check_set.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)}"
diff --git a/app/controllers/api/v1/internals/netex_imports_controller.rb b/app/controllers/api/v1/internals/netex_imports_controller.rb
index c8e33f7b8..89bc1b81d 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 < Api::V1::Internals::ApplicationController
+ class NetexImportsController < ApplicationController
include ControlFlow
def create
diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb
index 71cfabe80..ecc9b7fd4 100644
--- a/app/models/compliance_check_set.rb
+++ b/app/models/compliance_check_set.rb
@@ -22,6 +22,8 @@ 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/config/locales/compliance_check_sets.en.yml b/config/locales/compliance_check_sets.en.yml
index 5aa6f9740..1631ab06f 100644
--- a/config/locales/compliance_check_sets.en.yml
+++ b/config/locales/compliance_check_sets.en.yml
@@ -17,6 +17,8 @@ en:
search_no_results: No control reports match your search
executed:
title: Executed control report %{name}
+ errors:
+ no_parent: "The compliance check set doesn't any parent"
activerecord:
attributes:
compliance_check_set:
diff --git a/config/locales/compliance_check_sets.fr.yml b/config/locales/compliance_check_sets.fr.yml
index 8ad5af904..b915d044a 100644
--- a/config/locales/compliance_check_sets.fr.yml
+++ b/config/locales/compliance_check_sets.fr.yml
@@ -13,6 +13,8 @@ fr:
search_no_results: Aucun rapport de contrôle ne correspond à votre recherche
executed:
title: Jeu de contrôles exécutés %{name}
+ errors:
+ no_parent: "Le jeux de contrôle n'a pas de parent"
activerecord:
attributes:
compliance_check_set:
diff --git a/config/routes.rb b/config/routes.rb
index 92ff134b6..d6ff21bee 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -65,7 +65,7 @@ ChouetteIhm::Application.routes.draw do
resources :time_tables, only: [:index, :show]
resources :vehicle_journeys, only: :show
namespace :internals do
- get 'compliance_check_sets/:id/notify_parent', to: 'compliance_check_sets#notify_parent', as: 'compliance_check_set'
+ get 'compliance_check_sets/:id/notify_parent', to: 'compliance_check_sets#notify_parent', as: 'compliance_check_sets'
get 'netex_imports/:id/notify_parent', to: 'netex_imports#notify_parent', as: 'netex_imports'
end
end
diff --git a/config/secrets.yml b/config/secrets.yml
index 2f9d5abe6..0de3fd6ef 100644
--- a/config/secrets.yml
+++ b/config/secrets.yml
@@ -13,6 +13,7 @@
development:
secret_key_base: e901adb90fc1fff22f7237d138ef232a5425b67e81ccb3ce7003aab2c002d35a7c3d593c0fca3dcb21e8c911a8260c984a830d1d61776ad3005eb373abebc695
api_endpoint: "http://localhost:8080/chouette_iev/"
+ api_token: VFHir2GWWjuRNZnHHnQD5Hn+ubRMQ1kNLnu7oCLf+4KR8+PmYqb1EzKZmmuRfVP/yxS0aQ3NklfNbbgUatTtly5540oo4L6ePdbYkwDzrBXF9xgYekOlTCwIGSl430mluv3wcXNEbrRLu2CevIBULtiRZriAEYVOpp9G+lQI+t8=
google_analytic_tracker: "UA-AAAAAAAA"
# geoportail_api_key: "aaaaaaaaaaaaaaaaaaaaaa"
newrelic_licence_key: ""
@@ -21,6 +22,7 @@ development:
test:
secret_key_base: 54f61aab23322611dd0bbf73b7f034db34281f7f4b3c4992eaaff20ecc9673bbd467beaa6fcb48379ca69b80bc5662deac4e33ca144f2482146123d3e966016a
api_endpoint: "http://localhost:8080/chouette_iev/"
+ api_token: VFHir2GWWjuRNZnHHnQD5Hn+ubRMQ1kNLnu7oCLf+4KR8+PmYqb1EzKZmmuRfVP/yxS0aQ3NklfNbbgUatTtly5540oo4L6ePdbYkwDzrBXF9xgYekOlTCwIGSl430mluv3wcXNEbrRLu2CevIBULtiRZriAEYVOpp9G+lQI+t8=
google_analytic_tracker: "UA-AAAAAAAA"
# geoportail_api_key: "aaaaaaaaaaaaaaaaaaaaaa"
osrm_endpoint: "http://router.project-osrm.org"
@@ -30,6 +32,7 @@ test:
production:
secret_key_base: 54f61aab23322611dd0bbf73b7f034db34281f7f4b3c4992eaaff20ecc9673bbd467beaa6fcb48379ca69b80bc5662deac4e33ca144f2482146123d3e966016a
api_endpoint: "http://localhost:8080/chouette_iev/"
+ api_token: VFHir2GWWjuRNZnHHnQD5Hn+ubRMQ1kNLnu7oCLf+4KR8+PmYqb1EzKZmmuRfVP/yxS0aQ3NklfNbbgUatTtly5540oo4L6ePdbYkwDzrBXF9xgYekOlTCwIGSl430mluv3wcXNEbrRLu2CevIBULtiRZriAEYVOpp9G+lQI+t8=
google_analytic_tracker: "UA-AAAAAAAA"
# geoportail_api_key: "aaaaaaaaaaaaaaaaaaaaaa"
newrelic_licence_key: ""