/hats: don't list hats unavailable for use

Fix #1160
This commit is contained in:
Peter Bhat Harkins 2023-02-08 08:12:56 -06:00
parent 7c9dcc55a0
commit 29b0f1a243
2 changed files with 4 additions and 2 deletions

View File

@ -14,7 +14,7 @@ class HatsController < ApplicationController
@hat_groups = {}
Hat.all.includes(:user).each do |h|
Hat.active.includes(:user).each do |h|
@hat_groups[h.hat] ||= []
@hat_groups[h.hat].push h
end

View File

@ -1,12 +1,14 @@
class Hat < ApplicationRecord
belongs_to :user
belongs_to :granted_by_user, :class_name => "User", :inverse_of => false
belongs_to :granted_by_user, class_name: "User", inverse_of: false
after_create :log_moderation
validates :user, :granted_by_user, :hat, presence: true
validates :hat, :link, length: { maximum: 255 }
scope :active, -> { joins(:user).where(doffed_at: nil).merge(User.active) }
def doff_by_user_with_reason(user, reason)
m = Moderation.new
m.user_id = self.user_id