Skip to content

Commit

Permalink
[B] Allow accounts with ingestions to be deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
zdavis committed Nov 29, 2023
1 parent f1719a8 commit 8328370
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 22 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
9 changes: 9 additions & 0 deletions api/db/migrate/20231129172116_adjust_user_key_constraints.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AdjustUserKeyConstraints < ActiveRecord::Migration[6.1]
def change

remove_foreign_key :ingestions, :users, column: :creator_id
add_foreign_key :ingestions, :users, column: :creator_id, on_delete: :nullify

change_column_null :ingestions, :creator_id, true
end
end
7 changes: 4 additions & 3 deletions api/db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ CREATE TABLE public.ingestions (
strategy character varying,
external_source_url character varying,
ingestion_type character varying,
creator_id uuid NOT NULL,
creator_id uuid,
text_id uuid,
project_id uuid NOT NULL,
created_at timestamp without time zone NOT NULL,
Expand Down Expand Up @@ -6494,7 +6494,7 @@ ALTER TABLE ONLY public.reading_group_text_sections
--

ALTER TABLE ONLY public.ingestions
ADD CONSTRAINT fk_rails_a143919a1e FOREIGN KEY (creator_id) REFERENCES public.users(id) ON DELETE RESTRICT;
ADD CONSTRAINT fk_rails_a143919a1e FOREIGN KEY (creator_id) REFERENCES public.users(id) ON DELETE SET NULL;


--
Expand Down Expand Up @@ -7125,6 +7125,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230823232509'),
('20230921024546'),
('20231005175407'),
('20231010184158');
('20231010184158'),
('20231129172116');


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 "is 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
4 changes: 2 additions & 2 deletions api/spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
expect(project).to be_valid
end

it "is invalid without a creator" do
it "is valid without a creator" do
project = FactoryBot.build(:project, creator: nil)
expect(project).to_not be_valid
expect(project).to be_valid
end

it "triggers an event on create" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
},
"delete": {
"header": "Delete your account",
"description": "This will delete your entire account and record from our databases.",
"description": "This will delete your entire account and any annotations you created from our database. Projects and texts that you created will not be deleted. It is not possible to recover deleted accounts so proceed with caution.",
"button_label": "Delete my account",
"confirm_header": "Are you sure you want to delete your account?",
"confirm_instructions": "Please enter your email to continue.",
Expand Down

0 comments on commit 8328370

Please sign in to comment.