FIX: allow admin to change topic notification level via API (#21581)

* FIX: allow admin to change topic notification level via API

* default to `current_user` if admin changes own level

* check param existence

* simplify condition

* remove rescue

* Update spec/requests/topics_controller_spec.rb

Co-authored-by: Penar Musaraj <pmusaraj@gmail.com>

* added specs for other cases

---------

Co-authored-by: Penar Musaraj <pmusaraj@gmail.com>
This commit is contained in:
Faizaan Gagan
2023-05-23 00:47:58 +05:30
committed by GitHub
parent efdfddf7fc
commit a58c37bdc5
2 changed files with 81 additions and 1 deletions

View File

@@ -803,8 +803,16 @@ class TopicsController < ApplicationController
end
def set_notifications
user =
if is_api? && @guardian.is_admin? &&
(params[:username].present? || params[:external_id].present?)
fetch_user_from_params
else
current_user
end
topic = Topic.find(params[:topic_id].to_i)
TopicUser.change(current_user, topic.id, notification_level: params[:notification_level].to_i)
TopicUser.change(user, topic.id, notification_level: params[:notification_level].to_i)
render json: success_json
end