Make RSS's self-referential link an option (#3428)
* Create migration * Run migration * Update validations * Add additional form * Update RssReader::Assembler#thorough_parsing * Add spec for referential
This commit is contained in:
parent
90f54773dc
commit
28e5ef1d12
7 changed files with 89 additions and 60 deletions
|
|
@ -132,6 +132,7 @@ class User < ApplicationRecord
|
|||
length: { maximum: 500 }
|
||||
validates :inbox_type, inclusion: { in: %w[open private] }
|
||||
validates :currently_streaming_on, inclusion: { in: %w[twitch] }, allow_nil: true
|
||||
validates :feed_referential_link, inclusion: [true, false]
|
||||
validate :conditionally_validate_summary
|
||||
validate :validate_mastodon_url
|
||||
validate :validate_feed_url, if: :feed_url_changed?
|
||||
|
|
|
|||
|
|
@ -48,64 +48,67 @@ class UserPolicy < ApplicationPolicy
|
|||
end
|
||||
|
||||
def permitted_attributes
|
||||
%i[available_for
|
||||
behance_url
|
||||
bg_color_hex
|
||||
config_theme
|
||||
config_font
|
||||
contact_consent
|
||||
currently_hacking_on
|
||||
currently_learning
|
||||
display_sponsors
|
||||
dribbble_url
|
||||
education
|
||||
email
|
||||
email_badge_notifications
|
||||
email_comment_notifications
|
||||
email_digest_periodic
|
||||
email_follower_notifications
|
||||
email_membership_newsletter
|
||||
email_tag_mod_newsletter
|
||||
email_community_mod_newsletter
|
||||
email_mention_notifications
|
||||
email_connect_messages
|
||||
email_newsletter
|
||||
email_public
|
||||
editor_version
|
||||
email_unread_notifications
|
||||
mobile_comment_notifications
|
||||
employer_name
|
||||
employer_url
|
||||
employment_title
|
||||
experience_level
|
||||
facebook_url
|
||||
feed_admin_publish_permission
|
||||
feed_mark_canonical
|
||||
feed_url
|
||||
gitlab_url
|
||||
inbox_guidelines
|
||||
instagram_url
|
||||
linkedin_url
|
||||
location
|
||||
looking_for_work
|
||||
looking_for_work_publicly
|
||||
mastodon_url
|
||||
medium_url
|
||||
mostly_work_with
|
||||
name
|
||||
inbox_type
|
||||
permit_adjacent_sponsors
|
||||
password
|
||||
password_confirmation
|
||||
profile_image
|
||||
stackoverflow_url
|
||||
summary
|
||||
text_color_hex
|
||||
twitch_url
|
||||
twitch_username
|
||||
username
|
||||
website_url
|
||||
export_requested]
|
||||
%i[
|
||||
available_for
|
||||
behance_url
|
||||
bg_color_hex
|
||||
config_font
|
||||
config_theme
|
||||
contact_consent
|
||||
currently_hacking_on
|
||||
currently_learning
|
||||
display_sponsors
|
||||
dribbble_url
|
||||
editor_version
|
||||
education
|
||||
email
|
||||
email_badge_notifications
|
||||
email_comment_notifications
|
||||
email_community_mod_newsletter
|
||||
email_connect_messages
|
||||
email_digest_periodic
|
||||
email_follower_notifications
|
||||
email_membership_newsletter
|
||||
email_mention_notifications
|
||||
email_newsletter
|
||||
email_public
|
||||
email_tag_mod_newsletter
|
||||
email_unread_notifications
|
||||
employer_name
|
||||
employer_url
|
||||
employment_title
|
||||
experience_level
|
||||
export_requested
|
||||
facebook_url
|
||||
feed_admin_publish_permission
|
||||
feed_mark_canonical
|
||||
feed_referential_link
|
||||
feed_url
|
||||
gitlab_url
|
||||
inbox_guidelines
|
||||
inbox_type
|
||||
instagram_url
|
||||
linkedin_url
|
||||
location
|
||||
looking_for_work
|
||||
looking_for_work_publicly
|
||||
mastodon_url
|
||||
medium_url
|
||||
mobile_comment_notifications
|
||||
mostly_work_with
|
||||
name
|
||||
password
|
||||
password_confirmation
|
||||
permit_adjacent_sponsors
|
||||
profile_image
|
||||
stackoverflow_url
|
||||
summary
|
||||
text_color_hex
|
||||
twitch_url
|
||||
twitch_username
|
||||
username
|
||||
website_url
|
||||
]
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class RssReader
|
|||
|
||||
def thorough_parsing(content, feed_url)
|
||||
html_doc = Nokogiri::HTML(content)
|
||||
find_and_replace_possible_links!(html_doc)
|
||||
find_and_replace_possible_links!(html_doc) if @user.feed_referential_link
|
||||
if feed_url.include?("medium.com")
|
||||
parse_and_translate_gist_iframe!(html_doc)
|
||||
parse_and_translate_youtube_iframe!(html_doc)
|
||||
|
|
|
|||
|
|
@ -47,6 +47,14 @@
|
|||
If you check this box, the post will automatically mark the feed source as the canonical URL.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sub-field">
|
||||
<%= f.check_box :feed_referential_link %>
|
||||
<%= f.label :feed_referential_link, "Replace self-referential links with DEV-specific links" %>
|
||||
<div class="field-explainer">
|
||||
If you check this box, the post will automatically change any URLs included in the post to refer to the version of that article on DEV if available. This is primarily meant for folks migrating their entire blog onto DEV.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label></label>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
class AddFeedReferentialLinkToUsers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :users, :feed_referential_link, :boolean, null: false, default: true
|
||||
end
|
||||
end
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2019_07_04_105143) do
|
||||
ActiveRecord::Schema.define(version: 2019_07_09_192214) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
|
@ -963,6 +963,7 @@ ActiveRecord::Schema.define(version: 2019_07_04_105143) do
|
|||
t.boolean "feed_admin_publish_permission", default: true
|
||||
t.datetime "feed_fetched_at", default: "2017-01-01 05:00:00"
|
||||
t.boolean "feed_mark_canonical", default: false
|
||||
t.boolean "feed_referential_link", default: true, null: false
|
||||
t.string "feed_url"
|
||||
t.integer "following_orgs_count", default: 0, null: false
|
||||
t.integer "following_tags_count", default: 0, null: false
|
||||
|
|
|
|||
|
|
@ -73,6 +73,17 @@ RSpec.describe RssReader, vcr: vcr_option do
|
|||
end
|
||||
end
|
||||
|
||||
context "when feed_referential_link is false" do
|
||||
it "does not self-reference links for user" do
|
||||
# Article.find_by is used by find_and_replace_possible_links!
|
||||
# checking it's invocation s a shortcut to testing the functionality.
|
||||
allow(Article).to receive(:find_by).and_call_original
|
||||
create(:user, feed_url: nonpermanent_link, feed_referential_link: false)
|
||||
described_class.get_all_articles
|
||||
expect(Article).not_to have_received(:find_by)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#fetch_user" do
|
||||
before do
|
||||
[link, nonmedium_link, nonpermanent_link].each do |feed_url|
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue