FEATURE: Add all user update API scopes (#24016)

There are a few PUT requests that users can do in their preferences tab that aren't going through the standard `user#update` action.

This commit adds all the "trivial" ones (aka. except the security-related one, username and email changes) so you can now change the badge title, the avatar or featured topic of a user via the API.
This commit is contained in:
Régis Hanol 2023-10-19 15:37:25 +02:00 committed by GitHub
parent d7474e643a
commit 33715ccc57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -126,7 +126,14 @@ class ApiKeyScope < ActiveRecord::Base
params: %i[username],
},
update: {
actions: %w[users#update],
actions: %w[
users#update
users#badge_title
users#pick_avatar
users#select_avatar
users#feature_topic
users#clear_featured_topic
],
params: %i[username],
},
log_out: {

View File

@ -464,6 +464,21 @@ 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["users"].find { _1["key"] == "update" }["urls"]).to contain_exactly(
"/users/:username (PUT)",
"/users/:username/preferences/badge_title (PUT)",
"/users/:username/preferences/avatar/pick (PUT)",
"/users/:username/preferences/avatar/select (PUT)",
"/users/:username/feature-topic (PUT)",
"/users/:username/clear-featured-topic (PUT)",
"/u/:username (PUT)",
"/u/:username/preferences/badge_title (PUT)",
"/u/:username/preferences/avatar/pick (PUT)",
"/u/:username/preferences/avatar/select (PUT)",
"/u/:username/feature-topic (PUT)",
"/u/:username/clear-featured-topic (PUT)",
)
end
end