mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
FEATURE: missing API endpoint for topic tracking states
This commit is contained in:
parent
42593562f5
commit
afaba56de3
3 changed files with 42 additions and 4 deletions
|
@ -7,7 +7,9 @@ class UsersController < ApplicationController
|
||||||
skip_before_filter :authorize_mini_profiler, only: [:avatar]
|
skip_before_filter :authorize_mini_profiler, only: [:avatar]
|
||||||
skip_before_filter :check_xhr, only: [:show, :password_reset, :update, :account_created, :activate_account, :perform_account_activation, :user_preferences_redirect, :avatar, :my_redirect, :toggle_anon, :admin_login]
|
skip_before_filter :check_xhr, only: [:show, :password_reset, :update, :account_created, :activate_account, :perform_account_activation, :user_preferences_redirect, :avatar, :my_redirect, :toggle_anon, :admin_login]
|
||||||
|
|
||||||
before_filter :ensure_logged_in, only: [:username, :update, :user_preferences_redirect, :upload_user_image, :pick_avatar, :destroy_user_image, :destroy, :check_emails]
|
before_filter :ensure_logged_in, only: [:username, :update, :user_preferences_redirect, :upload_user_image,
|
||||||
|
:pick_avatar, :destroy_user_image, :destroy, :check_emails, :topic_tracking_state]
|
||||||
|
|
||||||
before_filter :respond_to_suspicious_request, only: [:create]
|
before_filter :respond_to_suspicious_request, only: [:create]
|
||||||
|
|
||||||
# we need to allow account creation with bad CSRF tokens, if people are caching, the CSRF token on the
|
# we need to allow account creation with bad CSRF tokens, if people are caching, the CSRF token on the
|
||||||
|
@ -140,6 +142,16 @@ class UsersController < ApplicationController
|
||||||
render json: failed_json, status: 403
|
render json: failed_json, status: 403
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def topic_tracking_state
|
||||||
|
user = fetch_user_from_params
|
||||||
|
guardian.ensure_can_edit!(user)
|
||||||
|
|
||||||
|
report = TopicTrackingState.report(user.id)
|
||||||
|
serializer = ActiveModel::ArraySerializer.new(report, each_serializer: TopicTrackingStateSerializer)
|
||||||
|
|
||||||
|
render json: MultiJson.dump(serializer)
|
||||||
|
end
|
||||||
|
|
||||||
def badge_title
|
def badge_title
|
||||||
params.require(:user_badge_id)
|
params.require(:user_badge_id)
|
||||||
|
|
||||||
|
|
|
@ -315,9 +315,7 @@ Discourse::Application.routes.draw do
|
||||||
get "users/:username/preferences/card-badge" => "users#card_badge", constraints: {username: USERNAME_ROUTE_FORMAT}
|
get "users/:username/preferences/card-badge" => "users#card_badge", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
put "users/:username/preferences/card-badge" => "users#update_card_badge", constraints: {username: USERNAME_ROUTE_FORMAT}
|
put "users/:username/preferences/card-badge" => "users#update_card_badge", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
get "users/:username/staff-info" => "users#staff_info", constraints: {username: USERNAME_ROUTE_FORMAT}
|
get "users/:username/staff-info" => "users#staff_info", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
|
|
||||||
get "users/:username/summary" => "users#summary", constraints: {username: USERNAME_ROUTE_FORMAT}
|
get "users/:username/summary" => "users#summary", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
|
|
||||||
get "users/:username/invited" => "users#invited", constraints: {username: USERNAME_ROUTE_FORMAT}
|
get "users/:username/invited" => "users#invited", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
get "users/:username/invited_count" => "users#invited_count", constraints: {username: USERNAME_ROUTE_FORMAT}
|
get "users/:username/invited_count" => "users#invited_count", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
get "users/:username/invited/:filter" => "users#invited", constraints: {username: USERNAME_ROUTE_FORMAT}
|
get "users/:username/invited/:filter" => "users#invited", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
|
@ -339,6 +337,9 @@ Discourse::Application.routes.draw do
|
||||||
get "users/by-external/:external_id" => "users#show", constraints: {external_id: /[^\/]+/}
|
get "users/by-external/:external_id" => "users#show", constraints: {external_id: /[^\/]+/}
|
||||||
get "users/:username/flagged-posts" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}
|
get "users/:username/flagged-posts" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
get "users/:username/deleted-posts" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}
|
get "users/:username/deleted-posts" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
|
|
||||||
|
get "users/:username/topic-tracking-state" => "users#topic_tracking_state", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
|
|
||||||
get "user-badges/:username.json" => "user_badges#username", constraints: {username: USERNAME_ROUTE_FORMAT}, defaults: {format: :json}
|
get "user-badges/:username.json" => "user_badges#username", constraints: {username: USERNAME_ROUTE_FORMAT}, defaults: {format: :json}
|
||||||
get "user-badges/:username" => "user_badges#username", constraints: {username: USERNAME_ROUTE_FORMAT}
|
get "user-badges/:username" => "user_badges#username", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
|
|
||||||
|
|
|
@ -1625,7 +1625,32 @@ describe UsersController do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context '#summary' do
|
describe '.topic_tracking_state' do
|
||||||
|
let(:user){Fabricate(:user)}
|
||||||
|
|
||||||
|
context 'anon' do
|
||||||
|
it "raises an error on anon for topic_tracking_state" do
|
||||||
|
expect{
|
||||||
|
xhr :get, :topic_tracking_state, username: user.username, format: :json
|
||||||
|
}.to raise_error(Discourse::NotLoggedIn)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'logged on' do
|
||||||
|
it "detects new topic" do
|
||||||
|
log_in_user(user)
|
||||||
|
|
||||||
|
topic = Fabricate(:topic)
|
||||||
|
xhr :get, :topic_tracking_state, username: user.username, format: :json
|
||||||
|
|
||||||
|
states = JSON.parse(response.body)
|
||||||
|
|
||||||
|
expect(states[0]["topic_id"]).to eq(topic.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.summary' do
|
||||||
|
|
||||||
it "generates summary info" do
|
it "generates summary info" do
|
||||||
user = Fabricate(:user)
|
user = Fabricate(:user)
|
||||||
|
|
Loading…
Reference in a new issue