mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-14 21:02:49 +00:00
perf: 管理员可以修改系统机器人基本资料
This commit is contained in:
parent
05680ab152
commit
34745fb3e5
@ -1720,21 +1720,36 @@ class UsersController extends AbstractController
|
|||||||
}
|
}
|
||||||
$userBot = UserBot::whereBotId($botUser->userid)->whereUserid($user->userid)->first();
|
$userBot = UserBot::whereBotId($botUser->userid)->whereUserid($user->userid)->first();
|
||||||
if (empty($userBot)) {
|
if (empty($userBot)) {
|
||||||
return Base::retError('不是你的机器人');
|
if (UserBot::systemBotName($botUser->email)) {
|
||||||
|
// 系统机器人(仅限管理员)
|
||||||
|
if (!$user->isAdmin()) {
|
||||||
|
return Base::retError('权限不足');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 其他用户的机器人(仅限主人)
|
||||||
|
return Base::retError('不是你的机器人');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Base::retSuccess('success', [
|
//
|
||||||
|
$data = [
|
||||||
'id' => $botUser->userid,
|
'id' => $botUser->userid,
|
||||||
'name' => $botUser->nickname,
|
'name' => $botUser->nickname,
|
||||||
'avatar' => $botUser->userimg,
|
'avatar' => $botUser->userimg,
|
||||||
'clear_day' => $userBot->clear_day,
|
'clear_day' => 0,
|
||||||
'webhook_url' => $userBot->webhook_url,
|
'webhook_url' => '',
|
||||||
]);
|
'system_name' => UserBot::systemBotName($botUser->email),
|
||||||
|
];
|
||||||
|
if ($userBot) {
|
||||||
|
$data['clear_day'] = $userBot->clear_day;
|
||||||
|
$data['webhook_url'] = $userBot->webhook_url;
|
||||||
|
}
|
||||||
|
return Base::retSuccess('success', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {post} api/users/bot/edit 30. 编辑机器人
|
* @api {post} api/users/bot/edit 30. 编辑机器人
|
||||||
*
|
*
|
||||||
* @apiDescription 需要token身份,编辑我的机器人信息
|
* @apiDescription 需要token身份,编辑 我的机器人 或 管理员修改系统机器人 信息
|
||||||
* @apiVersion 1.0.0
|
* @apiVersion 1.0.0
|
||||||
* @apiGroup users
|
* @apiGroup users
|
||||||
* @apiName bot__edit
|
* @apiName bot__edit
|
||||||
@ -1742,8 +1757,8 @@ class UsersController extends AbstractController
|
|||||||
* @apiParam {Number} id 机器人ID
|
* @apiParam {Number} id 机器人ID
|
||||||
* @apiParam {String} [name] 机器人名称
|
* @apiParam {String} [name] 机器人名称
|
||||||
* @apiParam {String} [avatar] 机器人头像
|
* @apiParam {String} [avatar] 机器人头像
|
||||||
* @apiParam {Number} [clear_day] 清理天数
|
* @apiParam {Number} [clear_day] 清理天数(仅 我的机器人)
|
||||||
* @apiParam {String} [webhook_url] Webhook地址
|
* @apiParam {String} [webhook_url] Webhook地址(仅 我的机器人)
|
||||||
*
|
*
|
||||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
@ -1760,7 +1775,15 @@ class UsersController extends AbstractController
|
|||||||
}
|
}
|
||||||
$userBot = UserBot::whereBotId($botUser->userid)->whereUserid($user->userid)->first();
|
$userBot = UserBot::whereBotId($botUser->userid)->whereUserid($user->userid)->first();
|
||||||
if (empty($userBot)) {
|
if (empty($userBot)) {
|
||||||
return Base::retError('不是你的机器人');
|
if (UserBot::systemBotName($botUser->email)) {
|
||||||
|
// 系统机器人(仅限管理员)
|
||||||
|
if (!$user->isAdmin()) {
|
||||||
|
return Base::retError('权限不足');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 其他用户的机器人(仅限主人)
|
||||||
|
return Base::retError('不是你的机器人');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
$data = Request::input();
|
$data = Request::input();
|
||||||
@ -1789,18 +1812,24 @@ class UsersController extends AbstractController
|
|||||||
$botUser->updateInstance($upUser);
|
$botUser->updateInstance($upUser);
|
||||||
$botUser->save();
|
$botUser->save();
|
||||||
}
|
}
|
||||||
if ($upBot) {
|
if ($upBot && $userBot) {
|
||||||
$userBot->updateInstance($upBot);
|
$userBot->updateInstance($upBot);
|
||||||
$userBot->save();
|
$userBot->save();
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
return Base::retSuccess('修改成功', [
|
$data = [
|
||||||
'id' => $botUser->userid,
|
'id' => $botUser->userid,
|
||||||
'name' => $botUser->nickname,
|
'name' => $botUser->nickname,
|
||||||
'avatar' => $botUser->userimg,
|
'avatar' => $botUser->userimg,
|
||||||
'clear_day' => $userBot->clear_day,
|
'clear_day' => 0,
|
||||||
'webhook_url' => $userBot->webhook_url,
|
'webhook_url' => '',
|
||||||
]);
|
'system_name' => UserBot::systemBotName($botUser->email),
|
||||||
|
];
|
||||||
|
if ($userBot) {
|
||||||
|
$data['clear_day'] = $userBot->clear_day;
|
||||||
|
$data['webhook_url'] = $userBot->webhook_url;
|
||||||
|
}
|
||||||
|
return Base::retSuccess('修改成功', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -607,32 +607,7 @@ class User extends AbstractModel
|
|||||||
])->save();
|
])->save();
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
switch ($key) {
|
$update['nickname'] = UserBot::systemBotName($email);
|
||||||
case 'system-msg':
|
|
||||||
$update['nickname'] = '系统消息';
|
|
||||||
break;
|
|
||||||
case 'task-alert':
|
|
||||||
$update['nickname'] = '任务提醒';
|
|
||||||
break;
|
|
||||||
case 'check-in':
|
|
||||||
$update['nickname'] = '签到打卡';
|
|
||||||
break;
|
|
||||||
case 'anon-msg':
|
|
||||||
$update['nickname'] = '匿名消息';
|
|
||||||
break;
|
|
||||||
case 'approval-alert':
|
|
||||||
$update['nickname'] = '审批';
|
|
||||||
break;
|
|
||||||
case 'ai-openai':
|
|
||||||
$update['nickname'] = 'ChatGPT';
|
|
||||||
break;
|
|
||||||
case 'ai-claude':
|
|
||||||
$update['nickname'] = 'Claude';
|
|
||||||
break;
|
|
||||||
case 'bot-manager':
|
|
||||||
$update['nickname'] = '机器人管理';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ($update) {
|
if ($update) {
|
||||||
$botUser->updateInstance($update);
|
$botUser->updateInstance($update);
|
||||||
|
|||||||
@ -36,6 +36,29 @@ use Carbon\Carbon;
|
|||||||
class UserBot extends AbstractModel
|
class UserBot extends AbstractModel
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统机器人名称
|
||||||
|
* @param $name string 邮箱 或 邮箱前缀
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function systemBotName($name)
|
||||||
|
{
|
||||||
|
if (str_contains($name, "@")) {
|
||||||
|
$name = explode("@", $name)[0];
|
||||||
|
}
|
||||||
|
return match ($name) {
|
||||||
|
'system-msg' => '系统消息',
|
||||||
|
'task-alert' => '任务提醒',
|
||||||
|
'check-in' => '签到打卡',
|
||||||
|
'anon-msg' => '匿名消息',
|
||||||
|
'approval-alert' => '审批',
|
||||||
|
'ai-openai' => 'ChatGPT',
|
||||||
|
'ai-claude' => 'Claude',
|
||||||
|
'bot-manager' => '机器人管理',
|
||||||
|
default => '', // 不是系统机器人时返回空(也可以拿来判断是否是系统机器人)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 机器人菜单
|
* 机器人菜单
|
||||||
* @param $email
|
* @param $email
|
||||||
|
|||||||
@ -78,7 +78,7 @@
|
|||||||
<div>{{$L('搜索消息')}}</div>
|
<div>{{$L('搜索消息')}}</div>
|
||||||
</EDropdownItem>
|
</EDropdownItem>
|
||||||
<template v-if="dialogData.type === 'user'">
|
<template v-if="dialogData.type === 'user'">
|
||||||
<EDropdownItem v-if="dialogData.bot == userId" command="modifyNormal">
|
<EDropdownItem v-if="isManageBot" command="modifyNormal">
|
||||||
<div>{{$L('修改资料')}}</div>
|
<div>{{$L('修改资料')}}</div>
|
||||||
</EDropdownItem>
|
</EDropdownItem>
|
||||||
<EDropdownItem command="openCreate">
|
<EDropdownItem command="openCreate">
|
||||||
@ -356,20 +356,23 @@
|
|||||||
:title="$L('修改资料')"
|
:title="$L('修改资料')"
|
||||||
:mask-closable="false">
|
:mask-closable="false">
|
||||||
<Form :model="modifyData" label-width="auto" @submit.native.prevent>
|
<Form :model="modifyData" label-width="auto" @submit.native.prevent>
|
||||||
|
<Alert v-if="modifyData.system_name" type="error" style="margin-bottom:18px">{{$L(`正在修改系统机器人:${modifyData.system_name}`)}}</Alert>
|
||||||
<FormItem prop="avatar" :label="$L('头像')">
|
<FormItem prop="avatar" :label="$L('头像')">
|
||||||
<ImgUpload v-model="modifyData.avatar" :num="1" :width="512" :height="512" :whcut="1"/>
|
<ImgUpload v-model="modifyData.avatar" :num="1" :width="512" :height="512" :whcut="1"/>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<FormItem v-if="typeof modifyData.name !== 'undefined'" prop="name" :label="$L('名称')">
|
<FormItem v-if="typeof modifyData.name !== 'undefined'" prop="name" :label="$L('名称')">
|
||||||
<Input v-model="modifyData.name" :maxlength="20" />
|
<Input v-model="modifyData.name" :maxlength="20" />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<FormItem v-if="typeof modifyData.clear_day !== 'undefined'" prop="clear_day" :label="$L('消息保留')">
|
<template v-if="dialogData.bot == userId">
|
||||||
<Input v-model="modifyData.clear_day" :maxlength="3" type="number">
|
<FormItem v-if="typeof modifyData.clear_day !== 'undefined'" prop="clear_day" :label="$L('消息保留')">
|
||||||
<div slot="append">{{$L('天')}}</div>
|
<Input v-model="modifyData.clear_day" :maxlength="3" type="number">
|
||||||
</Input>
|
<div slot="append">{{$L('天')}}</div>
|
||||||
</FormItem>
|
</Input>
|
||||||
<FormItem v-if="typeof modifyData.webhook_url !== 'undefined'" prop="webhook_url" label="Webhook">
|
</FormItem>
|
||||||
<Input v-model="modifyData.webhook_url" :maxlength="255" />
|
<FormItem v-if="typeof modifyData.webhook_url !== 'undefined'" prop="webhook_url" label="Webhook">
|
||||||
</FormItem>
|
<Input v-model="modifyData.webhook_url" :maxlength="255" />
|
||||||
|
</FormItem>
|
||||||
|
</template>
|
||||||
</Form>
|
</Form>
|
||||||
<div slot="footer" class="adaption">
|
<div slot="footer" class="adaption">
|
||||||
<Button type="default" @click="modifyShow=false">{{$L('取消')}}</Button>
|
<Button type="default" @click="modifyShow=false">{{$L('取消')}}</Button>
|
||||||
@ -889,6 +892,17 @@ export default {
|
|||||||
return dialogData.dialog_user && dialogData.dialog_user.userid == userId
|
return dialogData.dialog_user && dialogData.dialog_user.userid == userId
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isManageBot() {
|
||||||
|
const {dialogData, userId, userIsAdmin} = this;
|
||||||
|
if (!dialogData.bot) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (dialogData.bot == userId) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return dialogData.dialog_user && dialogData.dialog_user.userid == dialogData.bot && userIsAdmin
|
||||||
|
},
|
||||||
|
|
||||||
isMute() {
|
isMute() {
|
||||||
if (this.dialogData.group_type === 'all') {
|
if (this.dialogData.group_type === 'all') {
|
||||||
if (this.dialogData.all_group_mute === 'all') {
|
if (this.dialogData.all_group_mute === 'all') {
|
||||||
@ -1917,6 +1931,7 @@ export default {
|
|||||||
avatar: this.cacheUserBasic.find(item => item.userid === this.dialogData.dialog_user.userid)?.userimg,
|
avatar: this.cacheUserBasic.find(item => item.userid === this.dialogData.dialog_user.userid)?.userimg,
|
||||||
clear_day: 0,
|
clear_day: 0,
|
||||||
webhook_url: '',
|
webhook_url: '',
|
||||||
|
system_name: '',
|
||||||
})
|
})
|
||||||
this.modifyLoad++;
|
this.modifyLoad++;
|
||||||
this.$store.dispatch("call", {
|
this.$store.dispatch("call", {
|
||||||
@ -1927,6 +1942,7 @@ export default {
|
|||||||
}).then(({data}) => {
|
}).then(({data}) => {
|
||||||
this.modifyData.clear_day = data.clear_day
|
this.modifyData.clear_day = data.clear_day
|
||||||
this.modifyData.webhook_url = data.webhook_url
|
this.modifyData.webhook_url = data.webhook_url
|
||||||
|
this.modifyData.system_name = data.system_name
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
this.modifyLoad--;
|
this.modifyLoad--;
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user