Skip to content

Commit

Permalink
Merge pull request diaspora#8363 from cmrd-senya/fix-api-tags-stream-…
Browse files Browse the repository at this point in the history
…to-hide-ignores

API: update Search endpoint to be aware of ignored users
  • Loading branch information
SuperTux88 committed Jun 4, 2024
2 parents c3eaa21 + 834f158 commit fddfd8b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ We recommend setting up new pods using Ruby 3.3, and updating existing pods to t
* Fix scrolling issue after closing photo viewer on photos page [#8404](https://github.com/diaspora/diaspora/pull/8404)
* Filter unicode emojis from email headers [#8421](https://github.com/diaspora/diaspora/pull/8421)
* Do not show disabled services anymore [#8406](https://github.com/diaspora/diaspora/pull/8406)
* Update search endpoint to be aware of ignored users [#8363](https://github.com/diaspora/diaspora/pull/8363)

## Features
* Add client-side cropping of profile image uploads [#7581](https://github.com/diaspora/diaspora/pull/7581)
Expand Down
8 changes: 3 additions & 5 deletions app/controllers/api/v1/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,9 @@ def people_query
end

def posts_query
if private_read?
Stream::Tag.new(current_user, params.require(:tag)).posts
else
Stream::Tag.new(nil, params.require(:tag)).posts
end
opts = {}
opts[:public_only] = !private_read?
Stream::Tag.new(current_user, params.require(:tag), opts).stream_posts
end

def tags_query
Expand Down
14 changes: 8 additions & 6 deletions lib/stream/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
# the COPYRIGHT file.

class Stream::Tag < Stream::Base
attr_accessor :tag_name, :people_page , :people_per_page
attr_accessor :tag_name, :people_page , :people_per_page, :public_only

def initialize(user, tag_name, opts={})
self.tag_name = tag_name
self.people_page = opts[:page] || 1
self.people_per_page = 15
self.public_only = opts[:public_only] || false
super(user, opts)
end

Expand All @@ -31,11 +32,12 @@ def tagged_people_count
end

def posts
@posts ||= if user
StatusMessage.user_tag_stream(user, tag.id)
else
StatusMessage.public_tag_stream(tag.id)
end
return @posts unless @posts.nil?

if public_only || user.blank?
return @posts = StatusMessage.public_tag_stream(tag.id)
end
@posts = StatusMessage.user_tag_stream(user, tag.id)
end

def stream_posts
Expand Down
35 changes: 35 additions & 0 deletions spec/integration/api/search_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,41 @@ def add_contact(*aspects)
)
expect(response.status).to eq(401)
end

context 'when the author is blocked' do
before do
FactoryBot.create(
:block,
user: auth_public_only_read_only.user,
person: eve.person
)
FactoryBot.create(
:block,
user: auth.user,
person: eve.person
)
end

it "hides the blocked author's posts in with public only scopes" do
get(
"/api/v1/search/posts",
params: {tag: "tag2", access_token: access_token_public_only_read_only}
)
expect(response.status).to eq(200)
posts = response_body_data(response)
expect(posts.length).to eq(1)
end

it "hides the blocked author's posts in with default scopes" do
get(
"/api/v1/search/posts",
params: {tag: "tag2", access_token: access_token}
)
expect(response.status).to eq(200)
posts = response_body_data(response)
expect(posts.length).to eq(1)
end
end
end

describe "tag_index" do
Expand Down

0 comments on commit fddfd8b

Please sign in to comment.