Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove placeholder logic #2504

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions app/queries/get_content_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GetContentCollection
:states,
)

def initialize(fields:, document_types: [], filters: {}, pagination: Pagination.new, search_query: "", search_in: nil)
def initialize(fields:, document_types: @document_types, filters: {}, pagination: Pagination.new, search_query: "", search_in: nil)
self.document_types = Array(document_types)
self.fields = (fields || default_fields) + %w[total]
self.publishing_app = filters[:publishing_app]
Expand Down Expand Up @@ -47,17 +47,13 @@ def call

def editions
scope = Edition.with_document
scope = scope.where(document_type: document_types) if document_types.any?
scope = scope.where(document_type: @document_types) if @document_types.any?
scope = scope.where(publishing_app:) if publishing_app
scope = scope.where("documents.locale": locale) unless locale == "all"
scope = Link.filter_editions(scope, link_filters) if link_filters.present?
scope
end

def document_types
@document_types.flat_map { |d| [d, "placeholder_#{d}"] }
end

def validate_fields!
return unless fields

Expand Down
8 changes: 2 additions & 6 deletions app/queries/get_linkables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ def call
attr_reader :document_type

def latest_updated_at(document_type)
non_placeholder = Edition.where(document_type:)
.maximum("updated_at")
placeholder = Edition.where(document_type: "placeholder_#{document_type}")
.maximum("updated_at")
[non_placeholder, placeholder].compact.max
Edition.where(document_type:).maximum("updated_at")
end

def linkables_query(document_type)
Edition.with_document
.where(
document_type: [document_type, "placeholder_#{document_type}"],
document_type:,
state: %w[published draft],
"documents.locale": "en",
)
Expand Down
6 changes: 0 additions & 6 deletions app/validators/schema_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ def initialize(payload:, schema: nil, schema_name: nil, schema_type: :publisher)
end

def valid?
return true if schema_name_exception?

