0.3.5 共享功能修复
This commit is contained in:
@@ -32,6 +32,8 @@ export function DocumentShareDialog({
|
||||
const [username, setUsername] = useState("");
|
||||
const [permission, setPermission] = useState<SharePermission>("read");
|
||||
const [includeDescendants, setIncludeDescendants] = useState(false);
|
||||
const [disableDownload, setDisableDownload] = useState(false);
|
||||
const [disableCopy, setDisableCopy] = useState(false);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [shares, setShares] = useState<any[] | null>(null);
|
||||
@@ -40,6 +42,8 @@ export function DocumentShareDialog({
|
||||
const [groupShares, setGroupShares] = useState<any[] | null>(null);
|
||||
const [selectedGroupId, setSelectedGroupId] = useState("");
|
||||
const [groupIncludeDescendants, setGroupIncludeDescendants] = useState(false);
|
||||
const [groupDisableDownload, setGroupDisableDownload] = useState(false);
|
||||
const [groupDisableCopy, setGroupDisableCopy] = useState(false);
|
||||
const [groupMembers, setGroupMembers] = useState<Array<{ userId: string; username: string | null; role: string }>>(
|
||||
[],
|
||||
);
|
||||
@@ -121,6 +125,8 @@ export function DocumentShareDialog({
|
||||
setUsername("");
|
||||
setPermission("read");
|
||||
setIncludeDescendants(false);
|
||||
setDisableDownload(false);
|
||||
setDisableCopy(false);
|
||||
setSubmitting(false);
|
||||
setError(null);
|
||||
setShares(null);
|
||||
@@ -129,6 +135,8 @@ export function DocumentShareDialog({
|
||||
setGroupShares(null);
|
||||
setSelectedGroupId("");
|
||||
setGroupIncludeDescendants(false);
|
||||
setGroupDisableDownload(false);
|
||||
setGroupDisableCopy(false);
|
||||
setGroupMembers([]);
|
||||
setGroupEditableUserIds(new Set());
|
||||
return;
|
||||
@@ -150,10 +158,14 @@ export function DocumentShareDialog({
|
||||
const existing = rows.find((r: any) => String(r.groupId) === String(selectedGroupId));
|
||||
if (existing) {
|
||||
setGroupIncludeDescendants(Boolean(existing.includeDescendants));
|
||||
setGroupDisableDownload(Boolean(existing.disableDownload));
|
||||
setGroupDisableCopy(Boolean(existing.disableCopy));
|
||||
const editable = new Set<string>(Array.isArray(existing.editableUserIds) ? existing.editableUserIds.map(String) : []);
|
||||
setGroupEditableUserIds(editable);
|
||||
} else {
|
||||
setGroupIncludeDescendants(false);
|
||||
setGroupDisableDownload(false);
|
||||
setGroupDisableCopy(false);
|
||||
setGroupEditableUserIds(new Set());
|
||||
}
|
||||
}, [groupShares, open, selectedGroupId]);
|
||||
@@ -177,12 +189,40 @@ export function DocumentShareDialog({
|
||||
username: u,
|
||||
permission,
|
||||
includeDescendants: allowIncludeDescendants ? includeDescendants : false,
|
||||
disableDownload,
|
||||
disableCopy,
|
||||
});
|
||||
setUsername("");
|
||||
await loadShares();
|
||||
await onChanged?.();
|
||||
} catch (e: any) {
|
||||
setError(e?.message ?? "共享失败,请重试");
|
||||
const msg = e?.message ?? "共享失败,请重试";
|
||||
if (
|
||||
String(msg).includes("ArgumentValidationError") &&
|
||||
(String(msg).includes("disableCopy") || String(msg).includes("disableDownload"))
|
||||
) {
|
||||
// 兼容旧后端:先用旧参数重试,避免用户完全无法共享。
|
||||
try {
|
||||
await upsertShare({
|
||||
documentId,
|
||||
username: u,
|
||||
permission,
|
||||
includeDescendants: allowIncludeDescendants ? includeDescendants : false,
|
||||
} as any);
|
||||
setUsername("");
|
||||
await loadShares();
|
||||
await onChanged?.();
|
||||
setError(
|
||||
"已共享,但“禁止下载/禁止复制”未生效(当前 Convex 后端未更新)。请在 `wolai-frontend` 目录执行 `npx convex dev --env-file .env.local` 或 `npx convex deploy --env-file .env.local` 后再设置限制。",
|
||||
);
|
||||
} catch {
|
||||
setError(
|
||||
"共享功能已升级(新增“禁止下载/禁止复制”),但当前 Convex 后端未更新。请在 `wolai-frontend` 目录执行 `npx convex dev --env-file .env.local` 或 `npx convex deploy --env-file .env.local` 后刷新页面再试。",
|
||||
);
|
||||
}
|
||||
} else {
|
||||
setError(msg);
|
||||
}
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
@@ -216,11 +256,37 @@ export function DocumentShareDialog({
|
||||
groupId,
|
||||
includeDescendants: allowIncludeDescendants ? groupIncludeDescendants : false,
|
||||
editableUserIds: Array.from(groupEditableUserIds),
|
||||
disableDownload: groupDisableDownload,
|
||||
disableCopy: groupDisableCopy,
|
||||
});
|
||||
await loadGroupShares();
|
||||
await onChanged?.();
|
||||
} catch (e: any) {
|
||||
setError(e?.message ?? "公开失败,请重试");
|
||||
const msg = e?.message ?? "公开失败,请重试";
|
||||
if (
|
||||
String(msg).includes("ArgumentValidationError") &&
|
||||
(String(msg).includes("disableCopy") || String(msg).includes("disableDownload"))
|
||||
) {
|
||||
try {
|
||||
await upsertGroupShare({
|
||||
documentId,
|
||||
groupId,
|
||||
includeDescendants: allowIncludeDescendants ? groupIncludeDescendants : false,
|
||||
editableUserIds: Array.from(groupEditableUserIds),
|
||||
} as any);
|
||||
await loadGroupShares();
|
||||
await onChanged?.();
|
||||
setError(
|
||||
"已公开,但“禁止下载/禁止复制”未生效(当前 Convex 后端未更新)。请在 `wolai-frontend` 目录执行 `npx convex dev --env-file .env.local` 或 `npx convex deploy --env-file .env.local` 后再设置限制。",
|
||||
);
|
||||
} catch {
|
||||
setError(
|
||||
"共享功能已升级(新增“禁止下载/禁止复制”),但当前 Convex 后端未更新。请在 `wolai-frontend` 目录执行 `npx convex dev --env-file .env.local` 或 `npx convex deploy --env-file .env.local` 后刷新页面再试。",
|
||||
);
|
||||
}
|
||||
} else {
|
||||
setError(msg);
|
||||
}
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
@@ -294,6 +360,24 @@ export function DocumentShareDialog({
|
||||
包含子页面(共享文件夹)
|
||||
</label>
|
||||
)}
|
||||
<label className="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={disableDownload}
|
||||
onChange={(e) => setDisableDownload(e.target.checked)}
|
||||
disabled={submitting}
|
||||
/>
|
||||
禁止下载
|
||||
</label>
|
||||
<label className="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={disableCopy}
|
||||
onChange={(e) => setDisableCopy(e.target.checked)}
|
||||
disabled={submitting}
|
||||
/>
|
||||
禁止复制
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -325,6 +409,24 @@ export function DocumentShareDialog({
|
||||
包含子页面(公开文件夹)
|
||||
</label>
|
||||
)}
|
||||
<label className="flex items-center gap-2 text-sm text-gray-700">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={groupDisableDownload}
|
||||
onChange={(e) => setGroupDisableDownload(e.target.checked)}
|
||||
disabled={submitting}
|
||||
/>
|
||||
禁止下载
|
||||
</label>
|
||||
<label className="flex items-center gap-2 text-sm text-gray-700">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={groupDisableCopy}
|
||||
onChange={(e) => setGroupDisableCopy(e.target.checked)}
|
||||
disabled={submitting}
|
||||
/>
|
||||
禁止复制
|
||||
</label>
|
||||
<Button onClick={() => void handleUpsertGroupShare()} disabled={submitting || !selectedGroupId}>
|
||||
{submitting ? "处理中..." : "公开/更新"}
|
||||
</Button>
|
||||
@@ -396,6 +498,14 @@ export function DocumentShareDialog({
|
||||
{r.includeDescendants ? "包含子页面" : "仅当前页面"}
|
||||
{" · "}
|
||||
可编辑:{Array.isArray(r.editableUserIds) ? r.editableUserIds.length : 0} 人
|
||||
{(r.disableDownload || r.disableCopy) ? (
|
||||
<>
|
||||
{" · "}
|
||||
{r.disableDownload ? "禁止下载" : ""}
|
||||
{r.disableDownload && r.disableCopy ? " / " : ""}
|
||||
{r.disableCopy ? "禁止复制" : ""}
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
@@ -440,6 +550,14 @@ export function DocumentShareDialog({
|
||||
<div className="text-xs text-gray-500">
|
||||
权限:{row.permission === "edit" ? "可编辑" : "只读"}
|
||||
{row.includeDescendants ? " · 包含子页面" : ""}
|
||||
{(row.disableDownload || row.disableCopy) ? (
|
||||
<>
|
||||
{" · "}
|
||||
{row.disableDownload ? "禁止下载" : ""}
|
||||
{row.disableDownload && row.disableCopy ? " / " : ""}
|
||||
{row.disableCopy ? "禁止复制" : ""}
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
|
||||
Reference in New Issue
Block a user