Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archived post still displays on profile #20693

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/javascripts/initializers/initScrolling.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ function insertArticles(articles) {

function paginate(tag, params, requiresApproval) {
const searchHash = Object.assign(
{ per_page: 15, page: nextPage },
{ per_page: 15, page: nextPage, archived: false },
JSON.parse(params),
);

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class SearchController < ApplicationController
:sort_direction,
:tag,
:user_id,
:archived,
{
tag_names: [],
hidden_tags: [],
Expand Down Expand Up @@ -112,6 +113,7 @@ def feed_content
sort_direction: params[:sort_direction],
page: params[:page],
per_page: params[:per_page],
archived: feed_params[:archived],
)
elsif class_name.Comment?
Search::Comment.search_documents(
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,10 @@ def assign_user_comments
end

def assign_user_stories
@pinned_stories = Article.published.where(id: @user.profile_pins.select(:pinnable_id))
@pinned_stories = Article.published.where(id: @user.profile_pins.select(:pinnable_id), archived: false)
.limited_column_select
.order(published_at: :desc).decorate
@stories = ArticleDecorator.decorate_collection(@user.articles.published
@stories = ArticleDecorator.decorate_collection(@user.articles.where(archived: false).published
.includes(:distinct_reaction_categories)
.limited_column_select
.where.not(id: @pinned_stories.map(&:id))
Expand Down
8 changes: 6 additions & 2 deletions app/queries/homepage/articles_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ArticlesQuery
user_id
video_duration_in_seconds
video_thumbnail_url
archived
].freeze
DEFAULT_PER_PAGE = 60
MAX_PER_PAGE = 100
Expand All @@ -36,7 +37,8 @@ def initialize(
sort_by: nil,
sort_direction: nil,
page: 0,
per_page: DEFAULT_PER_PAGE
per_page: DEFAULT_PER_PAGE,
archived: nil
)
@relation = Article.published.select(*ATTRIBUTES)
.includes(:distinct_reaction_categories)
Expand All @@ -53,6 +55,7 @@ def initialize(

@page = page.to_i + 1
@per_page = [(per_page || DEFAULT_PER_PAGE).to_i, MAX_PER_PAGE].min
@archived = archived
end

def call
Expand All @@ -62,7 +65,7 @@ def call
private

attr_reader :relation, :approved, :published_at, :user_id, :organization_id, :tags, :hidden_tags,
:sort_by, :sort_direction, :page, :per_page
:sort_by, :sort_direction, :page, :per_page, :archived

def filter
@relation = @relation.where(approved: approved) unless approved.nil?
Expand All @@ -73,6 +76,7 @@ def filter
@relation = @relation.not_cached_tagged_with_any(hidden_tags) if hidden_tags.any?
@relation = @relation.includes(:distinct_reaction_categories)
@relation = @relation.where("score >= 0") # Never return negative score articles
@relation = @relation.where(archived: archived) unless archived.nil?

relation
end
Expand Down
1 change: 1 addition & 0 deletions app/serializers/homepage/article_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def self.serialized_collection_from(relation:)
:title,
:user_id,
:public_reaction_categories,
:archived
)

attribute :video_duration_string, &:video_duration_in_minutes
Expand Down
4 changes: 3 additions & 1 deletion app/services/homepage/fetch_articles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def self.call(
sort_by: nil,
sort_direction: nil,
page: 0,
per_page: DEFAULT_PER_PAGE
per_page: DEFAULT_PER_PAGE,
archived: nil
)
articles = Homepage::ArticlesQuery.call(
approved: approved,
Expand All @@ -31,6 +32,7 @@ def self.call(
sort_direction: sort_direction,
page: page,
per_page: per_page,
archived: archived
)

Homepage::ArticleSerializer.serialized_collection_from(relation: articles)
Expand Down
5 changes: 3 additions & 2 deletions app/services/search/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ def self.search_documents(
sort_by: nil,
sort_direction: nil,
page: nil,
per_page: nil
per_page: nil,
archived: nil
)
relation = Homepage::ArticlesQuery.call(user_id: user_id, page: page, per_page: per_page)
relation = Homepage::ArticlesQuery.call(user_id: user_id, page: page, per_page: per_page, archived: archived)

relation = relation.search_articles(term) if term.present?

Expand Down
28 changes: 28 additions & 0 deletions spec/queries/homepage/articles_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,33 @@
expect(Article).not_to have_received(:order)
end
end

describe "archived" do
it "returns both archived and not archived articles by default" do
archived_article = create(:article, archived: true)
not_archived_article = create(:article, archived: false)

expected_result = [archived_article.id, not_archived_article.id]
expect(described_class.call.ids).to match_array(expected_result)
end

it "returns archived articles", :aggregate_failures do
archived_article = create(:article, archived: true)
not_archived_article = create(:article, archived: false)

result = described_class.call(archived: true).ids
expect(result).to include(archived_article.id)
expect(result).not_to include(not_archived_article.id)
end

it "returns not archived articles" do
archived_article = create(:article, archived: true)
not_archived_article = create(:article, archived: false)

result = described_class.call(archived: false).ids
expect(result).not_to include(archived_article.id)
expect(result).to include(not_archived_article.id)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/services/homepage/fetch_articles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class_name cloudinary_video_url comments_count flare_tag id path
public_reactions_count public_reaction_categories
published_at_int readable_publish_date reading_time tag_list title
user user_id video_duration_string
user user_id video_duration_string archived
]
expect(result.keys.sort).to match_array(keys)

Expand Down
12 changes: 12 additions & 0 deletions spec/services/search/article_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@
expect(result.length).to eq(1)
end
end

context "when filtering by archived" do
it "returns archived articles belonging to a specific user", :aggregate_failures do
user = create(:user)
articles = create_list(:article, 2, user: user, archived: true)
article = create(:article, user: user, archived: false)

results = described_class.search_documents(user_id: user.id, archived: true).pluck(:id)
expect(results).not_to include(article.id)
expect(results).to match_array(articles.pluck(:id))
end
end
end
end

Expand Down