Skip to content

Commit fdc0f66

Browse files
committed
Remove unlisted as an option for privacy
This commit updates all tables that include a "privacy" column so that the default is uniformly set to "private". In addition, any existing records that were marked as "unlisted" (or "public") have been updated to "private", since the "unlisted" option is not currently implemented. Below is a summary of the changes made: | Table Name | Previous Default | New Default | |-----------------------------------------|------------------|-------------| | better_together_addresses | unlisted | private | | better_together_communities | public | private | | better_together_content_blocks | unlisted | private | | better_together_email_addresses | unlisted | private | | better_together_pages | public | private | | better_together_people | unlisted | private | | better_together_phone_numbers | unlisted | private | | better_together_platforms | public | private | | better_together_posts | private | private | | better_together_social_media_accounts | public | private | | better_together_website_links | unlisted | private |
1 parent d0ff490 commit fdc0f66

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

app/models/concerns/better_together/privacy.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ module Privacy
77

88
PRIVACY_LEVELS = {
99
public: 'public',
10-
private: 'private',
11-
unlisted: 'unlisted'
10+
private: 'private'
1211
}.freeze
1312

1413
included do
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
# Ensures that all tables with the privacy column default to private and replaces existing 'unlisted' values with 'private'
4+
class SetPrivacyDefaultPrivate < ActiveRecord::Migration[7.1]
5+
def up
6+
ActiveRecord::Base.connection.tables.each do |table|
7+
next unless column_exists?(table, :privacy)
8+
9+
# Replace existing 'unlisted' values with 'private'
10+
execute "UPDATE #{table} SET privacy = 'private' WHERE privacy = 'unlisted'"
11+
12+
privacy_column = ActiveRecord::Base.connection.columns(table).find { |col| col.name == 'privacy' }
13+
next unless privacy_column
14+
next if privacy_column.default == 'private'
15+
16+
say "Changing default privacy for table #{table} from #{privacy_column.default.inspect} to 'private'"
17+
change_column_default table, :privacy, 'private'
18+
end
19+
end
20+
21+
def down
22+
# No reversal defined as reverting the default value change and data update is not supported.
23+
end
24+
end

spec/dummy/db/schema.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.1].define(version: 2025_02_28_154526) do
13+
ActiveRecord::Schema[7.1].define(version: 2025_03_04_142407) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pgcrypto"
1616
enable_extension "plpgsql"
@@ -68,7 +68,7 @@
6868
t.string "state_province_name"
6969
t.string "postal_code"
7070
t.string "country_name"
71-
t.string "privacy", limit: 50, default: "unlisted", null: false
71+
t.string "privacy", limit: 50, default: "private", null: false
7272
t.uuid "contact_detail_id", null: false
7373
t.boolean "primary_flag", default: false, null: false
7474
t.index ["contact_detail_id", "primary_flag"], name: "index_bt_addresses_on_contact_detail_id_and_primary", unique: true, where: "(primary_flag IS TRUE)"
@@ -143,7 +143,7 @@
143143
t.string "identifier", limit: 100, null: false
144144
t.boolean "host", default: false, null: false
145145
t.boolean "protected", default: false, null: false
146-
t.string "privacy", limit: 50, default: "public", null: false
146+
t.string "privacy", limit: 50, default: "private", null: false
147147
t.string "slug"
148148
t.uuid "creator_id"
149149
t.string "type", default: "BetterTogether::Community", null: false
@@ -178,7 +178,7 @@
178178
t.jsonb "media_settings", default: {}, null: false
179179
t.jsonb "content_data", default: {}
180180
t.uuid "creator_id"
181-
t.string "privacy", limit: 50, default: "unlisted", null: false
181+
t.string "privacy", limit: 50, default: "private", null: false
182182
t.boolean "visible", default: true, null: false
183183
t.jsonb "content_area_settings", default: {}, null: false
184184
t.index ["creator_id"], name: "by_better_together_content_blocks_creator"
@@ -233,7 +233,7 @@
233233
t.datetime "updated_at", null: false
234234
t.string "email", null: false
235235
t.string "label", null: false
236-
t.string "privacy", limit: 50, default: "unlisted", null: false
236+
t.string "privacy", limit: 50, default: "private", null: false
237237
t.uuid "contact_detail_id", null: false
238238
t.boolean "primary_flag", default: false, null: false
239239
t.index ["contact_detail_id", "primary_flag"], name: "index_bt_email_addresses_on_contact_detail_id_and_primary", unique: true, where: "(primary_flag IS TRUE)"
@@ -543,7 +543,7 @@
543543
t.text "meta_description"
544544
t.string "keywords"
545545
t.datetime "published_at"
546-
t.string "privacy", default: "public", null: false
546+
t.string "privacy", default: "private", null: false
547547
t.string "layout"
548548
t.string "template"
549549
t.uuid "sidebar_nav_id"
@@ -562,7 +562,7 @@
562562
t.string "slug"
563563
t.uuid "community_id", null: false
564564
t.jsonb "preferences", default: {}, null: false
565-
t.string "privacy", limit: 50, default: "unlisted", null: false
565+
t.string "privacy", limit: 50, default: "private", null: false
566566
t.index ["community_id"], name: "by_person_community"
567567
t.index ["identifier"], name: "index_better_together_people_on_identifier", unique: true
568568
t.index ["privacy"], name: "by_better_together_people_privacy"
@@ -624,7 +624,7 @@
624624
t.datetime "updated_at", null: false
625625
t.string "number", null: false
626626
t.string "label", null: false
627-
t.string "privacy", limit: 50, default: "unlisted", null: false
627+
t.string "privacy", limit: 50, default: "private", null: false
628628
t.uuid "contact_detail_id", null: false
629629
t.boolean "primary_flag", default: false, null: false
630630
t.index ["contact_detail_id", "primary_flag"], name: "index_bt_phone_numbers_on_contact_detail_id_and_primary", unique: true, where: "(primary_flag IS TRUE)"
@@ -672,7 +672,7 @@
672672
t.string "identifier", limit: 100, null: false
673673
t.boolean "host", default: false, null: false
674674
t.boolean "protected", default: false, null: false
675-
t.string "privacy", limit: 50, default: "public", null: false
675+
t.string "privacy", limit: 50, default: "private", null: false
676676
t.string "slug"
677677
t.uuid "community_id"
678678
t.string "url", null: false
@@ -750,7 +750,7 @@
750750
t.string "platform", null: false
751751
t.string "handle", null: false
752752
t.string "url"
753-
t.string "privacy", limit: 50, default: "public", null: false
753+
t.string "privacy", limit: 50, default: "private", null: false
754754
t.uuid "contact_detail_id", null: false
755755
t.index ["contact_detail_id", "platform"], name: "index_bt_sma_on_contact_detail_and_platform", unique: true
756756
t.index ["contact_detail_id"], name: "idx_on_contact_detail_id_6380b64b3b"
@@ -790,7 +790,7 @@
790790
t.datetime "updated_at", null: false
791791
t.string "url", null: false
792792
t.string "label", null: false
793-
t.string "privacy", limit: 50, default: "unlisted", null: false
793+
t.string "privacy", limit: 50, default: "private", null: false
794794
t.uuid "contact_detail_id", null: false
795795
t.index ["contact_detail_id"], name: "index_better_together_website_links_on_contact_detail_id"
796796
t.index ["privacy"], name: "by_better_together_website_links_privacy"

0 commit comments

Comments
 (0)