A platform for community discussion. Free, open, simple.
FEATURE: Set upcoming events composer category (#44294)
Bryce Huhtalab40ffffded90
diff --git a/plugins/discourse-events/assets/javascripts/discourse/components/upcoming-events-calendar.gjs b/plugins/discourse-events/assets/javascripts/discourse/components/upcoming-events-calendar.gjsindex fe6ad2ade74..a1d1882ce68 100644--- a/plugins/discourse-events/assets/javascripts/discourse/components/upcoming-events-calendar.gjs+++ b/plugins/discourse-events/assets/javascripts/discourse/components/upcoming-events-calendar.gjs@@ -29,6 +29,17 @@ export default class UpcomingEventsCalendar extends Component {);}+ get composerCategory() {+ if (this.args.categoryId) {+ return Category.findById(this.args.categoryId) ?? null;+ }++ const category = Category.findById(+ this.siteSettings.calendar_upcoming_events_default_category+ );+ return category?.canCreateTopic ? category : null;+ }+get customButtons() {return {mineEvents: {@@ -107,9 +118,7 @@ export default class UpcomingEventsCalendar extends Component {currentUser: this.currentUser,siteSettings: this.siteSettings,info,- category: this.args.categoryId- ? (Category.findById(this.args.categoryId) ?? null)- : null,+ category: this.composerCategory,});}diff --git a/plugins/discourse-events/config/locales/server.en.yml b/plugins/discourse-events/config/locales/server.en.ymlindex 9dcdb717133..5218402343e 100644--- a/plugins/discourse-events/config/locales/server.en.yml+++ b/plugins/discourse-events/config/locales/server.en.yml@@ -91,6 +91,7 @@ en:event_participation_buttons: "List of event participation buttons users can use."sidebar_show_upcoming_events: "Show upcoming events link in the sidebar under 'More'."calendar_first_day_of_week: "Set the first day of the week for calendar display. Options are Saturday, Sunday, or Monday."+ calendar_upcoming_events_default_category: "Category for new events created from the upcoming events calendar. If empty or the member cannot create topics in this category, uses {{setting:default_composer_category}}."enable_events_category_type_setup: "Enables the Events category type option during category creation setup."enable_improved_event_reminders: "Lets members choose whether event reminders are sent as personal messages, notifications, or not at all."livestream_allowed_hosts: "Hosts that can be used as an event livestream."diff --git a/plugins/discourse-events/config/settings.yml b/plugins/discourse-events/config/settings.ymlindex 7222e780c15..d1aacd8f015 100644--- a/plugins/discourse-events/config/settings.yml+++ b/plugins/discourse-events/config/settings.yml@@ -133,6 +133,10 @@ discourse_events:enum: "DiscourseEvents::Configuration::UpcomingEventsDefaultView"default: monthclient: true+ calendar_upcoming_events_default_category:+ type: category+ default: ""+ client: trueenable_events_category_type_setup:default: falsehidden: truediff --git a/plugins/discourse-events/test/javascripts/acceptance/calendar-click-to-create-test.js b/plugins/discourse-events/test/javascripts/acceptance/calendar-click-to-create-test.jsindex 71f8ff52865..c8a0066d3a3 100644--- a/plugins/discourse-events/test/javascripts/acceptance/calendar-click-to-create-test.js+++ b/plugins/discourse-events/test/javascripts/acceptance/calendar-click-to-create-test.js@@ -158,11 +158,71 @@ acceptance(});+acceptance(+ "Calendar click to create - upcoming events default category",+ function (needs) {+ needs.user({ can_create_discourse_post_event: true });+ needs.settings({+ ...SETTINGS,+ default_composer_category: 1,+ calendar_upcoming_events_default_category: 2,+ });+ needs.site({+ categories: [+ { id: 1, name: "General", slug: "general", permission: 1 },+ { id: 2, name: "Events", slug: "events", permission: 1 },+ { id: 3, name: "Read only", slug: "read-only", permission: 3 },+ { id: 4, name: "Reply only", slug: "reply-only", permission: 2 },+ ],+ });+ needs.pretender(noEventsPretender);++ for (const [name, setting, expectedCategory] of [+ ["configured category", 2, "2"],+ ["category ID as a string", "2", "2"],+ ["unset category", "", "1"],+ ["missing category", 9999, "1"],+ ["read-only category", 3, "1"],+ ["reply-only category", 4, "1"],+ ]) {+ test(`clicking a day uses the expected composer category with ${name}`, async function (assert) {+ this.siteSettings.calendar_upcoming_events_default_category = setting;++ await visit("/upcoming-events");+ await waitFor(".fc-day-today");+ await click(".fc-day-today");+ await waitFor(".d-editor-input");++ assert.strictEqual(+ selectKit(".category-chooser").header().value(),+ expectedCategory+ );+ });+ }++ test("dragging across days uses the configured category", async function (assert) {+ await visit("/upcoming-events");+ await waitFor(".fc-day-today");++ const startDate = todayCellDate();+ const lastDate = moment(startDate).add(1, "day").format("YYYY-MM-DD");++ await dragSelect(cellFor(startDate), cellFor(lastDate));+ await waitFor(".d-editor-input");++ assert.strictEqual(selectKit(".category-chooser").header().value(), "2");+ });+ }+);+acceptance("Calendar click to create - category (with permission)",function (needs) {needs.user({ can_create_discourse_post_event: true });- needs.settings(SETTINGS);+ needs.settings({+ ...SETTINGS,+ calendar_upcoming_events_default_category: 2,+ });needs.pretender(noEventsPretender);test("clicking an empty day cell opens the composer prefilled with the category", async function (assert) {