mirror of
https://github.com/discourse/discourse.git
synced 2025-04-19 09:49:06 +08:00
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:
parent
b0f3061113
commit
ca12ea42a7
@ -60,7 +60,7 @@ Discourse.User = Discourse.Model.extend({
|
||||
|
||||
return this.get('website').split("/")[2];
|
||||
}.property('website'),
|
||||
|
||||
|
||||
/**
|
||||
This user's profile background(in CSS).
|
||||
|
||||
@ -70,10 +70,10 @@ Discourse.User = Discourse.Model.extend({
|
||||
profileBackground: function() {
|
||||
var background = this.get('profile_background');
|
||||
if(Em.isEmpty(background) || !Discourse.SiteSettings.allow_profile_backgrounds) { return; }
|
||||
|
||||
|
||||
return 'background-image: url(' + background + ')';
|
||||
}.property('profile_background'),
|
||||
|
||||
|
||||
statusIcon: function() {
|
||||
var desc;
|
||||
if(this.get('admin')) {
|
||||
@ -329,10 +329,10 @@ Discourse.User = Discourse.Model.extend({
|
||||
data: { use_uploaded_avatar: useUploadedAvatar }
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
Clear profile background
|
||||
|
||||
|
||||
@method clearProfileBackground
|
||||
@returns {Promise} the result of the clear profile background request
|
||||
*/
|
||||
@ -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));
|
||||
|
@ -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"
|
||||
@ -673,9 +674,9 @@ en:
|
||||
invite_only: "Public registration is disabled, new users must be invited"
|
||||
|
||||
login_required: "Require authentication to read posts"
|
||||
|
||||
|
||||
min_username_length: "Minimum username length. (Does not apply if global nickname uniqueness is forced)"
|
||||
|
||||
|
||||
min_password_length: "Minimum password length."
|
||||
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"
|
||||
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"
|
||||
|
||||
|
||||
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."
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user