Skip to content

Commit

Permalink
Add local_group.active to hide inactive local groups on registration …
Browse files Browse the repository at this point in the history
…form
  • Loading branch information
mhulet committed Feb 6, 2021
1 parent 04d1a78 commit 1d08ab7
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/models/local_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class LocalGroup < ApplicationRecord
presence: { message: 'Please provide a name for the local group (eg. <em>Ibiza</em>)' },
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
Expand Down
1 change: 1 addition & 0 deletions app/services/local_groups/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def local_group_params(params)
params
.require(:local_group)
.permit(
:active,
:email,
:mailtrain_list_id,
:name
Expand Down
1 change: 1 addition & 0 deletions app/services/local_groups/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def local_group_params(params)
params
.require(:local_group)
.permit(
:active,
:email,
:mailtrain_list_id,
:name
Expand Down
6 changes: 6 additions & 0 deletions app/views/local_groups/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
4 changes: 3 additions & 1 deletion app/views/local_groups/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/views/local_groups/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/public/rebels/new.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/rebels/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20210206215324_add_active_to_local_groups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddActiveToLocalGroups < ActiveRecord::Migration[6.0]
def change
add_column :local_groups, :active, :boolean, default: true
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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|
Expand Down
10 changes: 8 additions & 2 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1d08ab7

Please sign in to comment.