mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-01-02 22:47:45 -05:00
This commit introduces a new `Problem` model, analogous to `Crop`, to allow users to track problems they have on their plantings (e.g., aphids on tomatoes). Key features: - A new `Problem` model that can be curated by admins (`problem_wranglers`). - Users can associate problems with their plantings and upload photos of the problems. - Aggregated problem information is displayed on the crop detail page (e.g., "Problems: aphids (27), blight (13)"). - Users can mention problems in posts (e.g., `[aphids](problem)`), which automatically links to the problem's page. - Admin functionality for reviewing and approving new problem suggestions. Resolves merge conflict in app/controllers/plantings_controller.rb
26 lines
723 B
Ruby
26 lines
723 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Notification < ApplicationRecord
|
|
belongs_to :sender, class_name: 'Member', inverse_of: :sent_notifications
|
|
belongs_to :recipient, class_name: 'Member', inverse_of: :notifications
|
|
belongs_to :post, optional: true
|
|
|
|
validates :subject, length: { maximum: 255 }
|
|
|
|
scope :unread, -> { where(read: false) }
|
|
scope :by_recipient, ->(recipient) { where(recipient_id: recipient) }
|
|
|
|
before_create :replace_blank_subject
|
|
after_create :send_message
|
|
|
|
def send_message
|
|
sender.send_message(recipient, body, subject) if recipient.send_notification_email
|
|
end
|
|
|
|
private
|
|
|
|
def replace_blank_subject
|
|
self.subject = "(no subject)" if subject.nil? || subject =~ /^\s*$/
|
|
end
|
|
end
|