From fe27da42e42585ea061ec709755d07f9f95f2da4 Mon Sep 17 00:00:00 2001 From: Aaryan <53212802+Aaryanpal@users.noreply.github.com> Date: Sat, 21 Sep 2024 01:22:12 +0530 Subject: [PATCH] 4634 - Add the Delete button on the Partner Group Page (#4649) * Add the Delete button on the Partner Group Page * Replace Destroyed with Deleted * Resolve Comments * Added Request Spec for PartnerGroup and remove corresponding system-spec * Fix lint * fix the request-spec --- app/controllers/partner_groups_controller.rb | 18 +++++++- .../partners/_partner_groups_table.html.erb | 3 +- config/routes.rb | 2 +- spec/requests/partner_group_spec.rb | 46 +++++++++++++++++++ 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 spec/requests/partner_group_spec.rb diff --git a/app/controllers/partner_groups_controller.rb b/app/controllers/partner_groups_controller.rb index f54339d95c..b6ae82dc00 100644 --- a/app/controllers/partner_groups_controller.rb +++ b/app/controllers/partner_groups_controller.rb @@ -1,4 +1,6 @@ class PartnerGroupsController < ApplicationController + before_action :set_partner_group, only: %i[edit destroy] + def new @partner_group = current_organization.partner_groups.new @item_categories = current_organization.item_categories @@ -16,7 +18,6 @@ def create end def edit - @partner_group = current_organization.partner_groups.find(params[:id]) @item_categories = current_organization.item_categories end @@ -30,8 +31,23 @@ def update end end + def destroy + if @partner_group.partners.any? + redirect_to partners_path + "#nav-partner-groups", alert: "Partner Group cannot be deleted." + else + @partner_group.destroy + respond_to do |format| + format.html { redirect_to partners_path + "#nav-partner-groups", notice: "Partner Group was successfully deleted." } + end + end + end + private + def set_partner_group + @partner_group = current_organization.partner_groups.find(params[:id]) + end + def partner_group_params params.require(:partner_group).permit(:name, :send_reminders, :deadline_day, :reminder_day, item_category_ids: []) end diff --git a/app/views/partners/_partner_groups_table.html.erb b/app/views/partners/_partner_groups_table.html.erb index abc7dad2bb..94778851c3 100644 --- a/app/views/partners/_partner_groups_table.html.erb +++ b/app/views/partners/_partner_groups_table.html.erb @@ -52,8 +52,9 @@ No <% end %> -