diff --git a/app/controllers/space/agreements_controller.rb b/app/controllers/space/agreements_controller.rb index 847609110..870d34e49 100644 --- a/app/controllers/space/agreements_controller.rb +++ b/app/controllers/space/agreements_controller.rb @@ -15,6 +15,11 @@ def create end end + def destroy + agreement.destroy + redirect_to space.location(:edit), notice: t(".success", name: agreement.name) + end + helper_method def agreement @agreement ||= if params[:id] policy_scope(space.agreements).friendly.find(params[:id]) diff --git a/app/lib/space_routes.rb b/app/lib/space_routes.rb index 261009898..1da5316ee 100644 --- a/app/lib/space_routes.rb +++ b/app/lib/space_routes.rb @@ -1,6 +1,6 @@ module SpaceRoutes def self.append_routes(router) - router.resources :agreements, only: %i[show new create], controller: "space/agreements" + router.resources :agreements, only: %i[show new create destroy], controller: "space/agreements" router.resource :authenticated_session, only: %i[new create update destroy show] router.resources :invitations, only: %i[create destroy index] do router.resource :rsvp, only: %i[show update] diff --git a/app/policies/space/agreement_policy.rb b/app/policies/space/agreement_policy.rb index e6ee311e1..532d4b506 100644 --- a/app/policies/space/agreement_policy.rb +++ b/app/policies/space/agreement_policy.rb @@ -10,6 +10,8 @@ def create? person&.operator? || person&.member_of?(agreement.space) end + alias_method :destroy?, :create? + def permitted_attributes(_) %i[name body] end diff --git a/app/views/spaces/edit.html.erb b/app/views/spaces/edit.html.erb index 789e1bda2..07927aef0 100644 --- a/app/views/spaces/edit.html.erb +++ b/app/views/spaces/edit.html.erb @@ -76,19 +76,28 @@
<%= link_to t('utilities.new.link_to'), space.location(:new, child: :utility) %>
-<%= render CardComponent.new do %> +<%= render CardComponent.new(classes: "mt-3 gap-y-3") do %><%= t('space.agreements.help_text') %>