Skip to content

A platform for community discussion. Free, open, simple.

UX: Redesign the RSS Polling admin interface (#40790)

Régis Hanol4fc11445219f
diff --git a/db/structure.sql b/db/structure.sql
index b7c90cbf8ca..9dae54d3f02 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -4129,6 +4129,44 @@ CREATE SEQUENCE public.discourse_reactions_reactions_id_seq
ALTER SEQUENCE public.discourse_reactions_reactions_id_seq OWNED BY public.discourse_reactions_reactions.id;
+--
+-- Name: discourse_rss_polling_poll_attempts; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE public.discourse_rss_polling_poll_attempts (
+ id bigint NOT NULL,
+ rss_feed_id bigint NOT NULL,
+ status integer DEFAULT 0 NOT NULL,
+ imported_count integer DEFAULT 0 NOT NULL,
+ updated_count integer DEFAULT 0 NOT NULL,
+ skipped_count integer DEFAULT 0 NOT NULL,
+ failed_count integer DEFAULT 0 NOT NULL,
+ error text,
+ items jsonb DEFAULT '[]'::jsonb NOT NULL,
+ created_at timestamp(6) without time zone NOT NULL,
+ updated_at timestamp(6) without time zone NOT NULL
+);
+
+
+--
+-- Name: discourse_rss_polling_poll_attempts_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE public.discourse_rss_polling_poll_attempts_id_seq
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+
+--
+-- Name: discourse_rss_polling_poll_attempts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE public.discourse_rss_polling_poll_attempts_id_seq OWNED BY public.discourse_rss_polling_poll_attempts.id;
+
+
--
-- Name: discourse_rss_polling_rss_feeds; Type: TABLE; Schema: public; Owner: -
--
@@ -4142,7 +4180,8 @@ CREATE TABLE public.discourse_rss_polling_rss_feeds (
tags character varying,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
- user_id bigint
+ user_id bigint,
+ enabled boolean DEFAULT true NOT NULL
);
@@ -12782,6 +12821,13 @@ ALTER TABLE ONLY public.discourse_reactions_reaction_users ALTER COLUMN id SET D
ALTER TABLE ONLY public.discourse_reactions_reactions ALTER COLUMN id SET DEFAULT nextval('public.discourse_reactions_reactions_id_seq'::regclass);
+--
+-- Name: discourse_rss_polling_poll_attempts id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.discourse_rss_polling_poll_attempts ALTER COLUMN id SET DEFAULT nextval('public.discourse_rss_polling_poll_attempts_id_seq'::regclass);
+
+
--
-- Name: discourse_rss_polling_rss_feeds id; Type: DEFAULT; Schema: public; Owner: -
--
@@ -15075,6 +15121,14 @@ ALTER TABLE ONLY public.discourse_reactions_reactions
ADD CONSTRAINT discourse_reactions_reactions_pkey PRIMARY KEY (id);
+--
+-- Name: discourse_rss_polling_poll_attempts discourse_rss_polling_poll_attempts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.discourse_rss_polling_poll_attempts
+ ADD CONSTRAINT discourse_rss_polling_poll_attempts_pkey PRIMARY KEY (id);
+
+
--
-- Name: discourse_rss_polling_rss_feeds discourse_rss_polling_rss_feeds_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@@ -17435,6 +17489,13 @@ CREATE INDEX idx_posts_user_id_deleted_at ON public.posts USING btree (user_id)
CREATE INDEX idx_reviewables_score_desc_created_at_desc ON public.reviewables USING btree (score DESC, created_at DESC);
+--
+-- Name: idx_rss_polling_poll_attempts_on_feed_created_id_desc; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE INDEX idx_rss_polling_poll_attempts_on_feed_created_id_desc ON public.discourse_rss_polling_poll_attempts USING btree (rss_feed_id, created_at DESC, id DESC);
+
+
--
-- Name: idx_search_category; Type: INDEX; Schema: public; Owner: -
--
@@ -22362,6 +22423,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20260622201006'),
('20260622201005'),
('20260622140747'),
+('20260619085855'),
('20260617180115'),
('20260617104005'),
('20260617053237'),
@@ -22369,6 +22431,8 @@ INSERT INTO "schema_migrations" (version) VALUES
('20260615084100'),
('20260615082047'),
('20260612092612'),
+('20260612064730'),
+('20260611102547'),
('20260610205840'),
('20260610075829'),
('20260610064425'),
diff --git a/frontend/discourse/app/lib/url.js b/frontend/discourse/app/lib/url.js
index 5889d0a5aa3..132d8ff4362 100644
--- a/frontend/discourse/app/lib/url.js
+++ b/frontend/discourse/app/lib/url.js
@@ -577,6 +577,20 @@ export function prefixProtocol(url) {
return `https://${url}`;
}
+export function isHttpUrl(value) {
+ const trimmed = value?.trim();
+ if (!trimmed) {
+ return false;
+ }
+
+ try {
+ const { protocol } = new URL(trimmed);
+ return protocol === "http:" || protocol === "https:";
+ } catch {
+ return false;
+ }
+}
+
export function getCategoryAndTagUrl(category, subcategories, tag) {
let url;
diff --git a/frontend/discourse/tests/unit/lib/url-test.js b/frontend/discourse/tests/unit/lib/url-test.js
index 5bab2bf969b..8789ada1054 100644
--- a/frontend/discourse/tests/unit/lib/url-test.js
+++ b/frontend/discourse/tests/unit/lib/url-test.js
@@ -5,6 +5,7 @@ import { setPrefix } from "discourse/lib/get-url";
import DiscourseURL, {
getCanonicalUrl,
getCategoryAndTagUrl,
+ isHttpUrl,
prefixProtocol,
userPath,
} from "discourse/lib/url";
@@ -225,6 +226,20 @@ module("Unit | Utility | url", function (hooks) {
assert.strictEqual(prefixProtocol("#anchor-fragment"), "#anchor-fragment");
});
+ test("isHttpUrl", function (assert) {
+ assert.true(isHttpUrl("http://www.discourse.org"));
+ assert.true(isHttpUrl("https://www.discourse.org"));
+ assert.true(isHttpUrl(" https://www.discourse.org "));
+
+ assert.false(isHttpUrl("ftp://www.discourse.org"));
+ assert.false(isHttpUrl("mailto:[email protected]"));
+ assert.false(isHttpUrl("www.discourse.org"));
+ assert.false(isHttpUrl("not a url"));
+ assert.false(isHttpUrl(""));
+ assert.false(isHttpUrl(null));
+ assert.false(isHttpUrl(undefined));
+ });
+
test("getCategoryAndTagUrl", function (assert) {
const cat = { path: "/c/foo/1", default_list_filter: "all" };
const noneCat = { path: "/c/foo/1", default_list_filter: "none" };
diff --git a/plugins/discourse-rss-polling/admin/assets/javascripts/admin/models/rss-polling-feed-settings.js b/plugins/discourse-rss-polling/admin/assets/javascripts/admin/models/rss-polling-feed-settings.js
new file mode 100644
index 00000000000..c620631da79
--- /dev/null
+++ b/plugins/discourse-rss-polling/admin/assets/javascripts/admin/models/rss-polling-feed-settings.js
@@ -0,0 +1,65 @@
+import { ajax } from "discourse/lib/ajax";
+
+export default {
+ show() {
+ return ajax("/admin/plugins/rss_polling/feed_settings.json");
+ },
+
+ find(id) {
+ return ajax(`/admin/plugins/rss_polling/feed_settings/${id}.json`);
+ },
+
+ updateFeed(feedSetting) {
+ return ajax("/admin/plugins/rss_polling/feed_settings", {
+ type: "PUT",
+ contentType: "application/json",
+ processData: false,
+ data: JSON.stringify({ feed_setting: feedSetting }),
+ });
+ },
+
+ deleteFeed(feedSetting) {
+ return ajax(`/admin/plugins/rss_polling/feed_settings/${feedSetting.id}`, {
+ type: "DELETE",
+ });
+ },
+
+ setEnabled(feedSetting, enabled) {
+ return ajax(
+ `/admin/plugins/rss_polling/feed_settings/${feedSetting.id}/enabled`,
+ {
+ type: "PUT",
+ data: { enabled },
+ }
+ );
+ },
+
+ history(id) {
+ return ajax(`/admin/plugins/rss_polling/feed_settings/${id}/history.json`);
+ },
+
+ pollNow(id) {
+ return ajax(`/admin/plugins/rss_polling/feed_settings/${id}/poll`, {
+ type: "POST",
+ });
+ },
+
+ testFeed(feedSetting) {
+ return ajax("/admin/plugins/rss_polling/feed_settings/test", {
+ type: "POST",
+ data: {
+ feed_url: feedSetting.feed_url,
+ feed_category_filter: feedSetting.feed_category_filter,
+ },
+ });
+ },
+
+ categoryRequirements(categoryId) {
+ return ajax(
+ "/admin/plugins/rss_polling/feed_settings/category_requirements",
+ {
+ data: { category_id: categoryId },
+ }
+ );
+ },
+};
diff --git a/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/components/rss-polling-feed-form.gjs b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/components/rss-polling-feed-form.gjs
new file mode 100644
index 00000000000..0e2eb71f14c
--- /dev/null
+++ b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/components/rss-polling-feed-form.gjs
@@ -0,0 +1,467 @@
+import Component from "@glimmer/component";
+import { cached, tracked } from "@glimmer/tracking";
+import { fn, hash } from "@ember/helper";
+import { on } from "@ember/modifier";
+import { action } from "@ember/object";
+import { service } from "@ember/service";
+import AdminConfigAreaCard from "discourse/admin/components/admin-config-area-card";
+import Form from "discourse/components/form";
+import DButtonTooltip from "discourse/float-kit/components/d-button-tooltip";
+import DTooltip from "discourse/float-kit/components/d-tooltip";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+import { isHttpUrl } from "discourse/lib/url";
+import CategoryChooser from "discourse/select-kit/components/category-chooser";
+import TagChooser from "discourse/select-kit/components/tag-chooser";
+import UserChooser from "discourse/select-kit/components/user-chooser";
+import { not, or } from "discourse/truth-helpers";
+import DButton from "discourse/ui-kit/d-button";
+import DToggleSwitch from "discourse/ui-kit/d-toggle-switch";
+import dDiscourseTag from "discourse/ui-kit/helpers/d-discourse-tag";
+import { i18n } from "discourse-i18n";
+import RssPollingFeedItemList from "discourse/plugins/discourse-rss-polling/discourse/components/rss-polling-feed-item-list";
+import {
+ errorMessage,
+ FeedEnabledToggle,
+ previewSummary,
+} from "discourse/plugins/discourse-rss-polling/discourse/lib/rss-polling-item";
+import RssPollingFeedSettings from "../../admin/models/rss-polling-feed-settings";
+
+export default class RssPollingFeedForm extends Component {
+ @service dialog;
+ @service router;
+ @service toasts;
+
+ @tracked polling = false;
+ @tracked submitting = false;
+ @tracked dirty = false;
+ @tracked testing = false;
+ @tracked testResults = null;
+ @tracked testTotal = 0;
+ @tracked testError = null;
+ @tracked categoryRequirements = [];
+ #requirementsLoaded = Promise.resolve();
+
+ constructor() {
+ super(...arguments);
+ this.feedToggle = new FeedEnabledToggle(this.args.feed, this.toasts);
+ this.loadCategoryRequirements(this.args.feed?.discourse_category_id);
+ }
+
+ get isEditing() {
+ return !!this.args.feed;
+ }
+
+ @cached
+ get requiredTagNames() {
+ return [
+ ...new Set(this.categoryRequirements.flatMap((group) => group.tags)),
+ ];
+ }
+
+ get header() {
+ return this.isEditing
+ ? "admin.rss_polling.feeds.edit_header"
+ : "admin.rss_polling.feeds.add_header";
+ }
+
+ get formData() {
+ const feed = this.args.feed;
+
+ if (!feed) {
+ return {};
+ }
+
+ return {
+ feed_url: feed.feed_url,
+ feed_category_filter: feed.feed_category_filter,
+ author_username: feed.author ? [feed.author.username] : [],
+ discourse_category_id: feed.discourse_category_id,
+ discourse_tags: feed.discourse_tags,
+ };
+ }
+
+ get testErrorMessage() {
+ return errorMessage(this.testError);
+ }
+
+ get previewCounts() {
+ return previewSummary(this.testResults);
+ }
+
+ @action
+ dismissTest() {
+ this.testResults = null;
+ this.testError = null;
+ }
+
+ @action
+ markDirty() {
+ this.dirty = true;
+ }
+
+ get pollNowTitle() {
+ if (this.dirty) {
+ return "admin.rss_polling.history.poll_now_dirty";
+ }
+
+ if (!this.feedToggle.enabled) {
+ return "admin.rss_polling.history.poll_now_disabled";
+ }
+
+ return null;
+ }
+
+ @action
+ pollNow() {
+ this.dialog.confirm({
+ message: i18n("admin.rss_polling.history.poll_confirm"),
+ didConfirm: async () => {
+ this.polling = true;
+
+ try {
+ await RssPollingFeedSettings.pollNow(this.args.feed.id);
+ this.toasts.success({
+ duration: "short",
+ data: { message: i18n("admin.rss_polling.history.poll_started") },
+ });
+ } catch (error) {
+ popupAjaxError(error);
+ } finally {
+ this.polling = false;
+ }
+ },
+ });
+ }
+
+ loadCategoryRequirements(categoryId) {
+ this.#requirementsLoaded = (async () => {
+ if (!categoryId) {
+ this.categoryRequirements = [];
+ return;
+ }
+
+ try {
+ const result =
+ await RssPollingFeedSettings.categoryRequirements(categoryId);
+ this.categoryRequirements = result.required_tag_groups ?? [];
+ } catch {
+ this.categoryRequirements = [];
+ }
+ })();
+
+ return this.#requirementsLoaded;
+ }
+
+ @action
+ categoryChanged(field, categoryId) {
+ field.set(categoryId);
+ this.loadCategoryRequirements(categoryId);
+ }
+
+ @action
+ async validateForm(data, { addError }) {
+ await this.#requirementsLoaded;
+
+ if (data.feed_url && !isHttpUrl(data.feed_url)) {
+ addError("feed_url", {
+ title: i18n("admin.rss_polling.feed_url"),
+ message: i18n("admin.rss_polling.feed_url_must_be_http"),
+ });
+ }
+
+ const feedTags = data.discourse_tags ?? [];
+
+ this.categoryRequirements.forEach((group) => {
+ const matched = group.tags.filter((tag) => feedTags.includes(tag)).length;
+ if (matched < group.min_count) {
+ addError("discourse_tags", {
+ title: i18n("admin.rss_polling.discourse_tags"),
+ message: i18n("admin.rss_polling.required_tag_error", {
+ count: group.min_count,
+ tag_group: group.tag_group,
+ }),
+ });
+ }
+ });
+ }
+
+ @action
+ async save(data) {
+ this.submitting = true;
+
+ try {
+ const result = await RssPollingFeedSettings.updateFeed({
+ id: this.args.feed?.id,
+ feed_url: data.feed_url,
+ feed_category_filter: data.feed_category_filter,
+ author_username: data.author_username?.[0],
+ discourse_category_id: data.discourse_category_id,
+ discourse_tags: data.discourse_tags,
+ });
+
+ this.toasts.success({
+ duration: "short",
+ data: { message: i18n("admin.rss_polling.feeds.save_success") },
+ });
+
+ this.dismissTest();
+ this.dirty = false;
+
+ if (!this.isEditing) {
+ this.router.transitionTo(
+ "adminPlugins.show.discourse-rss-polling-feeds.edit",
+ result.id
+ );
+ }
+ } catch (error) {
+ popupAjaxError(error);
+ } finally {
+ this.submitting = false;
+ }
+ }
+
+ @action
+ async testFeed(data) {
+ this.testing = true;
+ this.testError = null;
+ this.testResults = null;
+
+ try {
+ const result = await RssPollingFeedSettings.testFeed(data);
+
+ this.testTotal = result.total;
+ this.testResults = result.items;
+ } catch (error) {
+ const key = error?.jqXHR?.responseJSON?.error;
+ if (key) {
+ this.testError = key;
+ } else {
+ popupAjaxError(error);
+ }
+ } finally {
+ this.testing = false;
+ }
+ }
+
+ <template>
+ <AdminConfigAreaCard @heading={{this.header}} class="rss-polling-feed-form">
+ <:headerAction>
+ {{#if this.isEditing}}
+ <div class="rss-polling-feed-form__enabled-control">
+ <DToggleSwitch
+ @state={{this.feedToggle.enabled}}
+ aria-label={{if
+ this.feedToggle.enabled
+ (i18n "admin.rss_polling.feeds.disable")
+ (i18n "admin.rss_polling.feeds.enable")
+ }}
+ class="rss-polling-feed-form__toggle"
+ {{on "click" this.feedToggle.toggle}}
+ />
+ <span
+ class="rss-polling-feed-form__enabled"
+ title={{unless
+ this.feedToggle.enabled
+ (i18n "admin.rss_polling.status.disabled_note")
+ }}
+ >
+ {{if
+ this.feedToggle.enabled
+ (i18n "admin.rss_polling.status.enabled")
+ (i18n "admin.rss_polling.status.disabled")
+ }}
+ </span>
+ </div>
+ {{/if}}
+ </:headerAction>
+ <:content>
+ <Form
+ @onSubmit={{this.save}}
+ @validate={{this.validateForm}}
+ @onSet={{this.markDirty}}
+ @data={{this.formData}}
+ as |form transientData|
+ >
+ <form.Fieldset @title={{i18n "admin.rss_polling.feed_settings"}}>
+ <form.Field
+ @name="feed_url"
+ @title={{i18n "admin.rss_polling.feed_url"}}
+ @validation="required"
+ @format="full"
+ @type="input-url"
+ as |field|
+ >
+ <field.Control placeholder="https://blog.example.com/feed" />
+ </form.Field>
+
+ <form.Field
+ @name="feed_category_filter"
+ @title={{i18n "admin.rss_polling.feed_category_filter"}}
+ @description={{i18n
+ "admin.rss_polling.feed_category_filter_description"
+ }}
+ @format="full"
+ @type="input"
+ as |field|
+ >
+ <field.Control />
+ </form.Field>
+ </form.Fieldset>
+
+ <form.Fieldset @title={{i18n "admin.rss_polling.discourse_settings"}}>
+ <div class="rss-polling-feed-form__discourse-fields">
+ <form.Field
+ @name="author_username"
+ @title={{i18n "admin.rss_polling.author"}}
+ @validation="required"
+ @format="full"
+ @type="custom"
+ as |field|
+ >
+ <field.Control>
+ <UserChooser
+ @value={{field.value}}
+ @onChange={{field.set}}
+ @options={{hash maximum=1 excludeCurrentUser=false}}
+ class="rss-polling-feed-form__author"
+ />
+ </field.Control>
+ </form.Field>
+
+ <form.Field
+ @name="discourse_category_id"
+ @title={{i18n "admin.rss_polling.discourse_category"}}
+ @format="full"
+ @type="custom"
+ as |field|
+ >
+ <field.Control>
+ <CategoryChooser
+ @value={{field.value}}
+ @onChange={{fn this.categoryChanged field}}
+ class="rss-polling-feed-form__category"
+ />
+ </field.Control>
+ </form.Field>
+
+ <form.Field
+ @name="discourse_tags"
+ @title={{i18n "admin.rss_polling.discourse_tags"}}
+ @format="full"
+ @type="custom"
+ as |field|
+ >
+ <field.Control>
+ <TagChooser
+ @tags={{field.value}}
+ @allowCreate={{false}}
+ @everyTag={{true}}
+ @unlimitedTagCount={{true}}
+ @onChange={{field.set}}
+ class="rss-polling-feed-form__tags"
+ />
+ </field.Control>
+ {{#if this.requiredTagNames.length}}
+ <div class="rss-polling-feed-form__tag-requirement">
+ <span>{{i18n "admin.rss_polling.required_tags_hint"}}</span>
+ {{#each this.requiredTagNames as |tag|}}
+ {{dDiscourseTag tag}}
+ {{/each}}
+ </div>
+ {{/if}}
+ </form.Field>
+ </div>
+ </form.Fieldset>
+
+ <div class="rss-polling-feed-form__buttons">
+ <DButton
+ @icon="check"
+ @label="admin.rss_polling.feeds.save"
+ @isLoading={{this.submitting}}
+ type="submit"
+ class="btn-primary form-kit__button rss-polling-feed-form__save"
+ />
+ <DButton
+ @action={{fn this.testFeed transientData}}
+ @icon="paper-plane"
+ @label="admin.rss_polling.test.button"
+ @isLoading={{this.testing}}
+ class="btn-default rss-polling-feed-form__test"
+ />
+
+ {{#if this.isEditing}}
+ <DButtonTooltip>
+ <:button>
+ <DButton
+ @action={{this.pollNow}}
+ @icon="arrows-rotate"
+ @label="admin.rss_polling.history.poll_now"
+ @isLoading={{this.polling}}
+ @disabled={{or
+ this.dirty
+ this.testing
+ (not this.feedToggle.enabled)
+ }}
+ class="btn-default rss-polling-feed-form__poll"
+ />
+ </:button>
+ <:tooltip>
+ {{#if this.pollNowTitle}}
+ <DTooltip
+ @icon="circle-info"
+ @content={{i18n this.pollNowTitle}}
+ />
+ {{/if}}
+ </:tooltip>
+ </DButtonTooltip>
+ {{/if}}
+ </div>
+ </Form>
+
+ {{#if this.testError}}
+ <div class="alert alert-error rss-polling-feed-test__error">
+ <span>{{this.testErrorMessage}}</span>
+ <DButton
+ @action={{this.dismissTest}}
+ @icon="xmark"
+ @title="admin.rss_polling.test.dismiss"
+ class="btn-flat btn-small rss-polling-feed-test__dismiss"
+ />
+ </div>
+ {{else if this.testResults}}
+ <div class="rss-polling-feed-test">
+ <div class="rss-polling-feed-test__header">
+ <h3 class="rss-polling-feed-test__title">
+ {{i18n "admin.rss_polling.test.title"}}
+ </h3>
+ {{#if this.previewCounts}}
+ <span class="rss-polling-feed-test__count">
+ {{this.previewCounts}}
+ </span>
+ {{/if}}
+ <DButton
+ @action={{this.dismissTest}}
+ @icon="xmark"
+ @label="admin.rss_polling.test.dismiss"
+ class="btn-flat btn-small rss-polling-feed-test__dismiss"
+ />
+ </div>
+
+ {{#if this.testResults.length}}
+ <div class="rss-polling-feed-test__panel">
+ <RssPollingFeedItemList
+ @items={{this.testResults}}
+ @total={{this.testTotal}}
+ />
+ </div>
+ {{else}}
+ <p class="rss-polling-feed-test__empty">
+ {{i18n "admin.rss_polling.test.empty"}}
+ </p>
+ {{/if}}
+ </div>
+ {{/if}}
+ </:content>
+ </AdminConfigAreaCard>
+ </template>
+}
diff --git a/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/components/rss-polling-feed-history.gjs b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/components/rss-polling-feed-history.gjs
new file mode 100644
index 00000000000..76aa8c5db5e
--- /dev/null
+++ b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/components/rss-polling-feed-history.gjs
@@ -0,0 +1,176 @@
+import Component from "@glimmer/component";
+import { cached, tracked } from "@glimmer/tracking";
+import { fn } from "@ember/helper";
+import { action } from "@ember/object";
+import { service } from "@ember/service";
+import AdminConfigAreaCard from "discourse/admin/components/admin-config-area-card";
+import { eq } from "discourse/truth-helpers";
+import DButton from "discourse/ui-kit/d-button";
+import dFormatDate from "discourse/ui-kit/helpers/d-format-date";
+import { i18n } from "discourse-i18n";
+import RssPollingFeedItemList from "discourse/plugins/discourse-rss-polling/discourse/components/rss-polling-feed-item-list";
+import {
+ errorMessage,
+ pollSummary,
+} from "discourse/plugins/discourse-rss-polling/discourse/lib/rss-polling-item";
+
+const VISIBLE_LIMIT = 10;
+const KEEP_LIMIT = 20;
+
+export default class RssPollingFeedHistory extends Component {
+ @service messageBus;
+
+ @tracked openId = null;
+ @tracked showAll = false;
+ @tracked rawAttempts;
+
+ constructor() {
+ super(...arguments);
+ this.rawAttempts = this.args.model.poll_attempts ?? [];
+ this.messageBus.subscribe(
+ this.channel,
+ this.onAttempt,
+ this.args.model.last_message_id
+ );
+ }
+
+ willDestroy() {
+ super.willDestroy(...arguments);
+ this.messageBus.unsubscribe(this.channel, this.onAttempt);
+ }
+
+ get channel() {
+ return `/rss-polling/feeds/${this.args.model.id}`;
+ }
+
+ @action
+ onAttempt(attempt) {
+ if (this.rawAttempts.some((existing) => existing.id === attempt.id)) {
+ return;
+ }
+
+ this.rawAttempts = [attempt, ...this.rawAttempts].slice(0, KEEP_LIMIT);
+ }
+
+ @cached
+ get attempts() {
+ return this.rawAttempts.map((attempt) => ({
+ id: attempt.id,
+ createdAt: attempt.created_at,
+ summary: pollSummary(attempt),
+ danger: attempt.status === "error",
+ items: attempt.items ?? [],
+ total:
+ attempt.imported_count +
+ attempt.updated_count +
+ attempt.skipped_count +
+ attempt.failed_count,
+ errorText: errorMessage(attempt.error),
+ }));
+ }
+
+ get visibleAttempts() {
+ return this.showAll ? this.attempts : this.attempts.slice(0, VISIBLE_LIMIT);
+ }
+
+ get hasMore() {
+ return !this.showAll && this.attempts.length > VISIBLE_LIMIT;
+ }
+
+ get showOlderLabel() {
+ return i18n("admin.rss_polling.history.show_older", {
+ count: this.attempts.length - VISIBLE_LIMIT,
+ });
+ }
+
+ @action
+ toggle(id) {
+ this.openId = this.openId === id ? null : id;
+ }
+
+ @action
+ showOlder() {
+ this.showAll = true;
+ }
+
+ <template>
+ <AdminConfigAreaCard
+ @heading="admin.rss_polling.history.recent"
+ class="rss-polling-feed-history"
+ >
+ <:content>
+ {{#if this.attempts.length}}
+ <table class="d-table rss-polling-feed-history__table">
+ <tbody class="d-table__body">
+ {{#each this.visibleAttempts as |attempt|}}
+ <tr
+ class="d-table__row rss-polling-feed-history__attempt
+ {{if attempt.danger '--danger'}}"
+ >
+ <td class="d-table__cell --overview">
+ <DButton
+ @action={{fn this.toggle attempt.id}}
+ @icon={{if
+ (eq this.openId attempt.id)
+ "angle-down"
+ "angle-right"
+ }}
+ @ariaExpanded={{eq this.openId attempt.id}}
+ @ariaLabel={{attempt.summary}}
+ @translatedLabel={{attempt.summary}}
+ class="btn-flat rss-polling-feed-history__summary"
+ >
+ <span class="rss-polling-feed-history__date">
+ {{dFormatDate attempt.createdAt}}
+ </span>
+ </DButton>
+ </td>
+ <td class="d-table__cell --detail">
+ <span class="rss-polling-feed-history__counts">
+ {{attempt.summary}}
+ </span>
+ </td>
+ </tr>
+
+ {{#if (eq this.openId attempt.id)}}
+ <tr class="d-table__row rss-polling-feed-history__detail">
+ <td class="d-table__cell" colspan="2">
+ {{#if attempt.errorText}}
+ <div class="alert alert-error">
+ {{attempt.errorText}}
+ </div>
+ {{/if}}
+
+ {{#if attempt.items.length}}
+ <RssPollingFeedItemList
+ @items={{attempt.items}}
+ @total={{attempt.total}}
+ />
+ {{else}}
+ <p class="rss-polling-feed-history__empty">
+ {{i18n "admin.rss_polling.history.no_items"}}
+ </p>
+ {{/if}}
+ </td>
+ </tr>
+ {{/if}}
+ {{/each}}
+ </tbody>
+ </table>
+
+ {{#if this.hasMore}}
+ <DButton
+ @action={{this.showOlder}}
+ @translatedLabel={{this.showOlderLabel}}
+ class="btn-flat rss-polling-feed-history__more"
+ />
+ {{/if}}
+ {{else}}
+ <p class="rss-polling-feed-history__empty">
+ {{i18n "admin.rss_polling.history.empty"}}
+ </p>
+ {{/if}}
+ </:content>
+ </AdminConfigAreaCard>
+ </template>
+}
diff --git a/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/components/rss-polling-feed-item-list.gjs b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/components/rss-polling-feed-item-list.gjs
new file mode 100644
index 00000000000..84ef0d38d37
--- /dev/null
+++ b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/components/rss-polling-feed-item-list.gjs
@@ -0,0 +1,70 @@
+import Component from "@glimmer/component";
+import { cached } from "@glimmer/tracking";
+import { isHttpUrl } from "discourse/lib/url";
+import dFormatDate from "discourse/ui-kit/helpers/d-format-date";
+import { i18n } from "discourse-i18n";
+import {
+ itemNote,
+ STATUS_MODIFIERS,
+} from "discourse/plugins/discourse-rss-polling/discourse/lib/rss-polling-item";
+
+export default class RssPollingFeedItemList extends Component {
+ @cached
+ get items() {
+ return (this.args.items ?? []).map((item) => ({
+ modifier: STATUS_MODIFIERS[item.status] ?? "--skip",
+ label: item.title || item.url,
+ url: isHttpUrl(item.url) ? item.url : null,
+ publishedAt: item.published_at,
+ note: itemNote(item),
+ }));
+ }
+
+ get truncated() {
+ return this.args.total != null && this.args.total > this.items.length;
+ }
+
+ <template>
+ <ul class="rss-polling-feed-test__list">
+ {{#each this.items as |item|}}
+ <li class="rss-polling-feed-test__item {{item.modifier}}">
+ <div class="rss-polling-feed-test__body">
+ {{#if item.url}}
+ <a
+ class="rss-polling-feed-test__item-title"
+ href={{item.url}}
+ target="_blank"
+ rel="noopener noreferrer"
+ >
+ {{item.label}}
+ </a>
+ {{else}}
+ <span class="rss-polling-feed-test__item-title">
+ {{item.label}}
+ </span>
+ {{/if}}
+ {{#if item.publishedAt}}
+ <span class="rss-polling-feed-test__item-date">
+ {{dFormatDate item.publishedAt}}
+ </span>
+ {{/if}}
+ {{#if item.note}}
+ <span class="rss-polling-feed-test__item-reason">
+ {{item.note}}
+ </span>
+ {{/if}}
+ </div>
+ </li>
+ {{/each}}
+ </ul>
+ {{#if this.truncated}}
+ <p class="rss-polling-feed-test__more">
+ {{i18n
+ "admin.rss_polling.showing"
+ count=this.items.length
+ total=@total
+ }}
+ </p>
+ {{/if}}
+ </template>
+}
diff --git a/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/components/rss-polling-feed-row.gjs b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/components/rss-polling-feed-row.gjs
new file mode 100644
index 00000000000..2524f5ef4d4
--- /dev/null
+++ b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/components/rss-polling-feed-row.gjs
@@ -0,0 +1,151 @@
+import Component from "@glimmer/component";
+import { cached } from "@glimmer/tracking";
+import { on } from "@ember/modifier";
+import { action } from "@ember/object";
+import { LinkTo } from "@ember/routing";
+import { service } from "@ember/service";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+import Category from "discourse/models/category";
+import DButton from "discourse/ui-kit/d-button";
+import DToggleSwitch from "discourse/ui-kit/d-toggle-switch";
+import DUserAvatar from "discourse/ui-kit/d-user-avatar";
+import DUserLink from "discourse/ui-kit/d-user-link";
+import dCategoryBadge from "discourse/ui-kit/helpers/d-category-badge";
+import dDiscourseTag from "discourse/ui-kit/helpers/d-discourse-tag";
+import icon from "discourse/ui-kit/helpers/d-icon";
+import { i18n } from "discourse-i18n";
+import { FeedEnabledToggle } from "discourse/plugins/discourse-rss-polling/discourse/lib/rss-polling-item";
+import RssPollingFeedSettings from "../../admin/models/rss-polling-feed-settings";
+
+export default class RssPollingFeedRow extends Component {
+ @service dialog;
+ @service toasts;
+
+ constructor() {
+ super(...arguments);
+ this.feedToggle = new FeedEnabledToggle(this.args.feed, this.toasts);
+ }
+
+ @cached
+ get category() {
+ if (!this.args.feed.discourse_category_id) {
+ return null;
+ }
+
+ return Category.findById(this.args.feed.discourse_category_id);
+ }
+
+ @action
+ delete() {
+ this.dialog.deleteConfirm({
+ message: i18n("admin.rss_polling.feeds.confirm_delete"),
+ didConfirm: async () => {
+ try {
+ await RssPollingFeedSettings.deleteFeed(this.args.feed);
+ this.args.deleteFeed(this.args.feed);
+ this.toasts.success({
+ duration: "short",
+ data: { message: i18n("admin.rss_polling.feeds.delete_success") },
+ });
+ } catch (error) {
+ popupAjaxError(error);
+ }
+ },
+ });
+ }
+
+ <template>
+ <tr
+ class="d-table__row rss-polling-feed
+ {{unless this.feedToggle.enabled 'is-disabled'}}"
+ >
+ <td class="d-table__cell --overview">
+ <LinkTo
+ class="d-table__overview-link"
+ @route="adminPlugins.show.discourse-rss-polling-feeds.edit"
+ @model={{@feed.id}}
+ >
+ <span
+ class="d-table__overview-name rss-polling-feed__url"
+ >{{@feed.redacted_feed_url}}</span>
+ </LinkTo>
+
+ <div class="rss-polling-feed__meta">
+ <span class="rss-polling-feed__author">
+ <span class="d-table__mobile-label">{{i18n
+ "admin.rss_polling.author"
+ }}</span>
+ <DUserAvatar @user={{@feed.author}} @size="small" />
+ <DUserLink
+ @user={{@feed.author}}
+ >{{@feed.author.username}}</DUserLink>
+ </span>
+ {{#if this.category}}
+ <span class="rss-polling-feed__category">
+ <span class="d-table__mobile-label">{{i18n
+ "admin.rss_polling.discourse_category"
+ }}</span>
+ {{dCategoryBadge this.category link=true}}
+ </span>
+ {{/if}}
+ {{#if @feed.discourse_tags.length}}
+ <span class="rss-polling-feed__tags">
+ <span class="d-table__mobile-label">{{i18n
+ "admin.rss_polling.discourse_tags"
+ }}</span>
+ {{#each @feed.discourse_tags as |tag|}}
+ {{dDiscourseTag tag}}
+ {{/each}}
+ </span>
+ {{/if}}
+ {{#if @feed.feed_category_filter}}
+ <span
+ class="rss-polling-feed__filter"
+ title={{i18n "admin.rss_polling.feed_category_filter"}}
+ >
+ <span class="d-table__mobile-label">{{i18n
+ "admin.rss_polling.feed_category_filter"
+ }}</span>
+ {{icon "filter"}}
+ {{@feed.feed_category_filter}}
+ </span>
+ {{/if}}
+ </div>
+ </td>
+ <td class="d-table__cell rss-polling-feed__status">
+ <DToggleSwitch
+ @state={{this.feedToggle.enabled}}
+ aria-label={{if
+ this.feedToggle.enabled
+ (i18n "admin.rss_polling.feeds.disable")
+ (i18n "admin.rss_polling.feeds.enable")
+ }}
+ class="rss-polling-feed__toggle"
+ {{on "click" this.feedToggle.toggle}}
+ />
+ <span class="d-table__mobile-label">{{if
+ this.feedToggle.enabled
+ (i18n "admin.rss_polling.status.enabled")
+ (i18n "admin.rss_polling.status.disabled")
+ }}</span>
+ </td>
+ <td class="d-table__cell --controls">
+ <div class="d-table__cell-actions">
+ <DButton
+ @route="adminPlugins.show.discourse-rss-polling-feeds.edit"
+ @routeModels={{@feed.id}}
+ @icon="pencil"
+ @title="admin.rss_polling.feeds.edit"
+ class="btn-default btn-small rss-polling-feed__edit"
+ />
+ <DButton
+ @action={{this.delete}}
+ @icon="trash-can"
+ @title="admin.rss_polling.feeds.delete"
+ class="btn-danger btn-small rss-polling-feed__delete"
+ />
+ </div>
+ </td>
+ </tr>
+ </template>
+}
diff --git a/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/controllers/admin-plugins/show/discourse-rss-polling-feeds/index.js b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/controllers/admin-plugins/show/discourse-rss-polling-feeds/index.js
new file mode 100644
index 00000000000..53dbcc83926
--- /dev/null
+++ b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/controllers/admin-plugins/show/discourse-rss-polling-feeds/index.js
@@ -0,0 +1,14 @@
+import Controller from "@ember/controller";
+import { action } from "@ember/object";
+import { removeValueFromArray } from "discourse/lib/array-tools";
+
+export default class AdminPluginsShowDiscourseRssPollingFeedsIndexController extends Controller {
+ get feeds() {
+ return this.model;
+ }
+
+ @action
+ deleteFeed(feed) {
+ removeValueFromArray(this.model, feed);
+ }
+}
diff --git a/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/lib/rss-polling-item.js b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/lib/rss-polling-item.js
new file mode 100644
index 00000000000..f043ab68cec
--- /dev/null
+++ b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/lib/rss-polling-item.js
@@ -0,0 +1,157 @@
+import { tracked } from "@glimmer/tracking";
+import { trustHTML } from "@ember/template";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+import { escapeExpression } from "discourse/lib/utilities";
+import { i18n } from "discourse-i18n";
+import RssPollingFeedSettings from "../../admin/models/rss-polling-feed-settings";
+
+async function setFeedEnabled(feed, enabled, toasts) {
+ await RssPollingFeedSettings.setEnabled(feed, enabled);
+ feed.enabled = enabled;
+ toasts.success({
+ duration: "short",
+ data: {
+ message: i18n(
+ enabled
+ ? "admin.rss_polling.feeds.enable_success"
+ : "admin.rss_polling.feeds.disable_success"
+ ),
+ },
+ });
+}
+
+export class FeedEnabledToggle {
+ @tracked optimisticEnabled = null;
+
+ toggle = async () => {
+ if (this.optimisticEnabled !== null) {
+ return;
+ }
+
+ const enabled = !this.enabled;
+ this.optimisticEnabled = enabled;
+
+ try {
+ await setFeedEnabled(this.feed, enabled, this.toasts);
+ } catch (error) {
+ popupAjaxError(error);
+ } finally {
+ this.optimisticEnabled = null;
+ }
+ };
+
+ constructor(feed, toasts) {
+ this.feed = feed;
+ this.toasts = toasts;
+ }
+
+ get enabled() {
+ return this.optimisticEnabled ?? this.feed?.enabled;
+ }
+}
+
+export const STATUS_MODIFIERS = {
+ would_import: "--import",
+ imported: "--import",
+ already_imported: "--update",
+ updated: "--update",
+ skipped: "--skip",
+ failed: "--skip",
+};
+
+export function errorMessage(error) {
+ return error ? i18n(`admin.rss_polling.test.errors.${error}`) : null;
+}
+
+export function pollSummary(attempt) {
+ const parts = ["imported", "updated", "skipped", "failed"]
+ .filter((name) => attempt[`${name}_count`] > 0)
+ .map((name) =>
+ i18n(`admin.rss_polling.history.${name}_count`, {
+ count: attempt[`${name}_count`],
+ })
+ );
+
+ if (parts.length) {
+ return parts.join(" · ");
+ }
+
+ return attempt.error
+ ? errorMessage(attempt.error)
+ : i18n("admin.rss_polling.history.no_changes");
+}
+
+export function previewSummary(items) {
+ const tally = (items ?? []).reduce((acc, item) => {
+ acc[item.status] = (acc[item.status] ?? 0) + 1;
+ return acc;
+ }, {});
+
+ return ["would_import", "already_imported", "skipped"]
+ .filter((status) => tally[status])
+ .map((status) =>
+ i18n(`admin.rss_polling.test.summary.${status}`, { count: tally[status] })
+ )
+ .join(" · ");
+}
+
+export function itemNote(item) {
+ switch (item.status) {
+ case "would_import":
+ return i18n("admin.rss_polling.test.would_import");
+ case "already_imported":
+ return topicNote(item, "admin.rss_polling.test.already_imported");
+ case "imported":
+ return topicNote(item, "admin.rss_polling.history.imported");
+ case "updated":
+ return topicNote(item, "admin.rss_polling.history.updated");
+ case "failed":
+ return failReason(item);
+ case "skipped":
+ return skipReason(item);
+ default:
+ return null;
+ }
+}
+
+function failReason(item) {
+ if (!item.reason) {
+ return i18n("admin.rss_polling.history.failed");
+ }
+
+ if (item.reason === "import_rejected") {
+ return i18n("admin.rss_polling.history.failed_reasons.import_rejected");
+ }
+
+ return i18n("admin.rss_polling.history.failed_reasons.import_error", {
+ error: item.reason,
+ });
+}
+
+function topicNote(item, messageKey) {
+ if (!item.topic_url) {
+ return i18n(`${messageKey}_plain`);
+ }
+
+ return trustHTML(
+ i18n(messageKey, { topic_url: escapeExpression(item.topic_url) })
+ );
+}
+
+function skipReason(item) {
+ if (!item.reason) {
+ return null;
+ }
+
+ if (item.reason === "category_filter_mismatch") {
+ return item.categories?.length
+ ? i18n("admin.rss_polling.test.skip_reasons.category_filter_mismatch", {
+ categories: item.categories.join(", "),
+ })
+ : i18n(
+ "admin.rss_polling.test.skip_reasons.category_filter_mismatch_none"
+ );
+ }
+
+ return i18n(`admin.rss_polling.test.skip_reasons.${item.reason}`);
+}
diff --git a/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-rss-polling-feeds/edit.js b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-rss-polling-feeds/edit.js
new file mode 100644
index 00000000000..fb319d29fa6
--- /dev/null
+++ b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-rss-polling-feeds/edit.js
@@ -0,0 +1,29 @@
+import { service } from "@ember/service";
+import DiscourseRoute from "discourse/routes/discourse";
+import { i18n } from "discourse-i18n";
+import RssPollingFeedSettings from "../../../../../admin/models/rss-polling-feed-settings";
+
+export default class AdminPluginsShowDiscourseRssPollingFeedsEditRoute extends DiscourseRoute {
+ @service router;
+
+ async model(params) {
+ const id = parseInt(params.id, 10);
+ const feedRequest = RssPollingFeedSettings.find(id);
+ const historyRequest = RssPollingFeedSettings.history(id);
+
+ let feed;
+ try {
+ feed = await feedRequest;
+ } catch {
+ historyRequest.catch(() => {});
+ this.router.replaceWith("adminPlugins.show.discourse-rss-polling-feeds");
+ return;
+ }
+
+ return { feed, history: await historyRequest };
+ }
+
+ titleToken() {
+ return i18n("admin.rss_polling.feeds.edit_header");
+ }
+}
diff --git a/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-rss-polling-feeds/index.js b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-rss-polling-feeds/index.js
new file mode 100644
index 00000000000..61e6b276ab4
--- /dev/null
+++ b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-rss-polling-feeds/index.js
@@ -0,0 +1,26 @@
+import { trackedArray } from "@ember/reactive/collections";
+import Category from "discourse/models/category";
+import DiscourseRoute from "discourse/routes/discourse";
+import { i18n } from "discourse-i18n";
+import RssPollingFeedSettings from "../../../../../admin/models/rss-polling-feed-settings";
+
+export default class AdminPluginsShowDiscourseRssPollingFeedsIndexRoute extends DiscourseRoute {
+ async model() {
+ const result = await RssPollingFeedSettings.show();
+
+ const categoryIds = [
+ ...new Set(
+ result.feed_settings
+ .map((feed) => feed.discourse_category_id)
+ .filter(Boolean)
+ ),
+ ];
+ await Category.asyncFindByIds(categoryIds);
+
+ return trackedArray(result.feed_settings);
+ }
+
+ titleToken() {
+ return i18n("admin.rss_polling.feeds.title");
+ }
+}
diff --git a/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-rss-polling-feeds/new.js b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-rss-polling-feeds/new.js
new file mode 100644
index 00000000000..84c675d6251
--- /dev/null
+++ b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-rss-polling-feeds/new.js
@@ -0,0 +1,8 @@
+import DiscourseRoute from "discourse/routes/discourse";
+import { i18n } from "discourse-i18n";
+
+export default class AdminPluginsShowDiscourseRssPollingFeedsNewRoute extends DiscourseRoute {
+ titleToken() {
+ return i18n("admin.rss_polling.feeds.add");
+ }
+}
diff --git a/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-rss-polling-feeds/edit.gjs b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-rss-polling-feeds/edit.gjs
new file mode 100644
index 00000000000..673ce1285c5
--- /dev/null
+++ b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-rss-polling-feeds/edit.gjs
@@ -0,0 +1,14 @@
+import BackButton from "discourse/components/back-button";
+import RssPollingFeedForm from "discourse/plugins/discourse-rss-polling/discourse/components/rss-polling-feed-form";
+import RssPollingFeedHistory from "discourse/plugins/discourse-rss-polling/discourse/components/rss-polling-feed-history";
+
+export default <template>
+ <BackButton
+ @route="adminPlugins.show.discourse-rss-polling-feeds"
+ @label="admin.rss_polling.feeds.back"
+ />
+ <div class="rss-polling-feed-editor">
+ <RssPollingFeedForm @feed={{@controller.model.feed}} />
+ <RssPollingFeedHistory @model={{@controller.model.history}} />
+ </div>
+</template>
diff --git a/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-rss-polling-feeds/index.gjs b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-rss-polling-feeds/index.gjs
new file mode 100644
index 00000000000..e3688203cd9
--- /dev/null
+++ b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-rss-polling-feeds/index.gjs
@@ -0,0 +1,51 @@
+import AdminConfigAreaEmptyList from "discourse/admin/components/admin-config-area-empty-list";
+import DBreadcrumbsItem from "discourse/ui-kit/d-breadcrumbs-item";
+import DPageSubheader from "discourse/ui-kit/d-page-subheader";
+import { i18n } from "discourse-i18n";
+import RssPollingFeedRow from "discourse/plugins/discourse-rss-polling/discourse/components/rss-polling-feed-row";
+
+export default <template>
+ <DBreadcrumbsItem
+ @path="/admin/plugins/discourse-rss-polling/feeds"
+ @label={{i18n "admin.rss_polling.feeds.title"}}
+ />
+
+ <section class="admin-detail">
+ <DPageSubheader
+ @titleLabel={{i18n "admin.rss_polling.feeds.title"}}
+ @descriptionLabel={{i18n "admin.rss_polling.feeds.description"}}
+ >
+ <:actions as |actions|>
+ {{#if @controller.feeds.length}}
+ <actions.Primary
+ @route="adminPlugins.show.discourse-rss-polling-feeds.new"
+ @icon="plus"
+ @label="admin.rss_polling.feeds.add"
+ @title="admin.rss_polling.feeds.add"
+ class="rss-polling-feeds__add"
+ />
+ {{/if}}
+ </:actions>
+ </DPageSubheader>
+
+ {{#if @controller.feeds.length}}
+ <table class="d-table rss-polling-feeds">
+ <tbody class="d-table__body">
+ {{#each @controller.feeds as |feed|}}
+ <RssPollingFeedRow
+ @feed={{feed}}
+ @deleteFeed={{@controller.deleteFeed}}
+ />
+ {{/each}}
+ </tbody>
+ </table>
+ {{else}}
+ <AdminConfigAreaEmptyList
+ @emptyLabel="admin.rss_polling.feeds.empty"
+ @ctaLabel="admin.rss_polling.feeds.add"
+ @ctaRoute="adminPlugins.show.discourse-rss-polling-feeds.new"
+ @ctaClass="rss-polling-feeds__add"
+ />
+ {{/if}}
+ </section>
+</template>
diff --git a/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-rss-polling-feeds/new.gjs b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-rss-polling-feeds/new.gjs
new file mode 100644
index 00000000000..a7fe6d7e2b0
--- /dev/null
+++ b/plugins/discourse-rss-polling/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-rss-polling-feeds/new.gjs
@@ -0,0 +1,12 @@
+import BackButton from "discourse/components/back-button";
+import RssPollingFeedForm from "discourse/plugins/discourse-rss-polling/discourse/components/rss-polling-feed-form";
+
+export default <template>
+ <BackButton
+ @route="adminPlugins.show.discourse-rss-polling-feeds"
+ @label="admin.rss_polling.feeds.back"
+ />
+ <div class="rss-polling-feed-editor">
+ <RssPollingFeedForm />
+ </div>
+</template>
diff --git a/plugins/discourse-rss-polling/app/controllers/discourse_rss_polling/feed_settings_controller.rb b/plugins/discourse-rss-polling/app/controllers/discourse_rss_polling/feed_settings_controller.rb
index 2191b71c4bf..6df67741c2a 100644
--- a/plugins/discourse-rss-polling/app/controllers/discourse_rss_polling/feed_settings_controller.rb
+++ b/plugins/discourse-rss-polling/app/controllers/discourse_rss_polling/feed_settings_controller.rb
@@ -5,7 +5,7 @@ module DiscourseRssPolling
requires_plugin "discourse-rss-polling"
def show
- feeds = RssFeed.includes(:user)
+ feeds = RssFeed.includes(:user).order(:url)
render json:
ActiveModel::ArraySerializer.new(
feeds,
@@ -14,9 +14,16 @@ module DiscourseRssPolling
).to_json
end
+ alias_method :index, :show
+
+ def feed
+ rss_feed = RssFeed.includes(:user).find_by(id: params[:id]) || raise(Discourse::NotFound)
+ render json: FeedSettingSerializer.new(rss_feed, include_url: true, root: false)
+ end
+
def update
- FeedSetting::Update.call(params: params[:feed_setting]) do
- on_success { render json: { success: true } }
+ RssFeed::Update.call(params: params[:feed_setting], guardian:) do
+ on_success { |rss_feed:| render json: { success: true, id: rss_feed.id } }
on_failed_contract do |contract|
render json: {
success: false,
@@ -36,6 +43,7 @@ module DiscourseRssPolling
},
status: :unprocessable_entity
end
+ on_model_not_found(:rss_feed) { raise Discourse::NotFound }
on_model_errors(:rss_feed) do |rss_feed|
render json: {
success: false,
@@ -47,15 +55,62 @@ module DiscourseRssPolling
end
end
+ def test
+ RssFeed::Test.call(**service_params) do
+ on_success do |preview:, fetched:|
+ render json: { items: preview || [], total: fetched.items.size }
+ end
+ on_failed_contract { render json: { error: :blank_feed_url }, status: :bad_request }
+ on_failed_step(:fetch) do |step|
+ render json: { error: step.error }, status: :unprocessable_entity
+ end
+ on_exceptions do |exception|
+ Discourse.warn_exception(exception, message: "RSS Polling: failed to test feed")
+ render json: { error: :unknown }, status: :unprocessable_entity
+ end
+ end
+ end
+
+ def history
+ rss_feed = RssFeed.find_by(id: params[:id]) || raise(Discourse::NotFound)
+
+ last_message_id = MessageBus.last_id(PollAttempt.message_bus_channel(rss_feed.id))
+ attempts = rss_feed.poll_attempts.recent.limit(PollAttempt::KEEP_PER_FEED)
+
+ render json: {
+ id: rss_feed.id,
+ feed_url: rss_feed.url,
+ poll_attempts: serialize_data(attempts, PollAttemptSerializer),
+ last_message_id:,
+ }
+ end
+
+ def poll
+ RssFeed::Poll.call(**service_params) do
+ on_success { head :no_content }
+ on_failed_contract { raise Discourse::NotFound }
+ on_model_not_found(:rss_feed) { raise Discourse::NotFound }
+ end
+ end
+
+ def set_enabled
+ RssFeed::SetEnabled.call(**service_params) do
+ on_success { head :no_content }
+ on_failed_contract { raise Discourse::InvalidParameters.new(:enabled) }
+ on_model_not_found(:rss_feed) { raise Discourse::NotFound }
+ end
+ end
+
+ def category_requirements
+ category = Category.find_by(id: params[:category_id])
+ render json: { required_tag_groups: RequiredTagGroups.for_category(category) }
+ end
+
def destroy
- feed = params[:feed_setting]
- rss_feed = RssFeed.find_by_id(feed["id"])
-
- if rss_feed
- rss_feed.destroy!
- render json: { success: true }
- else
- render json: { success: false, error: "Feed not found" }, status: :not_found
+ RssFeed::Destroy.call(**service_params) do
+ on_success { head :no_content }
+ on_failed_contract { raise Discourse::NotFound }
+ on_model_not_found(:rss_feed) { raise Discourse::NotFound }
end
end
end
diff --git a/plugins/discourse-rss-polling/app/jobs/jobs/discourse_rss_polling/poll_all_feeds.rb b/plugins/discourse-rss-polling/app/jobs/jobs/discourse_rss_polling/poll_all_feeds.rb
index 418dd8de28c..04b68517b2d 100644
--- a/plugins/discourse-rss-polling/app/jobs/jobs/discourse_rss_polling/poll_all_feeds.rb
+++ b/plugins/discourse-rss-polling/app/jobs/jobs/discourse_rss_polling/poll_all_feeds.rb
@@ -11,7 +11,7 @@ module Jobs
return unless SiteSetting.rss_polling_enabled
return unless not_polled_recently?
- ::DiscourseRssPolling::RssFeed.includes(:user).find_each(&:poll)
+ ::DiscourseRssPolling::RssFeed.enabled.includes(:user).find_each(&:poll)
end
private
diff --git a/plugins/discourse-rss-polling/app/jobs/jobs/discourse_rss_polling/poll_feed.rb b/plugins/discourse-rss-polling/app/jobs/jobs/discourse_rss_polling/poll_feed.rb
index e1bce2af1fa..ce75dc85399 100644
--- a/plugins/discourse-rss-polling/app/jobs/jobs/discourse_rss_polling/poll_feed.rb
+++ b/plugins/discourse-rss-polling/app/jobs/jobs/discourse_rss_polling/poll_feed.rb
@@ -1,28 +1,42 @@
# frozen_string_literal: true
-require "rss"
-
module Jobs
module DiscourseRssPolling
class PollFeed < ::Jobs::Base
def execute(args)
return unless SiteSetting.rss_polling_enabled
- @author = resolve_author(args)
-
- @discourse_category_id = args[:discourse_category_id]
- return if @discourse_category_id.present? && !Category.exists?(@discourse_category_id)
-
@feed_url = args[:feed_url]
+ @author = resolve_author(args)
@discourse_tags = args[:discourse_tags]
@feed_category_filter = args[:feed_category_filter]
+ @rss_feed_id = args[:rss_feed_id]
+ @discourse_category_id = args[:discourse_category_id]
+
+ return if feed_disabled?
+
+ if @discourse_category_id.present? && !Category.exists?(@discourse_category_id)
+ record_category_deleted(force: args[:force])
+ return
+ end
- poll_feed if not_polled_recently?
+ if args[:force]
+ mark_polled
+ else
+ return unless not_polled_recently?
+ end
+
+ poll_feed
end
private
- attr_reader :feed_url, :author, :discourse_category_id, :discourse_tags, :feed_category_filter
+ attr_reader :feed_url,
+ :author,
+ :discourse_category_id,
+ :discourse_tags,
+ :feed_category_filter,
+ :rss_feed_id
def resolve_author(args)
if args[:user_id]
@@ -30,14 +44,14 @@ module Jobs
return user if user
Rails.logger.warn(
- "RSS Polling: user_id #{args[:user_id]} not found for feed #{args[:feed_url]}, falling back to system user",
+ "RSS Polling: user_id #{args[:user_id]} not found for feed #{redacted_feed_url}, falling back to system user",
)
elsif args[:author_username].present?
user = User.find_by_username(args[:author_username])
return user if user
Rails.logger.warn(
- "RSS Polling: username '#{args[:author_username]}' not found for feed #{args[:feed_url]}, falling back to system user",
+ "RSS Polling: username '#{args[:author_username]}' not found for feed #{redacted_feed_url}, falling back to system user",
)
end
@@ -48,46 +62,83 @@ module Jobs
"rss-polling-feed-polled:#{Digest::SHA1.hexdigest(feed_url)}"
end
+ def poll_window
+ SiteSetting.rss_polling_frequency.minutes - 10.seconds
+ end
+
def not_polled_recently?
- Discourse.redis.set(
- feed_key,
- 1,
- ex: SiteSetting.rss_polling_frequency.minutes - 10.seconds,
- nx: true,
- )
+ Discourse.redis.set(feed_key, 1, ex: poll_window, nx: true)
+ end
+
+ def mark_polled
+ Discourse.redis.set(feed_key, 1, ex: poll_window)
+ end
+
+ def feed_disabled?
+ rss_feed_id.present? &&
+ !::DiscourseRssPolling::RssFeed.where(id: rss_feed_id, enabled: true).exists?
end
def poll_feed
- topics_polled_from_feed.each do |feed_item|
- next if feed_item.content.blank?
- next if feed_item.title.blank?
- if feed_category_filter.present? &&
- feed_item.categories.none? { |c| c.include?(feed_category_filter) }
+ outcomes = []
+
+ fetch = ::DiscourseRssPolling::RssFeed::Action::FetchFeed.call(feed_url:)
+
+ unless SiteSetting.rss_polling_update_tags
+ already_imported =
+ ::DiscourseRssPolling::RssFeed::Action::ImportedTopics.call(feed_items: fetch.items)
+ end
+
+ fetch.items.each do |feed_item|
+ status, reason =
+ ::DiscourseRssPolling::RssFeed::Action::AnalyzeItem.call(
+ feed_item:,
+ feed_category_filter:,
+ )
+
+ if status == ::DiscourseRssPolling::RssFeed::Action::AnalyzeItem::SKIPPED
+ outcomes << feed_item.outcome(status: :skipped, reason:)
+ log_verbose("Skipped '#{feed_item.title || feed_item.url}' (#{reason})")
next
end
cook_method = feed_item.is_youtube? ? Post.cook_methods[:regular] : nil
updated_tags = discourse_tags
- if !SiteSetting.rss_polling_update_tags
- url = TopicEmbed.normalize_url(feed_item.url)
- updated_tags = nil if TopicEmbed.topic_embed_by_url(url).present?
- end
+ updated_tags = nil if already_imported&.key?(feed_item)
post =
- TopicEmbed.import(
- author,
- feed_item.url,
- feed_item.title,
- CGI.unescapeHTML(feed_item.content),
- category_id: discourse_category_id,
- tags: updated_tags,
- cook_method: cook_method,
- )
- if post && (post.created_at == post.updated_at) # new post
- if SiteSetting.rss_polling_use_pubdate
+ begin
+ TopicEmbed.import(
+ author,
+ feed_item.url,
+ feed_item.title,
+ CGI.unescapeHTML(feed_item.content),
+ category_id: discourse_category_id,
+ tags: updated_tags,
+ cook_method: cook_method,
+ )
+ rescue => e
+ outcomes << feed_item.outcome(status: :failed, reason: e.message.to_s.truncate(200))
+ log_verbose("Failed to import '#{feed_item.title || feed_item.url}' (#{e.message})")
+ next
+ end
+
+ if post.nil?
+ outcomes << feed_item.outcome(status: :failed, reason: :import_rejected)
+ log_verbose("Failed to import '#{feed_item.title || feed_item.url}'")
+ next
+ end
+
+ new_post = post.created_at == post.updated_at
+ item_status = new_post ? :imported : :updated
+ outcomes << feed_item.outcome(status: item_status, topic_url: post.topic&.relative_url)
+
+ log_verbose("Imported '#{feed_item.title}' (#{feed_item.url})")
+
+ if new_post
+ if SiteSetting.rss_polling_use_pubdate && (post_time = feed_item.pubdate)
begin
- post_time = feed_item.pubdate
post.created_at = post_time
post.save!
post.topic.created_at = post_time
@@ -102,6 +153,46 @@ module Jobs
set_image_as_thumbnail(post, feed_item.image_link) if feed_item.image_link
end
end
+
+ record_attempt(outcomes, error: fetch.error&.to_s)
+ rescue => e
+ Discourse.warn_exception(
+ e,
+ message: "RSS Polling: error while polling feed #{redacted_feed_url}",
+ )
+ record_attempt(outcomes, error: "unknown")
+ raise
+ end
+
+ def record_category_deleted(force:)
+ return if rss_feed_id.blank?
+
+ unless force
+ latest = ::DiscourseRssPolling::PollAttempt.where(rss_feed_id:).recent.first
+ return if latest&.error == "category_deleted"
+ end
+
+ record_attempt([], error: "category_deleted")
+ end
+
+ def record_attempt(outcomes, error: nil)
+ return if rss_feed_id.blank?
+
+ ::DiscourseRssPolling::PollAttempt.record!(rss_feed_id:, items: outcomes, error:)
+ rescue => e
+ Rails.logger.warn(
+ "RSS Polling: failed to record poll attempt for feed #{rss_feed_id}: #{e.message}",
+ )
+ end
+
+ def redacted_feed_url
+ @redacted_feed_url ||= ::DiscourseRssPolling::FeedUrl.redact(feed_url)
+ end
+
+ def log_verbose(message)
+ return unless SiteSetting.rss_polling_verbose_logging
+
+ Rails.logger.info("RSS Polling: #{redacted_feed_url}: #{message}")
end
def set_image_as_thumbnail(post, image_link)
@@ -138,68 +229,6 @@ module Jobs
tmp&.close
tmp&.unlink
end
-
- def topics_polled_from_feed
- raw_feed = fetch_raw_feed
-
- if raw_feed.blank?
- Rails.logger.warn("RSS Polling: Failed to fetch feed from #{feed_url}")
- return []
- end
-
- parsed_feed = RSS::Parser.parse(raw_feed, false)
-
- if parsed_feed.blank?
- Rails.logger.warn("RSS Polling: Unable to parse feed from #{feed_url}")
- return []
- end
-
- parsed_feed.items.map { |item| ::DiscourseRssPolling::FeedItem.new(item) }
- rescue RSS::NotWellFormedError, RSS::InvalidRSSError => e
- Discourse.warn_exception(e, message: "RSS Polling: Invalid RSS from #{feed_url}")
- []
- end
-
- def fetch_raw_feed
- url, headers = extract_api_credentials(@feed_url)
- body = +""
-
- fd = FinalDestination.new(url, headers:)
- response_status = nil
-
- fd.get do |response, chunk, uri|
- if uri.blank? || !response.is_a?(Net::HTTPSuccess)
- response_status = response&.code
- throw :done
- end
- body << chunk
- end
-
- if body.blank? && response_status.present?
- Rails.logger.warn(
- "RSS Polling: HTTP #{response_status} when fetching #{feed_url} (status: #{fd.status})",
- )
- end
-
- body.presence
- end
-
- def extract_api_credentials(url)
- uri = URI.parse(url)
- return url, {} if uri.query.blank?
-
- params = CGI.parse(uri.query)
- api_key = params.delete("api_key")&.first
- api_username = params.delete("api_username")&.first
-
- return url, {} if api_key.blank?
-
- headers = { "Api-Key" => api_key }
- headers["Api-Username"] = api_username if api_username.present?
-
- uri.query = params.empty? ? nil : URI.encode_www_form(params)
- [uri.to_s, headers]
- end
end
end
end
diff --git a/plugins/discourse-rss-polling/app/models/discourse_rss_polling/feed_item.rb b/plugins/discourse-rss-polling/app/models/discourse_rss_polling/feed_item.rb
index 9ac96f01ec7..b03109e5684 100644
--- a/plugins/discourse-rss-polling/app/models/discourse_rss_polling/feed_item.rb
+++ b/plugins/discourse-rss-polling/app/models/discourse_rss_polling/feed_item.rb
@@ -9,30 +9,49 @@ module DiscourseRssPolling
end
def url
- url?(@accessor.link) ? @accessor.link : @accessor.element_content(:id)
+ return @url if defined?(@url)
+
+ @url = FeedUrl.http?(@accessor.link) ? @accessor.link : @accessor.element_content(:id)
end
def content
- content = nil
-
- CONTENT_ELEMENT_TAG_NAMES.each do |tag_name|
- break if content = @accessor.element_content(tag_name)
- end
-
- return url if is_youtube?
+ return @content if defined?(@content)
- content&.force_encoding("UTF-8")&.scrub
+ @content =
+ if is_youtube?
+ url
+ else
+ value = nil
+ CONTENT_ELEMENT_TAG_NAMES.each do |tag_name|
+ break if value = @accessor.element_content(tag_name)
+ end
+ value&.force_encoding("UTF-8")&.scrub
+ end
end
def title
- unclean_title = @accessor.element_content(:title)&.force_encoding("UTF-8")&.scrub
- unclean_title =
- TextCleaner.clean_title(TextSentinel.title_sentinel(unclean_title).text).presence
- CGI.unescapeHTML(unclean_title) if unclean_title
+ return @title if defined?(@title)
+
+ @title =
+ begin
+ unclean_title = @accessor.element_content(:title)&.force_encoding("UTF-8")&.scrub
+ unclean_title =
+ TextCleaner.clean_title(TextSentinel.title_sentinel(unclean_title).text).presence
+ CGI.unescapeHTML(unclean_title) if unclean_title
+ end
end
def categories
- @accessor.element_content(:categories).map { |c| c.content }
+ @categories ||=
+ Array(@accessor.element_content(:categories))
+ .map do |category|
+ if category.respond_to?(:content)
+ category.content.presence
+ elsif category.respond_to?(:term)
+ category.term
+ end
+ end
+ .compact
end
def image_link
@@ -44,16 +63,39 @@ module DiscourseRssPolling
end
def pubdate
- @accessor.element_content(:pubDate) || @accessor.element_content(:published)
+ return @pubdate if defined?(@pubdate)
+
+ @pubdate =
+ begin
+ raw =
+ @accessor.element_content(:pubDate) || @accessor.element_content(:published) ||
+ @accessor.element_content(:updated)
+ if raw.blank?
+ nil
+ elsif raw.respond_to?(:iso8601)
+ raw
+ else
+ Time.zone.parse(raw.to_s)
+ end
+ rescue ArgumentError, TypeError
+ nil
+ end
+ end
+
+ def outcome(status:, reason: nil, topic_url: nil)
+ {
+ "title" => title,
+ "url" => url,
+ "status" => status.to_s,
+ "reason" => reason&.to_s,
+ "categories" => categories,
+ "published_at" => pubdate&.iso8601,
+ "topic_url" => topic_url,
+ }
end
private
- # The tag name's relative order implies its priority.
CONTENT_ELEMENT_TAG_NAMES = %i[content_encoded content description summary]
-
- def url?(link)
- link.present? && link =~ %r{^https?\://}
- end
end
end
diff --git a/plugins/discourse-rss-polling/app/models/discourse_rss_polling/poll_attempt.rb b/plugins/discourse-rss-polling/app/models/discourse_rss_polling/poll_attempt.rb
new file mode 100644
index 00000000000..8d8f834c8f6
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/models/discourse_rss_polling/poll_attempt.rb
@@ -0,0 +1,76 @@
+# frozen_string_literal: true
+
+module DiscourseRssPolling
+ class PollAttempt < ActiveRecord::Base
+ self.table_name = "discourse_rss_polling_poll_attempts"
+
+ belongs_to :rss_feed, class_name: "DiscourseRssPolling::RssFeed"
+
+ enum :status, { success: 0, error: 1 }
+
+ KEEP_PER_FEED = 20
+ MAX_ITEMS = 50
+
+ scope :recent, -> { order(created_at: :desc, id: :desc) }
+
+ def self.record!(rss_feed_id:, items:, error: nil)
+ counts = items.map { |item| item["status"] }.tally
+ failed_count = counts.fetch("failed", 0)
+
+ attempt =
+ transaction do
+ create!(
+ rss_feed_id:,
+ status: (error || failed_count.positive?) ? :error : :success,
+ imported_count: counts.fetch("imported", 0),
+ updated_count: counts.fetch("updated", 0),
+ skipped_count: counts.fetch("skipped", 0),
+ failed_count:,
+ error:,
+ items: items.first(MAX_ITEMS),
+ ).tap { purge_old(rss_feed_id) }
+ end
+
+ publish(attempt)
+ attempt
+ end
+
+ def self.message_bus_channel(rss_feed_id)
+ "/rss-polling/feeds/#{rss_feed_id}"
+ end
+
+ def self.publish(attempt)
+ MessageBus.publish(
+ message_bus_channel(attempt.rss_feed_id),
+ PollAttemptSerializer.new(attempt, root: false).as_json,
+ group_ids: [Group::AUTO_GROUPS[:admins]],
+ )
+ end
+
+ def self.purge_old(rss_feed_id)
+ keep_ids = where(rss_feed_id:).recent.limit(KEEP_PER_FEED).select(:id)
+ where(rss_feed_id:).where.not(id: keep_ids).delete_all
+ end
+ end
+end
+
+# == Schema Information
+#
+# Table name: discourse_rss_polling_poll_attempts
+#
+# id :bigint not null, primary key
+# error :text
+# failed_count :integer default(0), not null
+# imported_count :integer default(0), not null
+# items :jsonb not null
+# skipped_count :integer default(0), not null
+# status :integer default("success"), not null
+# updated_count :integer default(0), not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# rss_feed_id :bigint not null
+#
+# Indexes
+#
+# idx_rss_polling_poll_attempts_on_feed_created_id_desc (rss_feed_id,created_at DESC,id DESC)
+#
diff --git a/plugins/discourse-rss-polling/app/models/discourse_rss_polling/rss_feed.rb b/plugins/discourse-rss-polling/app/models/discourse_rss_polling/rss_feed.rb
index 77b4b0e3782..438575afa52 100644
--- a/plugins/discourse-rss-polling/app/models/discourse_rss_polling/rss_feed.rb
+++ b/plugins/discourse-rss-polling/app/models/discourse_rss_polling/rss_feed.rb
@@ -5,18 +5,25 @@ module DiscourseRssPolling
self.ignored_columns += %i[author]
belongs_to :user, optional: true
+ has_many :poll_attempts, class_name: "DiscourseRssPolling::PollAttempt", dependent: :delete_all
validates :url, presence: true
- delegate :username, to: :user, prefix: :author, allow_nil: true
+ scope :enabled, -> { where(enabled: true) }
- def poll(inline: false)
+ def user
+ super || Discourse.system_user
+ end
+
+ def poll(inline: false, force: false)
args = {
+ rss_feed_id: id,
feed_url: url,
user_id: user_id,
discourse_category_id: category_id,
discourse_tags: tags&.split(","),
feed_category_filter: category_filter,
+ force: force,
}
if inline
@@ -34,6 +41,7 @@ end
#
# id :bigint not null, primary key
# category_filter :string
+# enabled :boolean default(TRUE), not null
# tags :string
# url :string not null
# created_at :datetime not null
diff --git a/plugins/discourse-rss-polling/app/serializers/discourse_rss_polling/feed_setting_serializer.rb b/plugins/discourse-rss-polling/app/serializers/discourse_rss_polling/feed_setting_serializer.rb
index 6923388ff2b..7a9d9b20382 100644
--- a/plugins/discourse-rss-polling/app/serializers/discourse_rss_polling/feed_setting_serializer.rb
+++ b/plugins/discourse-rss-polling/app/serializers/discourse_rss_polling/feed_setting_serializer.rb
@@ -4,16 +4,30 @@ module DiscourseRssPolling
class FeedSettingSerializer < ApplicationSerializer
attributes :id,
:feed_url,
- :user_id,
- :author_username,
+ :redacted_feed_url,
:discourse_category_id,
:discourse_tags,
- :feed_category_filter
+ :feed_category_filter,
+ :enabled
+
+ has_one :author, serializer: BasicUserSerializer, embed: :objects
def feed_url
object.url
end
+ def include_feed_url?
+ !!@options[:include_url]
+ end
+
+ def redacted_feed_url
+ FeedUrl.redact(object.url)
+ end
+
+ def author
+ object.user
+ end
+
def discourse_category_id
object.category_id
end
diff --git a/plugins/discourse-rss-polling/app/serializers/discourse_rss_polling/poll_attempt_serializer.rb b/plugins/discourse-rss-polling/app/serializers/discourse_rss_polling/poll_attempt_serializer.rb
new file mode 100644
index 00000000000..0488e3dd072
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/serializers/discourse_rss_polling/poll_attempt_serializer.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+module DiscourseRssPolling
+ class PollAttemptSerializer < ApplicationSerializer
+ attributes :id,
+ :status,
+ :imported_count,
+ :updated_count,
+ :skipped_count,
+ :failed_count,
+ :error,
+ :items,
+ :created_at
+ end
+end
diff --git a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/feed_setting/update.rb b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/feed_setting/update.rb
deleted file mode 100644
index 63c0dc5060e..00000000000
--- a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/feed_setting/update.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-# frozen_string_literal: true
-
-module DiscourseRssPolling
- module FeedSetting
- class Update
- include Service::Base
-
- params do
- attribute :id, :integer
- attribute :feed_url, :string
- attribute :author_username, :string
- attribute :discourse_category_id, :integer
- attribute :discourse_tags, :array
- attribute :feed_category_filter, :string
-
- validates :feed_url, presence: true
- validates :author_username, presence: true
-
- before_validation :normalize_tags
-
- def normalize_tags
- return if discourse_tags.blank?
-
- self.discourse_tags =
- discourse_tags.map { |tag| tag.is_a?(String) ? tag : tag["name"] || tag[:name] }.compact
- end
-
- def tag_names
- discourse_tags&.join(",").presence
- end
- end
-
- model :user
- model :rss_feed, :upsert_rss_feed
-
- private
-
- def fetch_user(params:)
- ::User.find_by_username(params.author_username)
- end
-
- def upsert_rss_feed(params:, user:)
- feed = RssFeed.find_or_initialize_by(id: params.id)
- feed.assign_attributes(
- url: params.feed_url,
- user: user,
- category_id: params.discourse_category_id,
- tags: params.tag_names,
- category_filter: params.feed_category_filter,
- )
- feed.save!
- feed
- end
- end
- end
-end
diff --git a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/feed_url.rb b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/feed_url.rb
new file mode 100644
index 00000000000..e10478db09c
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/feed_url.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module DiscourseRssPolling
+ module FeedUrl
+ CREDENTIAL_PARAMS = %w[api_key api_username]
+ HTTP_URL = %r{\Ahttps?://}i
+
+ def self.http?(url)
+ url.to_s.match?(HTTP_URL)
+ end
+
+ def self.redact(url)
+ split_credentials(url).first
+ end
+
+ # Returns [url_without_credentials, { "api_key" => ..., "api_username" => ... }].
+ def self.split_credentials(url)
+ uri = URI.parse(url.to_s.strip)
+ return url.to_s, {} if uri.query.blank?
+
+ params = CGI.parse(uri.query)
+ credentials = CREDENTIAL_PARAMS.to_h { |param| [param, params.delete(param)&.first] }
+ uri.query = params.empty? ? nil : URI.encode_www_form(params)
+ [uri.to_s, credentials]
+ rescue URI::InvalidURIError
+ [url.to_s.split("?", 2).first.to_s, {}]
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/required_tag_groups.rb b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/required_tag_groups.rb
new file mode 100644
index 00000000000..7e4a8cf6e42
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/required_tag_groups.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+module DiscourseRssPolling
+ module RequiredTagGroups
+ def self.for_category(category)
+ return [] if category.nil?
+
+ category
+ .category_required_tag_groups
+ .includes(tag_group: :tags)
+ .map do |required|
+ {
+ tag_group: required.tag_group.name,
+ min_count: required.min_count,
+ tags: required.tag_group.tags.map(&:name),
+ }
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/analyze_item.rb b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/analyze_item.rb
new file mode 100644
index 00000000000..35a73b7e3bc
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/analyze_item.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+module DiscourseRssPolling
+ class RssFeed
+ module Action
+ class AnalyzeItem < Service::ActionBase
+ WOULD_IMPORT = :would_import
+ SKIPPED = :skipped
+
+ option :feed_item
+ option :feed_category_filter, optional: true
+
+ def call
+ return SKIPPED, :missing_content if feed_item.content.blank?
+ return SKIPPED, :missing_title if feed_item.title.blank?
+ return SKIPPED, :invalid_url unless importable_url?
+ return SKIPPED, :category_filter_mismatch if filtered_out?
+
+ [WOULD_IMPORT, nil]
+ end
+
+ private
+
+ def importable_url?
+ FeedUrl.http?(feed_item.url)
+ end
+
+ def filtered_out?
+ filter = feed_category_filter.presence&.downcase
+ return false if filter.nil?
+
+ feed_item.categories.none? { |category| category.downcase.include?(filter) }
+ end
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/build_preview.rb b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/build_preview.rb
new file mode 100644
index 00000000000..2144df130bb
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/build_preview.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+module DiscourseRssPolling
+ class RssFeed
+ module Action
+ class BuildPreview < Service::ActionBase
+ option :feed_items
+ option :feed_category_filter, optional: true
+
+ def call
+ imported = ImportedTopics.call(feed_items:)
+
+ feed_items.map do |feed_item|
+ status, reason = AnalyzeItem.call(feed_item:, feed_category_filter:)
+
+ if status == AnalyzeItem::WOULD_IMPORT && (topic_url = imported[feed_item])
+ feed_item.outcome(status: :already_imported, reason:, topic_url:)
+ else
+ feed_item.outcome(status:, reason:)
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/fetch_feed.rb b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/fetch_feed.rb
new file mode 100644
index 00000000000..fb6e709fce3
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/fetch_feed.rb
@@ -0,0 +1,93 @@
+# frozen_string_literal: true
+
+require "rss"
+
+module DiscourseRssPolling
+ class RssFeed
+ module Action
+ class FetchFeed < Service::ActionBase
+ Result = Struct.new(:items, :error, keyword_init: true)
+
+ option :feed_url
+
+ def call
+ raw_feed = fetch_raw_feed
+
+ if raw_feed.blank?
+ Rails.logger.warn("RSS Polling: Failed to fetch feed from #{redacted_url}")
+ return Result.new(items: [], error: :fetch_failed)
+ end
+
+ parsed_feed = RSS::Parser.parse(raw_feed, false)
+
+ if parsed_feed.blank?
+ Rails.logger.warn("RSS Polling: Unable to parse feed from #{redacted_url}")
+ return Result.new(items: [], error: :parse_failed)
+ end
+
+ Result.new(items: parsed_feed.items.map { |item| FeedItem.new(item) }, error: nil)
+ rescue RSS::Error => e
+ Discourse.warn_exception(e, message: "RSS Polling: Invalid RSS from #{redacted_url}")
+ Result.new(items: [], error: :invalid_feed)
+ rescue => e
+ Discourse.warn_exception(
+ e,
+ message: "RSS Polling: Failed to fetch feed from #{redacted_url}",
+ )
+ Result.new(items: [], error: :fetch_failed)
+ end
+
+ private
+
+ def url
+ @url ||= feed_url.to_s.strip
+ end
+
+ def redacted_url
+ @redacted_url ||= FeedUrl.redact(url)
+ end
+
+ def fetch_raw_feed
+ request_url, headers = extract_api_credentials(url)
+ body = +""
+ response_status = nil
+
+ fd =
+ FinalDestination.new(
+ request_url,
+ headers:,
+ timeout: SiteSetting.rss_polling_feed_request_timeout,
+ )
+
+ fd.get do |response, chunk, uri|
+ if uri.blank? || !response.is_a?(Net::HTTPSuccess)
+ response_status = response&.code
+ throw :done
+ end
+ body << chunk
+ end
+
+ if body.blank? && response_status.present?
+ Rails.logger.warn(
+ "RSS Polling: HTTP #{response_status} when fetching #{redacted_url} (status: #{fd.status})",
+ )
+ end
+
+ body.presence
+ end
+
+ def extract_api_credentials(request_url)
+ clean_url, credentials = FeedUrl.split_credentials(request_url)
+ api_key, api_username = credentials.values_at("api_key", "api_username")
+
+ return request_url, {} if api_key.blank?
+
+ headers = { "Api-Key" => api_key }
+ headers["Api-Username"] = api_username if api_username.present?
+
+ [clean_url, headers]
+ end
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/imported_topics.rb b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/imported_topics.rb
new file mode 100644
index 00000000000..3992b836b22
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/imported_topics.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+module DiscourseRssPolling
+ class RssFeed
+ module Action
+ class ImportedTopics < Service::ActionBase
+ option :feed_items
+
+ def call
+ keys = feed_items.index_with { |feed_item| embed_key(feed_item.url) }
+ topic_urls = topic_urls_by_key(keys.values)
+
+ keys.each_with_object({}) do |(feed_item, key), imported|
+ imported[feed_item] = topic_urls[key] if key && topic_urls.key?(key)
+ end
+ end
+
+ private
+
+ def topic_urls_by_key(keys)
+ keys = keys.compact.uniq
+ return {} if keys.empty?
+
+ patterns = keys.map { |key| "^https?://#{Regexp.escape(key)}$" }
+
+ TopicEmbed
+ .where("embed_url ~* ANY(ARRAY[?])", patterns)
+ .includes(:topic)
+ .each_with_object({}) do |embed, topic_urls|
+ next if embed.topic.nil?
+
+ topic_urls[embed_key(embed.embed_url)] ||= embed.topic.relative_url
+ end
+ end
+
+ def embed_key(url)
+ return if url.blank?
+
+ TopicEmbed.normalize_url(url).sub(%r{\Ahttps?://}, "")
+ end
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/log_change.rb b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/log_change.rb
new file mode 100644
index 00000000000..40dbbf20125
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/action/log_change.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+module DiscourseRssPolling
+ class RssFeed
+ module Action
+ class LogChange < Service::ActionBase
+ option :actor
+ option :rss_feed
+ option :action
+
+ def call
+ StaffActionLogger.new(actor).log_custom(
+ "#{action}_rss_polling_feed",
+ url: FeedUrl.redact(rss_feed.url),
+ )
+ end
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/destroy.rb b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/destroy.rb
new file mode 100644
index 00000000000..b0b006b8d97
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/destroy.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module DiscourseRssPolling
+ class RssFeed
+ class Destroy
+ include Service::Base
+ include FindById
+
+ params { attribute :id, :integer }
+
+ model :rss_feed
+
+ transaction do
+ step :destroy_feed
+ step :log_deletion
+ end
+
+ private
+
+ def destroy_feed(rss_feed:)
+ rss_feed.destroy!
+ end
+
+ def log_deletion(guardian:, rss_feed:)
+ Action::LogChange.call(actor: guardian.user, rss_feed:, action: :destroy)
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/find_by_id.rb b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/find_by_id.rb
new file mode 100644
index 00000000000..3bcc6297800
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/find_by_id.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+module DiscourseRssPolling
+ class RssFeed
+ module FindById
+ private
+
+ def fetch_rss_feed(params:)
+ RssFeed.find_by(id: params.id)
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/poll.rb b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/poll.rb
new file mode 100644
index 00000000000..205dd41da44
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/poll.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+module DiscourseRssPolling
+ class RssFeed
+ class Poll
+ include Service::Base
+ include FindById
+
+ params { attribute :id, :integer }
+
+ model :rss_feed
+ step :enqueue_poll
+ step :log_poll
+
+ private
+
+ def enqueue_poll(rss_feed:)
+ rss_feed.poll(force: true)
+ end
+
+ def log_poll(guardian:, rss_feed:)
+ Action::LogChange.call(actor: guardian.user, rss_feed:, action: :poll)
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/set_enabled.rb b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/set_enabled.rb
new file mode 100644
index 00000000000..8414fa18e47
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/set_enabled.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+module DiscourseRssPolling
+ class RssFeed
+ class SetEnabled
+ include Service::Base
+ include FindById
+
+ params do
+ attribute :id, :integer
+ attribute :enabled
+
+ validates :enabled, inclusion: { in: [true, false, "true", "false"] }
+
+ def enabled?
+ ActiveModel::Type::Boolean.new.cast(enabled)
+ end
+ end
+
+ model :rss_feed
+
+ transaction do
+ step :change_status
+ step :log_status_change
+ end
+
+ private
+
+ def change_status(rss_feed:, params:)
+ rss_feed.update!(enabled: params.enabled?)
+ end
+
+ def log_status_change(guardian:, rss_feed:)
+ Action::LogChange.call(
+ actor: guardian.user,
+ rss_feed:,
+ action: rss_feed.enabled? ? :enable : :disable,
+ )
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/test.rb b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/test.rb
new file mode 100644
index 00000000000..d3b0f959a0b
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/test.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+module DiscourseRssPolling
+ class RssFeed
+ class Test
+ include Service::Base
+
+ PREVIEW_LIMIT = 20
+
+ params do
+ attribute :feed_url, :string
+ attribute :feed_category_filter, :string
+
+ validates :feed_url, presence: true
+ end
+
+ step :fetch
+ try { step :build_preview }
+
+ private
+
+ def fetch(params:)
+ fetched = Action::FetchFeed.call(feed_url: params.feed_url)
+ fail!(fetched.error) if fetched.error
+
+ context[:fetched] = fetched
+ end
+
+ def build_preview(params:, fetched:)
+ context[:preview] = Action::BuildPreview.call(
+ feed_items: fetched.items.first(PREVIEW_LIMIT),
+ feed_category_filter: params.feed_category_filter,
+ )
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/update.rb b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/update.rb
new file mode 100644
index 00000000000..be8489f375b
--- /dev/null
+++ b/plugins/discourse-rss-polling/app/services/discourse_rss_polling/rss_feed/update.rb
@@ -0,0 +1,123 @@
+# frozen_string_literal: true
+
+module DiscourseRssPolling
+ class RssFeed
+ class Update
+ include Service::Base
+
+ params do
+ attribute :id, :integer
+ attribute :feed_url, :string
+ attribute :author_username, :string
+ attribute :discourse_category_id, :integer
+ attribute :discourse_tags, :array
+ attribute :feed_category_filter, :string
+
+ validates :feed_url, presence: true
+ validates :author_username, presence: true
+ validate :feed_url_is_http
+ validate :satisfies_required_tag_groups
+
+ before_validation :normalize_feed_url
+ before_validation :normalize_tags
+
+ def feed_url_is_http
+ return if feed_url.blank? || DiscourseRssPolling::FeedUrl.http?(feed_url)
+
+ errors.add(:base, I18n.t("rss_polling.errors.feed_url_must_be_http"))
+ end
+
+ def satisfies_required_tag_groups
+ return if discourse_category_id.blank?
+
+ category = ::Category.find_by(id: discourse_category_id)
+ return if category.nil?
+
+ feed_tags = Array(discourse_tags)
+
+ DiscourseRssPolling::RequiredTagGroups
+ .for_category(category)
+ .each do |group|
+ next if (feed_tags & group[:tags]).size >= group[:min_count]
+
+ errors.add(
+ :base,
+ I18n.t(
+ "rss_polling.errors.required_tag_group",
+ category: category.name,
+ tag_group: group[:tag_group],
+ count: group[:min_count],
+ tags: group[:tags].join(", "),
+ ),
+ )
+ end
+ end
+
+ def normalize_feed_url
+ self.feed_url = feed_url&.strip
+ end
+
+ def normalize_tags
+ return if discourse_tags.blank?
+
+ self.discourse_tags =
+ discourse_tags
+ .map do |tag|
+ if tag.is_a?(String)
+ tag
+ elsif tag.is_a?(Numeric)
+ tag.to_s
+ else
+ tag["name"] || tag[:name]
+ end
+ end
+ .compact_blank
+ end
+
+ def tag_names
+ discourse_tags&.join(",").presence
+ end
+ end
+
+ model :user
+ model :rss_feed, :build_rss_feed
+
+ transaction do
+ step :save_rss_feed
+ step :log_change
+ end
+
+ private
+
+ def fetch_user(params:)
+ ::User.find_by_username(params.author_username)
+ end
+
+ def build_rss_feed(params:, user:)
+ feed = params.id.present? ? RssFeed.find_by(id: params.id) : RssFeed.new
+ return if feed.nil?
+
+ feed.assign_attributes(
+ url: params.feed_url,
+ user: user,
+ category_id: params.discourse_category_id,
+ tags: params.tag_names,
+ category_filter: params.feed_category_filter,
+ )
+ feed
+ end
+
+ def save_rss_feed(rss_feed:)
+ rss_feed.save!
+ end
+
+ def log_change(guardian:, rss_feed:)
+ Action::LogChange.call(
+ actor: guardian.user,
+ rss_feed:,
+ action: rss_feed.previously_new_record? ? :create : :update,
+ )
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/assets/javascripts/admin/models/rss-polling-feed-settings.js b/plugins/discourse-rss-polling/assets/javascripts/admin/models/rss-polling-feed-settings.js
deleted file mode 100644
index e9bae5d8e17..00000000000
--- a/plugins/discourse-rss-polling/assets/javascripts/admin/models/rss-polling-feed-settings.js
+++ /dev/null
@@ -1,25 +0,0 @@
-import { ajax } from "discourse/lib/ajax";
-
-export default {
- show() {
- return ajax("/admin/plugins/rss_polling/feed_settings.json");
- },
-
- updateFeed(feedSetting) {
- return ajax("/admin/plugins/rss_polling/feed_settings", {
- type: "PUT",
- contentType: "application/json",
- processData: false,
- data: JSON.stringify({ feed_setting: feedSetting }),
- });
- },
-
- deleteFeed(feedSetting) {
- return ajax("/admin/plugins/rss_polling/feed_settings", {
- type: "DELETE",
- contentType: "application/json",
- processData: false,
- data: JSON.stringify({ feed_setting: feedSetting }),
- });
- },
-};
diff --git a/plugins/discourse-rss-polling/assets/javascripts/discourse/admin-rss-polling-plugin-route-map.js b/plugins/discourse-rss-polling/assets/javascripts/discourse/admin-rss-polling-plugin-route-map.js
new file mode 100644
index 00000000000..e5db1ceac3c
--- /dev/null
+++ b/plugins/discourse-rss-polling/assets/javascripts/discourse/admin-rss-polling-plugin-route-map.js
@@ -0,0 +1,12 @@
+export default {
+ resource: "admin.adminPlugins.show",
+
+ path: "/plugins",
+
+ map() {
+ this.route("discourse-rss-polling-feeds", { path: "feeds" }, function () {
+ this.route("new");
+ this.route("edit", { path: "/:id/edit" });
+ });
+ },
+};
diff --git a/plugins/discourse-rss-polling/assets/javascripts/discourse/controllers/admin-plugins/rss-polling.js b/plugins/discourse-rss-polling/assets/javascripts/discourse/controllers/admin-plugins/rss-polling.js
deleted file mode 100644
index 580725cb26d..00000000000
--- a/plugins/discourse-rss-polling/assets/javascripts/discourse/controllers/admin-plugins/rss-polling.js
+++ /dev/null
@@ -1,133 +0,0 @@
-import { tracked } from "@glimmer/tracking";
-import Controller from "@ember/controller";
-import { action, set } from "@ember/object";
-import { service } from "@ember/service";
-import { isBlank } from "@ember/utils";
-import { popupAjaxError } from "discourse/lib/ajax-error";
-import {
- addUniqueValueToArray,
- removeValueFromArray,
-} from "discourse/lib/array-tools";
-import { bind } from "discourse/lib/decorators";
-import { i18n } from "discourse-i18n";
-import RssPollingFeedSettings from "../../../admin/models/rss-polling-feed-settings";
-
-export default class AdminPluginsRssPollingController extends Controller {
- @service dialog;
-
- @tracked saving = false;
- @tracked valid = false;
- @tracked disabled = true;
-
- get feedSettings() {
- return this.model;
- }
-
- get unsavable() {
- return !this.valid || this.saving;
- }
-
- // TODO: extract feed setting into its own component && more validation
- @bind
- validate() {
- let overallValidity = true;
-
- this.feedSettings.forEach((feedSetting) => {
- const localValidity =
- !isBlank(feedSetting.feed_url) && !isBlank(feedSetting.author_username);
- set(feedSetting, "valid", localValidity);
- overallValidity = overallValidity && localValidity;
- });
-
- if (this.valid !== overallValidity) {
- this.valid = overallValidity;
- }
- }
-
- @action
- create() {
- let newSetting = {
- feed_url: null,
- author_username: null,
- discourse_category_id: null,
- discourse_tags: null,
- feed_category_filter: null,
- disabled: false,
- editing: true,
- };
-
- addUniqueValueToArray(this.feedSettings, newSetting);
-
- this.validate();
- }
-
- @action
- destroyFeedSetting(setting) {
- this.dialog.deleteConfirm({
- message: i18n("admin.rss_polling.destroy_feed.confirm"),
- didConfirm: async () => {
- try {
- await RssPollingFeedSettings.deleteFeed(setting);
- removeValueFromArray(this.feedSettings, setting);
- } catch (error) {
- popupAjaxError(error);
- } finally {
- this.saving = false;
- }
- },
- });
-
- this.validate();
- }
-
- @action
- editFeedSetting(setting) {
- set(setting, "disabled", false);
- set(setting, "editing", true);
-
- this.validate();
- }
-
- @action
- cancelEdit(setting) {
- if (!setting.id) {
- removeValueFromArray(this.feedSettings, setting);
- }
- set(setting, "disabled", true);
- set(setting, "editing", false);
-
- this.validate();
- }
-
- @action
- async updateFeedSetting(setting) {
- this.saving = true;
-
- try {
- await RssPollingFeedSettings.updateFeed(setting);
- } catch (error) {
- popupAjaxError(error);
- } finally {
- this.saving = false;
-
- set(setting, "disabled", true);
- set(setting, "editing", false);
- }
-
- this.validate();
- }
-
- @action
- updateAuthorUsername(setting, selected) {
- set(setting, "author_username", selected[0]);
-
- this.validate();
- }
-
- @action
- updateSettingProperty(setting, property, event) {
- set(setting, property, event.target.value);
-
- this.validate();
- }
-}
diff --git a/plugins/discourse-rss-polling/assets/javascripts/discourse/initializers/rss-polling-admin-plugin-configuration-nav.js b/plugins/discourse-rss-polling/assets/javascripts/discourse/initializers/rss-polling-admin-plugin-configuration-nav.js
index d924fd4a9ff..62c5c08bd82 100644
--- a/plugins/discourse-rss-polling/assets/javascripts/discourse/initializers/rss-polling-admin-plugin-configuration-nav.js
+++ b/plugins/discourse-rss-polling/assets/javascripts/discourse/initializers/rss-polling-admin-plugin-configuration-nav.js
@@ -13,6 +13,13 @@ export default {
withPluginApi((api) => {
api.setAdminPluginIcon(PLUGIN_ID, "rss");
+ api.addAdminPluginConfigurationNav(PLUGIN_ID, [
+ {
+ label: "admin.rss_polling.feeds.title",
+ route: "adminPlugins.show.discourse-rss-polling-feeds",
+ description: "admin.rss_polling.feeds.nav_description",
+ },
+ ]);
});
},
};
diff --git a/plugins/discourse-rss-polling/assets/javascripts/discourse/routes/admin-plugins/rss-polling.js b/plugins/discourse-rss-polling/assets/javascripts/discourse/routes/admin-plugins/rss-polling.js
deleted file mode 100644
index 1cd44c2ad3b..00000000000
--- a/plugins/discourse-rss-polling/assets/javascripts/discourse/routes/admin-plugins/rss-polling.js
+++ /dev/null
@@ -1,21 +0,0 @@
-import { trackedArray } from "@ember/reactive/collections";
-import DiscourseRoute from "discourse/routes/discourse";
-import RssPollingFeedSettings from "../../../admin/models/rss-polling-feed-settings";
-
-export default class AdminPluginsRssPolling extends DiscourseRoute {
- async model() {
- const result = await RssPollingFeedSettings.show();
- return trackedArray(result.feed_settings);
- }
-
- setupController(controller, model) {
- model.forEach((setting) => {
- setting.disabled = true;
- setting.editing = false;
- });
-
- controller.setProperties({
- model,
- });
- }
-}
diff --git a/plugins/discourse-rss-polling/assets/javascripts/discourse/rss-polling-route-map.js b/plugins/discourse-rss-polling/assets/javascripts/discourse/rss-polling-route-map.js
deleted file mode 100644
index 99d51f31537..00000000000
--- a/plugins/discourse-rss-polling/assets/javascripts/discourse/rss-polling-route-map.js
+++ /dev/null
@@ -1,8 +0,0 @@
-/* eslint-disable ember/route-path-style */
-export default {
- resource: "admin.adminPlugins",
- path: "/plugins",
- map() {
- this.route("rss_polling");
- },
-};
diff --git a/plugins/discourse-rss-polling/assets/javascripts/discourse/templates/admin-plugins/rss-polling.gjs b/plugins/discourse-rss-polling/assets/javascripts/discourse/templates/admin-plugins/rss-polling.gjs
deleted file mode 100644
index eec8f472364..00000000000
--- a/plugins/discourse-rss-polling/assets/javascripts/discourse/templates/admin-plugins/rss-polling.gjs
+++ /dev/null
@@ -1,144 +0,0 @@
-import { fn, hash } from "@ember/helper";
-import { on } from "@ember/modifier";
-import CategoryChooser from "discourse/select-kit/components/category-chooser";
-import EmailGroupUserChooser from "discourse/select-kit/components/email-group-user-chooser";
-import TagChooser from "discourse/select-kit/components/tag-chooser";
-import DButton from "discourse/ui-kit/d-button";
-import { i18n } from "discourse-i18n";
-
-export default <template>
- <div class="rss-polling-feed-settings">
- <table>
- <thead>
- <tr>
- <th colspan="2">{{i18n "admin.rss_polling.feed"}}</th>
- <th colspan="3">{{i18n "admin.rss_polling.discourse"}}</th>
- <th rowspan="2" colspan="2">
- <DButton
- @action={{@controller.create}}
- @icon="plus"
- @disabled={{@controller.saving}}
- class="btn-primary wide-button add-rss-polling-feed"
- />
- </th>
- </tr>
- <tr>
- <th>{{i18n "admin.rss_polling.feed_url"}}</th>
- <th>{{i18n "admin.rss_polling.feed_category_filter"}}</th>
- <th>{{i18n "admin.rss_polling.author"}}</th>
- <th>{{i18n "admin.rss_polling.discourse_category"}}</th>
- <th>{{i18n "admin.rss_polling.discourse_tags"}}</th>
- </tr>
- </thead>
-
- <tbody>
- {{#each @controller.model as |setting|}}
- <tr>
- <td>
- <input
- class="rss-polling-feed-url"
- disabled={{setting.disabled}}
- placeholder="https://blog.example.com/feed"
- type="text"
- value={{setting.feed_url}}
- {{on
- "input"
- (fn @controller.updateSettingProperty setting "feed_url")
- }}
- />
- </td>
- <td>
- <input
- class="rss-polling-feed-updates"
- disabled={{setting.disabled}}
- placeholder="updates"
- type="text"
- value={{setting.feed_category_filter}}
- {{on
- "input"
- (fn
- @controller.updateSettingProperty
- setting
- "feed_category_filter"
- )
- }}
- />
- </td>
- <td>
- <EmailGroupUserChooser
- @value={{setting.author_username}}
- @onChange={{fn @controller.updateAuthorUsername setting}}
- @options={{hash disabled=setting.disabled maximum=1}}
- class="rss-polling-feed-user"
- />
- </td>
- <td>
- <CategoryChooser
- @value={{setting.discourse_category_id}}
- @onChange={{fn (mut setting.discourse_category_id)}}
- @options={{hash disabled=setting.disabled}}
- class="small rss-polling-feed-category"
- />
- </td>
- <td>
- <TagChooser
- @tags={{setting.discourse_tags}}
- @allowCreate={{false}}
- @everyTag={{true}}
- @unlimitedTagCount={{true}}
- @onChange={{fn (mut setting.discourse_tags)}}
- @options={{hash disabled=setting.disabled}}
- class="small rss-polling-feed-tag"
- />
- </td>
- <td>
- {{#if setting.editing}}
- <DButton
- @icon="floppy-disk"
- @action={{fn @controller.updateFeedSetting setting}}
- @disabled={{@controller.unsavable}}
- class="btn-primary save-rss-polling-feed"
- />
- <DButton
- @icon="xmark"
- @action={{fn @controller.cancelEdit setting}}
- @disabled={{@controller.saving}}
- />
- {{else}}
- <DButton
- @icon="pencil"
- @action={{fn @controller.editFeedSetting setting}}
- @disabled={{@controller.saving}}
- />
- <DButton
- @icon="trash-can"
- @action={{fn @controller.destroyFeedSetting setting}}
- @disabled={{@controller.saving}}
- />
- {{/if}}
- </td>
- </tr>
- {{/each}}
- </tbody>
-
- <tfoot>
- <tr>
- <td></td>
- <td></td>
- <td></td>
- <td></td>
- <td></td>
- <td></td>
- </tr>
- </tfoot>
- </table>
-
- <p>
- <a
- href="https://meta.discourse.org/t/configure-the-discourse-rss-polling-plugin/156387"
- >
- {{i18n "admin.rss_polling.documentation"}}
- </a>
- </p>
- </div>
-</template>
diff --git a/plugins/discourse-rss-polling/assets/stylesheets/rss-polling.scss b/plugins/discourse-rss-polling/assets/stylesheets/rss-polling.scss
index 94c150ba9cf..ddeef7d118b 100644
--- a/plugins/discourse-rss-polling/assets/stylesheets/rss-polling.scss
+++ b/plugins/discourse-rss-polling/assets/stylesheets/rss-polling.scss
@@ -1,35 +1,400 @@
-.rss-polling-feed-settings {
- table {
- tr {
- td {
- position: relative;
+@use "lib/viewport";
- &:first-child input {
- max-width: 200px;
- }
+@mixin feed-url {
+ font-family: var(--d-font-family--monospace);
+ font-weight: normal;
+ overflow-wrap: anywhere;
+}
+
+.rss-polling-feed-editor {
+ display: flex;
+ flex-direction: column;
+ gap: var(--space-4);
+}
+
+.rss-polling-feed-form {
+ .form-kit__fieldset {
+ width: 100%;
+ }
+
+ &__discourse-fields {
+ display: flex;
+ flex-wrap: wrap;
+ gap: var(--space-4);
+
+ > .form-kit__field {
+ flex: 1 1 14em;
+ }
+ }
+
+ &__buttons {
+ display: flex;
+ flex-wrap: wrap;
+ gap: var(--space-2);
+ align-items: center;
+ }
+
+ &__enabled-control {
+ display: flex;
+ align-items: center;
+ gap: var(--space-2);
+ }
+
+ &__enabled {
+ font-weight: 600;
+ }
+
+ &__tag-requirement {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: var(--space-2);
+ margin-top: var(--space-1);
+ font-size: var(--font-down-1);
+ color: var(--primary-medium);
+ }
+}
+
+.rss-polling-feed-test {
+ margin-top: var(--space-4);
+
+ &__error {
+ margin-top: var(--space-4);
+ display: flex;
+ align-items: flex-start;
+ justify-content: space-between;
+ gap: var(--space-2);
+ }
+
+ &__header {
+ display: flex;
+ align-items: center;
+ gap: var(--space-2);
+ }
+
+ &__title {
+ margin: 0;
+ font-size: var(--font-0);
+ font-weight: 600;
+ }
+
+ &__count {
+ color: var(--primary-medium);
+ font-size: var(--font-down-1);
+ }
+
+ &__dismiss {
+ margin-inline-start: auto;
+ }
+
+ &__panel {
+ max-height: 22em;
+ overflow-y: auto;
+ margin-top: var(--space-2);
+ border: 1px solid var(--primary-low);
+ border-radius: var(--d-border-radius);
+ }
+
+ &__list {
+ margin: 0;
+ padding: 0;
+ list-style: none;
+ }
+
+ &__item {
+ display: flex;
+ align-items: flex-start;
+ gap: var(--space-2);
+ padding: var(--space-2);
+ border-inline-start: 3px solid transparent;
+
+ & + & {
+ border-top: 1px solid var(--primary-low);
+ }
+
+ &.--import {
+ border-inline-start-color: var(--success);
+ }
+
+ &.--update {
+ border-inline-start-color: var(--tertiary);
+ }
+
+ &.--skip {
+ border-inline-start-color: var(--primary-low-mid);
+
+ .rss-polling-feed-test__item-title {
+ color: var(--primary-high);
+ }
+ }
+ }
+
+ &__body {
+ display: flex;
+ flex-direction: column;
+ gap: var(--space-half);
+ min-width: 0;
+ }
+
+ &__item-title {
+ overflow-wrap: anywhere;
+
+ &:hover {
+ text-decoration: underline;
+ }
+ }
+
+ &__item-date,
+ &__item-reason {
+ font-size: var(--font-down-1);
+ color: var(--primary-medium);
+ }
+
+ &__item-reason a {
+ color: var(--tertiary);
+
+ &:hover {
+ text-decoration: underline;
+ }
+ }
+
+ &__more,
+ &__empty {
+ color: var(--primary-medium);
+ font-size: var(--font-down-1);
+ }
+}
+
+.rss-polling-feed {
+ .d-table__overview-name.rss-polling-feed__url {
+ @include feed-url;
+ max-width: 100%;
+ }
+
+ .d-table__cell.--overview {
+ width: 100%;
+ }
+
+ &__meta {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ margin-top: var(--space-1);
+ font-size: var(--font-down-1);
+ line-height: var(--line-height-medium);
+ color: var(--primary-medium);
+
+ > * {
+ display: inline-flex;
+ align-items: center;
+ }
+
+ > * + *::before {
+ content: "·";
+ margin-inline: var(--space-2);
+ color: var(--primary-low-mid);
+ }
+
+ a,
+ .badge-category__name,
+ .discourse-tag {
+ font-size: inherit;
+ }
+
+ .avatar {
+ width: 1.5em;
+ height: 1.5em;
+ }
+ }
+
+ &__author {
+ gap: var(--space-2);
+
+ a {
+ color: var(--primary-high);
+
+ &:hover {
+ color: var(--primary);
+ }
+ }
+ }
+
+ &__tags {
+ flex-wrap: wrap;
+ gap: var(--space-1);
+ }
+
+ &__filter {
+ gap: var(--space-1);
- &:nth-child(2) input {
- max-width: 100px;
- }
+ .d-icon {
+ color: var(--primary-medium);
+ }
+ }
+
+ // Set on the .d-toggle-switch root, which defines these vars and passes them
+ // to the slider; the __toggle class lands on the inner button, a sibling that
+ // can't reach the slider via inheritance.
+ .d-toggle-switch {
+ --toggle-switch-width: 36px;
+ --toggle-switch-height: 20px;
+ }
+
+ &.is-disabled {
+ .d-table__overview-link,
+ .rss-polling-feed__meta {
+ opacity: 0.5;
+ }
+ }
+
+ .d-table__cell-actions {
+ align-items: center;
+ }
- .user-chooser,
- .category-chooser {
- max-width: 150px;
- }
+ @include viewport.until(md) {
+ display: flex;
+ flex-wrap: wrap;
+
+ .d-table__cell {
+ font-size: var(--font-down-1);
+ border-top: 0;
+ }
+
+ .d-table__cell.--overview {
+ flex: 0 0 100%;
+ padding-inline: 0;
+ border-bottom: 1px solid var(--content-border-color);
+
+ .d-table__overview-link {
+ padding-inline: var(--space-2);
+ }
+
+ .d-table__overview-name {
+ font-size: var(--font-0);
+ }
+ }
+
+ &__meta {
+ flex-direction: column;
+ align-items: flex-start;
+ gap: var(--space-1);
+ margin-top: var(--space-2);
+ padding: var(--space-2) var(--space-2) 0;
+ border-top: 1px solid var(--content-border-color);
+
+ .d-table__mobile-label {
+ min-width: 8.5em;
+ font-weight: 700;
+ color: var(--primary);
+ }
+
+ > * {
+ gap: var(--space-2);
+ }
+
+ > * + *::before {
+ content: none;
+ }
+ }
+
+ &__filter .d-icon {
+ display: none;
+ }
- input {
- margin-bottom: 0;
- }
+ &__status {
+ flex: 1 1 auto;
+ display: flex;
+ align-items: center;
+ gap: var(--space-2);
- .select-kit.multi-select {
- width: 120px;
- }
+ .d-table__mobile-label {
+ color: var(--primary-medium);
}
}
- .wide-button {
+ .d-table__cell.--controls {
+ flex: 0 0 auto;
+ position: static;
+ }
+
+ .d-table__cell-actions {
+ justify-content: flex-end;
+ }
+ }
+}
+
+.rss-polling-feed-history {
+ &__table {
+ margin: 0;
+ }
+
+ .d-button-label {
+ display: none;
+ }
+
+ &__attempt {
+ &.--danger .rss-polling-feed-history__counts {
+ color: var(--danger);
+ }
+
+ .d-table__cell.--overview {
width: 100%;
- text-align: center;
}
+
+ @include viewport.from(md) {
+ border-top: 1px solid var(--primary-low);
+
+ &:first-child {
+ border-top: 0;
+ }
+
+ > .d-table__cell.--detail {
+ text-align: end;
+ white-space: nowrap;
+ }
+ }
+ }
+
+ &__summary {
+ display: inline-flex;
+ gap: var(--space-2);
+ align-items: center;
+ text-align: start;
+ padding-inline-start: 0;
+ padding-inline-end: calc(var(--space-8) * 6);
+
+ svg.d-icon {
+ margin-inline-end: 0;
+ }
+ }
+
+ &__date {
+ font-weight: 600;
+ }
+
+ &__counts {
+ color: var(--primary-medium);
+ font-size: var(--font-down-1);
+ }
+
+ &__detail > .d-table__cell {
+ padding-top: 0;
+
+ @include viewport.from(md) {
+ padding-inline: var(--space-2);
+ }
+ }
+
+ &__more {
+ margin-top: var(--space-2);
+ }
+
+ &__empty {
+ color: var(--primary-medium);
+ font-size: var(--font-down-1);
+ }
+
+ .rss-polling-feed-test__list {
+ margin-top: var(--space-1);
}
}
diff --git a/plugins/discourse-rss-polling/config/locales/client.en.yml b/plugins/discourse-rss-polling/config/locales/client.en.yml
index f3eec28a502..8836b1730c9 100644
--- a/plugins/discourse-rss-polling/config/locales/client.en.yml
+++ b/plugins/discourse-rss-polling/config/locales/client.en.yml
@@ -9,14 +9,96 @@ en:
title: RSS Polling
admin:
+ logs:
+ staff_actions:
+ actions:
+ create_rss_polling_feed: create RSS feed
+ update_rss_polling_feed: update RSS feed
+ destroy_rss_polling_feed: delete RSS feed
+ enable_rss_polling_feed: enable RSS feed
+ disable_rss_polling_feed: disable RSS feed
+ poll_rss_polling_feed: poll RSS feed now
rss_polling:
- feed: Feed Settings
- discourse: Discourse Settings
+ feed_settings: Feed settings
+ discourse_settings: Discourse settings
author: Author
feed_url: URL
+ feed_url_must_be_http: Enter a valid feed URL starting with http:// or https://.
discourse_category: Category
discourse_tags: Tags
- feed_category_filter: Category Filter
- documentation: RSS Polling configuration documentation
- destroy_feed:
- confirm: "Are you sure you want to delete this feed?"
+ required_tags_hint: "This category requires one of these tags — add one or imported topics will be rejected:"
+ required_tag_error: 'Add at least %{count} tag(s) from the "%{tag_group}" group, otherwise imported topics will be rejected.'
+ feed_category_filter: Category filter
+ feed_category_filter_description: Only import items whose feed category contains this text (case-insensitive). Leave blank to import everything.
+ showing: "Showing the first %{count} of %{total} items."
+ feeds:
+ title: Feeds
+ nav_description: Manage the RSS/Atom feeds that are imported into Discourse.
+ description: Configure the RSS/Atom feeds that are polled and imported as topics.
+ add: Add feed
+ add_header: Add feed
+ edit_header: Edit feed
+ empty: You haven't configured any feeds yet.
+ edit: Edit
+ delete: Delete
+ enable: Enable feed
+ disable: Disable feed
+ back: Back to feeds
+ save: Save
+ confirm_delete: "Are you sure you want to delete this feed?"
+ delete_success: Feed deleted
+ save_success: Feed saved
+ enable_success: Feed enabled
+ disable_success: Feed disabled
+ test:
+ button: Test feed
+ title: Preview
+ empty: This feed returned no items.
+ dismiss: Dismiss
+ would_import: Would import
+ summary:
+ would_import: "%{count} would import"
+ already_imported: "%{count} already imported"
+ skipped: "%{count} would skip"
+ already_imported: "Already imported — polling would update the <a href='%{topic_url}' target='_blank' rel='noopener noreferrer'>existing topic</a>."
+ already_imported_plain: "Already imported — polling would update the existing topic."
+ skip_reasons:
+ missing_content: Skipped — the item has no content.
+ missing_title: Skipped — the item has no title.
+ invalid_url: Skipped — the item has no valid link to import from.
+ category_filter_mismatch: "Skipped — item categories: %{categories}"
+ category_filter_mismatch_none: Skipped — the item has no categories.
+ errors:
+ fetch_failed: Couldn't fetch the feed. Check that the URL is correct and reachable.
+ parse_failed: The response doesn't look like a valid RSS or Atom feed.
+ invalid_feed: The feed couldn't be read because it's malformed.
+ blank_feed_url: Enter a feed URL to test.
+ category_deleted: The category this feed imports into no longer exists. Edit the feed and choose a new category.
+ unknown: Couldn't read this feed. It may be temporarily unavailable or returning unexpected content. Test the feed to diagnose, or check the logs for details.
+ status:
+ enabled: Enabled
+ disabled: Disabled
+ disabled_note: Won't poll on schedule
+ history:
+ recent: Recent polls
+ show_older: "Show %{count} older"
+ poll_now: Poll now
+ poll_now_dirty: Save your changes before polling.
+ poll_now_disabled: Enable the feed before polling.
+ poll_confirm: Polling now will fetch this feed and import or update topics. Continue?
+ poll_started: Polling started — the latest attempt will appear here shortly.
+ empty: This feed hasn't been polled yet.
+ no_items: No items were processed in this poll.
+ no_changes: No changes
+ imported_count: "%{count} imported"
+ updated_count: "%{count} updated"
+ skipped_count: "%{count} skipped"
+ failed_count: "%{count} failed"
+ imported: "Imported as a new <a href='%{topic_url}' target='_blank' rel='noopener noreferrer'>topic</a>."
+ imported_plain: "Imported as a new topic."
+ updated: "Updated the <a href='%{topic_url}' target='_blank' rel='noopener noreferrer'>existing topic</a>."
+ updated_plain: "Updated the existing topic."
+ failed: Failed to import.
+ failed_reasons:
+ import_rejected: "Couldn't be imported — the item doesn't have a valid link to import from."
+ import_error: "Couldn't be imported: %{error}"
diff --git a/plugins/discourse-rss-polling/config/locales/server.en.yml b/plugins/discourse-rss-polling/config/locales/server.en.yml
index 2ce2728fb05..2649cbcc121 100644
--- a/plugins/discourse-rss-polling/config/locales/server.en.yml
+++ b/plugins/discourse-rss-polling/config/locales/server.en.yml
@@ -1,9 +1,13 @@
en:
site_settings:
- rss_polling_enabled: "[RSS Polling] Enable importing embed posts from multiple RSS feeds"
- rss_polling_frequency: "[RSS Polling] Feed polling frequency, in minutes"
- rss_polling_use_pubdate: "[RSS Polling] Set topic creation date to the pubDate found in the RSS feed"
- rss_polling_update_tags: "[RSS Polling] Update topic tags when a topic is updated. Disabling this pulls initial tags but disables further tag changes."
+ rss_polling_enabled: "Enable importing embed posts from multiple RSS feeds"
+ rss_polling_frequency: "Feed polling frequency, in minutes"
+ rss_polling_feed_request_timeout: "Maximum time, in seconds, to wait for a feed to respond when fetching it."
+ rss_polling_verbose_logging: "Log detailed information for each poll attempt, including which items were imported or skipped and why."
+ rss_polling_use_pubdate: "Set topic creation date to the pubDate found in the RSS feed"
+ rss_polling_update_tags: "Update topic tags when a topic is updated. Disabling this pulls initial tags but disables further tag changes."
rss_polling:
errors:
+ feed_url_must_be_http: "The feed URL must start with http:// or https://."
unknown_author_username: "No user found with username '%{username}'."
+ required_tag_group: "Topics in \"%{category}\" require at least %{count} tag(s) from the \"%{tag_group}\" group (%{tags}). Add one of those tags so imported items aren't rejected."
diff --git a/plugins/discourse-rss-polling/config/routes.rb b/plugins/discourse-rss-polling/config/routes.rb
index 15e325cf7c7..89d0864ee03 100644
--- a/plugins/discourse-rss-polling/config/routes.rb
+++ b/plugins/discourse-rss-polling/config/routes.rb
@@ -1,7 +1,20 @@
# frozen_string_literal: true
DiscourseRssPolling::Engine.routes.draw do
- root "feed_settings#show"
+ post "feed_settings/test" => "feed_settings#test", :constraints => StaffConstraint.new
+ get "feed_settings/category_requirements" => "feed_settings#category_requirements",
+ :constraints => StaffConstraint.new
+ get "feed_settings/:id/history" => "feed_settings#history", :constraints => StaffConstraint.new
+ put "feed_settings/:id/enabled" => "feed_settings#set_enabled",
+ :constraints => StaffConstraint.new
+ post "feed_settings/:id/poll" => "feed_settings#poll", :constraints => StaffConstraint.new
+ delete "feed_settings/:id" => "feed_settings#destroy", :constraints => StaffConstraint.new
+ get "feed_settings/:id" => "feed_settings#feed", :constraints => StaffConstraint.new
+ resource :feed_settings, constraints: StaffConstraint.new, only: %i[show update]
+end
- resource :feed_settings, constraints: StaffConstraint.new, only: %i[show update destroy]
+Discourse::Application.routes.draw do
+ scope "/admin/plugins/discourse-rss-polling", constraints: StaffConstraint.new do
+ get "/feeds(/*path)" => "discourse_rss_polling/feed_settings#index"
+ end
end
diff --git a/plugins/discourse-rss-polling/config/settings.yml b/plugins/discourse-rss-polling/config/settings.yml
index 4a865891280..dbb24f7a161 100644
--- a/plugins/discourse-rss-polling/config/settings.yml
+++ b/plugins/discourse-rss-polling/config/settings.yml
@@ -3,19 +3,22 @@ plugins:
default: false
shadowed_by_global: true
- # This stores a YAML serialized array of feed setting tuples, in the format of
- # [feed_url, author_username]
- rss_polling_feed_setting:
- default: "[]"
- hidden: true
- client: false
-
rss_polling_frequency:
min: 10
max: 180
default: 30
client: false
+ rss_polling_feed_request_timeout:
+ min: 5
+ max: 300
+ default: 30
+ client: false
+
+ rss_polling_verbose_logging:
+ default: false
+ client: false
+
rss_polling_use_pubdate:
default: false
client: false
diff --git a/plugins/discourse-rss-polling/db/migrate/20260611102547_create_rss_polling_poll_attempts.rb b/plugins/discourse-rss-polling/db/migrate/20260611102547_create_rss_polling_poll_attempts.rb
new file mode 100644
index 00000000000..2877ad669b2
--- /dev/null
+++ b/plugins/discourse-rss-polling/db/migrate/20260611102547_create_rss_polling_poll_attempts.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class CreateRssPollingPollAttempts < ActiveRecord::Migration[8.0]
+ def change
+ create_table :discourse_rss_polling_poll_attempts do |t|
+ t.bigint :rss_feed_id, null: false
+ t.integer :status, null: false, default: 0
+ t.integer :imported_count, null: false, default: 0
+ t.integer :updated_count, null: false, default: 0
+ t.integer :skipped_count, null: false, default: 0
+ t.integer :failed_count, null: false, default: 0
+ t.text :error
+ t.jsonb :items, null: false, default: []
+ t.timestamps null: false
+ end
+
+ add_index :discourse_rss_polling_poll_attempts,
+ %i[rss_feed_id created_at id],
+ order: {
+ created_at: :desc,
+ id: :desc,
+ },
+ name: "idx_rss_polling_poll_attempts_on_feed_created_id_desc"
+ end
+end
diff --git a/plugins/discourse-rss-polling/db/migrate/20260612064730_add_enabled_to_discourse_rss_polling_rss_feeds.rb b/plugins/discourse-rss-polling/db/migrate/20260612064730_add_enabled_to_discourse_rss_polling_rss_feeds.rb
new file mode 100644
index 00000000000..bc520d7f3a0
--- /dev/null
+++ b/plugins/discourse-rss-polling/db/migrate/20260612064730_add_enabled_to_discourse_rss_polling_rss_feeds.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddEnabledToDiscourseRssPollingRssFeeds < ActiveRecord::Migration[8.0]
+ def change
+ add_column :discourse_rss_polling_rss_feeds, :enabled, :boolean, null: false, default: true
+ end
+end
diff --git a/plugins/discourse-rss-polling/db/post_migrate/20260619085855_remove_rss_polling_feed_setting.rb b/plugins/discourse-rss-polling/db/post_migrate/20260619085855_remove_rss_polling_feed_setting.rb
new file mode 100644
index 00000000000..444ec5d34bc
--- /dev/null
+++ b/plugins/discourse-rss-polling/db/post_migrate/20260619085855_remove_rss_polling_feed_setting.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+class RemoveRssPollingFeedSetting < ActiveRecord::Migration[8.0]
+ def up
+ execute "DELETE FROM site_settings WHERE name = 'rss_polling_feed_setting'"
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
diff --git a/plugins/discourse-rss-polling/plugin.rb b/plugins/discourse-rss-polling/plugin.rb
index 3d46293018d..591f5360fd1 100644
--- a/plugins/discourse-rss-polling/plugin.rb
+++ b/plugins/discourse-rss-polling/plugin.rb
@@ -7,10 +7,11 @@
# url: https://github.com/discourse/discourse/tree/main/plugins/discourse-rss-polling
enabled_site_setting :rss_polling_enabled
-add_admin_route "rss_polling.title", "rss_polling"
+add_admin_route "rss_polling.title", "discourse-rss-polling", { use_new_show_route: true }
register_asset "stylesheets/rss-polling.scss"
-register_svg_icon "floppy-disk"
register_svg_icon "rss"
+register_svg_icon "filter"
+register_svg_icon "arrows-rotate"
module ::DiscourseRssPolling
PLUGIN_NAME = "discourse_rss_polling"
diff --git a/plugins/discourse-rss-polling/spec/fixtures/files/multiple_categories.atom b/plugins/discourse-rss-polling/spec/fixtures/files/multiple_categories.atom
index d67ac599090..0405e610ffc 100644
--- a/plugins/discourse-rss-polling/spec/fixtures/files/multiple_categories.atom
+++ b/plugins/discourse-rss-polling/spec/fixtures/files/multiple_categories.atom
@@ -11,8 +11,8 @@
<author>
<name>xrav3nz</name>
</author>
- <category>spec</category>
- <category>xrav3nz diary</category>
+ <category term="spec"/>
+ <category term="xrav3nz diary"/>
<link href="https://blog.discourse.org/2017/09/poll-feed-spec-fixture/" rel="alternate" type="text/html"/>
<published>2019-08-16T21:46:39Z</published>
<updated>2019-08-16T21:46:39Z</updated>
diff --git a/plugins/discourse-rss-polling/spec/jobs/poll_all_feeds_spec.rb b/plugins/discourse-rss-polling/spec/jobs/poll_all_feeds_spec.rb
index 119990f400a..ec2a95b93df 100644
--- a/plugins/discourse-rss-polling/spec/jobs/poll_all_feeds_spec.rb
+++ b/plugins/discourse-rss-polling/spec/jobs/poll_all_feeds_spec.rb
@@ -9,10 +9,10 @@ RSpec.describe Jobs::DiscourseRssPolling::PollAllFeeds do
before { SiteSetting.rss_polling_enabled = true }
describe "#execute" do
- before do
- Fabricate(:rss_feed, url: "https://www.example.com/feed", user: user_a)
- Fabricate(:rss_feed, url: "https://blog.discourse.org/feed/", user: user_b)
+ fab!(:feed_a) { Fabricate(:rss_feed, url: "https://www.example.com/feed", user: user_a) }
+ fab!(:feed_b) { Fabricate(:rss_feed, url: "https://blog.discourse.org/feed/", user: user_b) }
+ before do
Jobs.run_later!
Discourse.redis.del("rss-polling-feeds-polled")
end
@@ -46,5 +46,20 @@ RSpec.describe Jobs::DiscourseRssPolling::PollAllFeeds do
end
end
end
+
+ context "when a feed is disabled" do
+ before { feed_a.update!(enabled: false) }
+
+ it "only queues a PollFeed job for the enabled feeds" do
+ Sidekiq::Testing.fake! do
+ expect { job.execute({}) }.to change { Jobs::DiscourseRssPolling::PollFeed.jobs.size }.by(
+ 1,
+ )
+
+ enqueued = Jobs::DiscourseRssPolling::PollFeed.jobs.last["args"][0]
+ expect(enqueued["feed_url"]).to eq("https://blog.discourse.org/feed/")
+ end
+ end
+ end
end
end
diff --git a/plugins/discourse-rss-polling/spec/jobs/poll_feed_spec.rb b/plugins/discourse-rss-polling/spec/jobs/poll_feed_spec.rb
index d604a5eb605..c5d58bfe1c0 100644
--- a/plugins/discourse-rss-polling/spec/jobs/poll_feed_spec.rb
+++ b/plugins/discourse-rss-polling/spec/jobs/poll_feed_spec.rb
@@ -197,5 +197,203 @@ RSpec.describe Jobs::DiscourseRssPolling::PollFeed do
}.by(1)
end
end
+
+ context "with an rss_feed_id" do
+ let(:rss_feed) { Fabricate(:rss_feed, url: feed_url, user: author) }
+
+ it "records a poll attempt with per-item outcomes" do
+ expect {
+ job.execute(feed_url: feed_url, user_id: author.id, rss_feed_id: rss_feed.id)
+ }.to change { DiscourseRssPolling::PollAttempt.count }.by(1)
+
+ attempt = DiscourseRssPolling::PollAttempt.last
+ expect(attempt.rss_feed_id).to eq(rss_feed.id)
+ expect(attempt.status).to eq("success")
+ expect(attempt.imported_count).to eq(1)
+ expect(attempt.items.first).to include(
+ "status" => "imported",
+ "title" => "Poll Feed Spec Fixture",
+ )
+ expect(attempt.items.first["topic_url"]).to be_present
+ end
+
+ it "publishes the recorded attempt to the admin-only message bus channel" do
+ messages =
+ MessageBus.track_publish("/rss-polling/feeds/#{rss_feed.id}") do
+ job.execute(feed_url: feed_url, user_id: author.id, rss_feed_id: rss_feed.id)
+ end
+
+ expect(messages.size).to eq(1)
+ expect(messages.first.group_ids).to eq([Group::AUTO_GROUPS[:admins]])
+ expect(messages.first.data[:status]).to eq("success")
+ expect(messages.first.data[:imported_count]).to eq(1)
+ end
+
+ it "polls again when force is true even if it was polled recently" do
+ job.execute(feed_url: feed_url, user_id: author.id, rss_feed_id: rss_feed.id)
+ expect(DiscourseRssPolling::PollAttempt.count).to eq(1)
+
+ job.execute(feed_url: feed_url, user_id: author.id, rss_feed_id: rss_feed.id)
+ expect(DiscourseRssPolling::PollAttempt.count).to eq(1)
+
+ job.execute(feed_url: feed_url, user_id: author.id, rss_feed_id: rss_feed.id, force: true)
+ expect(DiscourseRssPolling::PollAttempt.count).to eq(2)
+ end
+
+ it "marks the feed as recently polled when forced so the next scheduled poll is throttled" do
+ job.execute(feed_url: feed_url, user_id: author.id, rss_feed_id: rss_feed.id, force: true)
+ expect(DiscourseRssPolling::PollAttempt.count).to eq(1)
+
+ job.execute(feed_url: feed_url, user_id: author.id, rss_feed_id: rss_feed.id)
+ expect(DiscourseRssPolling::PollAttempt.count).to eq(1)
+ end
+
+ it "does not poll a disabled feed on a scheduled (non-forced) run" do
+ rss_feed.update!(enabled: false)
+
+ expect {
+ job.execute(feed_url: feed_url, user_id: author.id, rss_feed_id: rss_feed.id)
+ }.not_to change { DiscourseRssPolling::PollAttempt.count }
+ end
+
+ it "does not poll a disabled feed even when forced" do
+ rss_feed.update!(enabled: false)
+
+ expect {
+ job.execute(feed_url: feed_url, user_id: author.id, rss_feed_id: rss_feed.id, force: true)
+ }.not_to change { DiscourseRssPolling::PollAttempt.count }
+ end
+
+ it "records a skipped outcome when the category filter doesn't match" do
+ job.execute(
+ feed_url: feed_url,
+ user_id: author.id,
+ rss_feed_id: rss_feed.id,
+ feed_category_filter: "does-not-match",
+ )
+
+ attempt = DiscourseRssPolling::PollAttempt.last
+ expect(attempt.skipped_count).to eq(1)
+ expect(attempt.items.first).to include(
+ "status" => "skipped",
+ "reason" => "category_filter_mismatch",
+ )
+ end
+
+ it "records a failed outcome with a reason when an item can't be imported" do
+ TopicEmbed.stubs(:import).returns(nil)
+
+ job.execute(feed_url: feed_url, user_id: author.id, rss_feed_id: rss_feed.id)
+
+ attempt = DiscourseRssPolling::PollAttempt.last
+ expect(attempt.status).to eq("error")
+ expect(attempt.failed_count).to eq(1)
+ expect(attempt.imported_count).to eq(0)
+ expect(attempt.items.first).to include("status" => "failed", "reason" => "import_rejected")
+ end
+
+ it "isolates a failing item, records its error message, and keeps polling" do
+ TopicEmbed.stubs(:import).raises(StandardError.new("boom"))
+
+ expect {
+ job.execute(feed_url: feed_url, user_id: author.id, rss_feed_id: rss_feed.id)
+ }.not_to raise_error
+
+ attempt = DiscourseRssPolling::PollAttempt.last
+ expect(attempt.status).to eq("error")
+ expect(attempt.failed_count).to eq(1)
+ expect(attempt.items.first["status"]).to eq("failed")
+ expect(attempt.items.first["reason"]).to include("boom")
+ end
+
+ it "records an error attempt and re-raises when the whole poll fails" do
+ DiscourseRssPolling::RssFeed::Action::FetchFeed.stubs(:call).raises(
+ StandardError.new("kaboom"),
+ )
+
+ expect {
+ job.execute(feed_url: feed_url, user_id: author.id, rss_feed_id: rss_feed.id)
+ }.to raise_error(StandardError)
+
+ attempt = DiscourseRssPolling::PollAttempt.last
+ expect(attempt).to be_present
+ expect(attempt.status).to eq("error")
+ expect(attempt.error).to eq("unknown")
+ end
+
+ it "records a breadcrumb attempt when the target category was deleted" do
+ category = Fabricate(:category)
+ deleted_id = category.id
+ category.destroy!
+
+ expect {
+ job.execute(
+ feed_url: feed_url,
+ user_id: author.id,
+ rss_feed_id: rss_feed.id,
+ discourse_category_id: deleted_id,
+ )
+ }.to change { DiscourseRssPolling::PollAttempt.count }.by(1)
+
+ attempt = DiscourseRssPolling::PollAttempt.last
+ expect(attempt.status).to eq("error")
+ expect(attempt.error).to eq("category_deleted")
+ expect(attempt.items).to be_empty
+ end
+
+ it "does not record duplicate category_deleted breadcrumbs on repeated scheduled polls" do
+ category = Fabricate(:category)
+ deleted_id = category.id
+ category.destroy!
+
+ 2.times do
+ job.execute(
+ feed_url: feed_url,
+ user_id: author.id,
+ rss_feed_id: rss_feed.id,
+ discourse_category_id: deleted_id,
+ )
+ end
+
+ expect(
+ DiscourseRssPolling::PollAttempt.where(
+ rss_feed_id: rss_feed.id,
+ error: "category_deleted",
+ ).count,
+ ).to eq(1)
+ end
+
+ it "resumes polling once the category is restored (throttle not consumed by the breadcrumb)" do
+ category = Fabricate(:category)
+ deleted_id = category.id
+ category.destroy!
+
+ job.execute(
+ feed_url: feed_url,
+ user_id: author.id,
+ rss_feed_id: rss_feed.id,
+ discourse_category_id: deleted_id,
+ )
+
+ new_category = Fabricate(:category)
+
+ expect {
+ job.execute(
+ feed_url: feed_url,
+ user_id: author.id,
+ rss_feed_id: rss_feed.id,
+ discourse_category_id: new_category.id,
+ )
+ }.to change { author.topics.count }.by(1)
+ end
+
+ it "keeps only the most recent attempts per feed" do
+ stub_const(DiscourseRssPolling::PollAttempt, "KEEP_PER_FEED", 2) do
+ 4.times { DiscourseRssPolling::PollAttempt.record!(rss_feed_id: rss_feed.id, items: []) }
+ end
+
+ expect(DiscourseRssPolling::PollAttempt.where(rss_feed_id: rss_feed.id).count).to eq(2)
+ end
+ end
end
end
diff --git a/plugins/discourse-rss-polling/spec/models/feed_item_spec.rb b/plugins/discourse-rss-polling/spec/models/feed_item_spec.rb
index bcfd1e9ef97..30d8e8869de 100644
--- a/plugins/discourse-rss-polling/spec/models/feed_item_spec.rb
+++ b/plugins/discourse-rss-polling/spec/models/feed_item_spec.rb
@@ -9,6 +9,8 @@ RSpec.describe DiscourseRssPolling::FeedItem do
it { expect(feed_item.content).to eq(expected[:content]) }
it { expect(feed_item.url).to eq(expected[:url]) }
it { expect(feed_item.title).to eq(expected[:title]) }
+
+ it { expect(feed_item.categories).to eq(expected[:categories]) } if expected.key?(:categories)
end
context "with empty item" do
diff --git a/plugins/discourse-rss-polling/spec/models/rss_feed_spec.rb b/plugins/discourse-rss-polling/spec/models/rss_feed_spec.rb
index e6926629572..88c62cd0925 100644
--- a/plugins/discourse-rss-polling/spec/models/rss_feed_spec.rb
+++ b/plugins/discourse-rss-polling/spec/models/rss_feed_spec.rb
@@ -8,23 +8,26 @@ RSpec.describe DiscourseRssPolling::RssFeed do
feed = Fabricate(:rss_feed, user: user)
expect(feed.user).to eq(user)
end
- end
- describe "#author_username" do
- it "returns the associated user's current username" do
- feed = Fabricate(:rss_feed, user: user)
- expect(feed.author_username).to eq(user.username)
+ it "falls back to the system user when the author is missing or was deleted" do
+ feed = Fabricate(:rss_feed, user: nil)
+ expect(feed.user).to eq(Discourse.system_user)
end
+ end
- it "reflects username changes without requiring a feed update" do
+ describe "#enabled" do
+ it "defaults to true" do
feed = Fabricate(:rss_feed, user: user)
- UsernameChanger.change(user, "shiny_new_name")
- expect(feed.reload.author_username).to eq("shiny_new_name")
+ expect(feed.enabled).to eq(true)
end
+ end
- it "returns nil when no user is associated" do
- feed = Fabricate(:rss_feed, user: nil)
- expect(feed.author_username).to be_nil
+ describe ".enabled" do
+ it "only returns enabled feeds" do
+ enabled_feed = Fabricate(:rss_feed, user: user)
+ Fabricate(:rss_feed, user: user, enabled: false)
+
+ expect(described_class.enabled).to contain_exactly(enabled_feed)
end
end
diff --git a/plugins/discourse-rss-polling/spec/requests/feed_settings_controller_spec.rb b/plugins/discourse-rss-polling/spec/requests/feed_settings_controller_spec.rb
index 86404df729e..ea0da4c0738 100644
--- a/plugins/discourse-rss-polling/spec/requests/feed_settings_controller_spec.rb
+++ b/plugins/discourse-rss-polling/spec/requests/feed_settings_controller_spec.rb
@@ -26,24 +26,356 @@ RSpec.describe DiscourseRssPolling::FeedSettingsController do
expect(response.status).to eq(200)
body = response.parsed_body
expect(body["feed_settings"].length).to eq(1)
- expect(body["feed_settings"].first).to include(
- "feed_url" => "https://blog.discourse.org/feed",
- "user_id" => Discourse.system_user.id,
- "author_username" => Discourse.system_user.username,
+ feed = body["feed_settings"].first
+ expect(feed).to include(
+ "redacted_feed_url" => "https://blog.discourse.org/feed",
"discourse_category_id" => 4,
"feed_category_filter" => "updates",
+ "enabled" => true,
)
+ expect(feed).not_to have_key("feed_url")
+ expect(feed["author"]).to include(
+ "id" => Discourse.system_user.id,
+ "username" => Discourse.system_user.username,
+ )
+ end
+
+ it "serializes the enabled flag for each feed" do
+ Fabricate(
+ :rss_feed,
+ url: "https://disabled.example.com/feed",
+ user: Discourse.system_user,
+ enabled: false,
+ )
+
+ get "/admin/plugins/rss_polling/feed_settings.json"
+
+ feeds = response.parsed_body["feed_settings"].index_by { |feed| feed["redacted_feed_url"] }
+ expect(feeds["https://blog.discourse.org/feed"]["enabled"]).to eq(true)
+ expect(feeds["https://disabled.example.com/feed"]["enabled"]).to eq(false)
+ end
+
+ it "omits the raw credential-bearing feed_url from the list, exposing only the redacted url" do
+ Fabricate(
+ :rss_feed,
+ url: "https://creds.example.com/feed?api_key=secret&api_username=system",
+ user: Discourse.system_user,
+ )
+
+ get "/admin/plugins/rss_polling/feed_settings.json"
+
+ feed =
+ response.parsed_body["feed_settings"].find do |f|
+ f["redacted_feed_url"].include?("creds.example.com")
+ end
+ expect(feed).not_to have_key("feed_url")
+ expect(feed["redacted_feed_url"]).not_to include("secret")
+ expect(feed["redacted_feed_url"]).not_to include("api_key")
+ end
+
+ it "sorts the feeds by URL" do
+ Fabricate(:rss_feed, url: "https://aaa.example.com/feed", user: Discourse.system_user)
+ Fabricate(:rss_feed, url: "https://zzz.example.com/feed", user: Discourse.system_user)
+
+ get "/admin/plugins/rss_polling/feed_settings.json"
+
+ urls = response.parsed_body["feed_settings"].map { |feed| feed["redacted_feed_url"] }
+ expect(urls).to eq(urls.sort)
+ end
+ end
+
+ describe "#feed" do
+ fab!(:rss_feed) do
+ Fabricate(
+ :rss_feed,
+ url: "https://creds.example.com/feed?api_key=secret&api_username=system",
+ user: Discourse.system_user,
+ category_id: 4,
+ category_filter: "updates",
+ )
+ end
+
+ it "returns the single feed with the raw feed_url for editing" do
+ get "/admin/plugins/rss_polling/feed_settings/#{rss_feed.id}.json"
+
+ expect(response.status).to eq(200)
+ body = response.parsed_body
+ expect(body["id"]).to eq(rss_feed.id)
+ expect(body["feed_url"]).to eq(
+ "https://creds.example.com/feed?api_key=secret&api_username=system",
+ )
+ expect(body["redacted_feed_url"]).not_to include("secret")
+ expect(body["feed_category_filter"]).to eq("updates")
+ expect(body["author"]["id"]).to eq(Discourse.system_user.id)
+ end
+
+ it "returns 404 for a feed that does not exist" do
+ get "/admin/plugins/rss_polling/feed_settings/0.json"
+
+ expect(response.status).to eq(404)
+ end
+ end
+
+ describe "#test" do
+ let(:feed_url) { "https://blog.discourse.org/feed/" }
+ let(:raw_feed) { file_from_fixtures("feed.rss", "feed") }
+
+ it "reports which items would be imported" do
+ stub_request(:get, feed_url).to_return(status: 200, body: raw_feed)
+
+ post "/admin/plugins/rss_polling/feed_settings/test.json", params: { feed_url: }
+
+ expect(response.status).to eq(200)
+ body = response.parsed_body
+ expect(body["items"]).to be_present
+ expect(body["items"].first["status"]).to eq("would_import")
+ expect(body["total"]).to eq(body["items"].length)
+ end
+
+ it "reports items skipped by the category filter with a reason" do
+ stub_request(:get, feed_url).to_return(status: 200, body: raw_feed)
+
+ post "/admin/plugins/rss_polling/feed_settings/test.json",
+ params: {
+ feed_url:,
+ feed_category_filter: "does-not-match",
+ }
+
+ body = response.parsed_body
+ expect(body["items"].map { |item| item["status"] }).to all(eq("skipped"))
+ expect(body["items"].first["reason"]).to eq("category_filter_mismatch")
+ end
+
+ it "returns an error when the feed cannot be fetched" do
+ stub_request(:get, feed_url).to_return(status: 500)
+
+ post "/admin/plugins/rss_polling/feed_settings/test.json", params: { feed_url: }
+
+ expect(response.status).to eq(422)
+ expect(response.parsed_body["error"]).to eq("fetch_failed")
+ end
+
+ it "requires a feed_url" do
+ post "/admin/plugins/rss_polling/feed_settings/test.json", params: {}
+
+ expect(response.status).to eq(400)
+ expect(response.parsed_body["error"]).to eq("blank_feed_url")
+ end
+
+ it "trims surrounding whitespace from the feed url before fetching" do
+ stub_request(:get, feed_url).to_return(status: 200, body: raw_feed)
+
+ post "/admin/plugins/rss_polling/feed_settings/test.json",
+ params: {
+ feed_url: " #{feed_url} ",
+ }
+
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["items"]).to be_present
+ end
+
+ it "handles Atom feeds (term-style categories, <updated>-only dates)" do
+ atom = <<~XML
+ <?xml version="1.0" encoding="utf-8"?>
+ <feed xmlns="http://www.w3.org/2005/Atom">
+ <title>Atom feed</title>
+ <entry>
+ <title>An atom entry</title>
+ <link href="https://example.com/atom-entry" rel="alternate" type="text/html"/>
+ <id>https://example.com/atom-entry</id>
+ <updated>2025-05-07T17:46:43Z</updated>
+ <content type="html">Body content</content>
+ <category term="ai"/>
+ <category term="llms"/>
+ </entry>
+ </feed>
+ XML
+ stub_request(:get, feed_url).to_return(status: 200, body: atom)
+
+ post "/admin/plugins/rss_polling/feed_settings/test.json", params: { feed_url: }
+
+ expect(response.status).to eq(200)
+ item = response.parsed_body["items"].first
+ expect(item["categories"]).to eq(%w[ai llms])
+ expect(item["published_at"]).to be_present
+ expect(item["status"]).to eq("would_import")
+ end
+
+ it "matches the category filter case-insensitively" do
+ stub_request(:get, feed_url).to_return(status: 200, body: raw_feed)
+
+ post "/admin/plugins/rss_polling/feed_settings/test.json",
+ params: {
+ feed_url:,
+ feed_category_filter: "SPEC",
+ }
+
+ expect(response.parsed_body["items"].first["status"]).to eq("would_import")
+ end
+
+ it "flags items that are already imported and links to the existing topic" do
+ stub_request(:get, feed_url).to_return(status: 200, body: raw_feed)
+ imported_post =
+ TopicEmbed.import(
+ Discourse.system_user,
+ "https://blog.discourse.org/2017/09/poll-feed-spec-fixture/",
+ "Poll Feed Spec Fixture",
+ "content",
+ )
+
+ post "/admin/plugins/rss_polling/feed_settings/test.json", params: { feed_url: }
+
+ item = response.parsed_body["items"].first
+ expect(item["status"]).to eq("already_imported")
+ expect(item["topic_url"]).to eq(imported_post.topic.relative_url)
+ end
+
+ it "returns 422 with an unknown error when building the preview raises unexpectedly" do
+ stub_request(:get, feed_url).to_return(status: 200, body: raw_feed)
+ DiscourseRssPolling::RssFeed::Action::BuildPreview
+ .any_instance
+ .stubs(:call)
+ .raises(StandardError.new("boom"))
+
+ post "/admin/plugins/rss_polling/feed_settings/test.json", params: { feed_url: }
+
+ expect(response.status).to eq(422)
+ expect(response.parsed_body["error"]).to eq("unknown")
+ end
+ end
+
+ describe "#category_requirements" do
+ it "returns the category's required tag groups with their tags" do
+ category = Fabricate(:category)
+ tag_group = Fabricate(:tag_group, tags: [Fabricate(:tag, name: "required-tag")])
+ CategoryRequiredTagGroup.create!(category:, tag_group:, min_count: 1)
+
+ get "/admin/plugins/rss_polling/feed_settings/category_requirements.json",
+ params: {
+ category_id: category.id,
+ }
+
+ expect(response.status).to eq(200)
+ group = response.parsed_body["required_tag_groups"].first
+ expect(group["tag_group"]).to eq(tag_group.name)
+ expect(group["min_count"]).to eq(1)
+ expect(group["tags"]).to eq(["required-tag"])
+ end
+
+ it "returns no requirements for a category without required tag groups" do
+ category = Fabricate(:category)
+
+ get "/admin/plugins/rss_polling/feed_settings/category_requirements.json",
+ params: {
+ category_id: category.id,
+ }
+
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["required_tag_groups"]).to eq([])
+ end
+ end
+
+ describe "#history" do
+ fab!(:rss_feed) { Fabricate(:rss_feed, url: "https://blog.discourse.org/feed", user: admin) }
+
+ it "returns the feed's recent poll attempts" do
+ DiscourseRssPolling::PollAttempt.record!(
+ rss_feed_id: rss_feed.id,
+ items: [
+ { "title" => "An item", "url" => "https://x.test/a", "status" => "imported" },
+ { "title" => "Another", "url" => "https://x.test/b", "status" => "imported" },
+ { "title" => "Skipped", "url" => "https://x.test/c", "status" => "skipped" },
+ ],
+ )
+
+ get "/admin/plugins/rss_polling/feed_settings/#{rss_feed.id}/history.json"
+
+ expect(response.status).to eq(200)
+ body = response.parsed_body
+ expect(body["feed_url"]).to eq(rss_feed.url)
+ expect(body["poll_attempts"].length).to eq(1)
+ attempt = body["poll_attempts"].first
+ expect(attempt["imported_count"]).to eq(2)
+ expect(attempt["skipped_count"]).to eq(1)
+ expect(attempt["items"].first["title"]).to eq("An item")
+ end
+
+ it "404s for an unknown feed" do
+ get "/admin/plugins/rss_polling/feed_settings/0/history.json"
+
+ expect(response.status).to eq(404)
end
end
describe "#update" do
- it "creates a feed setting" do
+ it "creates a feed setting and logs a staff action" do
+ expect {
+ put "/admin/plugins/rss_polling/feed_settings.json",
+ params: {
+ feed_setting: {
+ feed_url: "https://www.newsite.com/feed",
+ author_username: "system",
+ feed_category_filter: "updates",
+ },
+ }
+ }.to change { UserHistory.where(custom_type: "create_rss_polling_feed").count }.by(1)
+
+ expect(response.status).to eq(200)
+ expect(DiscourseRssPolling::RssFeed.count).to eq(1)
+ expect(response.parsed_body["id"]).to eq(DiscourseRssPolling::RssFeed.last.id)
+ end
+
+ it "logs an update staff action when an existing feed is changed" do
+ feed = Fabricate(:rss_feed, url: "https://old.example.com/feed", user: admin)
+
+ expect {
+ put "/admin/plugins/rss_polling/feed_settings.json",
+ params: {
+ feed_setting: {
+ id: feed.id,
+ feed_url: "https://new.example.com/feed",
+ author_username: "system",
+ },
+ }
+ }.to change { UserHistory.where(custom_type: "update_rss_polling_feed").count }.by(1)
+
+ expect(response.status).to eq(200)
+ end
+
+ it "rejects a feed whose category has an unsatisfied required tag group" do
+ SiteSetting.tagging_enabled = true
+ category = Fabricate(:category)
+ tag_group = Fabricate(:tag_group, tags: [Fabricate(:tag, name: "needed")])
+ CategoryRequiredTagGroup.create!(category:, tag_group:, min_count: 1)
+
put "/admin/plugins/rss_polling/feed_settings.json",
params: {
feed_setting: {
feed_url: "https://www.newsite.com/feed",
author_username: "system",
- feed_category_filter: "updates",
+ discourse_category_id: category.id,
+ discourse_tags: [],
+ },
+ }
+
+ expect(response.status).to eq(400)
+ expect(response.parsed_body["errors"].join).to match(/require/i)
+ expect(DiscourseRssPolling::RssFeed.count).to eq(0)
+ end
+
+ it "allows a feed that satisfies the category's required tag group" do
+ SiteSetting.tagging_enabled = true
+ category = Fabricate(:category)
+ tag_group = Fabricate(:tag_group, tags: [Fabricate(:tag, name: "needed")])
+ CategoryRequiredTagGroup.create!(category:, tag_group:, min_count: 1)
+
+ put "/admin/plugins/rss_polling/feed_settings.json",
+ params: {
+ feed_setting: {
+ feed_url: "https://www.newsite.com/feed",
+ author_username: "system",
+ discourse_category_id: category.id,
+ discourse_tags: ["needed"],
},
}
@@ -94,6 +426,19 @@ RSpec.describe DiscourseRssPolling::FeedSettingsController do
expect(response.parsed_body["errors"]).to be_present
end
+ it "trims surrounding whitespace from the feed url" do
+ put "/admin/plugins/rss_polling/feed_settings.json",
+ params: {
+ feed_setting: {
+ feed_url: " https://www.newsite.com/feed ",
+ author_username: "system",
+ },
+ }
+
+ expect(response.status).to eq(200)
+ expect(DiscourseRssPolling::RssFeed.last.url).to eq("https://www.newsite.com/feed")
+ end
+
it "allows duplicate rss feed urls" do
put "/admin/plugins/rss_polling/feed_settings.json",
params: {
@@ -119,5 +464,126 @@ RSpec.describe DiscourseRssPolling::FeedSettingsController do
expect(DiscourseRssPolling::RssFeed.count).to eq(2)
end
+
+ it "404s when updating a feed that does not exist" do
+ put "/admin/plugins/rss_polling/feed_settings.json",
+ params: {
+ feed_setting: {
+ id: 0,
+ feed_url: "https://www.newsite.com/feed",
+ author_username: "system",
+ },
+ }
+
+ expect(response.status).to eq(404)
+ expect(DiscourseRssPolling::RssFeed.count).to eq(0)
+ end
+
+ it "rejects a feed url that is not http(s)" do
+ put "/admin/plugins/rss_polling/feed_settings.json",
+ params: {
+ feed_setting: {
+ feed_url: "javascript:alert(1)",
+ author_username: "system",
+ },
+ }
+
+ expect(response.status).to eq(400)
+ expect(response.parsed_body["errors"].join).to match(/http/i)
+ expect(DiscourseRssPolling::RssFeed.count).to eq(0)
+ end
+ end
+
+ describe "#set_enabled" do
+ fab!(:rss_feed) { Fabricate(:rss_feed, user: admin) }
+
+ it "disables an enabled feed and logs a staff action" do
+ expect {
+ put "/admin/plugins/rss_polling/feed_settings/#{rss_feed.id}/enabled.json",
+ params: {
+ enabled: false,
+ }
+ }.to change { UserHistory.where(custom_type: "disable_rss_polling_feed").count }.by(1)
+
+ expect(response.status).to eq(204)
+ expect(rss_feed.reload.enabled).to eq(false)
+ end
+
+ it "re-enables a disabled feed" do
+ rss_feed.update!(enabled: false)
+
+ put "/admin/plugins/rss_polling/feed_settings/#{rss_feed.id}/enabled.json",
+ params: {
+ enabled: true,
+ }
+
+ expect(response.status).to eq(204)
+ expect(rss_feed.reload.enabled).to eq(true)
+ end
+
+ it "404s for an unknown feed" do
+ put "/admin/plugins/rss_polling/feed_settings/0/enabled.json", params: { enabled: false }
+
+ expect(response.status).to eq(404)
+ end
+
+ it "400s when the enabled parameter is missing" do
+ put "/admin/plugins/rss_polling/feed_settings/#{rss_feed.id}/enabled.json", params: {}
+
+ expect(response.status).to eq(400)
+ expect(rss_feed.reload.enabled).to eq(true)
+ end
+
+ it "400s when the enabled parameter is not a boolean instead of coercing it" do
+ put "/admin/plugins/rss_polling/feed_settings/#{rss_feed.id}/enabled.json",
+ params: {
+ enabled: "maybe",
+ }
+
+ expect(response.status).to eq(400)
+ expect(rss_feed.reload.enabled).to eq(true)
+ end
+ end
+
+ describe "#poll" do
+ fab!(:rss_feed) { Fabricate(:rss_feed, user: admin) }
+
+ it "enqueues a forced poll for the feed and logs a staff action" do
+ Sidekiq::Testing.fake! do
+ expect {
+ post "/admin/plugins/rss_polling/feed_settings/#{rss_feed.id}/poll.json"
+ }.to change { Jobs::DiscourseRssPolling::PollFeed.jobs.size }.by(1).and change {
+ UserHistory.where(custom_type: "poll_rss_polling_feed").count
+ }.by(1)
+
+ expect(response.status).to eq(204)
+ args = Jobs::DiscourseRssPolling::PollFeed.jobs.last["args"][0]
+ expect(args).to include("rss_feed_id" => rss_feed.id, "force" => true)
+ end
+ end
+
+ it "404s for an unknown feed" do
+ post "/admin/plugins/rss_polling/feed_settings/0/poll.json"
+
+ expect(response.status).to eq(404)
+ end
+ end
+
+ describe "#destroy" do
+ fab!(:rss_feed) { Fabricate(:rss_feed, user: admin) }
+
+ it "destroys the feed, returns 204, and logs a staff action" do
+ expect { delete "/admin/plugins/rss_polling/feed_settings/#{rss_feed.id}.json" }.to change {
+ DiscourseRssPolling::RssFeed.count
+ }.by(-1).and change { UserHistory.where(custom_type: "destroy_rss_polling_feed").count }.by(1)
+
+ expect(response.status).to eq(204)
+ end
+
+ it "404s for an unknown feed" do
+ delete "/admin/plugins/rss_polling/feed_settings/0.json"
+
+ expect(response.status).to eq(404)
+ end
end
end
diff --git a/plugins/discourse-rss-polling/spec/services/feed_setting/update_spec.rb b/plugins/discourse-rss-polling/spec/services/feed_setting/update_spec.rb
deleted file mode 100644
index 1c341105f6d..00000000000
--- a/plugins/discourse-rss-polling/spec/services/feed_setting/update_spec.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-# frozen_string_literal: true
-
-RSpec.describe DiscourseRssPolling::FeedSetting::Update do
- describe described_class::Contract, type: :model do
- it { is_expected.to validate_presence_of(:feed_url) }
- it { is_expected.to validate_presence_of(:author_username) }
- end
-
- describe ".call" do
- subject(:result) { described_class.call(params:, **dependencies) }
-
- fab!(:user)
- fab!(:category)
- fab!(:tag_1, :tag)
- fab!(:tag_2, :tag)
-
- let(:params) do
- {
- id: nil,
- feed_url: "https://blog.example.com/feed",
- author_username: user.username,
- discourse_category_id: category.id,
- discourse_tags: [tag_1.name, tag_2.name],
- feed_category_filter: "news",
- }
- end
- let(:dependencies) { {} }
-
- context "when the contract is invalid" do
- before { params[:feed_url] = nil }
-
- it { is_expected.to fail_a_contract }
- end
-
- context "when the author does not exist" do
- before { params[:author_username] = "ghost" }
-
- it { is_expected.to fail_to_find_a_model(:user) }
- end
-
- context "when everything is ok" do
- context "when creating a new feed" do
- it { is_expected.to run_successfully }
-
- it "creates a new rss_feed with the provided attributes" do
- expect { result }.to change { DiscourseRssPolling::RssFeed.count }.by(1)
-
- feed = result[:rss_feed]
- expect(feed).to have_attributes(
- url: "https://blog.example.com/feed",
- user_id: user.id,
- category_id: category.id,
- tags: "#{tag_1.name},#{tag_2.name}",
- category_filter: "news",
- )
- end
- end
-
- context "when updating an existing feed" do
- fab!(:rss_feed) { Fabricate(:rss_feed, url: "https://old.example.com/feed", user: user) }
-
- before { params[:id] = rss_feed.id }
-
- it { is_expected.to run_successfully }
-
- it "updates the existing rss_feed" do
- expect { result }.not_to change { DiscourseRssPolling::RssFeed.count }
- expect(rss_feed.reload).to have_attributes(
- url: "https://blog.example.com/feed",
- user_id: user.id,
- category_id: category.id,
- tags: "#{tag_1.name},#{tag_2.name}",
- category_filter: "news",
- )
- end
- end
-
- context "when discourse_tags is an array of hashes" do
- before { params[:discourse_tags] = [{ "name" => tag_1.name }, { "name" => tag_2.name }] }
-
- it { is_expected.to run_successfully }
-
- it "normalizes tags into a comma-separated string" do
- expect(result[:rss_feed].tags).to eq("#{tag_1.name},#{tag_2.name}")
- end
- end
-
- context "when discourse_tags is blank" do
- before { params[:discourse_tags] = nil }
-
- it { is_expected.to run_successfully }
-
- it "stores nil tags" do
- expect(result[:rss_feed].tags).to be_nil
- end
- end
- end
- end
-end
diff --git a/plugins/discourse-rss-polling/spec/services/feed_url_spec.rb b/plugins/discourse-rss-polling/spec/services/feed_url_spec.rb
new file mode 100644
index 00000000000..24f70c4a7de
--- /dev/null
+++ b/plugins/discourse-rss-polling/spec/services/feed_url_spec.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscourseRssPolling::FeedUrl do
+ describe ".redact" do
+ it "removes api_key and api_username from the query" do
+ redacted =
+ described_class.redact(
+ "https://example.com/feed?api_key=secret&api_username=system&foo=bar",
+ )
+
+ expect(redacted).to eq("https://example.com/feed?foo=bar")
+ expect(redacted).not_to include("secret")
+ expect(redacted).not_to include("system")
+ end
+
+ it "drops the query entirely when only credentials are present" do
+ expect(described_class.redact("https://example.com/feed?api_key=secret")).to eq(
+ "https://example.com/feed",
+ )
+ end
+
+ it "leaves a credential-free url untouched" do
+ expect(described_class.redact("https://example.com/feed")).to eq("https://example.com/feed")
+ end
+
+ it "does not leak credentials when the url is malformed" do
+ expect(described_class.redact("https://exa mple.com/feed?api_key=secret")).not_to include(
+ "secret",
+ )
+ end
+
+ it "handles blank input" do
+ expect(described_class.redact(nil)).to eq("")
+ end
+ end
+
+ describe ".http?" do
+ it "is true for http and https urls (any case)" do
+ expect(described_class.http?("http://example.com/feed")).to eq(true)
+ expect(described_class.http?("https://example.com/feed")).to eq(true)
+ expect(described_class.http?("HTTPS://example.com/feed")).to eq(true)
+ end
+
+ it "is false for other schemes, scheme-less urls, and blank input" do
+ expect(described_class.http?("javascript:alert(1)")).to eq(false)
+ expect(described_class.http?("ftp://example.com/feed")).to eq(false)
+ expect(described_class.http?("example.com/feed")).to eq(false)
+ expect(described_class.http?("")).to eq(false)
+ expect(described_class.http?(nil)).to eq(false)
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/spec/services/rss_feed/action/analyze_item_spec.rb b/plugins/discourse-rss-polling/spec/services/rss_feed/action/analyze_item_spec.rb
new file mode 100644
index 00000000000..a877ea15ef6
--- /dev/null
+++ b/plugins/discourse-rss-polling/spec/services/rss_feed/action/analyze_item_spec.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscourseRssPolling::RssFeed::Action::AnalyzeItem do
+ subject(:analysis) { described_class.call(feed_item:, feed_category_filter:) }
+
+ let(:feed_category_filter) { nil }
+
+ let(:feed_item) do
+ instance_double(
+ DiscourseRssPolling::FeedItem,
+ title: "A title",
+ content: "Some content",
+ categories: ["Announcements"],
+ url: "https://example.com/post",
+ )
+ end
+
+ it "would import an item with a title and content" do
+ expect(analysis).to eq([described_class::WOULD_IMPORT, nil])
+ end
+
+ it "skips an item without content" do
+ allow(feed_item).to receive(:content).and_return("")
+
+ expect(analysis).to eq([described_class::SKIPPED, :missing_content])
+ end
+
+ it "skips an item without a title" do
+ allow(feed_item).to receive(:title).and_return(nil)
+
+ expect(analysis).to eq([described_class::SKIPPED, :missing_title])
+ end
+
+ it "skips an item without a valid http(s) link" do
+ allow(feed_item).to receive(:url).and_return("urn:uuid:1234")
+
+ expect(analysis).to eq([described_class::SKIPPED, :invalid_url])
+ end
+
+ context "with a category filter" do
+ let(:feed_category_filter) { "announce" }
+
+ it "would import an item whose category matches the filter" do
+ expect(analysis).to eq([described_class::WOULD_IMPORT, nil])
+ end
+
+ it "matches the filter case-insensitively" do
+ allow(feed_item).to receive(:categories).and_return(["ANNOUNCEMENTS"])
+
+ expect(analysis).to eq([described_class::WOULD_IMPORT, nil])
+ end
+
+ it "skips an item whose categories do not match the filter" do
+ allow(feed_item).to receive(:categories).and_return(["Random"])
+
+ expect(analysis).to eq([described_class::SKIPPED, :category_filter_mismatch])
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/spec/services/rss_feed/action/build_preview_spec.rb b/plugins/discourse-rss-polling/spec/services/rss_feed/action/build_preview_spec.rb
new file mode 100644
index 00000000000..8daf2b43277
--- /dev/null
+++ b/plugins/discourse-rss-polling/spec/services/rss_feed/action/build_preview_spec.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscourseRssPolling::RssFeed::Action::BuildPreview do
+ subject(:preview) { described_class.call(feed_items:, feed_category_filter:) }
+
+ let(:feed_category_filter) { nil }
+
+ def feed_item(title:, content:, categories: [], url: "https://example.com/post")
+ item = instance_double(DiscourseRssPolling::FeedItem, title:, content:, categories:, url:)
+ allow(item).to receive(:outcome) do |status:, reason: nil, topic_url: nil|
+ {
+ "title" => title,
+ "status" => status.to_s,
+ "reason" => reason&.to_s,
+ "topic_url" => topic_url,
+ }
+ end
+ item
+ end
+
+ context "when an item would be imported" do
+ let(:feed_items) { [feed_item(title: "Hello", content: "Body")] }
+
+ it "marks the item as would_import" do
+ expect(preview.first).to include("status" => "would_import", "topic_url" => nil)
+ end
+ end
+
+ context "when an item is skipped" do
+ let(:feed_items) { [feed_item(title: nil, content: "Body")] }
+
+ it "marks the item as skipped with a reason" do
+ expect(preview.first).to include("status" => "skipped", "reason" => "missing_title")
+ end
+ end
+
+ context "when an item has already been imported" do
+ let(:imported_url) { "https://blog.discourse.org/2017/09/poll-feed-spec-fixture/" }
+
+ let(:feed_items) { [feed_item(title: "Hello", content: "Body", url: imported_url)] }
+
+ before do
+ TopicEmbed.import(Discourse.system_user, imported_url, "Poll Feed Spec Fixture", "content")
+ end
+
+ it "marks the item as already_imported with the existing topic url" do
+ item = preview.first
+ expect(item["status"]).to eq("already_imported")
+ expect(item["topic_url"]).to be_present
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/spec/services/rss_feed/action/fetch_feed_spec.rb b/plugins/discourse-rss-polling/spec/services/rss_feed/action/fetch_feed_spec.rb
new file mode 100644
index 00000000000..eb412117e79
--- /dev/null
+++ b/plugins/discourse-rss-polling/spec/services/rss_feed/action/fetch_feed_spec.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscourseRssPolling::RssFeed::Action::FetchFeed do
+ subject(:result) { described_class.call(feed_url:) }
+
+ let(:feed_url) { "https://blog.discourse.org/feed/" }
+ let(:raw_feed) { file_from_fixtures("feed.rss", "feed") }
+
+ context "when the feed is fetched and parsed successfully" do
+ before { stub_request(:get, feed_url).to_return(status: 200, body: raw_feed) }
+
+ it "returns the parsed feed items with no error" do
+ expect(result.error).to be_nil
+ expect(result.items.size).to eq(1)
+ expect(result.items.first).to be_a(DiscourseRssPolling::FeedItem)
+ expect(result.items.first.title).to eq("Poll Feed Spec Fixture")
+ end
+ end
+
+ context "when the HTTP request fails" do
+ before { stub_request(:get, feed_url).to_return(status: 500) }
+
+ it "returns a fetch_failed error and no items" do
+ expect(result.error).to eq(:fetch_failed)
+ expect(result.items).to be_empty
+ end
+ end
+
+ context "when the body is valid XML but not a feed" do
+ before do
+ stub_request(:get, feed_url).to_return(
+ status: 200,
+ body: "<html><body>not a feed</body></html>",
+ )
+ end
+
+ it "returns a parse_failed error and no items" do
+ expect(result.error).to eq(:parse_failed)
+ expect(result.items).to be_empty
+ end
+ end
+
+ context "when fetching raises an unexpected error" do
+ before { FinalDestination.any_instance.stubs(:get).raises(StandardError.new("boom")) }
+
+ it "returns a fetch_failed error instead of raising" do
+ expect(result.error).to eq(:fetch_failed)
+ expect(result.items).to be_empty
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/spec/services/rss_feed/action/imported_topics_spec.rb b/plugins/discourse-rss-polling/spec/services/rss_feed/action/imported_topics_spec.rb
new file mode 100644
index 00000000000..4eadb097ab4
--- /dev/null
+++ b/plugins/discourse-rss-polling/spec/services/rss_feed/action/imported_topics_spec.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscourseRssPolling::RssFeed::Action::ImportedTopics do
+ subject(:imported) { described_class.call(feed_items:) }
+
+ let(:imported_url) { "https://blog.discourse.org/2017/09/poll-feed-spec-fixture/" }
+ let(:other_url) { "https://blog.discourse.org/2018/01/not-imported/" }
+
+ let(:imported_item) { instance_double(DiscourseRssPolling::FeedItem, url: imported_url) }
+ let(:other_item) { instance_double(DiscourseRssPolling::FeedItem, url: other_url) }
+
+ let(:feed_items) { [imported_item, other_item] }
+
+ context "when an item has a matching imported topic" do
+ before do
+ TopicEmbed.import(Discourse.system_user, imported_url, "Poll Feed Spec Fixture", "content")
+ end
+
+ it "returns the topic url only for the imported item" do
+ expect(imported.keys).to contain_exactly(imported_item)
+ expect(imported[imported_item]).to be_present
+ end
+ end
+
+ context "when no item has been imported" do
+ it "returns an empty map" do
+ expect(imported).to be_empty
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/spec/services/rss_feed/destroy_spec.rb b/plugins/discourse-rss-polling/spec/services/rss_feed/destroy_spec.rb
new file mode 100644
index 00000000000..59fbe65e636
--- /dev/null
+++ b/plugins/discourse-rss-polling/spec/services/rss_feed/destroy_spec.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscourseRssPolling::RssFeed::Destroy do
+ describe ".call" do
+ subject(:result) { described_class.call(params:, **dependencies) }
+
+ fab!(:admin)
+ fab!(:rss_feed)
+
+ let(:params) { { id: rss_feed.id } }
+ let(:dependencies) { { guardian: admin.guardian } }
+
+ context "when the feed does not exist" do
+ let(:params) { { id: -1 } }
+
+ it { is_expected.to fail_to_find_a_model(:rss_feed) }
+ end
+
+ context "when the feed exists" do
+ it { is_expected.to run_successfully }
+
+ it "destroys the feed" do
+ expect { result }.to change { DiscourseRssPolling::RssFeed.count }.by(-1)
+ expect(DiscourseRssPolling::RssFeed.exists?(rss_feed.id)).to eq(false)
+ end
+
+ it "logs the deletion as a staff action" do
+ expect { result }.to change { UserHistory.count }.by(1)
+ expect(UserHistory.last).to have_attributes(
+ custom_type: "destroy_rss_polling_feed",
+ acting_user_id: admin.id,
+ )
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/spec/services/rss_feed/poll_spec.rb b/plugins/discourse-rss-polling/spec/services/rss_feed/poll_spec.rb
new file mode 100644
index 00000000000..77e8ed0baf8
--- /dev/null
+++ b/plugins/discourse-rss-polling/spec/services/rss_feed/poll_spec.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscourseRssPolling::RssFeed::Poll do
+ describe ".call" do
+ subject(:result) { described_class.call(params:, **dependencies) }
+
+ fab!(:admin)
+ fab!(:rss_feed)
+
+ let(:params) { { id: rss_feed.id } }
+ let(:dependencies) { { guardian: admin.guardian } }
+
+ context "when the feed does not exist" do
+ let(:params) { { id: -1 } }
+
+ it { is_expected.to fail_to_find_a_model(:rss_feed) }
+ end
+
+ context "when the feed exists" do
+ it { is_expected.to run_successfully }
+
+ it "enqueues a forced poll job for the feed" do
+ Sidekiq::Testing.fake! do
+ expect { result }.to change { Jobs::DiscourseRssPolling::PollFeed.jobs.size }.by(1)
+
+ args = Jobs::DiscourseRssPolling::PollFeed.jobs.last["args"].first
+ expect(args).to include("rss_feed_id" => rss_feed.id, "force" => true)
+ end
+ end
+
+ it "logs the poll as a staff action" do
+ Sidekiq::Testing.fake! do
+ expect { result }.to change { UserHistory.count }.by(1)
+ expect(UserHistory.last.custom_type).to eq("poll_rss_polling_feed")
+ end
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/spec/services/rss_feed/set_enabled_spec.rb b/plugins/discourse-rss-polling/spec/services/rss_feed/set_enabled_spec.rb
new file mode 100644
index 00000000000..027d37f08c5
--- /dev/null
+++ b/plugins/discourse-rss-polling/spec/services/rss_feed/set_enabled_spec.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscourseRssPolling::RssFeed::SetEnabled do
+ describe described_class::Contract, type: :model do
+ it { is_expected.to validate_inclusion_of(:enabled).in_array([true, false, "true", "false"]) }
+ end
+
+ describe ".call" do
+ subject(:result) { described_class.call(params:, **dependencies) }
+
+ fab!(:admin)
+ fab!(:rss_feed)
+
+ let(:enabled) { false }
+ let(:params) { { id: rss_feed.id, enabled: } }
+ let(:dependencies) { { guardian: admin.guardian } }
+
+ context "when the contract is invalid" do
+ let(:enabled) { "maybe" }
+
+ it { is_expected.to fail_a_contract }
+ end
+
+ context "when the feed does not exist" do
+ let(:params) { { id: -1, enabled: } }
+
+ it { is_expected.to fail_to_find_a_model(:rss_feed) }
+ end
+
+ context "when disabling an enabled feed" do
+ it { is_expected.to run_successfully }
+
+ it "disables the feed" do
+ expect { result }.to change { rss_feed.reload.enabled }.from(true).to(false)
+ end
+
+ it "logs the change as a staff action" do
+ expect { result }.to change { UserHistory.count }.by(1)
+ expect(UserHistory.last.custom_type).to eq("disable_rss_polling_feed")
+ end
+ end
+
+ context "when enabling a disabled feed" do
+ let(:enabled) { true }
+
+ before { rss_feed.update!(enabled: false) }
+
+ it { is_expected.to run_successfully }
+
+ it "enables the feed" do
+ expect { result }.to change { rss_feed.reload.enabled }.from(false).to(true)
+ end
+
+ it "logs the change as a staff action" do
+ expect { result }.to change { UserHistory.count }.by(1)
+ expect(UserHistory.last.custom_type).to eq("enable_rss_polling_feed")
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/spec/services/rss_feed/test_spec.rb b/plugins/discourse-rss-polling/spec/services/rss_feed/test_spec.rb
new file mode 100644
index 00000000000..daf4190707f
--- /dev/null
+++ b/plugins/discourse-rss-polling/spec/services/rss_feed/test_spec.rb
@@ -0,0 +1,68 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscourseRssPolling::RssFeed::Test do
+ describe described_class::Contract, type: :model do
+ it { is_expected.to validate_presence_of(:feed_url) }
+ end
+
+ describe ".call" do
+ subject(:result) { described_class.call(params:, **dependencies) }
+
+ let(:feed_url) { "https://blog.discourse.org/feed/" }
+ let(:raw_feed) { file_from_fixtures("feed.rss", "feed") }
+ let(:params) { { feed_url:, feed_category_filter: nil } }
+ let(:dependencies) { {} }
+
+ context "when the contract is invalid" do
+ let(:feed_url) { nil }
+
+ it { is_expected.to fail_a_contract }
+ end
+
+ context "when the feed cannot be fetched" do
+ before { stub_request(:get, feed_url).to_return(status: 500) }
+
+ it { is_expected.to fail_a_step(:fetch) }
+
+ it "exposes the fetch error and does not build a preview" do
+ expect(result[:fetched]).to be_nil
+ expect(result[:preview]).to be_nil
+ expect(result["result.step.fetch"].error).to eq(:fetch_failed)
+ end
+ end
+
+ context "when the feed is fetched successfully" do
+ before { stub_request(:get, feed_url).to_return(status: 200, body: raw_feed) }
+
+ it { is_expected.to run_successfully }
+
+ it "builds a preview for each item" do
+ expect(result[:preview].first).to include(
+ "title" => "Poll Feed Spec Fixture",
+ "status" => "would_import",
+ )
+ expect(result[:fetched].items.size).to eq(1)
+ end
+ end
+
+ context "when an item has already been imported" do
+ before do
+ stub_request(:get, feed_url).to_return(status: 200, body: raw_feed)
+ TopicEmbed.import(
+ Discourse.system_user,
+ "https://blog.discourse.org/2017/09/poll-feed-spec-fixture/",
+ "Poll Feed Spec Fixture",
+ "content",
+ )
+ end
+
+ it { is_expected.to run_successfully }
+
+ it "flags the item as already imported with a topic_url" do
+ item = result[:preview].first
+ expect(item["status"]).to eq("already_imported")
+ expect(item["topic_url"]).to be_present
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/spec/services/rss_feed/update_spec.rb b/plugins/discourse-rss-polling/spec/services/rss_feed/update_spec.rb
new file mode 100644
index 00000000000..d9e4873e647
--- /dev/null
+++ b/plugins/discourse-rss-polling/spec/services/rss_feed/update_spec.rb
@@ -0,0 +1,196 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscourseRssPolling::RssFeed::Update do
+ describe described_class::Contract, type: :model do
+ it { is_expected.to validate_presence_of(:feed_url) }
+ it { is_expected.to validate_presence_of(:author_username) }
+ end
+
+ describe ".call" do
+ subject(:result) { described_class.call(params:, **dependencies) }
+
+ fab!(:admin)
+ fab!(:user)
+ fab!(:category)
+ fab!(:tag_1, :tag)
+ fab!(:tag_2, :tag)
+
+ let(:params) do
+ {
+ id: nil,
+ feed_url: "https://blog.example.com/feed",
+ author_username: user.username,
+ discourse_category_id: category.id,
+ discourse_tags: [tag_1.name, tag_2.name],
+ feed_category_filter: "news",
+ }
+ end
+ let(:dependencies) { { guardian: admin.guardian } }
+
+ context "when the contract is invalid" do
+ before { params[:feed_url] = nil }
+
+ it { is_expected.to fail_a_contract }
+ end
+
+ context "when the feed_url is only whitespace" do
+ before { params[:feed_url] = " " }
+
+ it { is_expected.to fail_a_contract }
+ end
+
+ context "when the feed_url is not http(s)" do
+ before { params[:feed_url] = "javascript:alert(1)" }
+
+ it { is_expected.to fail_a_contract }
+ end
+
+ context "when updating a feed that does not exist" do
+ before { params[:id] = -1 }
+
+ it { is_expected.to fail_to_find_a_model(:rss_feed) }
+ end
+
+ context "when the feed_url has surrounding whitespace" do
+ before { params[:feed_url] = " https://blog.example.com/feed " }
+
+ it { is_expected.to run_successfully }
+
+ it "stores the trimmed url" do
+ expect(result[:rss_feed].url).to eq("https://blog.example.com/feed")
+ end
+ end
+
+ context "when the author does not exist" do
+ before { params[:author_username] = "ghost" }
+
+ it { is_expected.to fail_to_find_a_model(:user) }
+ end
+
+ context "when the category has an unsatisfied required tag group" do
+ before do
+ tag_group = Fabricate(:tag_group, tags: [Fabricate(:tag, name: "needed")])
+ CategoryRequiredTagGroup.create!(category:, tag_group:, min_count: 1)
+ params[:discourse_tags] = []
+ end
+
+ it { is_expected.to fail_a_contract }
+ end
+
+ context "when everything is ok" do
+ context "when creating a new feed" do
+ it { is_expected.to run_successfully }
+
+ it "creates a new rss_feed with the provided attributes" do
+ expect { result }.to change { DiscourseRssPolling::RssFeed.count }.by(1)
+
+ feed = result[:rss_feed]
+ expect(feed).to have_attributes(
+ url: "https://blog.example.com/feed",
+ user_id: user.id,
+ category_id: category.id,
+ tags: "#{tag_1.name},#{tag_2.name}",
+ category_filter: "news",
+ )
+ end
+
+ it "logs the creation as a staff action" do
+ expect { result }.to change { UserHistory.count }.by(1)
+ expect(UserHistory.last).to have_attributes(
+ custom_type: "create_rss_polling_feed",
+ acting_user_id: admin.id,
+ )
+ end
+
+ it "redacts feed-url credentials in the staff action log" do
+ params[:feed_url] = "https://blog.example.com/feed?api_key=secret&api_username=system"
+
+ result
+
+ expect(UserHistory.last.details).not_to include("secret")
+ expect(UserHistory.last.details).not_to include("api_key")
+ end
+ end
+
+ context "when updating an existing feed" do
+ fab!(:rss_feed) { Fabricate(:rss_feed, url: "https://old.example.com/feed", user: user) }
+
+ before { params[:id] = rss_feed.id }
+
+ it { is_expected.to run_successfully }
+
+ it "updates the existing rss_feed" do
+ expect { result }.not_to change { DiscourseRssPolling::RssFeed.count }
+ expect(rss_feed.reload).to have_attributes(
+ url: "https://blog.example.com/feed",
+ user_id: user.id,
+ category_id: category.id,
+ tags: "#{tag_1.name},#{tag_2.name}",
+ category_filter: "news",
+ )
+ end
+
+ it "logs the update as a staff action" do
+ expect { result }.to change { UserHistory.count }.by(1)
+ expect(UserHistory.last.custom_type).to eq("update_rss_polling_feed")
+ end
+ end
+
+ context "when updating a disabled feed" do
+ fab!(:rss_feed) do
+ Fabricate(:rss_feed, url: "https://old.example.com/feed", user: user, enabled: false)
+ end
+
+ before { params[:id] = rss_feed.id }
+
+ it { is_expected.to run_successfully }
+
+ it "leaves the feed disabled" do
+ result
+ expect(rss_feed.reload.enabled).to eq(false)
+ end
+ end
+
+ context "when discourse_tags is an array of hashes" do
+ before { params[:discourse_tags] = [{ "name" => tag_1.name }, { "name" => tag_2.name }] }
+
+ it { is_expected.to run_successfully }
+
+ it "normalizes tags into a comma-separated string" do
+ expect(result[:rss_feed].tags).to eq("#{tag_1.name},#{tag_2.name}")
+ end
+ end
+
+ context "when discourse_tags is an array of ActionController::Parameters (form submission)" do
+ before do
+ params[:discourse_tags] = [
+ ActionController::Parameters.new(id: 1, name: tag_1.name),
+ ActionController::Parameters.new(id: 2, name: tag_2.name),
+ ]
+ end
+
+ it "extracts the tag names rather than serializing the objects" do
+ expect(result[:rss_feed].tags).to eq("#{tag_1.name},#{tag_2.name}")
+ end
+ end
+
+ context "when discourse_tags contains a purely numeric tag name" do
+ before { params[:discourse_tags] = ["2024"] }
+
+ it "stores the numeric tag name without raising" do
+ expect(result[:rss_feed].tags).to eq("2024")
+ end
+ end
+
+ context "when discourse_tags is blank" do
+ before { params[:discourse_tags] = nil }
+
+ it { is_expected.to run_successfully }
+
+ it "stores nil tags" do
+ expect(result[:rss_feed].tags).to be_nil
+ end
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rss-polling/spec/system/admin_spec.rb b/plugins/discourse-rss-polling/spec/system/admin_spec.rb
index c2985ef8c58..e1164ce48c7 100644
--- a/plugins/discourse-rss-polling/spec/system/admin_spec.rb
+++ b/plugins/discourse-rss-polling/spec/system/admin_spec.rb
@@ -12,22 +12,40 @@ RSpec.describe "Rss Polling - admin" do
sign_in(current_user)
end
- it "can save an rss polling configuration" do
- visit("/admin/plugins/rss_polling")
-
- find(".add-rss-polling-feed").click
- find(".rss-polling-feed-url").fill_in(with: url)
- find(".rss-polling-feed-updates").fill_in(with: "updates")
- user = PageObjects::Components::SelectKit.new(".rss-polling-feed-user")
- user.search(current_user.username)
- user.select_row_by_value(current_user.username)
- category = PageObjects::Components::SelectKit.new(".rss-polling-feed-category")
+ it "tests a feed and saves the configuration" do
+ stub_request(:get, url).to_return(status: 200, body: file_from_fixtures("feed.rss", "feed"))
+
+ visit("/admin/plugins/discourse-rss-polling/feeds")
+
+ find(".rss-polling-feeds__add").click
+
+ form = PageObjects::Components::FormKit.new(".rss-polling-feed-form")
+ form.field("feed_url").fill_in(url)
+ form.field("feed_category_filter").fill_in("updates")
+
+ author = PageObjects::Components::SelectKit.new(".rss-polling-feed-form__author")
+ author.expand
+ author.search(current_user.username)
+ author.select_row_by_value(current_user.username)
+
+ category = PageObjects::Components::SelectKit.new(".rss-polling-feed-form__category")
+ category.expand
category.search(category_1.name)
category.select_row_by_value(category_1.id)
- tag = PageObjects::Components::SelectKit.new(".rss-polling-feed-tag")
+
+ tag = PageObjects::Components::SelectKit.new(".rss-polling-feed-form__tags")
+ tag.expand
tag.search(tag_1.name)
tag.select_row_by_name(tag_1.name)
- find(".save-rss-polling-feed").click
+ tag.collapse
+
+ find(".rss-polling-feed-form__test").click
+
+ expect(page).to have_css(".rss-polling-feed-test")
+
+ form.submit
+
+ expect(page).to have_css(".rss-polling-feed-form")
expect(DiscourseRssPolling::RssFeed.last).to have_attributes(
url:,
@@ -37,4 +55,101 @@ RSpec.describe "Rss Polling - admin" do
tags: tag_1.name,
)
end
+
+ it "keeps Test feed enabled and surfaces the server error for a blank URL" do
+ visit("/admin/plugins/discourse-rss-polling/feeds")
+
+ find(".rss-polling-feeds__add").click
+
+ expect(page).to have_no_css(".rss-polling-feed-form__test[disabled]")
+
+ find(".rss-polling-feed-form__test").click
+
+ expect(page).to have_css(".rss-polling-feed-test__error")
+ expect(page).to have_content(I18n.t("js.admin.rss_polling.test.errors.blank_feed_url"))
+ end
+
+ it "can disable and re-enable a feed without deleting it" do
+ feed = Fabricate(:rss_feed, user: current_user)
+
+ visit("/admin/plugins/discourse-rss-polling/feeds")
+
+ expect(page).to have_css(".rss-polling-feed")
+
+ toggle = PageObjects::Components::DToggleSwitch.new(".rss-polling-feed__toggle")
+ expect(toggle).to be_checked
+
+ toggle.toggle
+
+ expect(page).to have_css(".rss-polling-feed.is-disabled")
+ expect(toggle).to be_unchecked
+ try_until_success { expect(feed.reload.enabled).to eq(false) }
+
+ toggle.toggle
+
+ expect(page).to have_no_css(".rss-polling-feed.is-disabled")
+ expect(toggle).to be_checked
+ try_until_success { expect(feed.reload.enabled).to eq(true) }
+ end
+
+ it "shows the feed settings and its poll history on one page" do
+ feed = Fabricate(:rss_feed, user: current_user)
+ DiscourseRssPolling::PollAttempt.record!(
+ rss_feed_id: feed.id,
+ items: [
+ {
+ "title" => "An imported item",
+ "url" => "https://example.com/rss/item",
+ "status" => "imported",
+ "topic_url" => "/t/-/1",
+ },
+ ],
+ )
+
+ visit("/admin/plugins/discourse-rss-polling/feeds/#{feed.id}/edit")
+
+ expect(page).to have_css(".rss-polling-feed-form")
+ expect(page).to have_css(".rss-polling-feed-form__poll")
+ expect(page).to have_css(".rss-polling-feed-history")
+ expect(page).to have_content("1 imported")
+ end
+
+ it "disables Poll now while the feed has unsaved edits" do
+ feed = Fabricate(:rss_feed, user: current_user, category_filter: "old")
+
+ visit("/admin/plugins/discourse-rss-polling/feeds/#{feed.id}/edit")
+
+ expect(page).to have_css(".rss-polling-feed-form__poll")
+ expect(page).to have_no_css(".rss-polling-feed-form__poll[disabled]")
+
+ form = PageObjects::Components::FormKit.new(".rss-polling-feed-form")
+ form.field("feed_category_filter").fill_in("changed")
+
+ expect(page).to have_css(".rss-polling-feed-form__poll[disabled]")
+
+ form.submit
+
+ expect(page).to have_no_css(".rss-polling-feed-form__poll[disabled]")
+ expect(feed.reload.category_filter).to eq("changed")
+ end
+
+ it "disables Poll now while the feed is disabled" do
+ feed = Fabricate(:rss_feed, user: current_user, enabled: false)
+
+ visit("/admin/plugins/discourse-rss-polling/feeds/#{feed.id}/edit")
+
+ expect(page).to have_css(".rss-polling-feed-form__poll[disabled]")
+
+ PageObjects::Components::DToggleSwitch.new(".rss-polling-feed-form__toggle").toggle
+
+ expect(page).to have_no_css(".rss-polling-feed-form__poll[disabled]")
+ try_until_success { expect(feed.reload.enabled).to eq(true) }
+ end
+
+ it "redirects to the feeds list when editing a feed that no longer exists" do
+ visit("/admin/plugins/discourse-rss-polling/feeds/0/edit")
+
+ expect(page).to have_current_path("/admin/plugins/discourse-rss-polling/feeds")
+ expect(page).to have_css(".rss-polling-feeds__add")
+ end
end
diff --git a/plugins/poll/assets/stylesheets/common/poll.scss b/plugins/poll/assets/stylesheets/common/poll.scss
index 15a0649a99d..e37338b7320 100644
--- a/plugins/poll/assets/stylesheets/common/poll.scss
+++ b/plugins/poll/assets/stylesheets/common/poll.scss
@@ -514,7 +514,7 @@ div.poll-outer {
&::before {
mask-image: svg-uri(
- '<svg width="0.75em" height="0.75em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M201.4 374.6c12.5 12.5 32.8 12.5 45.3 0l160-160c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L224 306.7 86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l160 160z"/></svg>'
+ '<svg width="0.75em" height="0.75em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">\3c !--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M201.4 374.6c12.5 12.5 32.8 12.5 45.3 0l160-160c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L224 306.7 86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l160 160z"/></svg>'
);
z-index: 1;
width: 0.75em;
@@ -597,7 +597,7 @@ body.crawler {
&::before {
mask-image: svg-uri(
- '<svg width="0.75em" height="0.75em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M201.4 374.6c12.5 12.5 32.8 12.5 45.3 0l160-160c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L224 306.7 86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l160 160z"/></svg>'
+ '<svg width="0.75em" height="0.75em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">\3c !--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M201.4 374.6c12.5 12.5 32.8 12.5 45.3 0l160-160c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L224 306.7 86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l160 160z"/></svg>'
);
z-index: 1;
width: 0.75em;