From 2d890d73a291349288bc2272df8e00bafca01002 Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Thu, 29 Feb 2024 15:49:29 -0700 Subject: [PATCH] FEATURE: Add recover api scopes (#25978) This commit adds two new api scopes. One for recovering topics, and the other for recovering posts. --- app/models/api_key_scope.rb | 6 ++++++ config/locales/client.en.yml | 2 ++ spec/requests/admin/api_controller_spec.rb | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/app/models/api_key_scope.rb b/app/models/api_key_scope.rb index 270e06f92dd..59d2afad428 100644 --- a/app/models/api_key_scope.rb +++ b/app/models/api_key_scope.rb @@ -34,6 +34,9 @@ class ApiKeyScope < ActiveRecord::Base delete: { actions: %w[topics#destroy], }, + recover: { + actions: %w[topics#recover], + }, read: { actions: %w[topics#show topics#feed topics#posts topics#show_by_external_id], params: %i[topic_id external_id], @@ -61,6 +64,9 @@ class ApiKeyScope < ActiveRecord::Base delete: { actions: %w[posts#destroy], }, + recover: { + actions: %w[posts#recover], + }, list: { actions: %w[posts#latest], }, diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 8a13f510652..60b9aada133 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -5037,11 +5037,13 @@ en: write: Create a new topic or post to an existing one. update: Update a topic. Change the title, category, tags, status, archetype, featured_link etc. delete: Delete a topic. + recover: Recover a topic. read_lists: Read topic lists like top, new, latest, etc. RSS is also supported. status: "Update a topic's status. Status: closed, archive, visible, pinned. Enabled: true, false. Specify a category_id here and in the request payload to only allow status changes on topics in that category." posts: edit: Edit any post or a specific one. delete: Delete a post. + recover: Recover a post. list: List latest posts and private posts. RSS is also supported. tags: list: List tags. diff --git a/spec/requests/admin/api_controller_spec.rb b/spec/requests/admin/api_controller_spec.rb index 51f1e1d8ee7..9a1db21764b 100644 --- a/spec/requests/admin/api_controller_spec.rb +++ b/spec/requests/admin/api_controller_spec.rb @@ -478,6 +478,7 @@ RSpec.describe Admin::ApiController do "/t/:slug/:topic_id/last (GET)", "/t/:topic_id/posts (GET)", "/latest.rss (GET)", + "/t/:topic_id/recover (PUT)", ] topic_routes.each do |route| @@ -486,6 +487,9 @@ RSpec.describe Admin::ApiController do expect(scopes["posts"].any? { |h| h["urls"].include?("/posts (GET)") }).to be_truthy expect(scopes["posts"].any? { |h| h["urls"].include?("/private-posts (GET)") }).to be_truthy + expect( + scopes["posts"].any? { |h| h["urls"].include?("/posts/:post_id/recover (PUT)") }, + ).to be_truthy expect(scopes["users"].find { _1["key"] == "update" }["urls"]).to contain_exactly( "/users/:username (PUT)",