2021-04-02 12:36:40 +00:00
|
|
|
import { makeAutoObservable } from "mobx";
|
2021-02-01 17:33:39 +00:00
|
|
|
import api from "../api";
|
2021-02-20 14:31:58 +00:00
|
|
|
import { ARTICLE_PINNED_KEY, LANGUAGE } from "../constants";
|
2021-03-21 21:34:21 +00:00
|
|
|
import { combineUrl } from "../utils";
|
|
|
|
import { AppServerConfig } from "../constants";
|
|
|
|
const { proxyURL } = AppServerConfig;
|
2021-02-01 17:33:39 +00:00
|
|
|
|
|
|
|
class SettingsStore {
|
2021-02-03 12:42:47 +00:00
|
|
|
isLoading = false;
|
|
|
|
isLoaded = false;
|
|
|
|
|
2021-02-02 09:55:14 +00:00
|
|
|
currentProductId = "";
|
|
|
|
culture = "en-US";
|
|
|
|
cultures = [];
|
|
|
|
trustedDomains = [];
|
2021-05-04 12:35:09 +00:00
|
|
|
trustedDomainsType = 0;
|
|
|
|
trustedDomains = [];
|
2021-02-02 09:55:14 +00:00
|
|
|
timezone = "UTC";
|
|
|
|
timezones = [];
|
|
|
|
utcOffset = "00:00:00";
|
|
|
|
utcHoursOffset = 0;
|
2021-03-30 10:05:52 +00:00
|
|
|
defaultPage = combineUrl(
|
|
|
|
proxyURL,
|
2021-03-30 12:01:25 +00:00
|
|
|
window["AscDesktopEditor"] !== undefined ? "/products/files/" : "/"
|
2021-03-30 10:05:52 +00:00
|
|
|
);
|
2021-03-21 21:34:21 +00:00
|
|
|
homepage = "";
|
2021-02-02 09:55:14 +00:00
|
|
|
datePattern = "M/d/yyyy";
|
|
|
|
datePatternJQ = "00/00/0000";
|
|
|
|
dateTimePattern = "dddd, MMMM d, yyyy h:mm:ss tt";
|
|
|
|
datepicker = {
|
|
|
|
datePattern: "mm/dd/yy",
|
2021-02-04 09:52:43 +00:00
|
|
|
dateTimePattern: "DD, mm dd, yy h:mm:ss tt",
|
2021-02-02 09:55:14 +00:00
|
|
|
timePattern: "h:mm tt",
|
2021-02-01 17:33:39 +00:00
|
|
|
};
|
2021-02-02 09:55:14 +00:00
|
|
|
organizationName = "ONLYOFFICE";
|
|
|
|
greetingSettings = "Web Office Applications";
|
|
|
|
enableAdmMess = false;
|
2021-04-19 15:39:00 +00:00
|
|
|
enabledJoin = false;
|
2021-02-02 09:55:14 +00:00
|
|
|
urlLicense = "https://gnu.org/licenses/gpl-3.0.html";
|
|
|
|
urlSupport = "https://helpdesk.onlyoffice.com/";
|
2021-03-22 14:35:33 +00:00
|
|
|
logoUrl = combineUrl(proxyURL, "/static/images/nav.logo.opened.react.svg");
|
2021-02-02 09:55:14 +00:00
|
|
|
customNames = {
|
|
|
|
id: "Common",
|
|
|
|
userCaption: "User",
|
|
|
|
usersCaption: "Users",
|
|
|
|
groupCaption: "Group",
|
|
|
|
groupsCaption: "Groups",
|
|
|
|
userPostCaption: "Title",
|
|
|
|
regDateCaption: "Registration Date",
|
|
|
|
groupHeadCaption: "Head",
|
|
|
|
guestCaption: "Guest",
|
|
|
|
guestsCaption: "Guests",
|
|
|
|
};
|
2021-02-03 12:42:47 +00:00
|
|
|
isDesktopClient = window["AscDesktopEditor"] !== undefined;
|
2021-02-02 09:55:14 +00:00
|
|
|
//isDesktopEncryption: desktopEncryption;
|
|
|
|
isEncryptionSupport = false;
|
|
|
|
encryptionKeys = null;
|
2021-02-20 14:31:58 +00:00
|
|
|
|
|
|
|
isHeaderVisible = false;
|
2021-02-02 09:55:14 +00:00
|
|
|
isTabletView = false;
|
2021-02-23 09:00:44 +00:00
|
|
|
isArticlePinned =
|
|
|
|
localStorage.getItem(ARTICLE_PINNED_KEY) === "true" || false;
|
2021-02-20 14:31:58 +00:00
|
|
|
|
2021-04-07 10:35:32 +00:00
|
|
|
isArticleVisibleOnUnpin = false;
|
|
|
|
|
2021-02-02 09:55:14 +00:00
|
|
|
hashSettings = null;
|
2021-02-03 12:42:47 +00:00
|
|
|
title = "";
|
2021-02-03 14:34:26 +00:00
|
|
|
ownerId = null;
|
|
|
|
nameSchemaId = null;
|
2021-02-15 19:43:07 +00:00
|
|
|
owner = {};
|
2021-03-18 18:54:03 +00:00
|
|
|
wizardToken = null;
|
2021-02-15 19:43:07 +00:00
|
|
|
passwordSettings = null;
|
2021-03-19 16:02:43 +00:00
|
|
|
hasShortenService = false;
|
2021-02-01 17:33:39 +00:00
|
|
|
|
2021-04-16 14:10:37 +00:00
|
|
|
customSchemaList = [];
|
2021-04-13 11:34:04 +00:00
|
|
|
|
2021-02-01 17:33:39 +00:00
|
|
|
constructor() {
|
2021-04-01 09:42:23 +00:00
|
|
|
makeAutoObservable(this);
|
2021-02-01 17:33:39 +00:00
|
|
|
}
|
|
|
|
|
2021-02-02 09:55:14 +00:00
|
|
|
get urlAuthKeys() {
|
|
|
|
const splitted = this.culture.split("-");
|
|
|
|
const lang = splitted.length > 0 ? splitted[0] : "en";
|
|
|
|
return `https://helpcenter.onlyoffice.com/${lang}/installation/groups-authorization-keys.aspx`;
|
2021-02-01 17:33:39 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 18:54:03 +00:00
|
|
|
get wizardCompleted() {
|
|
|
|
return this.isLoaded && !this.wizardToken;
|
|
|
|
}
|
|
|
|
|
2021-04-13 11:47:46 +00:00
|
|
|
get helpUrlCommonSettings() {
|
|
|
|
const substring = this.culture.substring(0, this.culture.indexOf("-"));
|
|
|
|
const lang = substring.length > 0 ? substring : "en";
|
|
|
|
|
|
|
|
return `https://helpcenter.onlyoffice.com/${lang}/administration/configuration.aspx#CustomizingPortal_block`;
|
|
|
|
}
|
|
|
|
|
2021-03-03 11:46:05 +00:00
|
|
|
setValue = (key, value) => {
|
|
|
|
this[key] = value;
|
|
|
|
};
|
2021-03-18 18:54:03 +00:00
|
|
|
|
2021-02-02 09:55:14 +00:00
|
|
|
getSettings = async () => {
|
|
|
|
const newSettings = await api.settings.getSettings();
|
2021-02-01 17:33:39 +00:00
|
|
|
|
2021-02-02 09:55:14 +00:00
|
|
|
Object.keys(newSettings).map((key) => {
|
2021-02-03 14:06:47 +00:00
|
|
|
if (key in this) {
|
2021-03-21 21:34:21 +00:00
|
|
|
this.setValue(
|
|
|
|
key,
|
|
|
|
key === "defaultPage"
|
|
|
|
? combineUrl(proxyURL, newSettings[key])
|
|
|
|
: newSettings[key]
|
|
|
|
);
|
2021-04-07 13:33:00 +00:00
|
|
|
if (key === "culture") {
|
|
|
|
const language = localStorage.getItem(LANGUAGE);
|
|
|
|
if (!language || language == "undefined") {
|
|
|
|
localStorage.setItem(LANGUAGE, newSettings[key]);
|
|
|
|
}
|
2021-02-02 09:55:14 +00:00
|
|
|
}
|
|
|
|
} else if (key === "passwordHash") {
|
2021-03-03 11:46:05 +00:00
|
|
|
this.setValue("hashSettings", newSettings[key]);
|
2021-02-02 09:55:14 +00:00
|
|
|
}
|
|
|
|
});
|
2021-02-01 17:33:39 +00:00
|
|
|
|
2021-02-02 09:55:14 +00:00
|
|
|
return newSettings;
|
|
|
|
};
|
2021-02-01 17:33:39 +00:00
|
|
|
|
2021-02-02 09:55:14 +00:00
|
|
|
getCurrentCustomSchema = async (id) => {
|
|
|
|
this.customNames = await api.settings.getCurrentCustomSchema(id);
|
|
|
|
};
|
2021-02-01 17:33:39 +00:00
|
|
|
|
2021-04-16 12:35:02 +00:00
|
|
|
getCustomSchemaList = async () => {
|
2021-04-16 14:10:37 +00:00
|
|
|
this.customSchemaList = await api.settings.getCustomSchemaList();
|
2021-04-13 11:34:04 +00:00
|
|
|
};
|
|
|
|
|
2021-02-02 09:55:14 +00:00
|
|
|
getPortalSettings = async () => {
|
|
|
|
const origSettings = await this.getSettings();
|
|
|
|
|
|
|
|
if (origSettings.nameSchemaId) {
|
|
|
|
this.getCurrentCustomSchema(origSettings.nameSchemaId);
|
|
|
|
}
|
|
|
|
};
|
2021-02-03 12:42:47 +00:00
|
|
|
|
|
|
|
init = async () => {
|
|
|
|
this.setIsLoading(true);
|
|
|
|
|
|
|
|
await this.getPortalSettings();
|
|
|
|
|
|
|
|
this.setIsLoading(false);
|
|
|
|
this.setIsLoaded(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
setIsLoading = (isLoading) => {
|
|
|
|
this.isLoading = isLoading;
|
|
|
|
};
|
|
|
|
|
|
|
|
setIsLoaded = (isLoaded) => {
|
|
|
|
this.isLoaded = isLoaded;
|
|
|
|
};
|
2021-02-04 09:52:43 +00:00
|
|
|
|
|
|
|
getPortalCultures = async () => {
|
|
|
|
this.cultures = await api.settings.getPortalCultures();
|
|
|
|
};
|
|
|
|
|
2021-04-01 09:42:23 +00:00
|
|
|
setIsEncryptionSupport = (isEncryptionSupport) => {
|
|
|
|
this.isEncryptionSupport = isEncryptionSupport;
|
|
|
|
};
|
|
|
|
|
2021-02-04 09:52:43 +00:00
|
|
|
getIsEncryptionSupport = async () => {
|
2021-04-01 09:42:23 +00:00
|
|
|
const isEncryptionSupport = await api.files.getIsEncryptionSupport();
|
|
|
|
this.setIsEncryptionSupport(isEncryptionSupport);
|
2021-02-04 09:52:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
updateEncryptionKeys = (encryptionKeys) => {
|
|
|
|
this.encryptionKeys = encryptionKeys ?? {};
|
|
|
|
};
|
|
|
|
|
|
|
|
setEncryptionKeys = async (keys) => {
|
|
|
|
await api.files.setEncryptionKeys(keys);
|
|
|
|
this.updateEncryptionKeys(keys);
|
|
|
|
};
|
|
|
|
|
|
|
|
getEncryptionKeys = async () => {
|
|
|
|
const encryptionKeys = await api.files.getEncryptionKeys();
|
|
|
|
this.updateEncryptionKeys(encryptionKeys);
|
|
|
|
};
|
|
|
|
|
2021-04-04 13:39:35 +00:00
|
|
|
getOAuthToken = (tokenGetterWin) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
2021-03-24 13:49:42 +00:00
|
|
|
localStorage.removeItem("code");
|
2021-04-04 13:39:35 +00:00
|
|
|
let interval = null;
|
|
|
|
interval = setInterval(() => {
|
2021-03-24 13:49:42 +00:00
|
|
|
try {
|
|
|
|
const code = localStorage.getItem("code");
|
|
|
|
|
|
|
|
if (code) {
|
|
|
|
localStorage.removeItem("code");
|
|
|
|
clearInterval(interval);
|
|
|
|
resolve(code);
|
2021-04-04 13:39:35 +00:00
|
|
|
} else if (tokenGetterWin && tokenGetterWin.closed) {
|
|
|
|
clearInterval(interval);
|
|
|
|
reject();
|
2021-03-24 13:49:42 +00:00
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-04-21 13:31:18 +00:00
|
|
|
getLoginLink = (token, code) => {
|
2021-04-23 10:17:40 +00:00
|
|
|
return combineUrl(proxyURL, `/login.ashx?p=${token}&code=${code}`);
|
2021-04-21 13:31:18 +00:00
|
|
|
};
|
|
|
|
|
2021-02-04 09:52:43 +00:00
|
|
|
setModuleInfo = (homepage, productId) => {
|
2021-03-13 15:29:26 +00:00
|
|
|
if (this.homepage == homepage) return;
|
2021-02-04 09:52:43 +00:00
|
|
|
this.homepage = homepage;
|
2021-02-15 19:43:07 +00:00
|
|
|
this.setCurrentProductId(productId);
|
2021-03-22 14:35:33 +00:00
|
|
|
|
2021-03-13 15:29:26 +00:00
|
|
|
const baseElm = document.getElementsByTagName("base");
|
|
|
|
if (baseElm && baseElm.length === 1) {
|
|
|
|
const baseUrl = homepage
|
|
|
|
? homepage[homepage.length - 1] === "/"
|
|
|
|
? homepage
|
|
|
|
: `${homepage}/`
|
|
|
|
: "/";
|
|
|
|
console.log("SET base URL", baseUrl);
|
|
|
|
baseElm[0].setAttribute("href", baseUrl);
|
|
|
|
}
|
2021-02-15 19:43:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
setCurrentProductId = (currentProductId) => {
|
|
|
|
this.currentProductId = currentProductId;
|
|
|
|
};
|
|
|
|
|
|
|
|
getPortalOwner = async () => {
|
|
|
|
const owner = await api.people.getUserById(this.ownerId);
|
|
|
|
this.owner = owner;
|
|
|
|
return owner;
|
|
|
|
};
|
|
|
|
|
|
|
|
setWizardComplete = () => {
|
2021-03-18 18:54:03 +00:00
|
|
|
this.wizardToken = null;
|
2021-02-15 19:43:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
setPasswordSettings = (passwordSettings) => {
|
|
|
|
this.passwordSettings = passwordSettings;
|
|
|
|
};
|
|
|
|
|
|
|
|
getPortalPasswordSettings = async (confirmKey = null) => {
|
|
|
|
const settings = await api.settings.getPortalPasswordSettings(confirmKey);
|
|
|
|
this.setPasswordSettings(settings);
|
|
|
|
};
|
|
|
|
|
|
|
|
setTimezones = (timezones) => {
|
|
|
|
this.timezones = timezones;
|
|
|
|
};
|
|
|
|
|
|
|
|
getPortalTimezones = async (token = undefined) => {
|
|
|
|
const timezones = await api.settings.getPortalTimezones(token);
|
|
|
|
this.setTimezones(timezones);
|
2021-02-04 09:52:43 +00:00
|
|
|
};
|
2021-02-20 14:31:58 +00:00
|
|
|
|
|
|
|
setHeaderVisible = (isHeaderVisible) => {
|
|
|
|
this.isHeaderVisible = isHeaderVisible;
|
|
|
|
};
|
|
|
|
|
|
|
|
setIsTabletView = (isTabletView) => {
|
|
|
|
this.isTabletView = isTabletView;
|
|
|
|
};
|
|
|
|
|
|
|
|
setArticlePinned = (isPinned) => {
|
|
|
|
isPinned
|
|
|
|
? localStorage.setItem(ARTICLE_PINNED_KEY, isPinned)
|
|
|
|
: localStorage.removeItem(ARTICLE_PINNED_KEY);
|
|
|
|
this.isArticlePinned = isPinned;
|
|
|
|
};
|
2021-04-07 10:35:32 +00:00
|
|
|
|
|
|
|
setArticleVisibleOnUnpin = (visible) => {
|
|
|
|
this.isArticleVisibleOnUnpin = visible;
|
|
|
|
};
|
2021-02-01 17:33:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default SettingsStore;
|