docbrown/lib/data_update_scripts
Daniel Uber 1a07ad8d9e
Profile attribute names should be unique and non-empty (#16396)
* transliterate when generating attribute names to avoid emptiness

If you enter a non-ascii (non `\w` matching) string as the profile
field label, the attribute name is the empty string.

This causes problems outlined in #16391

To avoid losing user provided data, transliterate (Sterile is the same
tool we're using for Article#title_to_slug) before matching against
the word regex.

If we persist an empty string, or persist a non-`\w` name, the
coordinating regex in Profile::ATTRIBUTE_NAME_REGEX will leave a nil
match and raise NoMethodError (the method missing is for
match[:attribute_name] when match was nil, not Profile - that's the
next commit.

* Guard against nil matches

If an attribute name doesn't match the regex, the match is nil, and
trying to access (nil)[:attribute_name] raises a NoMethodError.

If there was no match, assume profile does not respond to the
selector, and don't handle it in method missing.

* Ensure generated attribute name is valid before saving

This raises a validation error if the generated name (from the label)
would be empty.

It's not an optimal error message (since the user can't see the
internal attribute name) but it prevents persisting broken/empty data

* actually raise error when validating

validate/valid? only return true or false (and set errors on the
object). In order to reject the creation, we need to raise a
validation error, not only call validate. I think this is because the
execution of before_create hooks happens after validation (which is
why the validation was only checked on update, not create).

* Generate an attribute name completely independent of the field label

This prevents mistakenly labeling a field "Class" or "Association" or
one of the other hundred public methods an AR model like Profile
exposes. Since attribute_name will be passed to `profile.public_send`
we really shouldn't build selectors from user supplied inputs.

* Use the admin supplied label in the sidebar

The profile decorator is used in the Users#show page to populate the
sidebar fields. Don't use the attribute name (which we mangled during
creation, and now generate randomly) as the label, use the label.

* Make the label lookup null safe, and filter attributes more

* Update data update script to not expect predictable labels

This is low impact since it ran in july, but we no longer know what
attribute name a label will create.

* Fix moderator spec

"Test Field" label no longer predictably generates :test_field as an
attribute name. Ask the field what it's name is before asking profile
about it.

* Fix profile preview card request spec

Remove the assumption that profile responds to a method name based on
the label for Work and Education fields.

* Update old DUS and its test

This can probably be archived

* Update profile spec to use fields generated attribute names

We used to "know" how attributes were generated from labels. Now we don't.

* update e2e seeds for profile field change

* Don't expect attribute name to be based on the label

* expect created profile fields respond to their attribute name

* Update system test

The label, not the attribute name, is shown on the profile form (the
field has an id related to the attribute name, but the view shows the
mutable/human-readable label).

* Keep the field title lowercase when sending the json preview card

The userMetadata component expects "work" and "education" to be
attributes of the metadata, but the ui_attributes_for() method was
titlizing these (for display).

Ideally we wouldn't have "special purposed" these two field names, but
they're there.

* update profile field by attribute name, not based on label

* Update profile field removal assumptions

We don't know what the method selectors will be, we have to ask.

* remove old test

* Update translations for Education and Work

Since the ui_attributes_for(area:) now gives the label, not the
attribute, we need to match the label of the profile field.

Note to self: this exposes an issue in localizing the custom profile
fields (probably a bigger problem for large, international communities
like DEV than some others, but trying to match static translation
files against user-modifiable database records seems like a problem
we'll see again).

* Empty commit to retrigger buildkite

* Remove profile field migration update scripts

Cloned the specs from the other "remove unused scripts" script.

* Remove unused scripts

The data update script removes the entry from the table (recording
that these have run) - we also want to remove the files (preventing
them from running again).

* remove unneeded spec for removed file

* when translation for header area field not found, use the title

Only Work and Education already have keys in the yml translation file,
and there's not a great (or easy?) way to make multiple translations
on these fields right now.

Since an admin can create a new field, and assign it to the header
area, we can't assume the code has a configured translation key for
this field.

Fallback to the title (we do this in another context already) if
there's no translation.

* PR feedback: Avoid n+1 query for labels

the original implementation of "label_for_attribute" had an n+1 query
looping over each matched key.

Follow suggested improvement and pull labels and attributes at once
from the db and modify the returned hash.

* Downcase title before looking for translation key

This avoids putting "odd" capitalized keys into the yml translation
file

Revert addition of "Work" and "Education" to the users files.

* use a let binding for duplicated test data

* Update app/models/profile_field.rb

prefer SecureRandom.hex for a dashless uuid (instead of removing the dashes).

Co-authored-by: Jamie Gaskins <jgaskins@hey.com>

Co-authored-by: Jamie Gaskins <jgaskins@hey.com>
2022-04-04 12:14:02 -05:00
..
20200226193303_backfill_column_for_broadcasts.rb Run BackfillColumnForBroadcasts only if the column still exists (#6508) 2020-03-09 15:38:34 +01:00
20200305201642_index_feed_content_to_elasticsearch.rb [deploy] Remove Elasticsearch from Index Worker Names (#7594) 2020-04-29 12:12:29 -05:00
20200313123108_index_users_to_elasticsearch.rb [deploy] Remove Elasticsearch from Index Worker Names (#7594) 2020-04-29 12:12:29 -05:00
20200324133751_update_tag_hotness_scores.rb Hotness Score for Tags Should Use Article positive_reactions_count (#6808) [deploy] 2020-03-31 09:04:20 -05:00
20200503134234_remove_github_issues.rb [deploy] Decouple GitHub authentication from fetching GitHub issues (#7660) 2020-05-04 16:17:16 -04:00
20200530085153_backfill_broadcasts_timestamps.rb Add timestamps to broadcasts (#8181) 2020-06-01 18:11:38 +02:00
20200708163323_backfill_broadcastable_for_broadcasts.rb Hotfix: Fix Typo in backfill_broadcastable_type_for_broadcasts (#9292) [deploy] 2020-07-13 10:50:29 -06:00
20200715140848_backfill_user_registered_at.rb [MERGE AFTER INVITATION PR] Add registered_at data script (#9331) 2020-07-27 12:28:06 -04:00
20200723070918_update_articles_cached_entities.rb Rubocop: Move from OpenStruct to Struct in Organization (#9431) 2020-07-30 21:04:05 +07:00
20200810083831_remove_orphaned_ahoy_rows.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200813072205_remove_orphaned_display_ad_events.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200818103028_nullify_orphaned_by_article_html_variant_trials.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200818170410_remove_orphaned_poll_votes.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200818170433_remove_orphaned_poll_skips.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200818170505_remove_orphaned_poll_options.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200818170523_remove_orphaned_polls.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200820153340_insert_facebook_connect_broadcast_message.rb Constantize broadcast messages (#16219) 2022-01-20 11:47:01 -06:00
20200821103125_nullify_orphaned_articles_by_organization.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200821103305_nullify_orphaned_collections_by_organization.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200821103405_remove_orphaned_credits_by_organization.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200821103718_remove_orphaned_display_ads_by_organization.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200821103834_remove_orphaned_listings_by_organization.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200822082229_remove_orphaned_notifications_by_organization.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200822083050_remove_orphaned_sponsorships_by_organization.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200825095512_nullify_orphaned_comments_by_article.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200825102635_remove_orphaned_notification_subscriptions_by_article.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200825102956_remove_orphaned_notifications_by_article.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200825103119_remove_orphaned_profile_pins_by_article.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200825103244_remove_orphaned_rating_votes_by_article.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200826092816_remove_orphaned_notes_by_user.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200826133748_nullify_orphaned_tweets_by_user.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200826140317_remove_orphaned_articles_by_user.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200826140754_remove_orphaned_collections_by_user.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200826140924_remove_orphaned_credits_by_user.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200826141015_remove_orphaned_github_repos_by_user.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200826141105_remove_orphaned_mentions_by_user.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200826141145_remove_orphaned_organization_memberships_by_user.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200826141447_nullify_orphaned_page_views_by_user.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200826141550_nullify_orphaned_rating_votes_by_user.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200826141652_remove_orphaned_reactions_by_user.rb Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
20200901040521_create_profile_fields.rb Profile generalization cleanup phase 2 (#14555) 2021-08-27 09:17:26 +07:00
20200901085230_remove_draft_articles_with_duplicate_canonical_url.rb Abstract DatadogStatsClient to ForemStatsClient (#12304) 2021-01-27 11:25:44 -05:00
20200904141057_cleanup_articles_with_invalid_feed_source_url.rb [deploy] Remove draft articles with duplicate feed source URL and cleanup invalid data: take 2 (#10239) 2020-09-08 11:53:41 -05:00
20200910135958_remove_draft_articles_with_duplicate_user_id_title_body_markdown.rb Bug Fix:Update Remove Draft Articles Scripts to not use Squish (#11445) 2020-11-16 13:20:37 -06:00
20200910140109_cleanup_published_articles_with_duplicate_user_id_title_body_markdown.rb Remove Elasticsearch ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ (#13606) 2021-05-03 11:09:45 -04:00
20200916202343_backfill_co_author_ids_for_articles.rb Removes second_user_id and third_user_id From the Articles Table (#10383) [deploy] 2020-10-02 13:14:32 -06:00
20200917115821_backfill_listing_published_date.rb Showing date in listing tile (#10217) 2020-09-21 10:14:26 +02:00
20200917150808_nullify_orphaned_tags_by_mod_chat_channel_id.rb [deploy] Cleanup orphan data from tags and feedback_messages (#10367) 2020-09-29 10:12:40 -04:00
20200917150838_nullify_orphaned_feedback_messages_by_reporter_id.rb [deploy] Cleanup orphan data from tags and feedback_messages (#10367) 2020-09-29 10:12:40 -04:00
20200922065307_fix_dribbble_url_profile_field.rb [deploy] /profile/settings page rendering (Ridhwana/Michael) (#10733) 2020-10-20 09:18:13 -04:00
20201015190914_update_article_main_image_path.rb [deploy] Store Article's main_image path unprocessed (#10867) 2020-10-16 14:46:37 -04:00
20201019192035_backfill_registered_for_users.rb Data update Script: Backfill Created, but Unregistered Users (#10939) [deploy] 2020-10-20 08:47:11 -06:00
20201022161311_backfill_user_registrations_in_registrations_controller_path.rb Fix missing registration data change (#11008) 2020-10-22 19:21:03 -04:00
20201026155851_resave_to_bust_cache_for_imgproxy.rb Update bust_user to EdgeCache::BustUser (#12051) 2020-12-29 09:53:00 +01:00
20201030015634_make_tags_with_mods_supported.rb Automatically mark tag supported when adding mod (#11151) 2020-10-30 09:46:10 -04:00
20201118141822_gradual_article_cache_bust.rb Rubocop fixes (#11862) 2020-12-11 17:36:42 +03:00
20201120001727_populate_explicit_follow_points.rb Add implicit points to follows to improve feed relevancy (in all algorithms) (#11513) 2020-11-25 16:09:51 -05:00
20201130041949_remove_name_profile_field.rb Drop profile columns from user (#10707) 2020-12-03 08:14:38 +07:00
20201208151516_set_onboarding_profile_fields_for_existing_forems.rb Profile attribute names should be unique and non-empty (#16396) 2022-04-04 12:14:02 -05:00
20201209134953_touch_articles_with_capitalized_paths.rb Ensure Article's username method returns a downcased string (#11813) 2020-12-09 12:56:40 -06:00
20201217162454_cleanup_orphan_git_hub_repositories.rb Remove GitHub repositories when GitHub identity is removed (#11951) 2020-12-20 15:15:40 +01:00
20210107151449_remove_feeds_import_feature_flag.rb Remove RssReader (#12169) 2021-01-08 11:45:15 -05:00
20210114174504_update_user_update_rate_limit_default.rb Create settings model for rate limits (#13381) 2021-04-20 11:29:22 +07:00
20210119060219_make_local_navigation_links_relative.rb Update NavigationLink handling (#12316) 2021-01-20 13:57:59 -05:00
20210119131811_replace_instances_of_banned_and_comment_banned.rb Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
20210209152726_add_fastly_http_purge_feature_flag.rb Fastly edge caching: use PURGE HTTP method instead of POST (#12627) 2021-02-17 13:34:37 -05:00
20210209185037_add_single_resource_role_to_tech_admins.rb Fix erroring data update script (#12628) 2021-02-09 11:16:44 -08:00
20210210124346_add_data_updates_scripts_feature_flag.rb Adds a feature flag for Data Update Scripts (#12641) 2021-02-10 18:22:27 +02:00
20210211164634_fix_profile_field_edge_cases.rb Fix edge cases in profile field UI migration (#12665) 2021-02-11 17:18:46 -05:00
20210329172336_remove_pro_roles.rb Remove pro role from users and database (#13176) 2021-03-31 09:34:10 -07:00
20210405152916_invoke_update_reading_list_document_trigger_on_articles.rb [Search 2.0] Optimize search reading list (#13275) 2021-04-12 16:40:40 +02:00
20210412183428_resave_all_comment_mentioned_messages.rb Rename comment-mentioned-user class added by Html::Parser (#13263) 2021-04-13 14:33:22 -07:00
20210412185444_resave_all_comment_mentioned_comments.rb Rename comment-mentioned-user class added by Html::Parser (#13263) 2021-04-13 14:33:22 -07:00
20210412185449_resave_all_comment_mentioned_articles.rb Rename comment-mentioned-user class added by Html::Parser (#13263) 2021-04-13 14:33:22 -07:00
20210503175027_move_summary_website_url_and_location_to_profile.rb Fix misnamed data update script (#13862) 2021-05-26 15:50:31 -05:00
20210503202046_remove_unused_data_update_scripts.rb Add reaction to articles when seeding the database (#15193) 2021-10-26 10:56:14 -05:00
20210506052235_remove_runtime_banner_feature_flag.rb Remove :runtime_banner feature flag (#13662) 2021-05-28 15:10:15 -06:00
20210512030719_mark_mascot_setting_dus_as_obsolete.rb Remove settings_mascots table (#13737) 2021-05-13 10:03:25 +07:00
20210512032437_remove_settings_data_update_scripts.rb Clean up SiteConfig (#13738) 2021-05-18 09:38:31 +07:00
20210518043957_remove_site_config_scripts.rb [Hotfix] Fix DataUpdateScripts::RemoveSiteConfigScripts script (#13824) 2021-05-21 16:34:21 +02:00
20210604104735_remove_email_addresses_scripts.rb Removing Settings::General.email_addresses (#13958) 2021-06-11 12:34:34 +03:00
20210622145212_backfill_forem_consumer_app_team_id.rb Make Consumer Apps dictate aasa results (#14015) 2021-06-24 08:36:11 -06:00
20210701134702_remove_notification_setting_migration_scripts.rb Use new UserSetting and UserNotificationSettings and Ignore Related User Table Fields (#14121) 2021-07-08 09:31:34 -05:00
20210712054300_remove_unused_profile_fields.rb Remove unused profile fields (#14206) 2021-07-16 09:45:12 -04:00
20210712162220_backfill_section_column_for_navigation_links.rb Static Sections for Site Navigation - Pt1 (#14213) 2021-07-14 11:01:56 -04:00
20210722135549_profile_website_url_format.rb [hotfix] website_url update script should handle parse errors (#14306) 2021-07-22 14:16:43 -05:00
20210722160452_profile_website_url_format_fixup.rb [hotfix] website_url update script should handle parse errors (#14306) 2021-07-22 14:16:43 -05:00
20210803161945_remove_apple_auth_feature_flag.rb Take Apple Authentication out of Beta (#12114) 2021-08-03 15:04:00 -06:00
20210824202334_backfill_creator_role_for_first_super_admin.rb Added the creator role for the first Forem instance admin (#14583) 2021-08-26 13:50:21 -04:00
20210831052422_add_connect_feature_flag.rb Add feature flag for Connect (#14644) 2021-09-13 10:45:56 -04:00
20210921235050_insert_forem_connect_broadcast_message.rb Constantize broadcast messages (#16219) 2022-01-20 11:47:01 -06:00
20210928044418_remove_checkbox_type_from_profile_fields.rb Remove check_box type from profile fields (#14832) 2021-09-30 13:27:39 -04:00
20211019063703_migrate_themes.rb Theme data update script, remove theme choices from UI (#15225) 2021-11-08 08:38:43 -05:00
20211020145958_remove_passport_feature_flag.rb Enable Forem (Passport) Auth (#15141) 2021-11-23 14:59:00 -06:00
20211104200856_update_each_articles_privileged_user_point_count.rb Caching sum privileged reaction scores (#15299) 2021-11-08 12:50:08 -05:00
20211109161231_migrate_themes_again.rb Rerun migrate themes script (#15312) 2021-11-09 10:38:17 -06:00
20211112173720_nullify_empty_tag_colors.rb Nullify invalid tag colors (#15361) 2021-11-12 14:35:08 -06:00
20211115154021_nullify_invalid_tag_fields.rb Revisit previous update script (#15373) 2021-12-09 14:10:59 -06:00
20211117204333_add_feature_flag_for_feed_experiment.rb Configurable weighted feed strategy (#15240) 2021-11-29 10:46:56 -05:00
20211206222716_remove_stackbit_page.rb Removing the stackbit integration (#15701) 2021-12-08 10:20:15 -05:00
20211209213849_remove_dangling_user_reactions.rb Remove reactions to a user when deleting the user (#15724) 2021-12-10 11:24:23 -06:00
20220104165348_nullify_empty_string_for_alias_for.rb Tidying up and documenting Tag model (#15949) 2022-01-07 09:14:31 -05:00
20220105112823_migrate_logo_svg_data.rb Fixing Rubocop's auto-correct recommendations (#16098) 2022-01-13 21:40:19 -05:00
20220107215659_insert_google_ouauth2_connect_broadcast_message.rb Constantize broadcast messages (#16219) 2022-01-20 11:47:01 -06:00
20220111192031_insert_apple_connect_broadcast_message.rb Constantize broadcast messages (#16219) 2022-01-20 11:47:01 -06:00
20220113085122_enable_creator_onboarding_feature_flag.rb Launch creator Onboarding with the Feature Flag [ To merge only on January 17 ] (#16090) 2022-01-17 16:46:38 +02:00
20220121114445_stripping_html_tags_from_tag_short_summary.rb Stripping tags from "tags.short_summary" column (#16248) 2022-01-21 09:38:26 -05:00
20220126102900_create_home_navigation_link.rb Make home link an admin-customisable navigation link (#16268) 2022-02-01 09:27:09 +00:00
20220128150709_add_admin_member_view_feature_flag.rb Add admin_member_view Feature Flag (#16346) 2022-01-28 09:13:35 -07:00
20220201114309_update_home_navigation_link_position.rb Fixes for home nav link positioning (#16381) 2022-02-01 14:06:51 +00:00
20220203143904_remove_logo_svg_from_database.rb Remove Remaining logo_svg Code (#16291) 2022-02-22 12:05:16 -07:00
20220203194510_update_article_flag_without_parsing_article.rb Short-circuiting parsing any articles to update (#16413) 2022-02-04 11:13:01 -05:00
20220214195145_remove_profile_field_update_scripts.rb Profile attribute names should be unique and non-empty (#16396) 2022-04-04 12:14:02 -05:00
20220217144931_remove_detect_animated_images_feature_flag.rb remove detect_animated_images feature flag (#16621) 2022-02-17 15:27:48 +00:00
20220223160059_coerce_identity_auth_data_format.rb Update identities where the auth data dump is a plain hash (#16676) 2022-02-23 14:14:14 -06:00
20220225063600_enable_admin_member_view.rb feat: enable the feature flag across all Forems (#16700) 2022-03-01 10:46:43 -07:00
20220309194124_remove_admin_member_view_feature_flag.rb Remove admin_member_view Feature Flag-Related Conditionals (#16764) 2022-03-10 08:29:05 -07:00
20220317151317_remove_fastly_http_purge_flag.rb Remove fastly http purge feature flag and conditional behavior (#16903) 2022-03-18 09:10:43 -05:00
20220330191441_remove_connect_feature_flag.rb Remove the connect feature flag (#17061) 2022-03-30 14:51:45 -05:00