From d896088190fccbf8b4e3866e7d12b35cbe9a2561 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 20 Jan 2021 18:47:23 +0100 Subject: [PATCH] Remove admin features from serializers We currently building the public frontend API with this and try to make this fast and feature parity as a replacement to the legacy JSON api from Alchemy core. Therefore we want to concentrate on the frontend attributes now and remove currently not even supported admin flag. --- .../alchemy/json_api/element_serializer.rb | 5 ----- .../alchemy/json_api/language_serializer.rb | 6 ------ .../alchemy/json_api/page_serializer.rb | 5 ----- .../alchemy/json_api/element_serializer_spec.rb | 9 --------- .../alchemy/json_api/language_serializer_spec.rb | 11 ----------- .../alchemy/json_api/page_serializer_spec.rb | 16 ---------------- 6 files changed, 52 deletions(-) diff --git a/app/serializers/alchemy/json_api/element_serializer.rb b/app/serializers/alchemy/json_api/element_serializer.rb index 9383a71..ed7e81a 100644 --- a/app/serializers/alchemy/json_api/element_serializer.rb +++ b/app/serializers/alchemy/json_api/element_serializer.rb @@ -25,11 +25,6 @@ class ElementSerializer end has_many :nested_elements, record_type: :element, serializer: self - - with_options if: ->(_, params) { params[:admin] == true } do - attribute :tag_list - attribute :display_name, &:display_name_with_preview_text - end end end end diff --git a/app/serializers/alchemy/json_api/language_serializer.rb b/app/serializers/alchemy/json_api/language_serializer.rb index 3ea9b14..a6e0d96 100644 --- a/app/serializers/alchemy/json_api/language_serializer.rb +++ b/app/serializers/alchemy/json_api/language_serializer.rb @@ -18,12 +18,6 @@ class LanguageSerializer end has_many :pages has_one :root_page, record_type: :page, serializer: ::Alchemy::JsonApi::PageSerializer - - with_options if: ->(_, params) { params[:admin] == true } do - attribute :created_at - attribute :updated_at - attribute :public - end end end end diff --git a/app/serializers/alchemy/json_api/page_serializer.rb b/app/serializers/alchemy/json_api/page_serializer.rb index 5841ffd..d982d8e 100644 --- a/app/serializers/alchemy/json_api/page_serializer.rb +++ b/app/serializers/alchemy/json_api/page_serializer.rb @@ -24,11 +24,6 @@ class PageSerializer has_many :all_elements, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer do |page| page.all_elements.select { |e| e.public? && !e.trashed? } end - - with_options if: ->(_, params) { params[:admin] == true } do - attribute :tag_list - attribute :status - end end end end diff --git a/spec/serializers/alchemy/json_api/element_serializer_spec.rb b/spec/serializers/alchemy/json_api/element_serializer_spec.rb index 32be395..da48bd6 100644 --- a/spec/serializers/alchemy/json_api/element_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/element_serializer_spec.rb @@ -40,15 +40,6 @@ expect(subject[:deprecated]).to eq(true) end end - - context "with admin set to true" do - let(:options) { { params: { admin: true } } } - - it "includes admin-only attributes" do - expect(subject[:tag_list]).to eq(["Tag1", "Tag2"]) - expect(subject[:display_name]).to eq("Article: ") - end - end end describe "relationships" do diff --git a/spec/serializers/alchemy/json_api/language_serializer_spec.rb b/spec/serializers/alchemy/json_api/language_serializer_spec.rb index 187c6d2..ef5a7cd 100644 --- a/spec/serializers/alchemy/json_api/language_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/language_serializer_spec.rb @@ -22,17 +22,6 @@ expect(attributes[:country_code]).to eq("DE") expect(attributes[:locale]).to eq("de") end - - context "with admin set to true" do - let(:options) { { params: { admin: true } } } - - it "includes admin-only attributes" do - attributes = subject[:data][:attributes] - expect(attributes[:created_at]).to be_present - expect(attributes[:updated_at]).to be_present - expect(attributes[:public]).to be true - end - end end describe "relationships" do diff --git a/spec/serializers/alchemy/json_api/page_serializer_spec.rb b/spec/serializers/alchemy/json_api/page_serializer_spec.rb index af172b3..2a1e48f 100644 --- a/spec/serializers/alchemy/json_api/page_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/page_serializer_spec.rb @@ -33,22 +33,6 @@ expect(attributes[:updated_at]).to eq(page.updated_at) expect(attributes.keys).not_to include(:tag_list, :status) end - - context "with admin set to true" do - let(:options) { { params: { admin: true } } } - - it "includes admin-only attributes" do - attributes = subject[:data][:attributes] - expect(attributes[:tag_list]).to eq(["Tag1", "Tag2"]) - expect(attributes[:status]).to eq( - { - public: false, - locked: false, - restricted: false, - }, - ) - end - end end describe "relationships" do