mirror of https://github.com/zulip/zulip.git
settings_data: Break circular dependency with people.
This commit is contained in:
parent
c7be17eb73
commit
231c536cad
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue