Files
growstuff/app/views/admin/crops/index.html.haml
google-labs-jules[bot] 460daf36f9 Add revert functionality to admin crops page (#4346)
* feat(admin): add revert functionality to crops page

This change adds a "Revert" button to the admin crops page, allowing crop wranglers to revert changes to a previous version.

It introduces a new `Admin::VersionsController` with a `revert` action that uses `paper_trail`'s `reify` method to restore a previous version of a `Crop` object.

The view is updated to include a "Revert" button, which is guarded by a `can?(:wrangle, Crop)` check to ensure only authorized users can see it.

The controller also includes an authorization check to prevent unauthorized users from accessing the revert action directly.

A feature spec is added to test the new functionality, including the authorization logic.

* Consistent UX

* Specs

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Daniel O'Connor <daniel.oconnor@gmail.com>
2025-11-30 15:05:13 +10:30

57 lines
1.8 KiB
Plaintext

- content_for :title, "Crop Wrangling"
%h1 Crop Wrangling
%nav.nav
= link_to "Full crop hierarchy", hierarchy_crops_path, class: 'nav-link'
= link_to "Add Crop", new_crop_path, class: 'btn'
%section.crop_wranglers
%h2 Crop Wranglers
- @crop_wranglers.each do |crop_wrangler|
= render 'members/tiny', member: crop_wrangler
%hr/
%section
%h2 Crops
%ul#myTab.nav.nav-tabs{role: "tablist"}
%li.nav-item
%a#home-tab.nav-link{ href: admin_crops_path, role: "tab", class: 'active'}
Recently edited
%li.nav-item
%a#home-tab.nav-link{ href: wrangle_crops_path, role: "tab"}
Recently added
%li.nav-item
%a#profile-tab.nav-link{ href: wrangle_crops_path(approval_status: "pending"), role: "tab"}
Pending approval
%li.nav-item
%a#contact-tab.nav-link{ href: wrangle_crops_path(approval_status: "rejected"), role: "tab"}
Rejected
.card
%ul.list-group.list-group-flush
- @versions.each do |version|
- crop = version.item || version.reify
- if crop
%li.list-group-item
.d-flex.w-100.justify-content-between
%h5.mb-1
- if version.event == "destroy"
= crop.name
- else
= link_to crop.name, crop
%small.text-muted= "was #{version.event}d"
.d-inline-block
%small.mr-2= time_ago_in_words(version.created_at) + " ago"
- if can?(:wrangle, Crop)
= link_to "Revert", revert_admin_version_path(version), method: :post, class: "btn btn-sm btn-outline-danger"
- member = @members[version.whodunnit.to_i]
- if member
%p.mb-1
Made by
= link_to member.name, member
= render 'shared/version_changeset', version: version