Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable some menu items in read-only mode #11733

Merged
merged 20 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ed3afe6
:art: kernel supports read-only publishing services
Zuoqiu-Yingyi May 12, 2024
0999115
:bug: Fix authentication vulnerabilities
Zuoqiu-Yingyi May 12, 2024
a24f509
:art: Protect secret information
Zuoqiu-Yingyi May 13, 2024
71efa33
:art: Adjust the permission control
Zuoqiu-Yingyi May 13, 2024
f8cca61
:art: Adjust the permission control
Zuoqiu-Yingyi May 13, 2024
b235527
:art: Fixed the vulnerability that `getFile` gets file `conf.json`
Zuoqiu-Yingyi May 13, 2024
e77faf7
:art: Add API `/api/setting/setPublish`
Zuoqiu-Yingyi May 13, 2024
56c565c
:art: Add API `/api/setting/getPublish`
Zuoqiu-Yingyi May 13, 2024
7049f89
Merge branch 'master' into feat/publish
Zuoqiu-Yingyi May 14, 2024
e33acd5
:bug: Fixed the issue that PWA-related files could not pass BasicAuth
Zuoqiu-Yingyi May 16, 2024
bf5ac0c
:art: Add a settings panel for publishing features
Zuoqiu-Yingyi May 16, 2024
9a6ee2d
Merge branch 'dev' into feat/publish
Zuoqiu-Yingyi May 16, 2024
0ccc969
:memo: Add guide for `Publish Service`
Zuoqiu-Yingyi May 16, 2024
fb79491
Merge branch 'dev' into feat/publish
Zuoqiu-Yingyi Jun 10, 2024
e242a8f
:memo: Update Japanese user guide
Zuoqiu-Yingyi Jun 10, 2024
484d3ee
:art: Merge fixed static file services
Zuoqiu-Yingyi Jun 10, 2024
717b250
Merge branch 'dev' into feat/publish
Zuoqiu-Yingyi Jun 15, 2024
e95a54d
:art: Disable some menu items in read-only mode
Zuoqiu-Yingyi Jun 15, 2024
2f2e743
:art: Disable some menu items in read-only mode
Zuoqiu-Yingyi Jun 15, 2024
9e79ce7
Update router.go
Zuoqiu-Yingyi Jun 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions app/src/config/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,12 @@ export const editor = {
if (fontFamilyElement.tagName === "SELECT") {
let fontFamilyHTML = `<option value="">${window.siyuan.languages.default}</option>`;
fetchPost("/api/system/getSysFonts", {}, (response) => {
response.data.forEach((item: string) => {
fontFamilyHTML += `<option value="${item}"${window.siyuan.config.editor.fontFamily === item ? " selected" : ""}>${item}</option>`;
});
fontFamilyElement.innerHTML = fontFamilyHTML;
if (response.code === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@88250 修改过后台请求处理,为保持所有请求的一致性处理,这个没有其他情况的话请不要进行修改。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用户在只读模式下打开设置面板后该请求会自动发出并返回异常, 因此需要额外处理一下

response.data.forEach((item: string) => {
fontFamilyHTML += `<option value="${item}"${window.siyuan.config.editor.fontFamily === item ? " selected" : ""}>${item}</option>`;
});
fontFamilyElement.innerHTML = fontFamilyHTML;
}
});
}
editor.element.querySelector("#clearHistory").addEventListener("click", () => {
Expand Down
46 changes: 32 additions & 14 deletions app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export class App {
registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);
/// #endif
addBaseURL();
addScriptSync(`${Constants.PROTYLE_CDN}/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}`, "protyleLuteScript"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一块比较复杂,没有必要请不要进行改动。如有必要的话请只修改关联部分即可。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一块是为了与其他端调用顺序统一, 方便之后进行维护

addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript"),

this.appId = Constants.SIYUAN_APPID;
window.siyuan = {
Expand Down Expand Up @@ -153,24 +155,40 @@ export class App {
};

fetchPost("/api/system/getConf", {}, async (response) => {
addScriptSync(`${Constants.PROTYLE_CDN}/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}`, "protyleLuteScript");
addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript");
window.siyuan.config = response.data.conf;
await loadPlugins(this);
getLocalStorage(() => {
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages: IObject) => {
window.siyuan.languages = lauguages;
window.siyuan.menus = new Menus(this);
bootSync();

const promises = [
loadPlugins(this),
new Promise<void>(resolve => getLocalStorage(resolve)),
new Promise<void>(resolve => fetchGet(
`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`,
(lauguages: IObject) => {
window.siyuan.languages = lauguages;
resolve();
},
)),
];

if (!window.siyuan.config.readonly) {
promises.push(new Promise<void>(resolve => {
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
window.siyuan.user = userResponse.data;
onGetConfig(response.data.start, this);
account.onSetaccount();
setTitle(window.siyuan.languages.siyuanNote);
initMessage();
resolve();
});
});
});
}));
}

await Promise.all(promises);

if (!window.siyuan.config.readonly) {
bootSync();
}

window.siyuan.menus = new Menus(this);
onGetConfig(response.data.start, this);
account.onSetaccount();
setTitle(window.siyuan.languages.siyuanNote);
initMessage();
});
setNoteBook();
initBlockPopover(this);
Expand Down
2 changes: 1 addition & 1 deletion app/src/layout/Wnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class Wnd {
this.headersElement.parentElement.addEventListener("click", (event) => {
let target = event.target as HTMLElement;
while (target && !target.isEqualNode(this.headersElement)) {
if (target.classList.contains("block__icon") && target.getAttribute("data-type") === "new") {
if (target.classList.contains("block__icon") && target.getAttribute("data-type") === "new" && !window.siyuan.config.readonly) {
setPanelFocus(this.headersElement.parentElement.parentElement);
newFile({
app,
Expand Down
1 change: 1 addition & 0 deletions app/src/layout/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const initStatus = (isWindow = false) => {
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.userGuide,
icon: "iconHelp",
disabled: window.siyuan.config.readonly,
click: () => {
mountHelp();
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/layout/topBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ const openPlugin = (app: App, target: Element) => {
menu.addItem({
icon: "iconSettings",
label: window.siyuan.languages.manage,
disabled: window.siyuan.config.readonly,
click() {
openSetting(app).element.querySelector('.b3-tab-bar [data-name="bazaar"]').dispatchEvent(new CustomEvent("click"));
}
Expand Down Expand Up @@ -374,7 +375,7 @@ const openPlugin = (app: App, target: Element) => {
}
});
if (!hasPlugin) {
window.siyuan.menus.menu.element.querySelector(".b3-menu__separator").remove();
window.siyuan.menus.menu.element.querySelector(".b3-menu__separator")?.remove();
}
let rect = target.getBoundingClientRect();
if (rect.width === 0) {
Expand Down
4 changes: 3 additions & 1 deletion app/src/menus/commonMenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ export const exportMd = (id: string) => {
label: window.siyuan.languages.template,
iconClass: "ft__error",
icon: "iconMarkdown",
disabled: window.siyuan.config.readonly,
click: async () => {
const result = await fetchSyncPost("/api/block/getRefText", {id: id});

Expand Down Expand Up @@ -507,8 +508,9 @@ export const exportMd = (id: string) => {
});
});
return;
} else if (response.code === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修改参见第一条

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处更改是为了避免出现异常但仍推送成功消息提示

showMessage(window.siyuan.languages.exportTplSucc);
}
showMessage(window.siyuan.languages.exportTplSucc);
});
dialog.destroy();
});
Expand Down
1 change: 1 addition & 0 deletions app/src/menus/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.userGuide,
icon: "iconHelp",
disabled: window.siyuan.config.readonly,
click: () => {
mountHelp();
}
Expand Down
73 changes: 48 additions & 25 deletions app/src/mobile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ class App {
if (!window.webkit?.messageHandlers && !window.JSAndroid) {
registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);
}
addBaseURL();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请参见第二点进行修改

addScriptSync(`${Constants.PROTYLE_CDN}/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}`, "protyleLuteScript");
addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript");
addBaseURL();

this.appId = Constants.SIYUAN_APPID;
window.siyuan = {
zIndex: 10,
Expand Down Expand Up @@ -89,30 +90,7 @@ class App {
fetchPost("/api/system/getConf", {}, async (confResponse) => {
window.siyuan.config = confResponse.data.conf;
correctHotkey(siyuanApp);
await loadPlugins(this);
getLocalStorage(() => {
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages: IObject) => {
window.siyuan.languages = lauguages;
window.siyuan.menus = new Menus(this);
document.title = window.siyuan.languages.siyuanNote;
bootSync();
loadAssets(confResponse.data.conf.appearance);
initMessage();
initAssets();
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
window.siyuan.user = userResponse.data;
fetchPost("/api/system/getEmojiConf", {}, emojiResponse => {
window.siyuan.emojis = emojiResponse.data as IEmoji[];
setNoteBook(() => {
initFramework(this, confResponse.data.start);
initRightMenu(this);
openChangelog();
});
});
});
addGA();
});
});

document.addEventListener("touchstart", handleTouchStart, false);
document.addEventListener("touchmove", handleTouchMove, false);
document.addEventListener("touchend", (event) => {
Expand Down Expand Up @@ -140,6 +118,51 @@ class App {
}
}
});

const promises = [
loadPlugins(this),
new Promise<void>(resolve => getLocalStorage(resolve)),
new Promise<void>(resolve => fetchGet(
`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`,
(lauguages: IObject) => {
window.siyuan.languages = lauguages;
resolve();
},
)),
new Promise<void>(resolve => {
fetchPost("/api/setting/getEmojiConf", {}, emojiResponse => {
window.siyuan.emojis = emojiResponse.data as IEmoji[];
resolve();
});
}),
];

if (!window.siyuan.config.readonly) {
promises.push(new Promise<void>(resolve => {
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
window.siyuan.user = userResponse.data;
resolve();
});
}));
}

await Promise.all(promises);

if (!window.siyuan.config.readonly) {
bootSync();
}

window.siyuan.menus = new Menus(this);
document.title = window.siyuan.languages.siyuanNote;
loadAssets(confResponse.data.conf.appearance);
initMessage();
initAssets();
setNoteBook(() => {
initFramework(this, confResponse.data.start);
initRightMenu(this);
openChangelog();
});
addGA();
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/protyle/gutter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,7 @@ export class Gutter {
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.wechatReminder,
icon: "iconMp",
disabled: window.siyuan.config.readonly,
click() {
openWechatNotify(nodeElement);
}
Expand All @@ -1676,6 +1677,7 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.editor.general.quickMakeCard.custom,
iconHTML: '<svg class="b3-menu__icon" style="color:var(--b3-theme-primary)"><use xlink:href="#iconRiffCard"></use></svg>',
icon: "iconRiffCard",
disabled: window.siyuan.config.readonly,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

相关的快捷键和其他菜单中的类似项也需要进行处理,须逐一核对。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如何禁用相关的快捷键?

目前已找到的其他菜单中的类似项已在只读模式下禁用,但不排除还有未找到的菜单项

click() {
quickMakeCard(protyle, [nodeElement]);
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/protyle/header/openTitleMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.wechatReminder,
icon: "iconMp",
disabled: window.siyuan.config.readonly,
click() {
openFileWechatNotify(protyle);
}
Expand All @@ -120,6 +121,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
iconHTML: "",
label: window.siyuan.languages.spaceRepetition,
accelerator: window.siyuan.config.keymap.editor.general.spaceRepetition.custom,
disabled: window.siyuan.config.readonly,
click: () => {
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => {
openCardByData(protyle.app, response.data, "doc", protyle.block.rootID, response.data.name);
Expand All @@ -128,6 +130,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
}, {
iconHTML: "",
label: window.siyuan.languages.manage,
disabled: window.siyuan.config.readonly,
click: () => {
fetchPost("/api/filetree/getHPathByID", {
id: protyle.block.rootID
Expand All @@ -139,6 +142,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
iconHTML: "",
label: window.siyuan.languages.quickMakeCard,
accelerator: window.siyuan.config.keymap.editor.general.quickMakeCard.custom,
disabled: window.siyuan.config.readonly,
click: () => {
let titleElement = protyle.title?.element;
if (!titleElement) {
Expand All @@ -153,6 +157,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
riffCardMenu.push({
iconHTML: "",
label: window.siyuan.languages.addToDeck,
disabled: window.siyuan.config.readonly,
click: () => {
makeCard(protyle.app, [protyle.block.rootID]);
}
Expand All @@ -163,6 +168,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
type: "submenu",
icon: "iconRiffCard",
submenu: riffCardMenu,
disabled: window.siyuan.config.readonly,
}).element);

window.siyuan.menus.menu.append(new MenuItem({
Expand Down
10 changes: 5 additions & 5 deletions app/src/protyle/scroll/saveScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {

export const getDocByScroll = (options: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个方法就是通过 scrollAttr 打开的,传入如果为空就没有意义了。这种场景是?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

场景未知, 该问题是在发现控制台输出异常后定位到的
复现步骤: 只读/发布模式下刷新当前文档

protyle: IProtyle,
scrollAttr: IScrollAttr,
scrollAttr?: IScrollAttr,
mergedOptions?: IOptions,
cb?: () => void
focus?: boolean,
Expand All @@ -61,7 +61,7 @@ export const getDocByScroll = (options: {
actions = [Constants.CB_GET_UNUNDO];
}
}
if (options.scrollAttr.zoomInId) {
if (options.scrollAttr?.zoomInId) {
fetchPost("/api/filetree/getDoc", {
id: options.scrollAttr.zoomInId,
size: Constants.SIZE_GET_MAX,
Expand Down Expand Up @@ -100,9 +100,9 @@ export const getDocByScroll = (options: {
return;
}
fetchPost("/api/filetree/getDoc", {
id: options.scrollAttr.rootId || options.mergedOptions?.blockId || options.protyle.block?.rootID || options.scrollAttr.startId,
startID: options.scrollAttr.startId,
endID: options.scrollAttr.endId,
id: options.scrollAttr?.rootId || options.mergedOptions?.blockId || options.protyle.block?.rootID || options.scrollAttr?.startId,
startID: options.scrollAttr?.startId,
endID: options.scrollAttr?.endId,
query: options.protyle.query?.key,
queryMethod: options.protyle.query?.method,
queryTypes: options.protyle.query?.types,
Expand Down
6 changes: 4 additions & 2 deletions app/src/util/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ export const initAssets = () => {
return;
}
}
window.siyuan.config.appearance = response.data.appearance;
loadAssets(response.data.appearance);
if (response.code === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参照第一点进行修改

window.siyuan.config.appearance = response.data.appearance;
loadAssets(response.data.appearance);
}
});
});
};
Expand Down
Loading