Update DisplayAd API to allow setting tag_list (#18891)

This commit is contained in:
Joshua Wehner 2023-01-04 13:59:20 +01:00 committed by GitHub
parent d61d9fbc9d
commit 0e25b1413e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 181 additions and 84 deletions

View file

@ -51,7 +51,7 @@ module Api
def permitted_params
params.permit :approved, :body_markdown, :display_to, :name,
:organization_id, :placement_area, :published, :tags
:organization_id, :placement_area, :published, :tag_list
end
end
end

View file

@ -74,6 +74,13 @@ class DisplayAd < ApplicationRecord
validate_tag_name(tag_list)
end
# This needs to correspond with Rails built-in method signature
# rubocop:disable Style/OptionHash
def as_json(options = {})
super(options.merge(except: %i[tags tag_list])).merge("tag_list" => cached_tag_list)
end
# rubocop:enable Style/OptionHash
private
def generate_display_ad_name

View file

@ -59,7 +59,7 @@ RSpec.describe "api/v1/display_ads" do
description: "Potentially limits visitors to whom the ad is visible" },
placement_area: { type: :string, enum: DisplayAd::ALLOWED_PLACEMENT_AREAS,
description: "Identifies which area of site layout the ad can appear in" },
tags: { type: :string, description: "Tags on which this ad can be displayed (blank is all/any tags)" }
tag_list: { type: :string, description: "Tags on which this ad can be displayed (blank is all/any tags)" }
},
required: %w[name body_markdown placement_area]
}
@ -181,7 +181,7 @@ RSpec.describe "api/v1/display_ads" do
description: "Potentially limits visitors to whom the ad is visible" },
placement_area: { type: :string, enum: DisplayAd::ALLOWED_PLACEMENT_AREAS,
description: "Identifies which area of site layout the ad can appear in" },
tags: { type: :string, description: "Tags on which this ad can be displayed (blank is all/any tags)" }
tag_list: { type: :string, description: "Tags on which this ad can be displayed (blank is all/any tags)" }
},
required: %w[name body_markdown placement_area]
}

View file

