From 1d08ab7d9a789b43d21f6ed7c344adb1f6b4817d Mon Sep 17 00:00:00 2001 From: Michael Hulet Date: Sat, 6 Feb 2021 23:03:16 +0100 Subject: [PATCH] Add local_group.active to hide inactive local groups on registration form --- app/models/local_group.rb | 2 ++ app/services/local_groups/create_service.rb | 1 + app/services/local_groups/update_service.rb | 1 + app/views/local_groups/_form.html.slim | 6 ++++++ app/views/local_groups/index.html.slim | 4 +++- app/views/local_groups/show.html.slim | 4 ++++ app/views/public/rebels/new.html.slim | 2 +- app/views/rebels/_form.html.slim | 2 +- .../20210206215324_add_active_to_local_groups.rb | 5 +++++ db/schema.rb | 3 ++- db/seeds.rb | 10 ++++++++-- 11 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20210206215324_add_active_to_local_groups.rb diff --git a/app/models/local_group.rb b/app/models/local_group.rb index c6a9d2f0..cfeecf85 100644 --- a/app/models/local_group.rb +++ b/app/models/local_group.rb @@ -19,6 +19,8 @@ class LocalGroup < ApplicationRecord presence: { message: 'Please provide a name for the local group (eg. Ibiza)' }, uniqueness: { message: 'A local group with this name has been found - Please provide another name' } + scope :active, -> { where(active: true) } + def destroyable_by?(user) user.admin? && !rebels.any? end diff --git a/app/services/local_groups/create_service.rb b/app/services/local_groups/create_service.rb index 545724a1..46d67a80 100644 --- a/app/services/local_groups/create_service.rb +++ b/app/services/local_groups/create_service.rb @@ -33,6 +33,7 @@ def local_group_params(params) params .require(:local_group) .permit( + :active, :email, :mailtrain_list_id, :name diff --git a/app/services/local_groups/update_service.rb b/app/services/local_groups/update_service.rb index 65b69854..b8ab6f18 100644 --- a/app/services/local_groups/update_service.rb +++ b/app/services/local_groups/update_service.rb @@ -51,6 +51,7 @@ def local_group_params(params) params .require(:local_group) .permit( + :active, :email, :mailtrain_list_id, :name diff --git a/app/views/local_groups/_form.html.slim b/app/views/local_groups/_form.html.slim index 481b9cc0..7114a8c9 100644 --- a/app/views/local_groups/_form.html.slim +++ b/app/views/local_groups/_form.html.slim @@ -8,4 +8,10 @@ label: "Email address", placeholder: "Email address" += f.input :active, + as: :boolean, + wrapper: :foundation_checkbox, + label: _("This local group is active"), + required: false + p = _("The Mailtrain list and its custom fields will be created once the local group has been saved.") diff --git a/app/views/local_groups/index.html.slim b/app/views/local_groups/index.html.slim index 50c5d862..45fe6bf3 100644 --- a/app/views/local_groups/index.html.slim +++ b/app/views/local_groups/index.html.slim @@ -21,8 +21,10 @@ table - @local_groups.each do |local_group| tr td - = link_to local_group.name, + => link_to local_group.name, local_group_path(local_group) + - if !local_group.active? + span.orange.label INACTIVE td = mail_to local_group.email, local_group.email diff --git a/app/views/local_groups/show.html.slim b/app/views/local_groups/show.html.slim index 7ce848de..97a55075 100644 --- a/app/views/local_groups/show.html.slim +++ b/app/views/local_groups/show.html.slim @@ -10,6 +10,10 @@ delete_link(@local_group) \ ].compact +- if !@local_group.active? + .warning.callout + | This local group is NOT active. + .grid-x.grid-padding-x .cell.auto p diff --git a/app/views/public/rebels/new.html.slim b/app/views/public/rebels/new.html.slim index e18cbc0b..e85552f7 100644 --- a/app/views/public/rebels/new.html.slim +++ b/app/views/public/rebels/new.html.slim @@ -23,7 +23,7 @@ p = f.input :local_group_id, as: :select, label: "#{_("Local group")} *", - collection: LocalGroup.all.order(:name), + collection: LocalGroup.active.order(:name), prompt: _("Select a local group"), hint: _("No local group (yet) next to you? Please select the one that makes the more sense to you."), required: true diff --git a/app/views/rebels/_form.html.slim b/app/views/rebels/_form.html.slim index 6d8b27e8..a055aba6 100644 --- a/app/views/rebels/_form.html.slim +++ b/app/views/rebels/_form.html.slim @@ -21,7 +21,7 @@ = f.input :local_group_id, as: :select, label: "Local Group *", - collection: LocalGroup.all.order(:name), + collection: LocalGroup.active.order(:name), prompt: "Select a local group", required: false diff --git a/db/migrate/20210206215324_add_active_to_local_groups.rb b/db/migrate/20210206215324_add_active_to_local_groups.rb new file mode 100644 index 00000000..5ee8f957 --- /dev/null +++ b/db/migrate/20210206215324_add_active_to_local_groups.rb @@ -0,0 +1,5 @@ +class AddActiveToLocalGroups < ActiveRecord::Migration[6.0] + def change + add_column :local_groups, :active, :boolean, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index a85a81e6..d5ab652e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_06_11_112214) do +ActiveRecord::Schema.define(version: 2021_02_06_215324) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -139,6 +139,7 @@ t.datetime "updated_at", precision: 6, null: false t.string "email" t.string "mailtrain_list_id" + t.boolean "active", default: true end create_table "rebel_skills", force: :cascade do |t| diff --git a/db/seeds.rb b/db/seeds.rb index f25fcefe..462a9a0d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -13,8 +13,14 @@ if Rebel.none? # Local groups - local_group = LocalGroup.find_or_create_by(name: FFaker::Address.unique.city) - local_group2 = LocalGroup.find_or_create_by(name: FFaker::Address.unique.city) + local_group = LocalGroup.find_or_create_by( + name: FFaker::Address.unique.city, + email: FFaker::Internet.unique.email + ) + local_group2 = LocalGroup.find_or_create_by( + name: FFaker::Address.unique.city, + email: FFaker::Internet.unique.email + ) # Local group coordinators user accounts User.create(