From 1c0fb1aeca8eafaf094371d33309a658c5389edb Mon Sep 17 00:00:00 2001
From: Zee <50284+zspencer@users.noreply.github.com>
Date: Wed, 18 Oct 2023 18:34:54 -0700
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=F0=9F=94=A8=20`Section`:=20Deletin?=
=?UTF-8?q?g=20Sections=20is=20possible=20again=20(#1900)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- https://github.com/zinc-collective/convene/issues/1841
So, this was caused by me being FANCY and putting the delete button in
the same form as the edit and update. A bad idea.
Now, deleting a Section is handled in it's own independent form, rather
than attempting to rewrite the forms hidden `_method` field to trick
Rails into doing a destroy.
This is also better from a design perspective because:
A) omg, a delete button so close to the save button is DANGEROUS
B) Deleting a Section is kinda a big deal, and while it would be better
to bubble-wrap the heck out of it so people who *do* delete a
section don't wind up in a sad-mad state; we can at least give them
lots of "DANGER WILL ROBINSON DANGER" messaging. This is...
irresponsible of us but what we can do now. If a motivated bystander
or contributor wanted to design and implement a way for Sections to be
Archived instead; I would be Very Happy :tm:
---
app/views/rooms/_form.html.erb | 5 ----
app/views/rooms/edit.html.erb | 14 +++++++++
config/locales/room/en.yml | 4 +--
spec/system/sections_spec.rb | 53 ++++++++++++++++++++++++++++++++++
4 files changed, 69 insertions(+), 7 deletions(-)
create mode 100644 spec/system/sections_spec.rb
diff --git a/app/views/rooms/_form.html.erb b/app/views/rooms/_form.html.erb
index 93e9a28eb..aa7138862 100644
--- a/app/views/rooms/_form.html.erb
+++ b/app/views/rooms/_form.html.erb
@@ -8,11 +8,6 @@
<%= render "radio_group", attribute: :access_level, options: Room::access_levels.values, form: room_form %>
diff --git a/app/views/rooms/edit.html.erb b/app/views/rooms/edit.html.erb
index d9d80fe79..8eef83d26 100644
--- a/app/views/rooms/edit.html.erb
+++ b/app/views/rooms/edit.html.erb
@@ -20,3 +20,17 @@
<%= render "furnitures/new", furniture: new_furniture %>
<%- end %>
<% end %>
+
+
+<%- if policy(room).destroy? && room.persisted? && !room.entrance? %>
+
+
Remove this Section?
+ <%- data = {} %>
+ <%- if !room.gizmos.reload.empty? %>
+
Warning! Deleting this Section will also delete all Gizmos and their related data. Please be very sure you want to do this! We recommend making the Section "internal" instead.
+<%- end %>
diff --git a/config/locales/room/en.yml b/config/locales/room/en.yml
index 22970b46c..0dccd1dec 100644
--- a/config/locales/room/en.yml
+++ b/config/locales/room/en.yml
@@ -7,10 +7,10 @@ en:
update:
success: You've updated Section '%{room_name}' successfully! 🎉
destroy:
+ link_to: "Remove Section 🗑️"
+ confirm: "Removing Section '%{room_name}' is permanent and irreversible! Do you still want to proceed?"
success: You've removed Section '%{room_name}' successfully! 🎉
failure: We couldn't remove Section '%{room_name}'.
- form:
- destroy: "Remove Section 🗑️"
helpers:
submit:
room:
diff --git a/spec/system/sections_spec.rb b/spec/system/sections_spec.rb
new file mode 100644
index 000000000..e363d7ab1
--- /dev/null
+++ b/spec/system/sections_spec.rb
@@ -0,0 +1,53 @@
+require "rails_helper"
+
+RSpec.describe "Sections" do
+ describe "Removing a Section" do
+ let(:space) { create(:space, :with_entrance, :with_members, member_count: 1) }
+
+ before do
+ sign_in(space.members.first, space)
+ visit(polymorphic_path(section.location(:edit)))
+ end
+
+ context "when the section is an entrance" do
+ let(:section) { space.entrance }
+
+ it "doesn't let you delete the entrance" do
+ expect(page).not_to have_content(I18n.t("rooms.destroy.link_to"))
+ end
+ end
+
+ context "when the section is not the entrance" do
+ let(:section) { create(:room, space: space) }
+
+ context "when the Section has no Gizmos" do
+ it "deletes the Section from the Database" do
+ click_on(I18n.t("rooms.destroy.link_to"))
+
+ expect(page).to have_content(I18n.t("rooms.destroy.success", room_name: section.name))
+ expect(space.rooms).not_to be_exist(id: section.id)
+ end
+ end
+
+ context "when the section has Gizmos" do
+ before {
+ create(:furniture, room: section)
+ refresh
+ }
+
+ # Design note: It would be far better for us to have a way to safely undo
+ # the deletion of a Section, or even put the Gizmos into a holding space
+ # or something to be re-assigned; but that is out of scope for me at the
+ # moment - ZS 10/18/23
+ it "requires confirmation" do
+ accept_alert(I18n.t("rooms.destroy.confirm", room_name: section.name)) do
+ click_on(I18n.t("rooms.destroy.link_to"))
+ end
+
+ expect(page).to have_content(I18n.t("rooms.destroy.success", room_name: section.name))
+ expect(space.rooms).not_to be_exist(id: section.id)
+ end
+ end
+ end
+ end
+end