mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FEATURE: do not redirect to top page when number of topis is low
This commit is contained in:
parent
90d20c4373
commit
aac4b55926
3 changed files with 34 additions and 7 deletions
|
@ -354,16 +354,18 @@ Discourse.User = Discourse.Model.extend({
|
|||
@type {String}
|
||||
**/
|
||||
homepage: function() {
|
||||
// top is the default for:
|
||||
// when there are enough topics, /top is the default for
|
||||
// - new users
|
||||
// - long-time-no-see user (ie. > 1 month)
|
||||
if (Discourse.SiteSettings.top_menu.indexOf("top") >= 0) {
|
||||
if (this.get("trust_level") === 0 || !this.get("hasBeenSeenInTheLastMonth")) {
|
||||
return "top";
|
||||
if (Discourse.Site.currentProp("has_enough_topic_to_redirect_to_top_page")) {
|
||||
if (Discourse.SiteSettings.top_menu.indexOf("top") >= 0) {
|
||||
if (this.get("trust_level") === 0 || !this.get("hasBeenSeenInTheLastMonth")) {
|
||||
return "top";
|
||||
}
|
||||
}
|
||||
}
|
||||
return Discourse.Utilities.defaultHomepage();
|
||||
}.property("trust_level", "hasBeenSeenInTheLastMonth"),
|
||||
}.property("trust_level", "hasBeenSeenInTheLastMonth", "Discourse.Site.has_enough_topic_to_redirect_to_top_page"),
|
||||
|
||||
updateMutedCategories: function() {
|
||||
this.set("mutedCategories", Discourse.Category.findByIds(this.muted_category_ids));
|
||||
|
|
|
@ -9,7 +9,8 @@ class SiteSerializer < ApplicationSerializer
|
|||
:top_menu_items,
|
||||
:anonymous_top_menu_items,
|
||||
:uncategorized_category_id, # this is hidden so putting it here
|
||||
:is_readonly
|
||||
:is_readonly,
|
||||
:has_enough_topic_to_redirect_to_top_page
|
||||
|
||||
has_many :categories, serializer: BasicCategorySerializer, embed: :objects
|
||||
has_many :post_action_types, embed: :objects
|
||||
|
@ -50,4 +51,12 @@ class SiteSerializer < ApplicationSerializer
|
|||
Discourse.readonly_mode?
|
||||
end
|
||||
|
||||
def has_enough_topic_to_redirect_to_top_page
|
||||
Topic.listable_topics
|
||||
.visible
|
||||
.includes(:category).references(:category)
|
||||
.where('COALESCE(categories.topic_id, 0) <> topics.id')
|
||||
.count > SiteSetting.topics_per_period_in_top_page
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -40,12 +40,28 @@ test("homepage when top is disabled", function() {
|
|||
equal(oldUser.get("homepage"), defaultHomepage, "long-time-no-see old user's homepage is default when top is disabled");
|
||||
});
|
||||
|
||||
test("homepage when top is enabled", function() {
|
||||
test("homepage when top is enabled and not enought topics", function() {
|
||||
var newUser = Discourse.User.create({ trust_level: 0, last_seen_at: moment() }),
|
||||
oldUser = Discourse.User.create({ trust_level: 1, last_seen_at: moment() }),
|
||||
defaultHomepage = Discourse.Utilities.defaultHomepage();
|
||||
|
||||
Discourse.SiteSettings.top_menu = "latest|top";
|
||||
Discourse.Site.currentProp("has_enough_topic_to_redirect_to_top_page", false);
|
||||
|
||||
equal(newUser.get("homepage"), defaultHomepage, "new user's homepage is default");
|
||||
equal(oldUser.get("homepage"), defaultHomepage, "old user's homepage is default");
|
||||
|
||||
oldUser.set("last_seen_at", moment().subtract('month', 2));
|
||||
equal(oldUser.get("homepage"), defaultHomepage, "long-time-no-see old user's homepage is default");
|
||||
});
|
||||
|
||||
test("homepage when top is enabled and has enough topics", function() {
|
||||
var newUser = Discourse.User.create({ trust_level: 0, last_seen_at: moment() }),
|
||||
oldUser = Discourse.User.create({ trust_level: 1, last_seen_at: moment() }),
|
||||
defaultHomepage = Discourse.Utilities.defaultHomepage();
|
||||
|
||||
Discourse.SiteSettings.top_menu = "latest|top";
|
||||
Discourse.Site.currentProp("has_enough_topic_to_redirect_to_top_page", true);
|
||||
|
||||
equal(newUser.get("homepage"), "top", "new user's homepage is top when top is enabled");
|
||||
equal(oldUser.get("homepage"), defaultHomepage, "old user's homepage is default when top is enabled");
|
||||
|
|
Loading…
Reference in a new issue