@ -9,8 +9,12 @@
"/api/articles": {
"get": {
"summary": "Published articles",
"security": [],
"tags": ["articles"],
"security": [
],
"tags": [
"articles"
],
"description": "This endpoint allows the client to retrieve a list of articles.\n\n\"Articles\" are all the posts that users create on DEV that typically\nshow up in the feed. They can be a blog post, a discussion question,\na help thread etc. but is referred to as article within the code.\n\nBy default it will return featured, published articles ordered\nby descending popularity.\n\nIt supports pagination, each page will contain `30` articles by default.",
"operationId": "getArticles",
"parameters": [
@ -67,7 +71,11 @@
"description": "Using this parameter will allow the client to check which articles are fresh or rising.\n If `state=fresh` the server will return fresh articles.\n If `state=rising` the server will return rising articles.\n This param can be used in conjuction with `username`, only if set to `all`.",
"schema": {
"type": "string",
"enum": ["fresh", "rising", "all"]
"enum": [
"fresh",
"rising",
"all"
]
},
"example": "fresh"
},
@ -103,45 +111,47 @@
"example": [
{
"type_of": "article",
"id": 1316,
"title": "Number the Stars172",
"description": "Swag marfa wes anderson mumblecore cornhole. Listicle xoxo polaroid vegan. Fashion axe echo blue...",
"readable_publish_date": "Dec 21",
"slug": "number-the-stars172-4g8l",
"path": "/username382/number-the-stars172-4g8l",
"url": "http://localhost:3000/username382/number-the-stars172-4g8l",
"id": 791,
"title": "The Parliament of Man172",
"description": "Normcore hoodie echo next level chia williamsburg. Small batch kogi skateboard vice master retro...",
"readable_publish_date": "Dec 22",
"slug": "the-parliament-of-man172-199d",
"path": "/username382/the-parliament-of-man172-199d",
"url": "http://localhost:3000/username382/the-parliament-of-man172-199d",
"comments_count": 0,
"public_reactions_count": 0,
"collection_id": null,
"published_timestamp": "2022-12-21T09:35:16Z",
"published_timestamp": "2022-12-22T13:50:45Z",
"positive_reactions_count": 0,
"cover_image": "http://localhost:3000/assets/14-5e64731cc7cd63e3b689647d9d3c3e4e1d907690c716d3dd1e356466726a2c2d.png",
"social_image": "http://localhost:3000/assets/14-5e64731cc7cd63e3b689647d9d3c3e4e1d907690c716d3dd1e356466726a2c2d.png",
"canonical_url": "http://localhost:3000/username382/number-the-stars172-4g8l",
"created_at": "2022-12-21T09:35:16Z",
"cover_image": "http://localhost:3000/assets/33-dc66b0d3c291181013c8bc7a6eb3b26755d85e90b63c9c589cb6c161624cc410.png",
"social_image": "http://localhost:3000/assets/33-dc66b0d3c291181013c8bc7a6eb3b26755d85e90b63c9c589cb6c161624cc410.png",
"canonical_url": "http://localhost:3000/username382/the-parliament-of-man172-199d",
"created_at": "2022-12-22T13:50:45Z",
"edited_at": null,
"crossposted_at": null,
"published_at": "2022-12-21T09:35:16Z",
"last_comment_at": "2022-12-21T09:35:16Z",
"published_at": "2022-12-22T13:50:45Z",
"last_comment_at": "2022-12-22T13:50:45Z",
"reading_time_minutes": 1,
"tag_list": ["discuss"],
"tag_list": [
"discuss"
],
"tags": "discuss",
"user": {
"name": "Elisha \"Dorene\" \\:/ Jacobs",
"name": "Charlie \"Sydney\" \\:/ Sipes",
"username": "username382",
"twitter_username": "twitter382",
"github_username": "github382",
"user_id": 3033,
"user_id": 1769,
"website_url": null,
"profile_image": "/uploads/user/profile_image/3033/08ec2a9c-544e-4e53-8440-b31ee28677ab.jpeg",
"profile_image_90": "/uploads/user/profile_image/3033/08ec2a9c-544e-4e53-8440-b31ee28677ab.jpeg"
"profile_image": "/uploads/user/profile_image/1769/c04bae58-32cf-452e-ba55-86ed65b8d57f.jpeg",
"profile_image_90": "/uploads/user/profile_image/1769/c04bae58-32cf-452e-ba55-86ed65b8d57f.jpeg"
},
"organization": {
"name": "O'Hara-Kerluke",
"name": "Walsh LLC",
"username": "org67",
"slug": "org67",
"profile_image": "/uploads/organization/profile_image/553/67755f9f-2b3f-4af6-85ce-e06837211465.png",
"profile_image_90": "/uploads/organization/profile_image/553/67755f9f-2b3f-4af6-85ce-e06837211465.png"
"profile_image": "/uploads/organization/profile_image/556/f2c0763c-f2e8-43a1-9f77-723c4b3944d5.png",
"profile_image_90": "/uploads/organization/profile_image/556/f2c0763c-f2e8-43a1-9f77-723c4b3944d5.png"
},
"flare_tag": {
"name": "discuss",
@ -165,7 +175,9 @@
"/api/articles/me": {
"get": {
"summary": "User's articles",
"tags": ["articles"],
"tags": [
"articles"
],
"description": "This endpoint allows the client to retrieve a list of published articles on behalf of an authenticated user.\n\n\"Articles\" are all the posts that users create on DEV that typically show up in the feed. They can be a blog post, a discussion question, a help thread etc. but is referred to as article within the code.\n\nPublished articles will be in reverse chronological publication order.\n\nIt will return published articles with pagination. By default a page will contain 30 articles.",
"operationId": "getUserArticles",
"parameters": [
@ -192,7 +204,9 @@
"description": "A List of the authenticated user's Articles",
"content": {
"application/json": {
"example": [],
"example": [
],
"schema": {
"type": "array",
"items": {
@ -208,7 +222,9 @@
"/api/articles/me/published": {
"get": {
"summary": "User's published articles",
"tags": ["articles"],
"tags": [
"articles"
],
"description": "This endpoint allows the client to retrieve a list of published articles on behalf of an authenticated user.\n\n\"Articles\" are all the posts that users create on DEV that typically show up in the feed. They can be a blog post, a discussion question, a help thread etc. but is referred to as article within the code.\n\nPublished articles will be in reverse chronological publication order.\n\nIt will return published articles with pagination. By default a page will contain 30 articles.",
"operationId": "getUserPublishedArticles",
"parameters": [
@ -235,7 +251,9 @@
"description": "A List of the authenticated user's Articles",
"content": {
"application/json": {
"example": [],
"example": [
],
"schema": {
"type": "array",
"items": {
@ -251,7 +269,9 @@
"/api/articles/me/unpublished": {
"get": {
"summary": "User's unpublished articles",
"tags": ["articles"],
"tags": [
"articles"
],
"description": "This endpoint allows the client to retrieve a list of unpublished articles on behalf of an authenticated user.\n\n\"Articles\" are all the posts that users create on DEV that typically show up in the feed. They can be a blog post, a discussion question, a help thread etc. but is referred to as article within the code.\n\nUnpublished articles will be in reverse chronological creation order.\n\nIt will return unpublished articles with pagination. By default a page will contain 30 articles.",
"operationId": "getUserUnpublishedArticles",
"parameters": [
@ -278,7 +298,9 @@
"description": "A List of the authenticated user's Articles",
"content": {
"application/json": {
"example": [],
"example": [
],
"schema": {
"type": "array",
"items": {
@ -294,7 +316,9 @@
"/api/articles/me/all": {
"get": {
"summary": "User's all articles",
"tags": ["articles"],
"tags": [
"articles"
],
"description": "This endpoint allows the client to retrieve a list of all articles on behalf of an authenticated user.\n\n\"Articles\" are all the posts that users create on DEV that typically show up in the feed. They can be a blog post, a discussion question, a help thread etc. but is referred to as article within the code.\n\nIt will return both published and unpublished articles with pagination.\n\nUnpublished articles will be at the top of the list in reverse chronological creation order. Published articles will follow in reverse chronological publication order.\n\nBy default a page will contain 30 articles.",
"operationId": "getUserAllArticles",
"parameters": [
@ -321,7 +345,9 @@
"description": "A List of the authenticated user's Articles",
"content": {
"application/json": {
"example": [],
"example": [
],
"schema": {
"type": "array",
"items": {
@ -337,7 +363,9 @@
"/api/articles/{id}/unpublish": {
"put": {
"summary": "Unpublish an article",
"tags": ["articles"],
"tags": [
"articles"
],
"description": "This endpoint allows the client to unpublish an article.\n\nThe user associated with the API key must have any 'admin' or 'moderator' role.\n\nThe article will be unpublished and will no longer be visible to the public. It will remain\nin the database and will set back to draft status on the author's posts dashboard. Any\nnotifications associated with the article will be deleted. Any comments on the article\nwill remain.",
"operationId": "unpublishArticle",
"parameters": [
@ -396,14 +424,18 @@
"/api/display_ads": {
"get": {
"summary": "display ads",
"tags": ["display ads"],
"tags": [
"display ads"
],
"description": "This endpoint allows the client to retrieve a list of all display ads.",
"responses": {
"200": {
"description": "successful",
"content": {
"application/json": {
"example": []
"example": [
]
}
}
},
@ -422,21 +454,25 @@
},
"post": {
"summary": "display ads",
"tags": ["display ads"],
"tags": [
"display ads"
],
"description": "This endpoint allows the client to create a new display ad.",
"parameters": [],
"parameters": [
],
"responses": {
"200": {
"description": "successful",
"content": {
"application/json": {
"example": {
"id": 82,
"id": 296,
"approved": true,
"body_markdown": "# Hi, this is ad\nYep, it's an ad",
"cached_tag_list": "",
"clicks_count": 0,
"created_at": "2022-12-21T05:35:17.206-04:00",
"created_at": "2022-12-22T10:20:47.377-03:30",
"display_to": "all",
"impressions_count": 0,
"name": "Example Ad",
@ -446,8 +482,8 @@
"published": true,
"success_rate": 0.0,
"type_of": "in_house",
"updated_at": "2022-12-21T05:35:17.206-04:00",
"tag_list": []
"updated_at": "2022-12-22T10:20:47.377-03:30",
"tag_list": ""
}
}
}
@ -484,7 +520,7 @@
"success_rate": 0.0,
"type_of": "in_house",
"updated_at": null,
"tag_list": []
"tag_list": null
}
}
}
@ -518,7 +554,11 @@
},
"display_to": {
"type": "string",
"enum": ["all", "logged_in", "logged_out"],
"enum": [
"all",
"logged_in",
"logged_out"
],
"default": "all",
"description": "Potentially limits visitors to whom the ad is visible"
},
@ -533,12 +573,16 @@
],
"description": "Identifies which area of site layout the ad can appear in"
},
"tags": {
"tag_list": {
"type": "string",
"description": "Tags on which this ad can be displayed (blank is all/any tags)"
}
},
"required": ["name", "body_markdown", "placement_area"]
"required": [
"name",
"body_markdown",
"placement_area"
]
}
}
}
@ -548,7 +592,9 @@
"/api/display_ads/{id}": {
"get": {
"summary": "display ad",
"tags": ["display ads"],
"tags": [
"display ads"
],
"description": "This endpoint allows the client to retrieve a single display ad, via its id.",
"parameters": [
{
@ -570,23 +616,23 @@
"content": {
"application/json": {
"example": {
"id": 83,
"id": 297,
"approved": false,
"body_markdown": "Hello _hey_ Hey hey 9",
"cached_tag_list": "",
"clicks_count": 0,
"created_at": "2022-12-21T05:35:17.381-04:00",
"created_at": "2022-12-22T10:20:47.575-03:30",
"display_to": "all",
"impressions_count": 0,
"name": "Display Ad 83",
"organization_id": 554,
"name": "Display Ad 297",
"organization_id": 557,
"placement_area": "sidebar_left",
"processed_html": "<p>Hello <em>hey</em> Hey hey 9</p>",
"published": false,
"success_rate": 0.0,
"type_of": "in_house",
"updated_at": "2022-12-21T05:35:17.384-04:00",
"tag_list": []
"updated_at": "2022-12-22T10:20:47.579-03:30",
"tag_list": ""
}
}
}
@ -617,7 +663,9 @@
},
"put": {
"summary": "display ads",
"tags": ["display ads"],
"tags": [
"display ads"
],
"description": "This endpoint allows the client to update the attributes of a single display ad, via its id.",
"parameters": [
{
@ -642,20 +690,20 @@
"approved": false,
"body_markdown": "Hello _hey_ Hey hey 10",
"display_to": "all",
"name": "Display Ad 84",
"organization_id": 555,
"name": "Display Ad 298",
"organization_id": 558,
"placement_area": "sidebar_left",
"published": false,
"processed_html": "<p>Hello <em>hey</em> Hey hey 10</p>",
"cached_tag_list": "",
"id": 84,
"id": 298,
"clicks_count": 0,
"created_at": "2022-12-21T05:35:17.606-04:00",
"created_at": "2022-12-22T10:20:47.796-03:30",
"impressions_count": 0,
"success_rate": 0.0,
"type_of": "in_house",
"updated_at": "2022-12-21T05:35:17.611-04:00",
"tag_list": []
"updated_at": "2022-12-22T10:20:47.800-03:30",
"tag_list": ""
}
}
}
@ -711,7 +759,11 @@
},
"display_to": {
"type": "string",
"enum": ["all", "logged_in", "logged_out"],
"enum": [
"all",
"logged_in",
"logged_out"
],
"default": "all",
"description": "Potentially limits visitors to whom the ad is visible"
},
@ -726,12 +778,16 @@
],
"description": "Identifies which area of site layout the ad can appear in"
},
"tags": {
"tag_list": {
"type": "string",
"description": "Tags on which this ad can be displayed (blank is all/any tags)"
}
},
"required": ["name", "body_markdown", "placement_area"]
"required": [
"name",
"body_markdown",
"placement_area"
]
}
}
}
@ -741,7 +797,9 @@
"/api/display_ads/{id}/unpublish": {
"put": {
"summary": "unpublish",
"tags": ["display ads"],
"tags": [
"display ads"
],
"description": "This endpoint allows the client to remove a display ad from rotation by un-publishing it.",
"parameters": [
{
@ -789,7 +847,9 @@
"/api/reactions/toggle": {
"post": {
"summary": "toggle reaction",
"tags": ["reactions"],
"tags": [
"reactions"
],
"description": "This endpoint allows the client to toggle the user's reaction to a specified reactable (eg, Article, Comment, or User). For examples:\n * \"Like\"ing an Article will create a new \"like\" Reaction from the user for that Articles\n * \"Like\"ing that Article a second time will remove the \"like\" from the user",
"parameters": [
{
@ -798,7 +858,11 @@
"required": true,
"schema": {
"type": "string",
"enum": ["like", "readinglist", "unicorn"]
"enum": [
"like",
"readinglist",
"unicorn"
]
}
},
{
@ -816,7 +880,11 @@
"required": true,
"schema": {
"type": "string",
"enum": ["Comment", "Article", "User"]
"enum": [
"Comment",
"Article",
"User"
]
}
}
],
@ -828,8 +896,8 @@
"example": {
"result": "create",
"category": "like",
"id": 78,
"reactable_id": 1320,
"id": 56,
"reactable_id": 795,
"reactable_type": "Article"
}
}
@ -852,7 +920,9 @@
"/api/reactions": {
"post": {
"summary": "create reaction",
"tags": ["reactions"],
"tags": [
"reactions"
],
"description": "This endpoint allows the client to create a reaction to a specified reactable (eg, Article, Comment, or User). For examples:\n * \"Like\"ing an Article will create a new \"like\" Reaction from the user for that Articles\n * \"Like\"ing that Article a second time will return the previous \"like\"",
"parameters": [
{
@ -861,7 +931,11 @@
"required": true,
"schema": {
"type": "string",
"enum": ["like", "readinglist", "unicorn"]
"enum": [
"like",
"readinglist",
"unicorn"
]
}
},
{
@ -879,7 +953,11 @@
"required": true,
"schema": {
"type": "string",
"enum": ["Comment", "Article", "User"]
"enum": [
"Comment",
"Article",
"User"
]
}
}
],
@ -891,8 +969,8 @@
"example": {
"result": "none",
"category": "like",
"id": 80,
"reactable_id": 1322,
"id": 58,
"reactable_id": 797,
"reactable_type": "Article"
}
}
@ -915,7 +993,9 @@
"/api/readinglist": {
"get": {
"summary": "Readinglist",
"tags": ["readinglist"],
"tags": [
"readinglist"
],
"description": "This endpoint allows the client to retrieve a list of articles that were saved to a Users readinglist.\n It supports pagination, each page will contain `30` articles by default",
"operationId": "getReadinglist",
"parameters": [
@ -942,7 +1022,9 @@
"description": "A list of articles in the users readinglist",
"content": {
"application/json": {
"example": [],
"example": [
],
"schema": {
"type": "array",
"items": {
@ -958,7 +1040,9 @@
"/api/users/{id}": {
"get": {
"summary": "A User",
"tags": ["users"],
"tags": [
"users"
],
"description": "This endpoint allows the client to retrieve a single user, either by id\nor by the user's username.\n\nFor complete documentumenation, see the v0 API docs: https://developers.forem.com/api/v0#tag/users/operation/getUser",
"operationId": "getUser",
"parameters": [
@ -981,7 +1065,9 @@
"/api/users/{id}/unpublish": {
"put": {
"summary": "Unpublish a User's Articles and Comments",
"tags": ["users"],
"tags": [
"users"
],
"description": "This endpoint allows the client to unpublish all of the articles and\ncomments created by a user.\n\nThe user associated with the API key must have any 'admin' or 'moderator' role.\n\nThis specified user's articles and comments will be unpublished and will no longer be\nvisible to the public. They will remain in the database and will set back to draft status\non the specified user's dashboard. Any notifications associated with the specified user's\narticles and comments will be deleted.\n\nNote this endpoint unpublishes articles and comments asychronously: it will return a 204 NO CONTENT\nstatus code immediately, but the articles and comments will not be unpublished until the\nrequest is completed on the server.",
"operationId": "unpublishUser",
"parameters": [
@ -1030,7 +1116,9 @@
"/api/users/{id}/suspend": {
"put": {
"summary": "Suspend a User",
"tags": ["users"],
"tags": [
"users"
],
"description": "This endpoint allows the client to suspend a user.\n\nThe user associated with the API key must have any 'admin' or 'moderator' role.\n\nThis specified user will be assigned the 'suspended' role. Suspending a user will stop the\nuser from posting new posts and comments. It doesn't delete any of the user's content, just\nprevents them from creating new content while suspended. Users are not notified of their suspension\nin the UI, so if you want them to know about this, you must notify them.",
"operationId": "suspendUser",
"parameters": [
@ -1085,7 +1173,9 @@
],
"security": [
{
"api-key": []
"api-key": [
]
}
],
"components": {
@ -1393,4 +1483,4 @@
}
}
}
}
}