diff options
| author | Zog | 2018-03-30 14:46:37 +0200 |
|---|---|---|
| committer | Zog | 2018-04-09 16:57:59 +0200 |
| commit | 745428deb8e0df2c7c8a991ab8a5f5231e6d6c7f (patch) | |
| tree | 40da9487591cef17947da0c2a23d05b5e06bd1bb /app/controllers | |
| parent | 98c723ee956b478e8ffb466e461c9889a272efdf (diff) | |
| download | chouette-core-745428deb8e0df2c7c8a991ab8a5f5231e6d6c7f.tar.bz2 | |
Refs #6367; Add metadata to routes
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/application_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/concerns/metadata_controller_support.rb | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9a83394e2..4a89410d3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,6 @@ class ApplicationController < ActionController::Base include PaperTrailSupport + include MetadataControllerSupport include Pundit include FeatureChecker @@ -10,7 +11,6 @@ class ApplicationController < ActionController::Base before_action :authenticate_user! before_action :set_locale - # Load helpers in rails engine helper LanguageEngine::Engine.helpers diff --git a/app/controllers/concerns/metadata_controller_support.rb b/app/controllers/concerns/metadata_controller_support.rb new file mode 100644 index 000000000..4ac625c01 --- /dev/null +++ b/app/controllers/concerns/metadata_controller_support.rb @@ -0,0 +1,21 @@ +module MetadataControllerSupport + extend ActiveSupport::Concern + + included do + after_action :set_creator_metadata, only: :create + after_action :set_modifier_metadata, only: :update + end + + def user_for_metadata + current_user ? current_user.username : '' + end + + def set_creator_metadata + resource.try(:set_metadata!, :creator_username, user_for_metadata) if resource.valid? + end + + def set_modifier_metadata + resource.try :set_metadata!, :modifier_username, user_for_metadata + end + +end |
