diff --git a/app/controllers/character_sheet_sections_controller.rb b/app/controllers/character_sheet_sections_controller.rb
index b550230..47a8975 100644
--- a/app/controllers/character_sheet_sections_controller.rb
+++ b/app/controllers/character_sheet_sections_controller.rb
@@ -6,6 +6,7 @@ class CharacterSheetSectionsController < ApplicationController
def index
@sections = @character.character_sheet_sections.top_level
+ @editable = ActiveModel::Type::Boolean.new.cast(params[:editable])
end
def new
diff --git a/app/views/character_sheet_sections/_character_sheet_section.html.erb b/app/views/character_sheet_sections/_character_sheet_section.html.erb
index ab2cb4a..f32486b 100644
--- a/app/views/character_sheet_sections/_character_sheet_section.html.erb
+++ b/app/views/character_sheet_sections/_character_sheet_section.html.erb
@@ -10,9 +10,11 @@
<%= render character_sheet_section.character_sheet_subsections %>
-
- <%= render partial: "edit_links",
- locals: { section: character_sheet_section, parent: character_sheet_section, id: nil } %>
-
+ <% if @editable %>
+
+ <%= render partial: "edit_links",
+ locals: { section: character_sheet_section, parent: character_sheet_section, id: nil } %>
+
+ <% end %>
diff --git a/app/views/character_sheet_sections/index.html.erb b/app/views/character_sheet_sections/index.html.erb
index fdaa23d..2cd199f 100644
--- a/app/views/character_sheet_sections/index.html.erb
+++ b/app/views/character_sheet_sections/index.html.erb
@@ -2,6 +2,12 @@
<%= @character.name %>
+<% if @editable %>
+ <%= link_to t(".stop_editing"), character_character_sheet_sections_path(editable: false) %>
+<% else %>
+ <%= link_to t(".edit"), character_character_sheet_sections_path(editable: true) %>
+<% end %>
+
<% if @sections.any? %>
<%= render @sections %>
@@ -10,7 +16,9 @@
<% end %>
-
- <%= link_to t(".add_section"), new_character_character_sheet_section_path(@character),
- data: { turbo_stream: true } %>
-
+<% if @editable %>
+
+ <%= link_to t(".add_section"), new_character_character_sheet_section_path(@character),
+ data: { turbo_stream: true } %>
+
+<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 77d26b5..2a64aa8 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -62,6 +62,8 @@ en:
confirm_delete: Are you sure you want to delete this section?
add_stat: Add stat
index:
+ edit: Edit character sheet
+ stop_editing: Stop editing
character_sheet: "%{name}’s character sheet"
no_sections: This character sheet has no content
add_section: Add section
diff --git a/test/integration/edit_character_sheet_test.rb b/test/integration/edit_character_sheet_test.rb
new file mode 100644
index 0000000..a98cb2c
--- /dev/null
+++ b/test/integration/edit_character_sheet_test.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+require "test_helper"
+
+class EditCharacterSheetTest < ActionDispatch::IntegrationTest
+ test "Sheet is only editable when parameter is set" do
+ user = users(:trevor)
+ sign_in user
+
+ get character_character_sheet_sections_path(characters(:nardren))
+ assert_response :success
+ assert_no_match I18n.t("character_sheet_sections.index.add_section"), response.body
+
+ get character_character_sheet_sections_path(characters(:nardren), editable: true)
+ assert_response :success
+ assert_match I18n.t("character_sheet_sections.index.add_section"), response.body
+ end
+end