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
app/assets/javascripts/discourse/models
config
test/javascripts/models

View file

@ -60,7 +60,7 @@ Discourse.User = Discourse.Model.extend({
return this.get('website').split("/")[2]; return this.get('website').split("/")[2];
}.property('website'), }.property('website'),
/** /**
This user's profile background(in CSS). This user's profile background(in CSS).
@ -70,10 +70,10 @@ Discourse.User = Discourse.Model.extend({
profileBackground: function() { profileBackground: function() {
var background = this.get('profile_background'); var background = this.get('profile_background');
if(Em.isEmpty(background) || !Discourse.SiteSettings.allow_profile_backgrounds) { return; } if(Em.isEmpty(background) || !Discourse.SiteSettings.allow_profile_backgrounds) { return; }
return 'background-image: url(' + background + ')'; return 'background-image: url(' + background + ')';
}.property('profile_background'), }.property('profile_background'),
statusIcon: function() { statusIcon: function() {
var desc; var desc;
if(this.get('admin')) { if(this.get('admin')) {
@ -329,10 +329,10 @@ Discourse.User = Discourse.Model.extend({
data: { use_uploaded_avatar: useUploadedAvatar } data: { use_uploaded_avatar: useUploadedAvatar }
}); });
}, },
/* /*
Clear profile background Clear profile background
@method clearProfileBackground @method clearProfileBackground
@returns {Promise} the result of the clear profile background request @returns {Promise} the result of the clear profile background request
*/ */
@ -373,10 +373,16 @@ Discourse.User = Discourse.Model.extend({
}); });
}, },
hasBeenSeenInTheLastMonth: function() { hasNotBeenSeenInTheLastMonth: function() {
return moment().diff(moment(this.get('last_seen_at')), 'month', true) < 1.0; return moment().diff(moment(this.get("last_seen_at")), "month", true) >= 1.0;
}.property("last_seen_at"), }.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 Homepage of the user
@ -389,13 +395,13 @@ Discourse.User = Discourse.Model.extend({
// - long-time-no-see user (ie. > 1 month) // - long-time-no-see user (ie. > 1 month)
if (Discourse.Site.currentProp("has_enough_topic_to_redirect_to_top_page")) { if (Discourse.Site.currentProp("has_enough_topic_to_redirect_to_top_page")) {
if (Discourse.SiteSettings.top_menu.indexOf("top") >= 0) { 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 "top";
} }
} }
} }
return Discourse.Utilities.defaultHomepage(); return Discourse.Utilities.defaultHomepage();
}.property("trust_level", "hasBeenSeenInTheLastMonth"), }.property("shouldBeRedirectToTopPage", "hasNotBeenSeenInTheLastMonth"),
updateMutedCategories: function() { updateMutedCategories: function() {
this.set("mutedCategories", Discourse.Category.findByIds(this.muted_category_ids)); 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_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" 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)" 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" email_domains_blacklist: "A pipe-delimited list of email domains that are not allowed. Example: mailinator.com|trashmail.net"
@ -673,9 +674,9 @@ en:
invite_only: "Public registration is disabled, new users must be invited" invite_only: "Public registration is disabled, new users must be invited"
login_required: "Require authentication to read posts" login_required: "Require authentication to read posts"
min_username_length: "Minimum username length. (Does not apply if global nickname uniqueness is forced)" min_username_length: "Minimum username length. (Does not apply if global nickname uniqueness is forced)"
min_password_length: "Minimum password length." min_password_length: "Minimum password length."
block_common_passwords: "Don't allow passwords that are in the 5000 most common passwords." block_common_passwords: "Don't allow passwords that are in the 5000 most common passwords."
@ -821,9 +822,9 @@ en:
detect_custom_avatars: "Whether or not to check that users have uploaded custom avatars" detect_custom_avatars: "Whether or not to check that users have uploaded custom avatars"
max_daily_gravatar_crawls: "The maximum amount of times Discourse will check gravatar for custom avatars in a day" max_daily_gravatar_crawls: "The maximum amount of times Discourse will check gravatar for custom avatars in a day"
allow_profile_backgrounds: "Allows users to upload profile backgrounds" allow_profile_backgrounds: "Allows users to upload profile backgrounds"
sequential_replies_threshold: "The amount of posts a user has to make in a row in a topic before being notified" sequential_replies_threshold: "The amount of posts a user has to make in a row in a topic before being notified"
enable_mobile_theme: "Mobile devices use a mobile-friendly theme, with the ability to switch to the full site. Disable this if you want to use a custom stylesheet that is fully responsive." enable_mobile_theme: "Mobile devices use a mobile-friendly theme, with the ability to switch to the full site. Disable this if you want to use a custom stylesheet that is fully responsive."

View file

@ -69,6 +69,9 @@ basic:
default: 20 default: 20
topics_per_period_in_top_page: topics_per_period_in_top_page:
default: 50 default: 50
redirect_new_users_to_top_page_duration:
client: true
default: 7
users: users:
enable_sso: 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() { test("homepage when top is enabled and has enough topics", function() {
var newUser = Discourse.User.create({ trust_level: 0, 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() }), oldUser = Discourse.User.create({ trust_level: 1, last_seen_at: moment(), created_at: moment().subtract("month", 2) }),
defaultHomepage = Discourse.Utilities.defaultHomepage(); defaultHomepage = Discourse.Utilities.defaultHomepage();
Discourse.SiteSettings.top_menu = "latest|top"; 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); 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(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"); 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() { asyncTestDiscourse("findByUsername", function() {
expect(3); expect(3);