Skip to content
Open
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
3 changes: 2 additions & 1 deletion app/assets/stylesheets/pages/projects/_show.scss
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,8 @@ turbo-frame#project_hero {
// Destructive action (Unfollow / Delete). Per branding §4.1 destructive uses
// salmon (`--color-brand-salmon`) — transparent + salmon-bordered when
// resting, salmon-filled on hover so the destructive intent is unambiguous.
.project-show__pill--following {
.project-show__pill--following,
.project-show__pill--destructive {
border-color: var(--color-brand-salmon);
color: var(--color-brand-salmon);

Expand Down
29 changes: 28 additions & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,34 @@ def soft_delete!(force: false)
errors.add(:base, "Cannot delete a project that has been shipped")
raise ActiveRecord::RecordInvalid.new(self)
end
update!(deleted_at: Time.current)

transaction do
now = Time.current
update!(deleted_at: now)

devlogs.find_each { |d| d.update_columns(deleted_at: now) }

Post::Repost.unscoped.where(original_post_id: posts.pluck(:id)).find_each do |repost|
repost.update_columns(deleted_at: now)
end
end
end

def restore!
transaction do
deleted_at_was = deleted_at
update!(deleted_at: nil)

Post::Devlog.unscoped.where(deleted_at: deleted_at_was)
.where(id: posts.of_devlogs.pluck(:postable_id))
.update_all(deleted_at: nil)

repost_ids = Post::Repost.unscoped.where(deleted_at: deleted_at_was)
.where(original_post_id: posts.pluck(:id))
.pluck(:id)

Post::Repost.unscoped.where(id: repost_ids).update_all(deleted_at: nil)
end
end

def shipped?
Expand Down
9 changes: 9 additions & 0 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@
# Only highlight the unfinished sections when the user arrived via the
# "Complete project info" button (which adds ?complete=1).
highlight_incomplete_fields = (can_edit_project && params[:complete].present?) ? @project.incomplete_info_fields : []
can_delete_project = policy(@project).destroy? && (!@project.shipped? || policy(@project).force_destroy?)
%>

<div class="app-layout" data-controller="profile-modal">
<div class="app-layout__main">
<%= turbo_frame_tag "project_hero" do %>
<% if can_edit_project && (params[:editing].present? || @project.errors.any?) %>
<% if can_delete_project %>
<%= form_with(url: project_path(@project), method: :delete, id: "delete-project-form", style: "display: none;", data: { turbo: true }) do %>
<% end %>
<% end %>

<%= form_with(model: @project,
url: project_path(@project),
method: :patch,
Expand Down Expand Up @@ -271,6 +277,9 @@
<% if @project.fire? %>
<span class="project-show__badge project-show__badge--fire">⭐ Super Star Project</span>
<% end %>
<% if can_delete_project %>
<button type="submit" form="delete-project-form" class="project-show__pill project-show__pill--destructive">Delete project</button>
<% end %>
<%= link_to "Discard changes", project_path(@project), class: "project-show__pill project-show__pill--outline", data: { turbo_frame: "project_hero" } %>
<%= form.submit "Save", class: "project-show__pill project-show__pill--save", data: { "project-form-target": "submit" } %>
</div>
Expand Down