Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/assets/stylesheets/components/activities.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
color: var(--color-text-secondary);
}

.activity-actions {
margin-top: var(--spacing-2);
}

.activity-tags {
display: flex;
flex-wrap: wrap;
Expand Down
22 changes: 22 additions & 0 deletions app/assets/stylesheets/components/notes.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 19 additions & 2 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -39,12 +39,29 @@ 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"
redirect_back fallback_location: topic_path(@note.topic), alert: "You can edit or delete your own notes"
return
end
end
Expand Down
3 changes: 3 additions & 0 deletions app/views/activities/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions app/views/notes/_note.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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?" } }
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down