@errors += JSON::Validator.fully_validate(
schema,
payload,
Expand Down Expand Up @@ -55,10 +53,6 @@ def schema_name
@schema_name || payload[:schema_name]
end

def schema_name_exception?
schema_name.to_s.match(/placeholder_/)
end

def missing_schema_message
"Unable to find schema for schema_name #{schema_name}"
end
Expand Down
1 change: 0 additions & 1 deletion content_schemas/allowed_document_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
- personal_information_charter
- petitions_and_campaigns
- place
- placeholder
- policy_paper
- press_release
- procurement
Expand Down
1 change: 0 additions & 1 deletion content_schemas/dist/formats/generic/frontend/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
"personal_information_charter",
"petitions_and_campaigns",
"place",
"placeholder",
"policy_paper",
"press_release",
"procurement",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@
"personal_information_charter",
"petitions_and_campaigns",
"place",
"placeholder",
"policy_paper",
"press_release",
"procurement",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
"personal_information_charter",
"petitions_and_campaigns",
"place",
"placeholder",
"policy_paper",
"press_release",
"procurement",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
"personal_information_charter",
"petitions_and_campaigns",
"place",
"placeholder",
"policy_paper",
"press_release",
"procurement",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@
"personal_information_charter",
"petitions_and_campaigns",
"place",
"placeholder",
"policy_paper",
"press_release",
"procurement",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
"personal_information_charter",
"petitions_and_campaigns",
"place",
"placeholder",
"policy_paper",
"press_release",
"procurement",
Expand Down
6 changes: 3 additions & 3 deletions content_schemas/dist/formats/placeholder/frontend/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
"personal_information_charter",
"petitions_and_campaigns",
"place",
"placeholder",
"policy_paper",
"press_release",
"procurement",
Expand Down Expand Up @@ -399,9 +398,10 @@
]
},
"schema_name": {
"description": "Should be of the form 'placeholder_my_format_name'. 'placeholder' is allowed for backwards compatibility.",
"type": "string",
"pattern": "^(placeholder|placeholder_.+)$"
"enum": [
"placeholder"
]
},
"title": {
"$ref": "#/definitions/title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@
"personal_information_charter",
"petitions_and_campaigns",
"place",
"placeholder",
"policy_paper",
"press_release",
"procurement",
Expand Down Expand Up @@ -483,9 +482,10 @@
"$ref": "#/definitions/routes"
},
"schema_name": {
"description": "Should be of the form 'placeholder_my_format_name'. 'placeholder' is allowed for backwards compatibility.",
"type": "string",
"pattern": "^(placeholder|placeholder_.+)$"
"enum": [
"placeholder"
]
},
"search_user_need_document_supertype": {
"description": "Document supertype grouping core and government documents",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
"personal_information_charter",
"petitions_and_campaigns",
"place",
"placeholder",
"policy_paper",
"press_release",
"procurement",
Expand Down Expand Up @@ -286,9 +285,10 @@
"$ref": "#/definitions/routes"
},
"schema_name": {
"description": "Should be of the form 'placeholder_my_format_name'. 'placeholder' is allowed for backwards compatibility.",
"type": "string",
"pattern": "^(placeholder|placeholder_.+)$"
"enum": [
"placeholder"
]
},
"title": {
"$ref": "#/definitions/title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2015-05-13T10:09:06Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "HM Revenue & Customs",
"withdrawn": false,
"details": {
Expand Down
2 changes: 1 addition & 1 deletion content_schemas/examples/answer/frontend/answer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2015-05-13T10:09:06Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "HM Revenue & Customs",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2016-08-09T10:56:17Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "UK Trade & Investment",
"withdrawn": false,
"details": {
Expand All @@ -50,7 +50,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2016-08-09T10:56:17Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "UK Trade & Investment",
"withdrawn": false,
"details": {
Expand Down Expand Up @@ -105,7 +105,7 @@
"document_type": "worldwide_organisation",
"locale": "en",
"public_updated_at": "2016-11-11T16:13:06Z",
"schema_name": "placeholder",
"schema_name": "worldwide_organisation",
"title": "Department for International Trade Turkey",
"withdrawn": false,
"links": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2016-08-01T15:38:37Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "Department for Business, Innovation & Skills",
"withdrawn": false,
"details": {
Expand All @@ -65,10 +65,10 @@
"api_path": "/api/content/government/topics/consumer-rights-and-issues",
"base_path": "/government/topics/consumer-rights-and-issues",
"content_id": "9d7b90e5-625c-4203-a62a-be9be43d35f3",
"document_type": "placeholder_policy_area",
"document_type": "policy_area",
"locale": "en",
"public_updated_at": "2016-02-04T11:25:05Z",
"schema_name": "placeholder_policy_area",
"schema_name": "policy_area",
"title": "Consumer rights and issues",
"withdrawn": false,
"links": {
Expand All @@ -86,7 +86,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2016-08-01T15:38:37Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "Department for Business, Innovation & Skills",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2015-05-13T10:09:06Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "HM Revenue & Customs",
"details": {
"brand": "hm-revenue-customs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2015-05-13T10:09:06Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "HM Revenue & Customs",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2015-05-13T10:09:06Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "HM Revenue & Customs",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2015-02-17T11:00:13Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "Intellectual Property Office",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2018-01-09T10:07:59Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "Ministry of Defence",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2018-01-09T10:08:03Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "Department for Transport",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2016-03-31T15:08:50Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "National Measurement and Regulation Office",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2017-08-11T15:05:39Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "Natural England",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2017-12-12T21:20:49Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "Driver and Vehicle Standards Agency",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2014-11-11T11:26:34Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "Independent Reconfiguration Panel",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2015-07-24T14:52:30Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "Civil Nuclear Constabulary",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2016-08-01T15:38:37Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "Department for Business, Innovation & Skills",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2017-10-05T08:43:12Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "Environment Agency",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2018-01-09T10:08:03Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "Department for Transport",
"withdrawn": false,
"details": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"document_type": "organisation",
"locale": "en",
"public_updated_at": "2017-07-04T14:35:36Z",
"schema_name": "placeholder",
"schema_name": "organisation",
"title": "Ofsted",
"withdrawn": false,
"details": {
Expand Down
Loading