1.优化后台管理员管理页面的权限设置,新增zihuaadmin账号
This commit is contained in:
@@ -91,10 +91,7 @@ class Group extends Backend
|
||||
if (!$this->auth->isSuperAdmin() && $pidInt !== 0 && !in_array($pidInt, $this->manageableGroupIds, true)) {
|
||||
return $this->error(__('You have no permission'));
|
||||
}
|
||||
$inheritRes = $this->applyChannelInheritance($data, $pidInt);
|
||||
if ($inheritRes !== null) {
|
||||
return $inheritRes;
|
||||
}
|
||||
unset($data['channel_id']);
|
||||
$rulesRes = $this->handleRules($data, $pidInt);
|
||||
if ($rulesRes instanceof Response) return $rulesRes;
|
||||
|
||||
@@ -162,10 +159,7 @@ class Group extends Backend
|
||||
if (!$this->auth->isSuperAdmin() && $pidInt !== 0 && !in_array($pidInt, $this->manageableGroupIds, true)) {
|
||||
return $this->error(__('You have no permission'));
|
||||
}
|
||||
$inheritRes = $this->applyChannelInheritance($data, $pidInt);
|
||||
if ($inheritRes !== null) {
|
||||
return $inheritRes;
|
||||
}
|
||||
unset($data['channel_id']);
|
||||
$rulesRes = $this->handleRules($data, $pidInt);
|
||||
if ($rulesRes instanceof Response) return $rulesRes;
|
||||
|
||||
@@ -193,7 +187,6 @@ class Group extends Backend
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false) {
|
||||
$this->syncDescendantChannelIds(intval((string)$row['id']));
|
||||
return $this->success(__('Update successful'));
|
||||
}
|
||||
return $this->error(__('No rows updated'));
|
||||
@@ -213,39 +206,11 @@ class Group extends Backend
|
||||
}
|
||||
$rowData = $row->toArray();
|
||||
$rowData['rules'] = array_values($rules);
|
||||
$rowData = $this->enrichChannelDisplay($rowData);
|
||||
return $this->success('', [
|
||||
'row' => $rowData
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单只读展示:根据 channel_id 解析渠道名称与渠道负责人(admin.channel_id → admin.username,取首个)
|
||||
*/
|
||||
public function channelBindPreview(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
$cid = $request->get('channel_id') ?? $request->post('channel_id');
|
||||
if ($cid === null || $cid === '') {
|
||||
return $this->success('', [
|
||||
'channel_name' => '',
|
||||
'channel_admin_username' => '',
|
||||
]);
|
||||
}
|
||||
if (!Db::name('channel')->where('id', $cid)->value('id')) {
|
||||
return $this->error(__('Record not found'));
|
||||
}
|
||||
$row = $this->enrichChannelDisplay(['channel_id' => $cid]);
|
||||
|
||||
return $this->success('', [
|
||||
'channel_name' => $row['channel_name'] ?? '',
|
||||
'channel_admin_username' => $row['channel_admin_username'] ?? '',
|
||||
]);
|
||||
}
|
||||
|
||||
public function del(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
@@ -413,21 +378,7 @@ class Group extends Backend
|
||||
}
|
||||
$data = $this->model->where($where)->select()->toArray();
|
||||
|
||||
$channelIds = [];
|
||||
foreach ($data as $datum) {
|
||||
$c = $datum['channel_id'] ?? null;
|
||||
if ($c !== null && $c !== '') {
|
||||
$channelIds[] = $c;
|
||||
}
|
||||
}
|
||||
$channelNames = [];
|
||||
if ($channelIds !== []) {
|
||||
$channelNames = Db::name('channel')->where('id', 'in', array_unique($channelIds))->column('name', 'id');
|
||||
}
|
||||
|
||||
foreach ($data as &$datum) {
|
||||
$c = $datum['channel_id'] ?? null;
|
||||
$datum['channel_name'] = ($c !== null && $c !== '') ? ($channelNames[$c] ?? '') : '';
|
||||
if ($datum['rules']) {
|
||||
if ($datum['rules'] == '*') {
|
||||
$datum['rules'] = __('Super administrator');
|
||||
@@ -466,87 +417,6 @@ class Group extends Backend
|
||||
return array_values(array_unique(array_merge($own, $children)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 顶级角色组可选渠道;子级继承父级 channel_id(不信任客户端提交的子级 channel_id)。
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
private function applyChannelInheritance(array &$data, int $pidInt): ?Response
|
||||
{
|
||||
if ($pidInt === 0) {
|
||||
if (!$this->auth->isSuperAdmin()) {
|
||||
unset($data['channel_id']);
|
||||
$cc = $this->getCreatorChannelId();
|
||||
if ($cc !== null && $cc !== '') {
|
||||
$data['channel_id'] = $cc;
|
||||
}
|
||||
}
|
||||
$cid = $data['channel_id'] ?? null;
|
||||
if ($cid !== null && $cid !== '') {
|
||||
$exists = Db::name('channel')->where('id', $cid)->value('id');
|
||||
if (!$exists) {
|
||||
return $this->error(__('Record not found'));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
unset($data['channel_id']);
|
||||
$parent = Db::name('admin_group')->where('id', $pidInt)->find();
|
||||
if (!$parent) {
|
||||
return $this->error(__('Record not found'));
|
||||
}
|
||||
$data['channel_id'] = $parent['channel_id'];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $row
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function enrichChannelDisplay(array $row): array
|
||||
{
|
||||
$row['channel_name'] = '';
|
||||
$row['channel_admin_username'] = '';
|
||||
$cid = $row['channel_id'] ?? null;
|
||||
if ($cid === null || $cid === '') {
|
||||
return $row;
|
||||
}
|
||||
$ch = Db::name('channel')->where('id', $cid)->field(['id', 'name'])->find();
|
||||
if (!$ch) {
|
||||
return $row;
|
||||
}
|
||||
$row['channel_name'] = $ch['name'] ?? '';
|
||||
$row['channel_admin_username'] = (string) (Db::name('admin')->where('channel_id', $cid)->order('id', 'asc')->value('username') ?? '');
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
private function syncDescendantChannelIds(int $groupId): void
|
||||
{
|
||||
$channelId = Db::name('admin_group')->where('id', $groupId)->value('channel_id');
|
||||
$children = Db::name('admin_group')->where('pid', $groupId)->column('id');
|
||||
foreach ($children as $childId) {
|
||||
Db::name('admin_group')->where('id', $childId)->update(['channel_id' => $channelId]);
|
||||
$this->syncDescendantChannelIds($childId);
|
||||
}
|
||||
}
|
||||
|
||||
private function getCreatorChannelId(): mixed
|
||||
{
|
||||
$currentAdmin = Db::name('admin')
|
||||
->field(['id', 'channel_id'])
|
||||
->where('id', $this->auth->id)
|
||||
->find();
|
||||
if ($currentAdmin && !empty($currentAdmin['channel_id'])) {
|
||||
return $currentAdmin['channel_id'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function canManageRoleGroups(): bool
|
||||
{
|
||||
foreach (['auth/group/index', 'auth/group/add', 'auth/group/edit', 'auth/Group/index', 'auth/Group/add', 'auth/Group/edit'] as $routePath) {
|
||||
|
||||
Reference in New Issue
Block a user