mirror of
https://github.com/discourse/discourse.git
synced 2025-07-02 07:12:25 +00:00
UX: Various improvements to welcome topic CTA (#21010)
- Update welcome topic copy - Edit the welcome topic automatically when the title or description changes - Remove “Create your Welcome Topic” banner/CTA - Add "edit welcome topic" user tip
This commit is contained in:
parent
b85d057df4
commit
b73a9a1faa
@ -1,4 +1,5 @@
|
|||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
|
import { schedule } from "@ember/runloop";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
import Component from "@glimmer/component";
|
import Component from "@glimmer/component";
|
||||||
import { hideUserTip } from "discourse/lib/user-tips";
|
import { hideUserTip } from "discourse/lib/user-tips";
|
||||||
@ -13,19 +14,22 @@ export default class UserTip extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { id, selector, content, placement } = this.args;
|
schedule("afterRender", () => {
|
||||||
this.currentUser.showUserTip({
|
const { id, selector, content, placement } = this.args;
|
||||||
id,
|
this.currentUser.showUserTip({
|
||||||
|
id,
|
||||||
|
|
||||||
titleText: I18n.t(`user_tips.${id}.title`),
|
titleText: I18n.t(`user_tips.${id}.title`),
|
||||||
contentText: content || I18n.t(`user_tips.${id}.content`),
|
contentText: content || I18n.t(`user_tips.${id}.content`),
|
||||||
|
|
||||||
reference: selector
|
reference: selector
|
||||||
? element.parentElement.querySelector(selector) || element.parentElement
|
? element.parentElement.querySelector(selector) ||
|
||||||
: element,
|
element.parentElement
|
||||||
appendTo: element.parentElement,
|
: element,
|
||||||
|
appendTo: element.parentElement,
|
||||||
|
|
||||||
placement: placement || "top",
|
placement: placement || "top",
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
<div class="welcome-cta">
|
|
||||||
<div class="welcome-cta__content">
|
|
||||||
<h1 class="welcome-cta__title">{{i18n "welcome_topic_banner.title"}}</h1>
|
|
||||||
<p class="welcome-cta__description">{{i18n
|
|
||||||
"welcome_topic_banner.description"
|
|
||||||
}}</p>
|
|
||||||
</div>
|
|
||||||
<DButton
|
|
||||||
@class="btn-primary welcome-cta__button"
|
|
||||||
@action={{action "editWelcomeTopic"}}
|
|
||||||
@label="welcome_topic_banner.button_title"
|
|
||||||
@icon="pencil-alt"
|
|
||||||
/>
|
|
||||||
</div>
|
|
@ -1,32 +0,0 @@
|
|||||||
import Component from "@glimmer/component";
|
|
||||||
import { action } from "@ember/object";
|
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
|
||||||
import Topic from "discourse/models/topic";
|
|
||||||
import Composer from "discourse/models/composer";
|
|
||||||
import { inject as service } from "@ember/service";
|
|
||||||
|
|
||||||
export default class WelcomeTopicBanner extends Component {
|
|
||||||
@service siteSettings;
|
|
||||||
@service store;
|
|
||||||
|
|
||||||
@action
|
|
||||||
editWelcomeTopic() {
|
|
||||||
const topicController = getOwner(this).lookup("controller:topic");
|
|
||||||
|
|
||||||
Topic.find(this.siteSettings.welcome_topic_id, {}).then((topic) => {
|
|
||||||
this.store
|
|
||||||
.createRecord("topic", {
|
|
||||||
id: topic.id,
|
|
||||||
slug: topic.slug,
|
|
||||||
})
|
|
||||||
.postStream.loadPostByPostNumber(1)
|
|
||||||
.then((post) => {
|
|
||||||
post.topic.setProperties({
|
|
||||||
draft_key: Composer.EDIT,
|
|
||||||
"details.can_edit": true,
|
|
||||||
});
|
|
||||||
topicController.send("editPost", post);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,7 +2,6 @@ import Controller, { inject as controller } from "@ember/controller";
|
|||||||
import { alias, equal, not } from "@ember/object/computed";
|
import { alias, equal, not } from "@ember/object/computed";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import Category from "discourse/models/category";
|
import Category from "discourse/models/category";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
@ -22,24 +21,6 @@ export default Controller.extend({
|
|||||||
|
|
||||||
loadedAllItems: not("discoveryTopics.model.canLoadMore"),
|
loadedAllItems: not("discoveryTopics.model.canLoadMore"),
|
||||||
|
|
||||||
@discourseComputed(
|
|
||||||
"router.currentRouteName",
|
|
||||||
"router.currentRoute.queryParams.f",
|
|
||||||
"site.show_welcome_topic_banner"
|
|
||||||
)
|
|
||||||
showEditWelcomeTopicBanner(
|
|
||||||
currentRouteName,
|
|
||||||
hasParams,
|
|
||||||
showWelcomeTopicBanner
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
this.currentUser?.staff &&
|
|
||||||
currentRouteName === "discovery.latest" &&
|
|
||||||
showWelcomeTopicBanner &&
|
|
||||||
!hasParams
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
loadingBegan() {
|
loadingBegan() {
|
||||||
this.set("loading", true);
|
this.set("loading", true);
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
import { bind } from "discourse-common/utils/decorators";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: "welcome-topic-banner",
|
|
||||||
after: "message-bus",
|
|
||||||
|
|
||||||
initialize(container) {
|
|
||||||
this.site = container.lookup("service:site");
|
|
||||||
this.messageBus = container.lookup("service:message-bus");
|
|
||||||
|
|
||||||
if (this.site.show_welcome_topic_banner) {
|
|
||||||
this.messageBus.subscribe("/site/welcome-topic-banner", this.onMessage);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
teardown() {
|
|
||||||
this.messageBus.unsubscribe("/site/welcome-topic-banner", this.onMessage);
|
|
||||||
},
|
|
||||||
|
|
||||||
@bind
|
|
||||||
onMessage(disabled) {
|
|
||||||
this.site.set("show_welcome_topic_banner", disabled);
|
|
||||||
},
|
|
||||||
};
|
|
@ -1,3 +1,4 @@
|
|||||||
|
import { isTesting } from "discourse-common/config/environment";
|
||||||
import { iconHTML } from "discourse-common/lib/icon-library";
|
import { iconHTML } from "discourse-common/lib/icon-library";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import { escape } from "pretty-text/sanitizer";
|
import { escape } from "pretty-text/sanitizer";
|
||||||
@ -25,6 +26,7 @@ export function showUserTip(options) {
|
|||||||
trigger: "manual",
|
trigger: "manual",
|
||||||
theme: "user-tips",
|
theme: "user-tips",
|
||||||
zIndex: "",
|
zIndex: "",
|
||||||
|
delay: isTesting() ? 0 : 100,
|
||||||
|
|
||||||
// It must be interactive to make buttons work.
|
// It must be interactive to make buttons work.
|
||||||
interactive: true,
|
interactive: true,
|
||||||
|
@ -28,10 +28,6 @@
|
|||||||
<PluginOutlet @name="discovery-above" @connectorTagName="div" />
|
<PluginOutlet @name="discovery-above" @connectorTagName="div" />
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{{#if this.showEditWelcomeTopicBanner}}
|
|
||||||
<WelcomeTopicBanner />
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
<div class="container list-container {{if this.loading 'hidden'}}">
|
<div class="container list-container {{if this.loading 'hidden'}}">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="full-width">
|
<div class="full-width">
|
||||||
|
@ -149,6 +149,14 @@
|
|||||||
class="edit-topic"
|
class="edit-topic"
|
||||||
title={{i18n "edit"}}
|
title={{i18n "edit"}}
|
||||||
>{{d-icon "pencil-alt"}}</a>
|
>{{d-icon "pencil-alt"}}</a>
|
||||||
|
|
||||||
|
{{#if (eq this.siteSettings.welcome_topic_id this.model.id)}}
|
||||||
|
<UserTip
|
||||||
|
@id="welcome_topic"
|
||||||
|
@selector=".edit-topic"
|
||||||
|
@placement="bottom"
|
||||||
|
/>
|
||||||
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<PluginOutlet
|
<PluginOutlet
|
||||||
|
@ -1,66 +0,0 @@
|
|||||||
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
|
|
||||||
import { test } from "qunit";
|
|
||||||
import { visit } from "@ember/test-helpers";
|
|
||||||
import Site from "discourse/models/site";
|
|
||||||
|
|
||||||
acceptance("Welcome Topic Banner", function (needs) {
|
|
||||||
needs.user({ admin: true });
|
|
||||||
needs.site({ show_welcome_topic_banner: true });
|
|
||||||
|
|
||||||
test("Is shown on latest", async function (assert) {
|
|
||||||
await visit("/latest");
|
|
||||||
assert.ok(exists(".welcome-cta"), "has the welcome topic banner");
|
|
||||||
assert.ok(
|
|
||||||
exists("button.welcome-cta__button"),
|
|
||||||
"has the welcome topic edit button"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Does not show if edited", async function (assert) {
|
|
||||||
const site = Site.current();
|
|
||||||
site.set("show_welcome_topic_banner", false);
|
|
||||||
|
|
||||||
await visit("/latest");
|
|
||||||
assert.ok(!exists(".welcome-cta"), "has the welcome topic banner");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Does not show on latest with query param tracked present", async function (assert) {
|
|
||||||
await visit("/latest?f=tracked");
|
|
||||||
assert.ok(
|
|
||||||
!exists(".welcome-cta"),
|
|
||||||
"does not have the welcome topic banner"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Does not show on latest with query param watched present", async function (assert) {
|
|
||||||
await visit("/latest?f=watched");
|
|
||||||
assert.ok(
|
|
||||||
!exists(".welcome-cta"),
|
|
||||||
"does not have the welcome topic banner"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Does not show on /categories page", async function (assert) {
|
|
||||||
await visit("/categories");
|
|
||||||
assert.ok(
|
|
||||||
!exists(".welcome-cta"),
|
|
||||||
"does not have the welcome topic banner"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Does not show on /top page", async function (assert) {
|
|
||||||
await visit("/top");
|
|
||||||
assert.ok(
|
|
||||||
!exists(".welcome-cta"),
|
|
||||||
"does not have the welcome topic banner"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Does not show on /unseen page", async function (assert) {
|
|
||||||
await visit("/unseen");
|
|
||||||
assert.ok(
|
|
||||||
!exists(".welcome-cta"),
|
|
||||||
"does not have the welcome topic banner"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
@ -3,6 +3,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.user-tip-container {
|
.user-tip-container {
|
||||||
|
font-weight: normal;
|
||||||
min-width: 300px;
|
min-width: 300px;
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
|
@ -249,21 +249,3 @@
|
|||||||
.container.list-container {
|
.container.list-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome-cta {
|
|
||||||
background-color: var(--secondary);
|
|
||||||
border: 1px solid var(--primary-low);
|
|
||||||
box-shadow: shadow("menu-panel");
|
|
||||||
border-radius: 4px;
|
|
||||||
padding: 12px 20px;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: space-between;
|
|
||||||
z-index: z("usercard");
|
|
||||||
&__content {
|
|
||||||
width: 70%;
|
|
||||||
}
|
|
||||||
&__button {
|
|
||||||
align-self: center;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -420,10 +420,7 @@ class Category < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def clear_related_site_settings
|
def clear_related_site_settings
|
||||||
if self.id == SiteSetting.general_category_id
|
SiteSetting.general_category_id = -1 if self.id == SiteSetting.general_category_id
|
||||||
SiteSetting.general_category_id = -1
|
|
||||||
Site.clear_show_welcome_topic_cache
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def topic_url
|
def topic_url
|
||||||
|
@ -216,40 +216,4 @@ class Site
|
|||||||
# the cache is validated based on the sequence
|
# the cache is validated based on the sequence
|
||||||
MessageBus.publish(SITE_JSON_CHANNEL, "")
|
MessageBus.publish(SITE_JSON_CHANNEL, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.welcome_topic_banner_cache_key(user_id)
|
|
||||||
"show_welcome_topic_banner:#{user_id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.welcome_topic_exists_and_is_not_edited?
|
|
||||||
Post
|
|
||||||
.joins(:topic)
|
|
||||||
.where(
|
|
||||||
"topics.id = :topic_id AND topics.deleted_at IS NULL AND posts.post_number = 1 AND posts.version = 1 AND posts.created_at > :created_at",
|
|
||||||
topic_id: SiteSetting.welcome_topic_id,
|
|
||||||
created_at: 1.month.ago,
|
|
||||||
)
|
|
||||||
.exists?
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.clear_show_welcome_topic_cache
|
|
||||||
Discourse
|
|
||||||
.cache
|
|
||||||
.keys("show_welcome_topic_banner:*")
|
|
||||||
.each { |key| Discourse.cache.redis.del(key) }
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.show_welcome_topic_banner?(guardian)
|
|
||||||
return false if !guardian.is_admin?
|
|
||||||
return false if guardian.user.id != User.first_login_admin_id
|
|
||||||
user_id = guardian.user.id
|
|
||||||
|
|
||||||
show_welcome_topic_banner = Discourse.cache.read(welcome_topic_banner_cache_key(user_id))
|
|
||||||
return show_welcome_topic_banner unless show_welcome_topic_banner.nil?
|
|
||||||
|
|
||||||
show_welcome_topic_banner = welcome_topic_exists_and_is_not_edited?
|
|
||||||
|
|
||||||
Discourse.cache.write(welcome_topic_banner_cache_key(user_id), show_welcome_topic_banner)
|
|
||||||
show_welcome_topic_banner
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -355,6 +355,7 @@ class User < ActiveRecord::Base
|
|||||||
post_menu: 3,
|
post_menu: 3,
|
||||||
topic_notification_levels: 4,
|
topic_notification_levels: 4,
|
||||||
suggested_topics: 5,
|
suggested_topics: 5,
|
||||||
|
welcome_topic: 6,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ class SiteSerializer < ApplicationSerializer
|
|||||||
:hashtag_configurations,
|
:hashtag_configurations,
|
||||||
:hashtag_icons,
|
:hashtag_icons,
|
||||||
:displayed_about_plugin_stat_groups,
|
:displayed_about_plugin_stat_groups,
|
||||||
:show_welcome_topic_banner,
|
|
||||||
:anonymous_default_sidebar_tags,
|
:anonymous_default_sidebar_tags,
|
||||||
:anonymous_sidebar_sections,
|
:anonymous_sidebar_sections,
|
||||||
:whispers_allowed_groups_names,
|
:whispers_allowed_groups_names,
|
||||||
@ -249,10 +248,6 @@ class SiteSerializer < ApplicationSerializer
|
|||||||
About.displayed_plugin_stat_groups
|
About.displayed_plugin_stat_groups
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_welcome_topic_banner
|
|
||||||
Site.show_welcome_topic_banner?(scope)
|
|
||||||
end
|
|
||||||
|
|
||||||
def anonymous_default_sidebar_tags
|
def anonymous_default_sidebar_tags
|
||||||
SiteSetting.default_sidebar_tags.split("|") - DiscourseTagging.hidden_tag_names(scope)
|
SiteSetting.default_sidebar_tags.split("|") - DiscourseTagging.hidden_tag_names(scope)
|
||||||
end
|
end
|
||||||
|
@ -65,4 +65,22 @@ DiscourseEvent.on(:site_setting_changed) do |name, old_value, new_value|
|
|||||||
end
|
end
|
||||||
|
|
||||||
Emoji.clear_cache && Discourse.request_refresh! if name == :emoji_deny_list
|
Emoji.clear_cache && Discourse.request_refresh! if name == :emoji_deny_list
|
||||||
|
|
||||||
|
if (name == :title || name == :site_description) &&
|
||||||
|
topic = Topic.find_by(id: SiteSetting.welcome_topic_id)
|
||||||
|
PostRevisor.new(topic.first_post, topic).revise!(
|
||||||
|
Discourse.system_user,
|
||||||
|
{
|
||||||
|
title: I18n.t("discourse_welcome_topic.title", site_title: SiteSetting.title),
|
||||||
|
raw:
|
||||||
|
I18n.t(
|
||||||
|
"discourse_welcome_topic.body",
|
||||||
|
base_path: Discourse.base_path,
|
||||||
|
site_title: SiteSetting.title,
|
||||||
|
site_description: SiteSetting.site_description,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
skip_revision: true,
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -1930,6 +1930,10 @@ en:
|
|||||||
title: "Keep reading!"
|
title: "Keep reading!"
|
||||||
content: "Here are some topics we think you might like to read next."
|
content: "Here are some topics we think you might like to read next."
|
||||||
|
|
||||||
|
welcome_topic:
|
||||||
|
title: "Edit the welcome topic"
|
||||||
|
content: "Help new members feel at home by customizing this topic to suit your community's needs."
|
||||||
|
|
||||||
loading: "Loading..."
|
loading: "Loading..."
|
||||||
errors:
|
errors:
|
||||||
prev_page: "while trying to load"
|
prev_page: "while trying to load"
|
||||||
|
@ -678,21 +678,19 @@ en:
|
|||||||
staff_category_description: "Private category for staff discussions. Topics are only visible to admins and moderators."
|
staff_category_description: "Private category for staff discussions. Topics are only visible to admins and moderators."
|
||||||
|
|
||||||
discourse_welcome_topic:
|
discourse_welcome_topic:
|
||||||
title: "Welcome to our community!"
|
title: "Welcome to %{site_title}! :wave:"
|
||||||
body: |
|
body: |
|
||||||
|
We're so glad you've joined us. %{site_description}
|
||||||
|
|
||||||
The first paragraph of this pinned topic will be visible as a welcome message to all new visitors on your homepage. It's important!
|
%{site_title} is powered by Discourse.org, the powerful, open platform for communities of all kinds. Here are some things you can do to get started:
|
||||||
|
|
||||||
**Edit this** into a brief description of your community:
|
:speaking_head: **Introduce yourself** by adding your picture and information about yourself and your interests to [your profile](%{base_path}/my/profile). What is one thing you’d like to be asked about?
|
||||||
|
|
||||||
- Who is it for?
|
:open_book: **Get to know the community** by [browsing discussions](%{base_path}/top) that are already happening here. When you find a post interesting, informative, or entertaining, use the :heart: to show your appreciation or support!
|
||||||
- What can they find here?
|
|
||||||
- Why should they come here?
|
|
||||||
- Where can they read more (links, resources, etc)?
|
|
||||||
|
|
||||||
<img src="%{base_path}/images/welcome/discourse-edit-post-animated.gif" width="508" height="106">
|
:handshake: **Contribute** by commenting, sharing your own perspective, asking questions, or offering feedback in the discussion. Before replying or starting new topics, please review the [Community Guidelines](%{base_path}/faq).
|
||||||
|
|
||||||
You may want to close this topic via the admin :wrench: (at the upper right and bottom), so that replies don't pile up on an announcement.
|
> If you need help or have a suggestion, feel free to ask in [#feedback](%{base_path}/c/site-feedback) or [contact the admins](%{base_path}/about).
|
||||||
|
|
||||||
admin_quick_start_title: "READ ME FIRST: Admin Quick Start Guide"
|
admin_quick_start_title: "READ ME FIRST: Admin Quick Start Guide"
|
||||||
|
|
||||||
|
@ -694,7 +694,6 @@ class PostRevisor
|
|||||||
|
|
||||||
update_topic_excerpt
|
update_topic_excerpt
|
||||||
update_category_description
|
update_category_description
|
||||||
hide_welcome_topic_banner
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_topic_excerpt
|
def update_topic_excerpt
|
||||||
@ -716,15 +715,6 @@ class PostRevisor
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def hide_welcome_topic_banner
|
|
||||||
return unless guardian.is_admin?
|
|
||||||
return unless @topic.id == SiteSetting.welcome_topic_id
|
|
||||||
return unless Discourse.cache.read(Site.welcome_topic_banner_cache_key(@editor.id))
|
|
||||||
|
|
||||||
Discourse.cache.write(Site.welcome_topic_banner_cache_key(@editor.id), false)
|
|
||||||
MessageBus.publish("/site/welcome-topic-banner", false)
|
|
||||||
end
|
|
||||||
|
|
||||||
def advance_draft_sequence
|
def advance_draft_sequence
|
||||||
@post.advance_draft_sequence
|
@post.advance_draft_sequence
|
||||||
end
|
end
|
||||||
|
@ -84,8 +84,14 @@ module SeedData
|
|||||||
if general_category = Category.find_by(id: SiteSetting.general_category_id)
|
if general_category = Category.find_by(id: SiteSetting.general_category_id)
|
||||||
topics << {
|
topics << {
|
||||||
site_setting_name: "welcome_topic_id",
|
site_setting_name: "welcome_topic_id",
|
||||||
title: I18n.t("discourse_welcome_topic.title"),
|
title: I18n.t("discourse_welcome_topic.title", site_title: SiteSetting.title),
|
||||||
raw: I18n.t("discourse_welcome_topic.body", base_path: Discourse.base_path),
|
raw:
|
||||||
|
I18n.t(
|
||||||
|
"discourse_welcome_topic.body",
|
||||||
|
base_path: Discourse.base_path,
|
||||||
|
site_title: SiteSetting.title,
|
||||||
|
site_description: SiteSetting.site_description,
|
||||||
|
),
|
||||||
category: general_category,
|
category: general_category,
|
||||||
after_create: proc { |post| post.topic.update_pinned(true, true) },
|
after_create: proc { |post| post.topic.update_pinned(true, true) },
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,6 @@ module TopicQueryParams
|
|||||||
:no_subcategories
|
:no_subcategories
|
||||||
].present?
|
].present?
|
||||||
|
|
||||||
if hide_welcome_topic?
|
|
||||||
options[:except_topic_ids] ||= []
|
|
||||||
options[:except_topic_ids] << SiteSetting.welcome_topic_id
|
|
||||||
end
|
|
||||||
|
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def hide_welcome_topic?
|
|
||||||
return false if !SiteSetting.bootstrap_mode_enabled
|
|
||||||
Site.welcome_topic_exists_and_is_not_edited?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 161 KiB |
@ -879,26 +879,6 @@ RSpec.describe PostRevisor do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "welcome topic" do
|
|
||||||
before { SiteSetting.welcome_topic_id = topic.id }
|
|
||||||
|
|
||||||
it "should publish welcome topic edit message" do
|
|
||||||
revisor = PostRevisor.new(post)
|
|
||||||
first_post = topic.first_post
|
|
||||||
UserAuthToken.generate!(user_id: admin.id)
|
|
||||||
Discourse.cache.write(Site.welcome_topic_banner_cache_key(admin.id), true)
|
|
||||||
|
|
||||||
messages =
|
|
||||||
MessageBus.track_publish("/site/welcome-topic-banner") do
|
|
||||||
revisor.revise!(admin, { raw: "updated welcome topic body" })
|
|
||||||
end
|
|
||||||
welcome_topic_banner_message =
|
|
||||||
messages.find { |message| message.channel == "/site/welcome-topic-banner" }
|
|
||||||
expect(welcome_topic_banner_message).to be_present
|
|
||||||
expect(welcome_topic_banner_message.data).to eq(false)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it "doesn't strip starting whitespaces" do
|
it "doesn't strip starting whitespaces" do
|
||||||
subject.revise!(post.user, raw: " <-- whitespaces --> ")
|
subject.revise!(post.user, raw: " <-- whitespaces --> ")
|
||||||
post.reload
|
post.reload
|
||||||
|
@ -19,9 +19,16 @@ RSpec.describe SeedData::Topics do
|
|||||||
expect { create_topic }.to change { Topic.count }.by(1).and change { Post.count }.by(1)
|
expect { create_topic }.to change { Topic.count }.by(1).and change { Post.count }.by(1)
|
||||||
|
|
||||||
topic = Topic.last
|
topic = Topic.last
|
||||||
expect(topic.title).to eq(I18n.t("discourse_welcome_topic.title"))
|
expect(topic.title).to eq(
|
||||||
|
I18n.t("discourse_welcome_topic.title", site_title: SiteSetting.title),
|
||||||
|
)
|
||||||
expect(topic.first_post.raw).to eq(
|
expect(topic.first_post.raw).to eq(
|
||||||
I18n.t("discourse_welcome_topic.body", base_path: Discourse.base_path).rstrip,
|
I18n.t(
|
||||||
|
"discourse_welcome_topic.body",
|
||||||
|
base_path: Discourse.base_path,
|
||||||
|
site_title: SiteSetting.title,
|
||||||
|
site_description: SiteSetting.site_description,
|
||||||
|
).rstrip,
|
||||||
)
|
)
|
||||||
expect(topic.category_id).to eq(SiteSetting.general_category_id)
|
expect(topic.category_id).to eq(SiteSetting.general_category_id)
|
||||||
expect(topic.user_id).to eq(Discourse::SYSTEM_USER_ID)
|
expect(topic.user_id).to eq(Discourse::SYSTEM_USER_ID)
|
||||||
@ -81,9 +88,16 @@ RSpec.describe SeedData::Topics do
|
|||||||
update_topic
|
update_topic
|
||||||
topic.reload
|
topic.reload
|
||||||
|
|
||||||
expect(topic.title).to eq(I18n.t("discourse_welcome_topic.title"))
|
expect(topic.title).to eq(
|
||||||
|
I18n.t("discourse_welcome_topic.title", site_title: SiteSetting.title),
|
||||||
|
)
|
||||||
expect(topic.first_post.raw).to eq(
|
expect(topic.first_post.raw).to eq(
|
||||||
I18n.t("discourse_welcome_topic.body", base_path: Discourse.base_path).rstrip,
|
I18n.t(
|
||||||
|
"discourse_welcome_topic.body",
|
||||||
|
base_path: Discourse.base_path,
|
||||||
|
site_title: SiteSetting.title,
|
||||||
|
site_description: SiteSetting.site_description,
|
||||||
|
).rstrip,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1345,7 +1345,7 @@ RSpec.describe TopicsFilter do
|
|||||||
.new(guardian: Guardian.new)
|
.new(guardian: Guardian.new)
|
||||||
.filter_from_query_string("order:category")
|
.filter_from_query_string("order:category")
|
||||||
.pluck(:id),
|
.pluck(:id),
|
||||||
).to eq([topic2.id, topic.id, topic5.id, topic3.id, topic4.id])
|
).to eq([topic2.id, [topic.id, topic5.id].sort, [topic3.id, topic4.id].sort].flatten)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -188,66 +188,4 @@ RSpec.describe Site do
|
|||||||
data = JSON.parse(Site.json_for(Guardian.new))
|
data = JSON.parse(Site.json_for(Guardian.new))
|
||||||
expect(data["auth_providers"].map { |a| a["name"] }).to contain_exactly("facebook", "twitter")
|
expect(data["auth_providers"].map { |a| a["name"] }).to contain_exactly("facebook", "twitter")
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".show_welcome_topic_banner?" do
|
|
||||||
it "returns false when the user is not admin" do
|
|
||||||
first_post = Fabricate(:post, created_at: 25.days.ago)
|
|
||||||
SiteSetting.welcome_topic_id = first_post.topic.id
|
|
||||||
|
|
||||||
expect(Site.show_welcome_topic_banner?(Guardian.new(Fabricate(:user)))).to eq(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns false when the user is not first admin who logs in" do
|
|
||||||
admin = Fabricate(:admin)
|
|
||||||
first_post = Fabricate(:post, created_at: 25.days.ago)
|
|
||||||
SiteSetting.welcome_topic_id = first_post.topic.id
|
|
||||||
|
|
||||||
expect(Site.show_welcome_topic_banner?(Guardian.new(admin))).to eq(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns true when welcome topic is less than month old" do
|
|
||||||
admin = Fabricate(:admin)
|
|
||||||
UserAuthToken.generate!(user_id: admin.id)
|
|
||||||
|
|
||||||
first_post = Fabricate(:post, created_at: 25.days.ago)
|
|
||||||
SiteSetting.welcome_topic_id = first_post.topic.id
|
|
||||||
|
|
||||||
expect(Site.show_welcome_topic_banner?(Guardian.new(admin))).to eq(true)
|
|
||||||
expect(Discourse.cache.read(Site.welcome_topic_banner_cache_key(admin.id))).to eq(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns false when welcome topic is more than month old" do
|
|
||||||
admin = Fabricate(:admin)
|
|
||||||
UserAuthToken.generate!(user_id: admin.id)
|
|
||||||
|
|
||||||
first_post = Fabricate(:post, created_at: 35.days.ago)
|
|
||||||
SiteSetting.welcome_topic_id = first_post.topic.id
|
|
||||||
|
|
||||||
expect(Site.show_welcome_topic_banner?(Guardian.new(admin))).to eq(false)
|
|
||||||
expect(Discourse.cache.read(Site.welcome_topic_banner_cache_key(admin.id))).to eq(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns false when welcome topic has been edited" do
|
|
||||||
admin = Fabricate(:admin)
|
|
||||||
UserAuthToken.generate!(user_id: admin.id)
|
|
||||||
|
|
||||||
first_post = Fabricate(:post, version: 2, created_at: 25.days.ago)
|
|
||||||
SiteSetting.welcome_topic_id = first_post.topic.id
|
|
||||||
|
|
||||||
expect(Site.show_welcome_topic_banner?(Guardian.new(admin))).to eq(false)
|
|
||||||
expect(Discourse.cache.read(Site.welcome_topic_banner_cache_key(admin.id))).to eq(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns false when welcome topic has been deleted" do
|
|
||||||
admin = Fabricate(:admin)
|
|
||||||
UserAuthToken.generate!(user_id: admin.id)
|
|
||||||
|
|
||||||
topic = Fabricate(:topic, deleted_at: 1.minute.ago)
|
|
||||||
first_post = Fabricate(:post, topic: topic, created_at: 25.days.ago)
|
|
||||||
SiteSetting.welcome_topic_id = topic.id
|
|
||||||
|
|
||||||
expect(Site.show_welcome_topic_banner?(Guardian.new(admin))).to eq(false)
|
|
||||||
expect(Discourse.cache.read(Site.welcome_topic_banner_cache_key(admin.id))).to eq(false)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -241,6 +241,9 @@
|
|||||||
},
|
},
|
||||||
"suggested_topics": {
|
"suggested_topics": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"welcome_topic": {
|
||||||
|
"type": "integer"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
@ -752,9 +755,6 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"show_welcome_topic_banner": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"archetypes": {
|
"archetypes": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items":
|
"items":
|
||||||
|
@ -261,74 +261,6 @@ RSpec.describe CategoriesController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "welcome topic" do
|
|
||||||
fab!(:category) { Fabricate(:category) }
|
|
||||||
fab!(:topic1) do
|
|
||||||
Fabricate(
|
|
||||||
:topic,
|
|
||||||
category: category,
|
|
||||||
created_at: 5.days.ago,
|
|
||||||
updated_at: Time.now,
|
|
||||||
bumped_at: Time.now,
|
|
||||||
)
|
|
||||||
end
|
|
||||||
fab!(:topic2) do
|
|
||||||
Fabricate(:topic, category: category, created_at: 2.days.ago, bumped_at: 2.days.ago)
|
|
||||||
end
|
|
||||||
fab!(:topic3) do
|
|
||||||
Fabricate(:topic, category: category, created_at: 1.day.ago, bumped_at: 1.day.ago)
|
|
||||||
end
|
|
||||||
fab!(:welcome_topic) { Fabricate(:topic) }
|
|
||||||
fab!(:post) { Fabricate(:post, topic: welcome_topic) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
SiteSetting.desktop_category_page_style = "categories_and_latest_topics"
|
|
||||||
SiteSetting.welcome_topic_id = welcome_topic.id
|
|
||||||
SiteSetting.editing_grace_period = 1.minute.to_i
|
|
||||||
SiteSetting.bootstrap_mode_enabled = true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is hidden for non-admins" do
|
|
||||||
get "/categories_and_latest.json"
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
expect(response.parsed_body["topic_list"]["topics"].map { |t| t["id"] }).not_to include(
|
|
||||||
welcome_topic.id,
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is shown to non-admins when there is an edit" do
|
|
||||||
post.revise(post.user, { raw: "#{post.raw}2" }, revised_at: post.updated_at + 2.minutes)
|
|
||||||
post.reload
|
|
||||||
expect(post.version).to eq(2)
|
|
||||||
|
|
||||||
get "/categories_and_latest.json"
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
expect(response.parsed_body["topic_list"]["topics"].map { |t| t["id"] }).to include(
|
|
||||||
welcome_topic.id,
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is hidden to admins" do
|
|
||||||
sign_in(admin)
|
|
||||||
|
|
||||||
get "/categories_and_latest.json"
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
expect(response.parsed_body["topic_list"]["topics"].map { |t| t["id"] }).not_to include(
|
|
||||||
welcome_topic.id,
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is shown to users when bootstrap mode is disabled" do
|
|
||||||
SiteSetting.bootstrap_mode_enabled = false
|
|
||||||
|
|
||||||
get "/categories_and_latest.json"
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
expect(response.parsed_body["topic_list"]["topics"].map { |t| t["id"] }).to include(
|
|
||||||
welcome_topic.id,
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it "includes subcategories and topics by default when view is subcategories_with_featured_topics" do
|
it "includes subcategories and topics by default when view is subcategories_with_featured_topics" do
|
||||||
SiteSetting.max_category_nesting = 3
|
SiteSetting.max_category_nesting = 3
|
||||||
subcategory = Fabricate(:category, user: admin, parent_category: category)
|
subcategory = Fabricate(:category, user: admin, parent_category: category)
|
||||||
|
@ -1078,57 +1078,6 @@ RSpec.describe ListController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "welcome topic" do
|
|
||||||
fab!(:welcome_topic) { Fabricate(:topic) }
|
|
||||||
fab!(:post) { Fabricate(:post, topic: welcome_topic) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
SiteSetting.welcome_topic_id = welcome_topic.id
|
|
||||||
SiteSetting.editing_grace_period = 1.minute.to_i
|
|
||||||
SiteSetting.bootstrap_mode_enabled = true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is hidden for non-admins" do
|
|
||||||
get "/latest.json"
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
parsed = response.parsed_body
|
|
||||||
expect(parsed["topic_list"]["topics"].length).to eq(1)
|
|
||||||
expect(parsed["topic_list"]["topics"].first["id"]).not_to eq(welcome_topic.id)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is shown to non-admins when there is an edit" do
|
|
||||||
post.revise(post.user, { raw: "#{post.raw}2" }, revised_at: post.updated_at + 2.minutes)
|
|
||||||
post.reload
|
|
||||||
expect(post.version).to eq(2)
|
|
||||||
|
|
||||||
get "/latest.json"
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
parsed = response.parsed_body
|
|
||||||
expect(parsed["topic_list"]["topics"].length).to eq(2)
|
|
||||||
expect(parsed["topic_list"]["topics"].first["id"]).to eq(welcome_topic.id)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is hidden to admins" do
|
|
||||||
sign_in(admin)
|
|
||||||
|
|
||||||
get "/latest.json"
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
parsed = response.parsed_body
|
|
||||||
expect(parsed["topic_list"]["topics"].length).to eq(1)
|
|
||||||
expect(parsed["topic_list"]["topics"].first["id"]).not_to eq(welcome_topic.id)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is shown to users when bootstrap mode is disabled" do
|
|
||||||
SiteSetting.bootstrap_mode_enabled = false
|
|
||||||
|
|
||||||
get "/latest.json"
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
parsed = response.parsed_body
|
|
||||||
expect(parsed["topic_list"]["topics"].length).to eq(2)
|
|
||||||
expect(parsed["topic_list"]["topics"].first["id"]).to eq(welcome_topic.id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#filter" do
|
describe "#filter" do
|
||||||
fab!(:category) { Fabricate(:category, slug: "category-slug") }
|
fab!(:category) { Fabricate(:category, slug: "category-slug") }
|
||||||
fab!(:tag) { Fabricate(:tag, name: "tag1") }
|
fab!(:tag) { Fabricate(:tag, name: "tag1") }
|
||||||
|
@ -131,19 +131,6 @@ RSpec.describe SiteSerializer do
|
|||||||
expect(serialized[:shared_drafts_category_id]).to eq(nil)
|
expect(serialized[:shared_drafts_category_id]).to eq(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "includes show_welcome_topic_banner" do
|
|
||||||
admin = Fabricate(:admin)
|
|
||||||
admin_guardian = Guardian.new(admin)
|
|
||||||
UserAuthToken.generate!(user_id: admin.id)
|
|
||||||
|
|
||||||
first_post = Fabricate(:post, created_at: 25.days.ago)
|
|
||||||
SiteSetting.welcome_topic_id = first_post.topic.id
|
|
||||||
|
|
||||||
serialized =
|
|
||||||
described_class.new(Site.new(admin_guardian), scope: admin_guardian, root: false).as_json
|
|
||||||
expect(serialized[:show_welcome_topic_banner]).to eq(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#anonymous_default_sidebar_tags" do
|
describe "#anonymous_default_sidebar_tags" do
|
||||||
fab!(:user) { Fabricate(:user) }
|
fab!(:user) { Fabricate(:user) }
|
||||||
fab!(:tag) { Fabricate(:tag, name: "dev") }
|
fab!(:tag) { Fabricate(:tag, name: "dev") }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user