FEATURE: Option to configure the holiday emoji (#385)

This allows setting a custom emoji for the holiday status and changes the default from 🏝️ to 📅
This commit is contained in:
Jan Cernik 2023-01-24 16:21:00 -03:00 committed by GitHub
parent 7b24ba5cad
commit 0e3369e370
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 15 deletions

View File

@ -1,7 +1,5 @@
import { emojiUrlFor } from "discourse/lib/text";
const HOLIDAY_EMOJI_NAME = "desert_island";
export default {
shouldRender(args, context) {
return (
@ -12,9 +10,11 @@ export default {
},
setupComponent(args, component) {
const holidayEmojiName =
this.get("siteSettings.holiday_status_emoji") || "date";
component.setProperties({
holidayEmojiName: `:${HOLIDAY_EMOJI_NAME}:`,
holidayEmoji: emojiUrlFor(HOLIDAY_EMOJI_NAME),
holidayEmojiName: `:${holidayEmojiName}:`,
holidayEmoji: emojiUrlFor(holidayEmojiName),
});
},
};

View File

@ -38,6 +38,7 @@ en:
discourse_post_event_allowed_custom_fields: "Allows to let each event to set the value of custom fields."
discourse_post_event_edit_notifications_time_extension: "Extends (in minutes) the period after the end of an event when `going` invitees are still being notified from edit in the original post."
holiday_calendar_topic_id: "Topic ID of staffs holiday / absence calendar."
holiday_status_emoji: Defines the emoji used for the holiday status.
delete_expired_event_posts_after: "Posts with expired events will be automatically deleted after (n) hours. Set to -1 to disable deletion."
all_day_event_start_time: "Events that do not have a start time specified will start at this time. Format is HH:mm. For 6:00 am, enter 06:00"
all_day_event_end_time: "Events that do not have a end time specified will end at this time. Format is HH:mm. For 6:00 pm, enter 18:00"

View File

@ -5,6 +5,9 @@ discourse_calendar:
holiday_calendar_topic_id:
default: ""
client: true
holiday_status_emoji:
client: true
default: "date"
delete_expired_event_posts_after:
min: -1
default: -1

View File

@ -2,14 +2,15 @@
module DiscourseCalendar
class HolidayStatus
EMOJI = "desert_island"
def self.set!(user, ends_at)
status = user.user_status
if status.blank? || status.expired? ||
(is_holiday_status?(status) && status.ends_at != ends_at)
user.set_status!(I18n.t("discourse_calendar.holiday_status.description"), EMOJI, ends_at)
user.set_status!(
I18n.t("discourse_calendar.holiday_status.description"),
emoji_name,
ends_at,
)
end
end
@ -20,8 +21,13 @@ module DiscourseCalendar
private
def self.is_holiday_status?(status)
status.emoji == EMOJI &&
status.emoji == emoji_name &&
status.description == I18n.t("discourse_calendar.holiday_status.description")
end
def self.emoji_name
emoji = SiteSetting.holiday_status_emoji
emoji.blank? ? "date" : emoji
end
end
end

View File

@ -572,7 +572,7 @@ describe Post do
status = post.user.user_status
expect(status).to be_present
expect(status.description).to eq(I18n.t("discourse_calendar.holiday_status.description"))
expect(status.emoji).to eq(DiscourseCalendar::HolidayStatus::EMOJI)
expect(status.emoji).to eq(SiteSetting.holiday_status_emoji)
expect(status.ends_at).to eq_time(Time.utc(2018, 6, 6, 10, 20))
end
@ -592,6 +592,44 @@ describe Post do
expect(status.description).to eq(custom_status[:description])
expect(status.emoji).to eq(custom_status[:emoji])
end
context "when custom emoji is set" do
custom_emoji = "palm_tree"
before { SiteSetting.holiday_status_emoji = custom_emoji }
it "sets holiday user status with custom emoji" do
freeze_time Time.utc(2018, 6, 5, 10, 30)
raw =
'Vacation [date="2018-06-05" time="10:20:00"] to [date="2018-06-06" time="10:20:00"]'
post = create_post(raw: raw, topic: calendar_post.topic)
status = post.user.user_status
expect(status).to be_present
expect(status.description).to eq(I18n.t("discourse_calendar.holiday_status.description"))
expect(status.emoji).to eq(custom_emoji)
expect(status.ends_at).to eq_time(Time.utc(2018, 6, 6, 10, 20))
end
end
context "when custom emoji is blank" do
before { SiteSetting.holiday_status_emoji = "" }
it "sets holiday user status with the default emoji" do
freeze_time Time.utc(2018, 6, 5, 10, 30)
raw =
'Vacation [date="2018-06-05" time="10:20:00"] to [date="2018-06-06" time="10:20:00"]'
post = create_post(raw: raw, topic: calendar_post.topic)
status = post.user.user_status
expect(status).to be_present
expect(status.description).to eq(I18n.t("discourse_calendar.holiday_status.description"))
expect(status.emoji).to eq("date")
expect(status.ends_at).to eq_time(Time.utc(2018, 6, 6, 10, 20))
end
end
end
context "when updating event dates" do
@ -610,7 +648,7 @@ describe Post do
status = post.user.user_status
expect(status).to be_present
expect(status.description).to eq(I18n.t("discourse_calendar.holiday_status.description"))
expect(status.emoji).to eq(DiscourseCalendar::HolidayStatus::EMOJI)
expect(status.emoji).to eq(SiteSetting.holiday_status_emoji)
expect(status.ends_at).to eq_time(Time.utc(2018, 6, 6, 0, 0))
end
@ -650,7 +688,7 @@ describe Post do
status = post.user.user_status
expect(status).to be_present
expect(status.description).to eq(I18n.t("discourse_calendar.holiday_status.description"))
expect(status.emoji).to eq(DiscourseCalendar::HolidayStatus::EMOJI)
expect(status.emoji).to eq(SiteSetting.holiday_status_emoji)
expect(status.ends_at).to eq_time(Time.utc(2018, 6, 6, 10, 20))
# after destroying the post the holiday status disappears:
@ -671,7 +709,7 @@ describe Post do
status = post.user.user_status
expect(status).to be_present
expect(status.description).to eq(I18n.t("discourse_calendar.holiday_status.description"))
expect(status.emoji).to eq(DiscourseCalendar::HolidayStatus::EMOJI)
expect(status.emoji).to eq(SiteSetting.holiday_status_emoji)
expect(status.ends_at).to eq_time(Time.utc(2018, 6, 6, 10, 20))
# user sets a custom status

View File

@ -94,7 +94,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
status = post.user.user_status
expect(status).to be_present
expect(status.description).to eq(I18n.t("discourse_calendar.holiday_status.description"))
expect(status.emoji).to eq(DiscourseCalendar::HolidayStatus::EMOJI)
expect(status.emoji).to eq(SiteSetting.holiday_status_emoji)
expect(status.ends_at).to eq_time(Time.utc(2018, 6, 6, 10, 20))
end
@ -157,7 +157,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
status = post.user.user_status
expect(status).to be_present
expect(status.description).to eq(I18n.t("discourse_calendar.holiday_status.description"))
expect(status.emoji).to eq(DiscourseCalendar::HolidayStatus::EMOJI)
expect(status.emoji).to eq(SiteSetting.holiday_status_emoji)
expect(status.ends_at).to eq_time(Time.utc(2018, 6, 8, 10, 20))
end