From d087b7db53d07c67ce0b4b3dda27bc88c980f915 Mon Sep 17 00:00:00 2001 From: Kai Wagner Date: Tue, 16 Dec 2025 07:53:06 +0100 Subject: [PATCH 1/2] Add a note delete button - you can now delete notes from within threads and the activity tab Signed-off-by: Kai Wagner --- .../stylesheets/components/activities.css | 4 ++++ app/assets/stylesheets/components/notes.css | 22 +++++++++++++++++++ app/controllers/notes_controller.rb | 19 +++++++++++++++- app/views/activities/index.html.slim | 3 +++ app/views/notes/_note.html.slim | 8 ++++--- config/routes.rb | 2 +- 6 files changed, 53 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/components/activities.css b/app/assets/stylesheets/components/activities.css index 45831cd..a75753c 100644 --- a/app/assets/stylesheets/components/activities.css +++ b/app/assets/stylesheets/components/activities.css @@ -56,6 +56,10 @@ color: var(--color-text-secondary); } +.activity-actions { + margin-top: var(--spacing-2); +} + .activity-tags { display: flex; flex-wrap: wrap; diff --git a/app/assets/stylesheets/components/notes.css b/app/assets/stylesheets/components/notes.css index bd249db..a9c1e1f 100644 --- a/app/assets/stylesheets/components/notes.css +++ b/app/assets/stylesheets/components/notes.css @@ -121,6 +121,28 @@ justify-content: flex-end; } +.note-actions-row { + display: flex; + align-items: center; + gap: var(--spacing-3); + margin-top: var(--spacing-2); +} + +.note-delete-button { + padding: 0; + background: none; + border: none; + color: var(--color-text-link); + font-size: var(--font-size-sm); + font-weight: var(--font-weight-medium); + cursor: pointer; + text-decoration: none; + + &:hover { + text-decoration: underline; + } +} + .notes-inline-add { margin: var(--spacing-3) 0; } diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 7933fb5..1460bca 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -2,7 +2,7 @@ class NotesController < ApplicationController before_action :require_authentication - before_action :set_note, only: [:update] + before_action :set_note, only: [:update, :destroy] def create topic = Topic.find(note_params[:topic_id]) @@ -39,10 +39,27 @@ def update redirect_back fallback_location: topic_path(@note.topic) end + def destroy + return if performed? + + @note.transaction do + @note.update!(deleted_at: Time.current) + @note.note_mentions.delete_all + @note.note_tags.delete_all + @note.activities.update_all(hidden: true) + end + + redirect_back fallback_location: topic_path(@note.topic), notice: "Note deleted" + end + private def set_note @note = Note.find(params[:id]) + if @note.deleted_at? + redirect_back fallback_location: topic_path(@note.topic), alert: "Note has been deleted" + return + end unless @note.author_id == current_user.id redirect_back fallback_location: topic_path(@note.topic), alert: "You can only edit your own notes" return diff --git a/app/views/activities/index.html.slim b/app/views/activities/index.html.slim index 521eebf..3a1f61e 100644 --- a/app/views/activities/index.html.slim +++ b/app/views/activities/index.html.slim @@ -29,6 +29,9 @@ .activity-tags - note.note_tags.each do |tag| span.note-tag ##{tag.tag} + - if current_user.id == note.author_id + .activity-actions + = button_to "Delete note", note_path(note), method: :delete, class: "note-delete-button", form: { data: { turbo_confirm: "Delete this note?" } } - else .activity-body span.activity-missing Content not available anymore. diff --git a/app/views/notes/_note.html.slim b/app/views/notes/_note.html.slim index 4b9d21c..e068dfb 100644 --- a/app/views/notes/_note.html.slim +++ b/app/views/notes/_note.html.slim @@ -19,6 +19,8 @@ span.note-mention = note_mention_label(mention) - if current_user&.id == note.author_id - details.note-edit-toggle - summary Edit - = render "notes/form", note: note, topic: note.topic, message: note.message, submit_text: "Update note" + .note-actions-row + details.note-edit-toggle + summary Edit + = render "notes/form", note: note, topic: note.topic, message: note.message, submit_text: "Update note" + = button_to "Delete", note_path(note), method: :delete, class: "note-delete-button", form: { data: { turbo_confirm: "Delete this note?" } } diff --git a/config/routes.rb b/config/routes.rb index 6d4a7ad..e8ca12f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,7 +35,7 @@ resources :activities, only: [:index] do post :mark_all_read, on: :collection end - resources :notes, only: [:create, :update] + resources :notes, only: [:create, :update, :destroy] # Authentication resource :session, only: [:new, :create, :destroy] From 5c50f83856f17cc0ccdd5fee3e534992b1813a0d Mon Sep 17 00:00:00 2001 From: Kai Wagner Date: Tue, 16 Dec 2025 09:08:21 +0100 Subject: [PATCH 2/2] change error message Signed-off-by: Kai Wagner --- app/controllers/notes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 1460bca..7f79833 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -61,7 +61,7 @@ def set_note return end unless @note.author_id == current_user.id - redirect_back fallback_location: topic_path(@note.topic), alert: "You can only edit your own notes" + redirect_back fallback_location: topic_path(@note.topic), alert: "You can edit or delete your own notes" return end end