Skip to content

Commit

Permalink
[B] Allow creators to be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
zdavis committed Aug 12, 2021
1 parent 17cdb97 commit 30ff1ef
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api/app/models/concerns/tracked_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module TrackedCreator
extend ActiveSupport::Concern

included do
belongs_to :creator, class_name: "User", foreign_key: "creator_id"
belongs_to :creator, class_name: "User", foreign_key: "creator_id", optional: true

delegate :name, to: :creator, prefix: true
end
Expand Down
2 changes: 1 addition & 1 deletion api/app/serializers/v1/annotation_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AnnotationSerializer < ManifoldSerializer
anonymous?(object, params)
end
typed_attribute :creator_name, Types::String.meta(read_only: true) do |object, params|
next object.creator.full_name if creator_identity_visible?(object, params)
next object.creator&.full_name if creator_identity_visible?(object, params)

object.anonymous_label
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def execute

def excluded
@excluded ||= [creator].tap do |out|
out << parent.creator if parent.present?
out << parent.creator if parent&.creator.present?
end.compact
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ class FetchUsersForReplyNotification < ActiveInteraction::Base

def execute
[].tap do |recipients|
recipients.push(parent.creator) if notify_parent_creator?
recipients.push(subject.creator) if notify_subject_creator?
recipients.push(parent.creator) if notify_parent_creator? && parent.creator.present?
recipients.push(subject.creator) if notify_subject_creator? && subject.creator.present?
end
end

def notify_parent_creator?
parent.present? && !reply_to_self? && creator_wants_notification?(parent.creator)
parent.present? && !reply_to_self? && parent.creator.present? && creator_wants_notification?(parent.creator)
end

def notify_subject_creator?
on_annotation? && creator_wants_notification?(subject.creator)
on_annotation? && subject.creator && creator_wants_notification?(subject.creator)
end

private
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
<%= @comment.creator.full_name %> replied to your comment on <a href="<%= @comment.subject_url %>"><%= @comment.title %></a>.
<%= @comment.creator&.full_name || "A deleted user" %> replied to your comment on <a href="<%= @comment.subject_url %>"><%= @comment.title %></a>.

<p style="margin-top: 15px; margin-bottom: 0;">
<em><%= @comment.body %></em>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= @comment.creator.full_name %> replied to your comment on "<%= @comment.title %>."
<%= @comment.creator&.full_name || "A deleted user" %> replied to your comment on "<%= @comment.title %>."

-----------------------------------------------------------
<%= @comment.body %>
Expand Down
4 changes: 2 additions & 2 deletions api/spec/models/annotation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
expect(@annotation).to be_valid
end

it "invalid without a creator" do
it "valid without a creator" do
@annotation.creator = nil
expect(@annotation).to_not be_valid
expect(@annotation).to be_valid
end

it "enqueues a TEXT_ANNOTATED event on creation" do
Expand Down
5 changes: 0 additions & 5 deletions api/spec/models/flag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
describe "is invalid when" do
let(:flag) { FactoryBot.build(:flag) }

it "creator is nil" do
flag.creator = nil
expect(flag).to_not be_valid
end

it "flaggable is nil" do
flag.flaggable = nil
expect(flag).to_not be_valid
Expand Down

0 comments on commit 30ff1ef

Please sign in to comment.