From 4c964fea0d9e43abe3926c3de7d238e70fa303f0 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 21 Jul 2019 22:48:36 +0100 Subject: [PATCH] Replace views/json/_current_user.rabl with an ams injector with serializer --- app/helpers/injection_helper.rb | 4 ++++ app/serializers/api/user_serializer.rb | 3 +++ app/views/json/_current_user.rabl | 2 -- app/views/layouts/darkswarm.html.haml | 2 +- app/views/layouts/registration.html.haml | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 app/serializers/api/user_serializer.rb delete mode 100644 app/views/json/_current_user.rabl diff --git a/app/helpers/injection_helper.rb b/app/helpers/injection_helper.rb index aa85939fbe..2422ff7e0e 100644 --- a/app/helpers/injection_helper.rb +++ b/app/helpers/injection_helper.rb @@ -111,6 +111,10 @@ module InjectionHelper inject_json_ams "savedCreditCards", data, Api::CreditCardSerializer end + def inject_current_user + inject_json_ams "user", spree_current_user, Api::UserSerializer + end + def inject_json(name, partial, opts = {}) render partial: "json/injection", locals: { name: name, partial: partial }.merge(opts) end diff --git a/app/serializers/api/user_serializer.rb b/app/serializers/api/user_serializer.rb new file mode 100644 index 0000000000..b73b9a5b47 --- /dev/null +++ b/app/serializers/api/user_serializer.rb @@ -0,0 +1,3 @@ +class Api::UserSerializer < ActiveModel::Serializer + attributes :id, :email +end diff --git a/app/views/json/_current_user.rabl b/app/views/json/_current_user.rabl deleted file mode 100644 index b07ae07b66..0000000000 --- a/app/views/json/_current_user.rabl +++ /dev/null @@ -1,2 +0,0 @@ -object spree_current_user -attributes :email, :id diff --git a/app/views/layouts/darkswarm.html.haml b/app/views/layouts/darkswarm.html.haml index 3a352950d9..b95f87085e 100644 --- a/app/views/layouts/darkswarm.html.haml +++ b/app/views/layouts/darkswarm.html.haml @@ -43,7 +43,7 @@ = yield :scripts = inject_current_hub - = inject_json "user", "current_user" + = inject_current_user = inject_json "railsFlash", "flash" = inject_taxons = inject_properties diff --git a/app/views/layouts/registration.html.haml b/app/views/layouts/registration.html.haml index 0221b1ce3a..2902f6683e 100644 --- a/app/views/layouts/registration.html.haml +++ b/app/views/layouts/registration.html.haml @@ -31,7 +31,7 @@ = javascript_include_tag "darkswarm/all" = yield :scripts - = inject_json "user", "current_user" + = inject_current_user = yield :injection_data = render "layouts/i18n_script"