diff --git a/app/assets/javascripts/discourse/models/user.js b/app/assets/javascripts/discourse/models/user.js index 8fc12997d..4c279d563 100644 --- a/app/assets/javascripts/discourse/models/user.js +++ b/app/assets/javascripts/discourse/models/user.js @@ -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)); diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index a74d5013a..5296dd9c4 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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." diff --git a/config/site_settings.yml b/config/site_settings.yml index 7ddbc29f0..56572418f 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -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: diff --git a/test/javascripts/models/user_test.js b/test/javascripts/models/user_test.js index 5d668147a..13aa9b88b 100644 --- a/test/javascripts/models/user_test.js +++ b/test/javascripts/models/user_test.js @@ -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);