feat: 用户管理直接开通/撤销商业认证
All checks were successful
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 16s
Test / e2e-test (push) Successful in 48s
All checks were successful
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 16s
Test / e2e-test (push) Successful in 48s
- 用户列表每行加💼按钮,未认证点击开通,已认证点击撤销 - 新增 /api/business-grant/{id} 端点 - 开通/撤销时通知用户 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -614,6 +614,21 @@ def reject_translation(sid: int, user=Depends(require_role("admin"))):
|
|||||||
return {"ok": True}
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/api/business-grant/{user_id}")
|
||||||
|
def grant_business(user_id: int, user=Depends(require_role("admin"))):
|
||||||
|
conn = get_db()
|
||||||
|
conn.execute("UPDATE users SET business_verified = 1 WHERE id = ?", (user_id,))
|
||||||
|
target = conn.execute("SELECT role, display_name, username FROM users WHERE id = ?", (user_id,)).fetchone()
|
||||||
|
if target:
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO notifications (target_role, title, body, target_user_id) VALUES (?, ?, ?, ?)",
|
||||||
|
(target["role"], "🎉 商业认证已开通", "管理员已为你开通商业用户认证,现在可以使用商业核算等功能。", user_id)
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/business-revoke/{user_id}")
|
@app.post("/api/business-revoke/{user_id}")
|
||||||
def revoke_business(user_id: int, body: dict = None, user=Depends(require_role("admin"))):
|
def revoke_business(user_id: int, body: dict = None, user=Depends(require_role("admin"))):
|
||||||
conn = get_db()
|
conn = get_db()
|
||||||
|
|||||||
@@ -102,6 +102,8 @@
|
|||||||
<option value="editor">编辑</option>
|
<option value="editor">编辑</option>
|
||||||
<option value="senior_editor">高级编辑</option>
|
<option value="senior_editor">高级编辑</option>
|
||||||
</select>
|
</select>
|
||||||
|
<button v-if="!u.business_verified" class="btn-sm btn-outline" @click="grantBusiness(u)" title="开通商业认证">💼</button>
|
||||||
|
<button v-else class="btn-sm btn-outline" @click="revokeBusiness(u)" title="撤销商业认证" style="opacity:0.5">💼✕</button>
|
||||||
<button class="btn-sm btn-delete" @click="removeUser(u)" title="删除用户">🗑️</button>
|
<button class="btn-sm btn-delete" @click="removeUser(u)" title="删除用户">🗑️</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -240,6 +242,36 @@ async function removeUser(user) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function grantBusiness(user) {
|
||||||
|
const ok = await showConfirm(`直接为「${user.display_name || user.username}」开通商业认证?`)
|
||||||
|
if (!ok) return
|
||||||
|
const id = user._id || user.id
|
||||||
|
try {
|
||||||
|
const res = await api(`/api/business-grant/${id}`, { method: 'POST' })
|
||||||
|
if (res.ok) {
|
||||||
|
user.business_verified = 1
|
||||||
|
ui.showToast('已开通商业认证')
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
ui.showToast('操作失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function revokeBusiness(user) {
|
||||||
|
const ok = await showConfirm(`撤销「${user.display_name || user.username}」的商业认证?`)
|
||||||
|
if (!ok) return
|
||||||
|
const id = user._id || user.id
|
||||||
|
try {
|
||||||
|
const res = await api(`/api/business-revoke/${id}`, { method: 'POST' })
|
||||||
|
if (res.ok) {
|
||||||
|
user.business_verified = 0
|
||||||
|
ui.showToast('已撤销商业认证')
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
ui.showToast('操作失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function approveTranslation(t) {
|
async function approveTranslation(t) {
|
||||||
const id = t._id || t.id
|
const id = t._id || t.id
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user