Skip to content

Commit de29259

Browse files
authored
Merge pull request #2030 from codidact/art/user-profile
2 parents affda6f + 735fcea commit de29259

5 files changed

Lines changed: 31 additions & 14 deletions

File tree

app/controllers/reports_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def posts
2121
@answers = Answer.recent(1.year.ago).undeleted
2222
@comments = Comment.recent(1.year.ago).undeleted
2323
@this_month = Post.recent(1.month.ago).undeleted
24-
@categories = Category.where('IFNULL(categories.min_view_trust_level, 0) <= ?', current_user&.trust_level || 0)
24+
@categories = Category.where('categories.min_view_trust_level <= ?', current_user&.trust_level || 0)
2525
.order(:sequence)
2626
@posts_categories = Post.in(@categories).group(:category_id).count
2727
end
@@ -51,7 +51,7 @@ def posts_global
5151
@comments = Comment.unscoped.recent(1.year.ago).undeleted
5252
@this_month = Post.unscoped.recent(1.month.ago).undeleted
5353
@categories = Category.unscoped
54-
.where('IFNULL(categories.min_view_trust_level, 0) <= ?', current_user&.trust_level || 0)
54+
.where('categories.min_view_trust_level <= ?', current_user&.trust_level || 0)
5555
.includes(:community).order(:community_id, :sequence)
5656
@posts_categories = Post.unscoped.in(@categories).group(:category_id).count
5757
@global = true

app/controllers/users_controller.rb

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,15 @@ def show
5050
@posts = set_posts.user_sort({ term: params[:sort], default: :score },
5151
age: :created_at, score: :score)
5252

53-
@total_post_count = @posts.count
53+
@total_post_count = if @user == current_user || current_user&.at_least_moderator?
54+
Post.all.by(@user).count
55+
else
56+
Post.all.by(@user)
57+
.undeleted
58+
.joins(:category)
59+
.where('categories.min_view_trust_level <= ?', current_user&.trust_level || 0)
60+
.count
61+
end
5462
@posts = @posts.first(@limit)
5563
render layout: 'without_sidebar'
5664
end
@@ -651,14 +659,16 @@ def filter_params
651659
end
652660

653661
def set_posts
654-
@posts = if current_user&.privilege?('flag_curate') || @user == current_user
655-
@user.posts
656-
else
657-
@user.posts.undeleted
658-
end
659-
.list_includes
660-
.joins(:category)
661-
.where('IFNULL(categories.min_view_trust_level, 0) <= ?', current_user&.trust_level || 0)
662+
Rack::MiniProfiler.step('set_posts') do
663+
@posts = if current_user&.privilege?('flag_curate') || @user == current_user
664+
@user.posts
665+
else
666+
@user.posts.undeleted
667+
end
668+
.list_includes
669+
.joins(:category)
670+
.where('categories.min_view_trust_level <= ?', current_user&.trust_level || 0)
671+
end
662672
end
663673

664674
def set_user

app/models/category.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def self.accessible_to(user)
7272
end
7373

7474
trust_level = user&.trust_level || 0
75-
Category.where('IFNULL(min_view_trust_level, -1) <= ?', trust_level)
75+
Category.where('min_view_trust_level <= ?', trust_level)
7676
end
7777

7878
# Gets category matching a given name
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class AddNotNullDefaultToCategories < ActiveRecord::Migration[7.2]
2+
def change
3+
Category.unscoped.where(min_view_trust_level: nil).update_all(min_view_trust_level: 0)
4+
change_column :categories, :min_view_trust_level, :integer, default: 0, null: false
5+
add_index :categories, :min_view_trust_level
6+
end
7+
end

db/schema.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.2].define(version: 2026_03_04_104100) do
13+
ActiveRecord::Schema[7.2].define(version: 2026_03_20_104406) do
1414
create_table "abilities", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
1515
t.bigint "community_id"
1616
t.string "name"
@@ -104,7 +104,7 @@
104104
t.string "color_code"
105105
t.text "asking_guidance_override", size: :medium
106106
t.text "answering_guidance_override", size: :medium
107-
t.integer "min_view_trust_level"
107+
t.integer "min_view_trust_level", default: 0, null: false
108108
t.bigint "license_id"
109109
t.integer "sequence"
110110
t.boolean "use_for_hot_posts", default: true

0 commit comments

Comments
 (0)