DEV: Allow user api key scope for notifications#totals (#26205)

The `/notifications/totals` route is a stripped down version of `notifications#index`. This just allows the mobile app to use this new route.
This commit is contained in:
Penar Musaraj 2024-03-15 16:06:32 -04:00 committed by GitHub
parent 8cf2f909f5
commit 531e33b303
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View File

@ -10,6 +10,7 @@ class UserApiKeyScope < ActiveRecord::Base
notifications: [ notifications: [
RouteMatcher.new(methods: :post, actions: "message_bus"), RouteMatcher.new(methods: :post, actions: "message_bus"),
RouteMatcher.new(methods: :get, actions: "notifications#index"), RouteMatcher.new(methods: :get, actions: "notifications#index"),
RouteMatcher.new(methods: :get, actions: "notifications#totals"),
RouteMatcher.new(methods: :put, actions: "notifications#mark_read"), RouteMatcher.new(methods: :put, actions: "notifications#mark_read"),
], ],
session_info: [ session_info: [

View File

@ -626,4 +626,28 @@ RSpec.describe NotificationsController do
end end
end end
end end
context "with user api keys" do
fab!(:user)
let(:user_api_key) do
UserApiKey.create!(
application_name: "my app",
client_id: "",
scopes: ["notifications"].map { |name| UserApiKeyScope.new(name: name) },
user_id: user.id,
)
end
before { SiteSetting.user_api_key_allowed_groups = Group::AUTO_GROUPS[:trust_level_0] }
it "allows access to notifications#totals" do
get "/notifications/totals.json", headers: { "User-Api-Key": user_api_key.key }
expect(response.status).to eq(200)
end
it "allows access to notifications#index" do
get "/notifications.json", headers: { "User-Api-Key": user_api_key.key }
expect(response.status).to eq(200)
end
end
end end