mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 07:23:22 +00:00
settings_data: Break circular dependency with people.
This commit is contained in:
committed by
Tim Abbott
parent
c7be17eb73
commit
231c536cad
@@ -6,7 +6,6 @@ const {zrequire} = require("../zjsunit/namespace");
|
|||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
const {page_params} = require("../zjsunit/zpage_params");
|
const {page_params} = require("../zjsunit/zpage_params");
|
||||||
|
|
||||||
const people = zrequire("people");
|
|
||||||
const settings_data = zrequire("settings_data");
|
const settings_data = zrequire("settings_data");
|
||||||
const settings_config = zrequire("settings_config");
|
const settings_config = zrequire("settings_config");
|
||||||
|
|
||||||
@@ -23,7 +22,6 @@ const isaac = {
|
|||||||
user_id: 30,
|
user_id: 30,
|
||||||
full_name: "Isaac",
|
full_name: "Isaac",
|
||||||
};
|
};
|
||||||
people.add_active_user(isaac);
|
|
||||||
|
|
||||||
run_test("email_for_user_settings", () => {
|
run_test("email_for_user_settings", () => {
|
||||||
const email = settings_data.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[policy] = settings_config.common_policy_values.by_full_members.code;
|
||||||
page_params.user_id = 30;
|
page_params.user_id = 30;
|
||||||
people.add_active_user(isaac);
|
|
||||||
isaac.date_joined = new Date(Date.now());
|
isaac.date_joined = new Date(Date.now());
|
||||||
|
settings_data.initialize(isaac.date_joined);
|
||||||
page_params.realm_waiting_period_threshold = 10;
|
page_params.realm_waiting_period_threshold = 10;
|
||||||
assert.equal(validation_func(), false);
|
assert.equal(validation_func(), false);
|
||||||
|
|
||||||
isaac.date_joined = new Date(Date.now() - 20 * 86400000);
|
isaac.date_joined = new Date(Date.now() - 20 * 86400000);
|
||||||
|
settings_data.initialize(isaac.date_joined);
|
||||||
assert.equal(validation_func(), true);
|
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[policy] = settings_config.common_message_policy_values.by_full_members.code;
|
||||||
page_params.user_id = 30;
|
page_params.user_id = 30;
|
||||||
people.add_active_user(isaac);
|
|
||||||
isaac.date_joined = new Date(Date.now());
|
isaac.date_joined = new Date(Date.now());
|
||||||
page_params.realm_waiting_period_threshold = 10;
|
page_params.realm_waiting_period_threshold = 10;
|
||||||
|
settings_data.initialize(isaac.date_joined);
|
||||||
assert.equal(validation_func(), false);
|
assert.equal(validation_func(), false);
|
||||||
|
|
||||||
isaac.date_joined = new Date(Date.now() - 20 * 86400000);
|
isaac.date_joined = new Date(Date.now() - 20 * 86400000);
|
||||||
|
settings_data.initialize(isaac.date_joined);
|
||||||
assert.equal(validation_func(), true);
|
assert.equal(validation_func(), true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import {page_params} from "./page_params";
|
import {page_params} from "./page_params";
|
||||||
import * as people from "./people";
|
|
||||||
import * as settings_config from "./settings_config";
|
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,
|
This is a close cousin of settings_config,
|
||||||
but this has a bit more logic, and we
|
but this has a bit more logic, and we
|
||||||
@@ -121,12 +125,10 @@ function user_has_permission(policy_value) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const person = people.get_by_user_id(page_params.user_id);
|
const current_datetime = new Date();
|
||||||
const current_datetime = new Date(Date.now());
|
const person_date_joined = new Date(user_join_date);
|
||||||
const person_date_joined = new Date(person.date_joined);
|
const user_join_days = (current_datetime - person_date_joined) / 1000 / 86400;
|
||||||
const days = (current_datetime - person_date_joined) / 1000 / 86400;
|
return user_join_days >= page_params.realm_waiting_period_threshold;
|
||||||
|
|
||||||
return days >= page_params.realm_waiting_period_threshold;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function user_can_invite_others_to_realm() {
|
export function user_can_invite_others_to_realm() {
|
||||||
|
|||||||
@@ -499,6 +499,7 @@ export function initialize_everything() {
|
|||||||
popover_menus.initialize();
|
popover_menus.initialize();
|
||||||
|
|
||||||
people.initialize(page_params.user_id, people_params);
|
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
|
// These components must be initialized early, because other
|
||||||
// modules' initialization has not been audited for whether they
|
// modules' initialization has not been audited for whether they
|
||||||
|
|||||||
Reference in New Issue
Block a user