From 1b9e2ff4f95d130bda90d3a4baf7a60850606719 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Fri, 24 Jan 2025 09:29:22 +1000 Subject: [PATCH] FEATURE: Add attribution to staff notice and rename functionality (#30920) The name "Staff Notice" was not quite right since TL4 users can also add these notices. This commit changes the wording to "Official Notice". In addition to this, currently you have to go look into the staff action logs to see who is responsible for a notice. This commit stores the ID of the user who created the notice, then shows this information on each notice to staff users. Finally, I migrated the ChangePostNoticeModal component to gjs. --- .../components/modal/change-post-notice.gjs | 110 ++++++++++++++++++ .../components/modal/change-post-notice.hbs | 30 ----- .../components/modal/change-post-notice.js | 63 ---------- .../discourse/app/lib/transform-post.js | 1 + .../javascripts/discourse/app/models/post.js | 5 +- .../javascripts/discourse/app/widgets/post.js | 27 ++++- .../components/widgets/post-test.js | 32 +++++ .../stylesheets/common/base/topic-post.scss | 4 + app/controllers/posts_controller.rb | 6 +- app/serializers/post_serializer.rb | 15 +++ .../post_stream_serializer_mixin.rb | 14 +++ config/locales/client.en.yml | 7 +- spec/requests/api/posts_spec.rb | 3 + spec/requests/posts_controller_spec.rb | 2 + spec/serializers/post_serializer_spec.rb | 108 ++++++++++++++--- spec/system/post_menu_spec.rb | 2 +- 16 files changed, 308 insertions(+), 121 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/modal/change-post-notice.gjs delete mode 100644 app/assets/javascripts/discourse/app/components/modal/change-post-notice.hbs delete mode 100644 app/assets/javascripts/discourse/app/components/modal/change-post-notice.js diff --git a/app/assets/javascripts/discourse/app/components/modal/change-post-notice.gjs b/app/assets/javascripts/discourse/app/components/modal/change-post-notice.gjs new file mode 100644 index 00000000000..97bef5aaede --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/modal/change-post-notice.gjs @@ -0,0 +1,110 @@ +import Component from "@glimmer/component"; +import { tracked } from "@glimmer/tracking"; +import { fn } from "@ember/helper"; +import { on } from "@ember/modifier"; +import { action } from "@ember/object"; +import { service } from "@ember/service"; +import { isEmpty } from "@ember/utils"; +import DButton from "discourse/components/d-button"; +import DModal from "discourse/components/d-modal"; +import DModalCancel from "discourse/components/d-modal-cancel"; +import withEventValue from "discourse/helpers/with-event-value"; +import { i18n } from "discourse-i18n"; + +export default class ChangePostNoticeModal extends Component { + @service currentUser; + @tracked post = this.args.model.post; + @tracked notice = this.args.model.post.notice?.raw ?? ""; + @tracked saving = false; + + resolve = this.args.model.resolve; + reject = this.args.model.reject; + + get disabled() { + return ( + this.saving || + isEmpty(this.notice) || + this.notice === this.post.notice?.raw + ); + } + + @action + saveNotice() { + this.setNotice(this.notice); + } + + @action + deleteNotice() { + this.setNotice(); + } + + @action + setNotice(notice) { + const { resolve, reject } = this; + + this.saving = true; + this.resolve = null; + this.reject = null; + + this.post + .updatePostField("notice", notice) + .then((response) => { + if (notice) { + return response.cooked_notice; + } + }) + .then((cooked) => { + this.post.set( + "notice", + cooked + ? { + type: "custom", + raw: notice, + cooked: cooked.toString(), + } + : null + ); + this.post.set("noticeCreatedByUser", this.currentUser); + }) + .then(resolve, reject) + .finally(() => this.args.closeModal()); + } + +