From 0af24b52aca05be810cb38e8f11bbe66e1ee210d Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 2 Apr 2022 17:09:49 +0800 Subject: [PATCH] feat(web): multiple permissions for user --- web/app/controllers/super_manage.php | 18 +++++++++++++++--- web/app/libs/uoj-utility-lib.php | 12 ++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/web/app/controllers/super_manage.php b/web/app/controllers/super_manage.php index 6aa3191..4e688d7 100644 --- a/web/app/controllers/super_manage.php +++ b/web/app/controllers/super_manage.php @@ -142,11 +142,23 @@ break; case 'problem_uploader': DB::update("update user_info set usergroup = 'U' where username = '{$username}'"); - DB::update("update user_info set usertype = 'problem_uploader' where username = '{$username}'"); + $user = queryUser($username); + $usertype = explode(',', $user['usertype']); + if (!in_array('problem_uploader', $usertype)) { + $usertype[] = 'problem_uploader'; + } + $usertype = implode(',', $usertype); + DB::update("update user_info set usertype = '{$usertype}' where username = '{$username}'"); break; case 'problem_manager': DB::update("update user_info set usergroup = 'U' where username = '{$username}'"); - DB::update("update user_info set usertype = 'problem_manager' where username = '{$username}'"); + $user = queryUser($username); + $usertype = explode(',', $user['usertype']); + if (!in_array('problem_manager', $usertype)) { + $usertype[] = 'problem_manager'; + } + $usertype = implode(',', $usertype); + DB::update("update user_info set usertype = '{$usertype}' where username = '{$username}'"); break; case 'superuser': DB::update("update user_info set usergroup = 'S' where username = '{$username}'"); @@ -427,7 +439,7 @@ EOD; echo << ${hislink} - {$row['usergroup']} + {$row['usergroup']}, {$row['usertype']} {$row['register_time']} EOD; diff --git a/web/app/libs/uoj-utility-lib.php b/web/app/libs/uoj-utility-lib.php index 6fecced..902d7ef 100644 --- a/web/app/libs/uoj-utility-lib.php +++ b/web/app/libs/uoj-utility-lib.php @@ -130,10 +130,18 @@ function blog_name_decode($name) { } function isProblemUploader($user) { - return $user != null && $user['usertype'] == 'problem_uploader'; + if ($user == null) { + return false; + } + $usertype = explode(',', $user['usertype']); + return in_array('problem_uploader', $usertype); } function isProblemManager($user) { - return $user != null && $user['usertype'] == 'problem_manager'; + if ($user == null) { + return false; + } + $usertype = explode(',', $user['usertype']); + return in_array('problem_manager', $usertype); } function isSuperUser($user) {