diff --git a/frontend_tests/node_tests/settings_data.js b/frontend_tests/node_tests/settings_data.js index f3ff94bb28..36a03320e6 100644 --- a/frontend_tests/node_tests/settings_data.js +++ b/frontend_tests/node_tests/settings_data.js @@ -6,7 +6,6 @@ const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const {page_params} = require("../zjsunit/zpage_params"); -const people = zrequire("people"); const settings_data = zrequire("settings_data"); const settings_config = zrequire("settings_config"); @@ -23,7 +22,6 @@ const isaac = { user_id: 30, full_name: "Isaac", }; -people.add_active_user(isaac); run_test("email_for_user_settings", () => { const email = settings_data.email_for_user_settings; @@ -151,12 +149,13 @@ function test_policy(label, policy, validation_func) { page_params[policy] = settings_config.common_policy_values.by_full_members.code; page_params.user_id = 30; - people.add_active_user(isaac); isaac.date_joined = new Date(Date.now()); + settings_data.initialize(isaac.date_joined); page_params.realm_waiting_period_threshold = 10; assert.equal(validation_func(), false); isaac.date_joined = new Date(Date.now() - 20 * 86400000); + settings_data.initialize(isaac.date_joined); assert.equal(validation_func(), true); }); } @@ -215,12 +214,13 @@ function test_message_policy(label, policy, validation_func) { page_params[policy] = settings_config.common_message_policy_values.by_full_members.code; page_params.user_id = 30; - people.add_active_user(isaac); isaac.date_joined = new Date(Date.now()); page_params.realm_waiting_period_threshold = 10; + settings_data.initialize(isaac.date_joined); assert.equal(validation_func(), false); isaac.date_joined = new Date(Date.now() - 20 * 86400000); + settings_data.initialize(isaac.date_joined); assert.equal(validation_func(), true); }); } diff --git a/static/js/settings_data.js b/static/js/settings_data.js index 5c9a21b066..0d56f30fb6 100644 --- a/static/js/settings_data.js +++ b/static/js/settings_data.js @@ -1,7 +1,11 @@ import {page_params} from "./page_params"; -import * as people from "./people"; import * as settings_config from "./settings_config"; +let user_join_date; +export function initialize(current_user_join_date) { + user_join_date = current_user_join_date; +} + /* This is a close cousin of settings_config, but this has a bit more logic, and we @@ -121,12 +125,10 @@ function user_has_permission(policy_value) { return true; } - const person = people.get_by_user_id(page_params.user_id); - const current_datetime = new Date(Date.now()); - const person_date_joined = new Date(person.date_joined); - const days = (current_datetime - person_date_joined) / 1000 / 86400; - - return days >= page_params.realm_waiting_period_threshold; + const current_datetime = new Date(); + const person_date_joined = new Date(user_join_date); + const user_join_days = (current_datetime - person_date_joined) / 1000 / 86400; + return user_join_days >= page_params.realm_waiting_period_threshold; } export function user_can_invite_others_to_realm() { diff --git a/static/js/ui_init.js b/static/js/ui_init.js index 1ab9834abd..37770a4c27 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -499,6 +499,7 @@ export function initialize_everything() { popover_menus.initialize(); people.initialize(page_params.user_id, people_params); + settings_data.initialize(people.get_by_user_id(page_params.user_id).date_joined); // These components must be initialized early, because other // modules' initialization has not been audited for whether they