fix:修复管理员可通过后台使自己部分权限丢失的问题

This commit is contained in:
妙码生花 2022-07-05 11:08:57 +08:00
parent 81bd814520
commit 77d2c6fb9c
3 changed files with 61 additions and 2 deletions

View File

@ -60,6 +60,7 @@ class Group extends Backend
$this->success('', [
'list' => $this->getGroups(),
'remark' => get_route_remark(),
'group' => Db::name('admin_group_access')->where('uid', $this->auth->id)->column('group_id'),
]);
}
@ -139,6 +140,11 @@ class Group extends Backend
$this->error(__('Parameter %s can not be empty', ['']));
}
$adminGroup = Db::name('admin_group_access')->where('uid', $this->auth->id)->column('group_id');
if (in_array($data['id'], $adminGroup)) {
$this->error(__('You cannot modify your own management group!'));
}
$data = $this->excludeFields($data);
if (is_array($data['rules']) && $data['rules']) {
$rules = MenuRule::select();
@ -205,6 +211,42 @@ class Group extends Backend
]);
}
/**
* 删除
* @param null $ids
*/
public function del($ids = null)
{
if (!$this->request->isDelete() || !$ids) {
$this->error(__('Parameter error'));
}
$pk = $this->model->getPk();
$data = $this->model->where($pk, 'in', $ids)->select();
$adminGroup = Db::name('admin_group_access')->where('uid', $this->auth->id)->column('group_id');
$count = 0;
Db::startTrans();
try {
foreach ($data as $v) {
if (!in_array($v['id'], $adminGroup)) {
$count += $v->delete();
}
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success(__('Deleted successfully'));
} else {
$this->error(__('No rows were deleted'));
}
}
public function select()
{
$data = $this->getGroups([['status', '=', 1]]);

View File

@ -1,5 +1,6 @@
<?php
return [
'Super administrator' => '超级管理员',
'No permission' => '无权限',
'Super administrator' => '超级管理员',
'No permission' => '无权限',
'You cannot modify your own management group!' => '不能修改自己所在的管理组!',
];

View File

@ -30,6 +30,7 @@ import { defaultOptButtons } from '/@/components/table'
import { useI18n } from 'vue-i18n'
import { cloneDeep } from 'lodash'
import { ElForm } from 'element-plus'
import { getArrayKey } from '/@/utils/common'
const formRef = ref()
const tableRef = ref()
@ -115,6 +116,21 @@ const baTable = new baTableClass(
}
return false
},
//
onTableDblclick: ({ row, column }: { row: TableRow; column: any }) => {
return baTable.table.extend!['adminGroup'].indexOf(row.id) === -1
},
},
{
getIndex: ({ res }: { res: ApiResponse }) => {
baTable.table.extend!['adminGroup'] = res.data.group
let buttonsKey = getArrayKey(baTable.table.column, 'render', 'buttons')
baTable.table.column[buttonsKey].buttons!.forEach((value, index) => {
value.display = (row, field) => {
return res.data.group.indexOf(row.id) === -1
}
})
},
}
)