FEATURE: only redirect new users to top page for a limited period

That period is defined by the `redirect_new_users_to_top_page_duration`
site setting and defaults to 7 days.
This commit is contained in:
Régis Hanol 2014-03-05 22:11:01 +01:00
parent b0f3061113
commit ca12ea42a7
4 changed files with 37 additions and 15 deletions

View File

@ -373,10 +373,16 @@ Discourse.User = Discourse.Model.extend({
});
},
hasBeenSeenInTheLastMonth: function() {
return moment().diff(moment(this.get('last_seen_at')), 'month', true) < 1.0;
hasNotBeenSeenInTheLastMonth: function() {
return moment().diff(moment(this.get("last_seen_at")), "month", true) >= 1.0;
}.property("last_seen_at"),
shouldBeRedirectToTopPage: function() {
if (this.get("trust_level") > 0) { return false; }
var duration = Discourse.SiteSettings.redirect_new_users_to_top_page_duration;
return moment().diff(moment(this.get("created_at")), "days", true) < duration;
}.property("trust_level", "created_at"),
/**
Homepage of the user
@ -389,13 +395,13 @@ Discourse.User = Discourse.Model.extend({
// - long-time-no-see user (ie. > 1 month)
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")) {
if (this.get("shouldBeRedirectToTopPage") || this.get("hasNotBeenSeenInTheLastMonth")) {
return "top";
}
}
}
return Discourse.Utilities.defaultHomepage();
}.property("trust_level", "hasBeenSeenInTheLastMonth"),
}.property("shouldBeRedirectToTopPage", "hasNotBeenSeenInTheLastMonth"),
updateMutedCategories: function() {
this.set("mutedCategories", Discourse.Category.findByIds(this.muted_category_ids));

View File

@ -656,6 +656,7 @@ en:
topics_per_period_in_top_summary: "How many topics loaded on the top topics summary"
topics_per_period_in_top_page: "How many topics loaded on the top topics page"
redirect_new_users_to_top_page_duration: "Number of days during which new users are automatically redirect to the top page"
allow_index_in_robots_txt: "Site should be indexed by search engines (update robots.txt)"
email_domains_blacklist: "A pipe-delimited list of email domains that are not allowed. Example: mailinator.com|trashmail.net"

View File

@ -69,6 +69,9 @@ basic:
default: 20
topics_per_period_in_top_page:
default: 50
redirect_new_users_to_top_page_duration:
client: true
default: 7
users:
enable_sso:

View File

@ -56,11 +56,12 @@ test("homepage when top is enabled and not enough topics", function() {
});
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() }),
var newUser = Discourse.User.create({ trust_level: 0, last_seen_at: moment(), created_at: moment().subtract("day", 6) }),
oldUser = Discourse.User.create({ trust_level: 1, last_seen_at: moment(), created_at: moment().subtract("month", 2) }),
defaultHomepage = Discourse.Utilities.defaultHomepage();
Discourse.SiteSettings.top_menu = "latest|top";
Discourse.SiteSettings.redirect_new_users_to_top_page_duration = 7;
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");
@ -70,6 +71,17 @@ test("homepage when top is enabled and has enough topics", function() {
equal(oldUser.get("homepage"), "top", "long-time-no-see old user's homepage is top when top is enabled");
});
test("new user's homepage when top is enabled, there's enough topics and duration is over", function() {
var newUser = Discourse.User.create({ trust_level: 0, last_seen_at: moment(), created_at: moment().subtract("month", 1) }),
defaultHomepage = Discourse.Utilities.defaultHomepage();
Discourse.SiteSettings.top_menu = "latest|top";
Discourse.SiteSettings.redirect_new_users_to_top_page_duration = 7;
Discourse.Site.currentProp("has_enough_topic_to_redirect_to_top_page", true);
equal(newUser.get("homepage"), defaultHomepage, "new user's homepage is default when redirect duration is over");
});
asyncTestDiscourse("findByUsername", function() {
expect(3);