mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-09 03:03:24 +08:00
Load WhatsApp accessGrant into bot settings (4.9.1-ops.7).
Settings button only forwarded accessPolicy, so the graded ACL page always opened empty; also refresh grant from connection.status on mount. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
93672dfd91
commit
a4508a7caa
7 changed files with 110 additions and 8 deletions
|
|
@ -221,12 +221,47 @@ export function AccessGrantSettingsPage({ channel, account, rpcCall, onSaved })
|
|||
const [saving, setSaving] = React.useState(false);
|
||||
const [feedback, setFeedback] = React.useState(null);
|
||||
const [newGroupJid, setNewGroupJid] = React.useState('');
|
||||
const [loadingGrant, setLoadingGrant] = React.useState(!initialGrant);
|
||||
|
||||
React.useEffect(() => {
|
||||
setDraft(cloneGrant(normalizeAccessGrant(account?.accessGrant), ownerPhone));
|
||||
setGroupSessionScope(normalizeGroupSessionScope(account?.groupSessionScope));
|
||||
}, [account?.botId, initialKey, account?.groupSessionScope, ownerPhone]);
|
||||
|
||||
// Settings open payload historically omitted accessGrant; always refresh from status.
|
||||
React.useEffect(() => {
|
||||
if (typeof rpcCall !== 'function' || !account?.botId) return undefined;
|
||||
let cancelled = false;
|
||||
setLoadingGrant(true);
|
||||
void (async () => {
|
||||
try {
|
||||
const value = unwrapRpcResult(await rpcCall('connection.status', {}));
|
||||
if (cancelled) return;
|
||||
const bot = Array.isArray(value?.bots)
|
||||
? value.bots.find((entry) => entry?.botId === account.botId)
|
||||
: null;
|
||||
const grant = normalizeAccessGrant(bot?.accessGrant);
|
||||
if (grant) {
|
||||
setDraft(cloneGrant(grant, ownerPhone));
|
||||
onSaved?.(grant);
|
||||
}
|
||||
if (bot?.groupSessionScope) {
|
||||
setGroupSessionScope(normalizeGroupSessionScope(bot.groupSessionScope));
|
||||
}
|
||||
} catch (error) {
|
||||
if (!cancelled) {
|
||||
setFeedback({
|
||||
tone: 'error',
|
||||
message: error?.message || '无法读取访问授权,请返回刷新后重试。',
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
if (!cancelled) setLoadingGrant(false);
|
||||
}
|
||||
})();
|
||||
return () => { cancelled = true; };
|
||||
}, [account?.botId, rpcCall, ownerPhone]);
|
||||
|
||||
const contacts = draft.contacts ?? [];
|
||||
const knownGroupJids = React.useMemo(() => {
|
||||
const set = new Set(Object.keys(draft.groups ?? {}));
|
||||
|
|
@ -319,6 +354,9 @@ export function AccessGrantSettingsPage({ channel, account, rpcCall, onSaved })
|
|||
className: 'dim-accessPage',
|
||||
onSubmit: (event) => void save(event),
|
||||
},
|
||||
loadingGrant
|
||||
? h('div', { className: 'dim-accessState', 'aria-busy': 'true' }, '正在读取分级访问设置…')
|
||||
: null,
|
||||
h('p', { className: 'dim-accessUsersEmpty' },
|
||||
'WhatsApp 按电话号码授权:全局管理员管私聊;群管理员只批本群。成员不可跨群、有群权也不自动获得私聊权。'),
|
||||
h(AdminPhones, {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,15 @@ function SettingsGlyph() {
|
|||
h('path', { d: 'M19.4 15a1.7 1.7 0 0 0 .34 1.88l.06.06-2.83 2.83-.06-.06a1.7 1.7 0 0 0-1.88-.34 1.7 1.7 0 0 0-1.03 1.55V21h-4v-.08A1.7 1.7 0 0 0 8.97 19.4a1.7 1.7 0 0 0-1.88.34l-.06.06-2.83-2.83.06-.06A1.7 1.7 0 0 0 4.6 15a1.7 1.7 0 0 0-1.52-1.03H3v-4h.08A1.7 1.7 0 0 0 4.6 8.97a1.7 1.7 0 0 0-.34-1.88l-.06-.06L7.03 4.2l.06.06a1.7 1.7 0 0 0 1.88.34A1.7 1.7 0 0 0 10 3.08V3h4v.08a1.7 1.7 0 0 0 1.03 1.52 1.7 1.7 0 0 0 1.88-.34l.06-.06 2.83 2.83-.06.06a1.7 1.7 0 0 0-.34 1.88A1.7 1.7 0 0 0 20.92 10H21v4h-.08A1.7 1.7 0 0 0 19.4 15Z' }));
|
||||
}
|
||||
|
||||
export function BotSettingsButton({ channel, botId, botName, connected, accessPolicy }) {
|
||||
export function BotSettingsButton({
|
||||
channel,
|
||||
botId,
|
||||
botName,
|
||||
connected,
|
||||
accessPolicy,
|
||||
accessGrant,
|
||||
groupSessionScope,
|
||||
}) {
|
||||
const { openBotSettings } = React.useContext(BotSettingsContext);
|
||||
const tooltipId = React.useId();
|
||||
return h('span', { className: 'dim-botSettingsAction' },
|
||||
|
|
@ -38,6 +46,8 @@ export function BotSettingsButton({ channel, botId, botName, connected, accessPo
|
|||
botName,
|
||||
connected: Boolean(connected),
|
||||
accessPolicy,
|
||||
accessGrant,
|
||||
groupSessionScope,
|
||||
}),
|
||||
}, h(SettingsGlyph)),
|
||||
h('span', {
|
||||
|
|
|
|||
|
|
@ -220,6 +220,8 @@ export function WhatsappAccountCard({
|
|||
botName: account.bot.name,
|
||||
connected: account.connected,
|
||||
accessPolicy: account.accessPolicy,
|
||||
accessGrant: account.accessGrant,
|
||||
groupSessionScope: account.groupSessionScope,
|
||||
}))),
|
||||
h(WorkspaceEditor, {
|
||||
workspace: account.workspace,
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ const EN = Object.freeze({
|
|||
'机器人设置页签': 'Bot settings tabs',
|
||||
'投递设置': 'Delivery settings',
|
||||
'访问设置': 'Access settings',
|
||||
"无法读取访问授权,请返回刷新后重试。": "Could not load the access grant. Go back, refresh, and try again.",
|
||||
|
||||
"正在读取分级访问设置…": "Loading graded access settings…",
|
||||
|
||||
"加本群": "Add to group",
|
||||
|
||||
"已在本群": "Already in group",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue