From 066f12e8996a793641dc7136f43b4ae115f08b6d Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 2 Feb 2023 14:25:39 +0800 Subject: [PATCH] refactor(problem/manage): permissions manage --- web/app/controllers/problem_data_manage.php | 36 ++- .../controllers/problem_managers_manage.php | 189 ----------- .../problem_permissions_manage.php | 306 ++++++++++++++++++ .../controllers/problem_statement_manage.php | 158 ++------- web/app/models/HTML.php | 10 +- web/app/route.php | 2 +- 6 files changed, 359 insertions(+), 342 deletions(-) delete mode 100644 web/app/controllers/problem_managers_manage.php create mode 100644 web/app/controllers/problem_permissions_manage.php diff --git a/web/app/controllers/problem_data_manage.php b/web/app/controllers/problem_data_manage.php index 65746cd..88edaa6 100644 --- a/web/app/controllers/problem_data_manage.php +++ b/web/app/controllers/problem_data_manage.php @@ -11,6 +11,22 @@ requirePHPLib('data'); UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404(); UOJProblem::cur()->userCanManage(Auth::user()) || UOJResponse::page403(); UOJProblem::info('type') === 'local' || UOJResponse::page404(); + +$tabs_info = [ + 'statement' => [ + 'name' => '题面', + 'url' => UOJProblem::cur()->getUri('/manage/statement'), + ], + 'permissions' => [ + 'name' => '权限', + 'url' => UOJProblem::cur()->getUri('/manage/permissions'), + ], + 'data' => [ + 'name' => '数据', + 'url' => UOJProblem::cur()->getUri('/manage/data'), + ], +]; + $problem = UOJProblem::info(); $problem_extra_config = UOJProblem::cur()->getExtraConfig(); @@ -535,23 +551,9 @@ if ($problem['hackable']) { getTitle(['with' => 'id']) ?> 管理 - +
+ +
diff --git a/web/app/controllers/problem_managers_manage.php b/web/app/controllers/problem_managers_manage.php deleted file mode 100644 index 9e6dd9a..0000000 --- a/web/app/controllers/problem_managers_manage.php +++ /dev/null @@ -1,189 +0,0 @@ -userCanManage(Auth::user()) || UOJResponse::page403(); - -$managers_form = newAddDelCmdForm( - 'managers', - 'validateUserAndStoreByUsername', - function ($type, $username, &$vdata) { - $user = $vdata['user'][$username]; - if ($type == '+') { - DB::insert([ - "insert into problems_permissions", - "(problem_id, username)", - "values", DB::tuple([UOJProblem::info('id'), $user['username']]) - ]); - } else if ($type == '-') { - DB::delete([ - "delete from problems_permissions", - "where", [ - "problem_id" => UOJProblem::info('id'), - "username" => $user['username'] - ] - ]); - } - } -); - -$managers_form->runAtServer(); - -if (isSuperUser(Auth::user())) { - $update_uploader_form = new UOJForm('update_uploader'); - $update_uploader_form->appendHTML( - HTML::tag( - 'div', - ['class' => 'col-auto'], - HTML::tag('label', ['class' => 'col-form-label'], '上传者') - ) - ); - $update_uploader_form->addInput( - 'new_uploader_username', - [ - 'div_class' => 'col-auto', - 'default_value' => UOJProblem::info('uploader') ?: 'root', - 'validator_php' => function ($username, &$vdata) { - if (!UOJUser::query($username)) { - return '用户不存在'; - } - - $vdata['username'] = $username; - - return ''; - }, - ] - ); - $update_uploader_form->config['form']['class'] = 'mt-2 row g-3 align-items-center'; - $update_uploader_form->config['submit_container']['class'] = 'col-auto'; - $update_uploader_form->config['submit_button']['class'] = 'btn btn-warning'; - $update_uploader_form->config['submit_button']['text'] = '修改上传者'; - $update_uploader_form->config['confirm']['smart'] = true; - $update_uploader_form->handle = function (&$vdata) { - DB::update([ - "update problems", - "set", ["uploader" => $vdata['username']], - "where", ["id" => UOJProblem::info('id')] - ]); - }; - $update_uploader_form->runAtServer(); -} -?> - - -
- -
-

- getTitle() ?> 管理 -

- - - -
-
- - - - - - - - - - UOJProblem::info('id')] - ]); - foreach ($res as $row) { - $row_id++; - echo '', '', '', ''; - } - ?> - -
#用户名
', $row_id, '', UOJUser::getLink($row['username']), '
-

命令格式:命令一行一个,+mike表示把mike加入管理者,-mike表示把mike从管理者中移除

- printHTML(); ?> - - -
- - printHTML(); ?> - - -
-
- - -
- - - - - -
- - diff --git a/web/app/controllers/problem_permissions_manage.php b/web/app/controllers/problem_permissions_manage.php new file mode 100644 index 0000000..3451be2 --- /dev/null +++ b/web/app/controllers/problem_permissions_manage.php @@ -0,0 +1,306 @@ +userCanManage(Auth::user()) || UOJResponse::page403(); + +$tabs_info = [ + 'statement' => [ + 'name' => '题面', + 'url' => UOJProblem::cur()->getUri('/manage/statement'), + ], + 'permissions' => [ + 'name' => '权限', + 'url' => UOJProblem::cur()->getUri('/manage/permissions'), + ], +]; + +if (UOJProblem::info('type') === 'local') { + $tabs_info['data'] = [ + 'name' => '数据', + 'url' => UOJProblem::cur()->getUri('/manage/data'), + ]; +} else if (UOJProblem::info('type') === 'remote') { + // +} + +$managers_form = newAddDelCmdForm( + 'managers', + 'validateUserAndStoreByUsername', + function ($type, $username, &$vdata) { + $user = $vdata['user'][$username]; + if ($type == '+') { + DB::insert([ + "insert into problems_permissions", + "(problem_id, username)", + "values", DB::tuple([UOJProblem::info('id'), $user['username']]) + ]); + } else if ($type == '-') { + DB::delete([ + "delete from problems_permissions", + "where", [ + "problem_id" => UOJProblem::info('id'), + "username" => $user['username'] + ] + ]); + } + } +); + +$managers_form->runAtServer(); + +if (isSuperUser(Auth::user())) { + $update_uploader_form = new UOJForm('update_uploader'); + $update_uploader_form->addInput('new_uploader_username', [ + 'div_class' => 'col-auto', + 'label' => '上传者', + 'default_value' => UOJProblem::info('uploader') ?: 'root', + 'validator_php' => function ($username, &$vdata) { + if (!UOJUser::query($username)) { + return '用户不存在'; + } + + $vdata['username'] = $username; + + return ''; + }, + ]); + $update_uploader_form->config['submit_button']['class'] = 'btn btn-warning'; + $update_uploader_form->config['submit_button']['text'] = '修改上传者'; + $update_uploader_form->config['confirm']['smart'] = true; + $update_uploader_form->handle = function (&$vdata) { + DB::update([ + "update problems", + "set", ["uploader" => $vdata['username']], + "where", ["id" => UOJProblem::info('id')] + ]); + }; + $update_uploader_form->runAtServer(); +} + +$view_type_form = new UOJForm('view_type'); +$view_type_form->addSelect('view_content_type', [ + 'div_class' => 'row align-items-center g-0', + 'label_class' => 'form-label col-auto m-0 flex-grow-1 me-2', + 'select_class' => 'col-auto form-select w-auto', + 'label' => '查看提交文件', + 'options' => [ + 'NONE' => '禁止', + 'ALL_AFTER_AC' => 'AC 后', + 'ALL' => '所有人', + ], + 'default_value' => UOJProblem::cur()->getExtraConfig('view_content_type'), +]); +$view_type_form->addSelect('view_all_details_type', [ + 'div_class' => 'row align-items-center g-0 mt-3', + 'label_class' => 'form-label col-auto m-0 flex-grow-1 me-2', + 'select_class' => 'col-auto form-select w-auto', + 'label' => '查看全部详细信息', + 'options' => [ + 'NONE' => '禁止', + 'SELF' => '仅自己', + 'ALL_AFTER_AC' => 'AC 后', + 'ALL' => '所有人' + ], + 'default_value' => UOJProblem::cur()->getExtraConfig('view_all_details_type'), +]); +$view_type_form->addSelect('view_details_type', [ + 'div_class' => 'row align-items-center g-0 mt-3', + 'label_class' => 'form-label col-auto m-0 flex-grow-1 me-2', + 'select_class' => 'col-auto form-select w-auto', + 'label' => '查看测试点详细信息', + 'options' => [ + 'NONE' => '禁止', + 'SELF' => '仅自己', + 'ALL_AFTER_AC' => 'AC 后', + 'ALL' => '所有人', + ], + 'default_value' => UOJProblem::cur()->getExtraConfig('view_details_type'), +]); +$view_type_form->handle = function () { + $config = UOJProblem::cur()->getExtraConfig(); + $config['view_content_type'] = $_POST['view_content_type']; + $config['view_all_details_type'] = $_POST['view_all_details_type']; + $config['view_details_type'] = $_POST['view_details_type']; + $esc_config = json_encode($config); + + DB::update([ + "update problems", + "set", ["extra_config" => $esc_config], + "where", ["id" => UOJProblem::info('id')] + ]); +}; +$view_type_form->runAtServer(); + +$solution_view_type_form = new UOJForm('solution_view_type'); +$solution_view_type_form->addSelect('view_solution_type', [ + 'div_class' => 'row align-items-center g-0', + 'label_class' => 'form-label col-auto m-0 flex-grow-1 me-2', + 'select_class' => 'col-auto form-select w-auto', + 'label' => '查看题解', + 'options' => [ + 'NONE' => '禁止', + 'ALL_AFTER_AC' => 'AC 后', + 'ALL' => '所有人', + ], + 'default_value' => UOJProblem::cur()->getExtraConfig('view_solution_type'), +]); +$solution_view_type_form->addSelect('submit_solution_type', [ + 'div_class' => 'row align-items-center g-0 mt-3', + 'label_class' => 'form-label col-auto m-0 flex-grow-1 me-2', + 'select_class' => 'col-auto form-select w-auto', + 'label' => '提交题解', + 'options' => [ + 'NONE' => '禁止', + 'ALL_AFTER_AC' => 'AC 后', + 'ALL' => '所有人', + ], + 'default_value' => UOJProblem::cur()->getExtraConfig('submit_solution_type'), +]); +$solution_view_type_form->handle = function () { + $config = UOJProblem::cur()->getExtraConfig(); + $config['view_solution_type'] = $_POST['view_solution_type']; + $config['submit_solution_type'] = $_POST['submit_solution_type']; + $esc_config = json_encode($config); + + DB::update([ + "update problems", + "set", ["extra_config" => $esc_config], + "where", ["id" => UOJProblem::info('id')] + ]); +}; +$solution_view_type_form->runAtServer(); +?> + + +
+ +
+

+ getTitle() ?> 管理 +

+ +
+ +
+ +
+
管理者
+
+ + + + + + + + + UOJProblem::info('id')] + ]); + foreach ($res as $row) { + $row_id++; + echo '', '', '', ''; + } + ?> + +
#用户名
', $row_id, '', UOJUser::getLink($row['username']), '
+

+ 命令格式:命令一行一个,+mike 表示把 mike 加入管理者,-mike 表示把 mike 从管理者中移除。 +

+ + printHTML() ?> +
+
+ +
+
+
+
+ 提交记录可视权限 +
+
+ printHTML() ?> +
+
+
+ +
+
+
+ 题解可视权限 +
+
+ printHTML() ?> +
+
+
+ + +
+
+
+ 题目上传者 +
+
+ printHTML() ?> +
+
+
+ +
+
+ + + + + +
+ + diff --git a/web/app/controllers/problem_statement_manage.php b/web/app/controllers/problem_statement_manage.php index 55dcb6a..3ccc75b 100644 --- a/web/app/controllers/problem_statement_manage.php +++ b/web/app/controllers/problem_statement_manage.php @@ -6,6 +6,27 @@ Auth::check() || redirectToLogin(); UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404(); UOJProblem::cur()->userCanManage(Auth::user()) || UOJResponse::page403(); + +$tabs_info = [ + 'statement' => [ + 'name' => '题面', + 'url' => UOJProblem::cur()->getUri('/manage/statement'), + ], + 'permissions' => [ + 'name' => '权限', + 'url' => UOJProblem::cur()->getUri('/manage/permissions'), + ], +]; + +if (UOJProblem::info('type') === 'local') { + $tabs_info['data'] = [ + 'name' => '数据', + 'url' => UOJProblem::cur()->getUri('/manage/data'), + ]; +} else if (UOJProblem::info('type') === 'remote') { + // +} + $problem_content = UOJProblem::cur()->queryContent(); $problem_editor = new UOJBlogEditor(); @@ -195,102 +216,9 @@ if (UOJProblem::info('type') == 'remote') { $convert_local_form->config['confirm']['text'] = '您真的要*不可逆*地将本题转换为本地题目吗?'; $convert_local_form->runAtServer(); } - -$view_type_form = new UOJForm('view_type'); -$view_type_form->addSelect('view_content_type', [ - 'div_class' => 'row align-items-center g-0', - 'label_class' => 'form-label col-auto m-0 flex-grow-1', - 'select_class' => 'col-auto form-select w-auto', - 'label' => '查看提交文件', - 'options' => [ - 'NONE' => '禁止', - 'ALL_AFTER_AC' => 'AC 后', - 'ALL' => '所有人', - ], - 'default_value' => UOJProblem::cur()->getExtraConfig('view_content_type'), -]); -$view_type_form->addSelect('view_all_details_type', [ - 'div_class' => 'row align-items-center g-0 mt-3', - 'label_class' => 'form-label col-auto m-0 flex-grow-1', - 'select_class' => 'col-auto form-select w-auto', - 'label' => '查看全部详细信息', - 'options' => [ - 'NONE' => '禁止', - 'SELF' => '仅自己', - 'ALL_AFTER_AC' => 'AC 后', - 'ALL' => '所有人' - ], - 'default_value' => UOJProblem::cur()->getExtraConfig('view_all_details_type'), -]); -$view_type_form->addSelect('view_details_type', [ - 'div_class' => 'row align-items-center g-0 mt-3', - 'label_class' => 'form-label col-auto m-0 flex-grow-1', - 'select_class' => 'col-auto form-select w-auto', - 'label' => '查看测试点详细信息', - 'options' => [ - 'NONE' => '禁止', - 'SELF' => '仅自己', - 'ALL_AFTER_AC' => 'AC 后', - 'ALL' => '所有人', - ], - 'default_value' => UOJProblem::cur()->getExtraConfig('view_details_type'), -]); -$view_type_form->handle = function () { - $config = UOJProblem::cur()->getExtraConfig(); - $config['view_content_type'] = $_POST['view_content_type']; - $config['view_all_details_type'] = $_POST['view_all_details_type']; - $config['view_details_type'] = $_POST['view_details_type']; - $esc_config = json_encode($config); - - DB::update([ - "update problems", - "set", ["extra_config" => $esc_config], - "where", ["id" => UOJProblem::info('id')] - ]); -}; -$view_type_form->runAtServer(); - -$solution_view_type_form = new UOJForm('solution_view_type'); -$solution_view_type_form->addSelect('view_solution_type', [ - 'div_class' => 'row align-items-center g-0', - 'label_class' => 'form-label col-auto m-0 flex-grow-1', - 'select_class' => 'col-auto form-select w-auto', - 'label' => '查看题解', - 'options' => [ - 'NONE' => '禁止', - 'ALL_AFTER_AC' => 'AC 后', - 'ALL' => '所有人', - ], - 'default_value' => UOJProblem::cur()->getExtraConfig('view_solution_type'), -]); -$solution_view_type_form->addSelect('submit_solution_type', [ - 'div_class' => 'row align-items-center g-0 mt-3', - 'label_class' => 'form-label col-auto m-0 flex-grow-1', - 'select_class' => 'col-auto form-select w-auto', - 'label' => '提交题解', - 'options' => [ - 'NONE' => '禁止', - 'ALL_AFTER_AC' => 'AC 后', - 'ALL' => '所有人', - ], - 'default_value' => UOJProblem::cur()->getExtraConfig('submit_solution_type'), -]); -$solution_view_type_form->handle = function () { - $config = UOJProblem::cur()->getExtraConfig(); - $config['view_solution_type'] = $_POST['view_solution_type']; - $config['submit_solution_type'] = $_POST['submit_solution_type']; - $esc_config = json_encode($config); - - DB::update([ - "update problems", - "set", ["extra_config" => $esc_config], - "where", ["id" => UOJProblem::info('id')] - ]); -}; -$solution_view_type_form->runAtServer(); ?> - +
@@ -299,25 +227,9 @@ $solution_view_type_form->runAtServer(); getTitle(['with' => 'id']) ?> 管理 - +
+ +
@@ -330,7 +242,7 @@ $solution_view_type_form->runAtServer();

提示

    -
  1. 请勿引用不稳定的外部资源(如来自个人服务器的图片或文档等),以便备份及后期维护;
  2. +
  3. 请勿引用不稳定的外部资源(如来自个人服务器的图片或文档等),可以上传至 题目资源 中,以便备份及后期维护;
  4. 请勿在题面中直接插入大段 HTML 代码,这可能会破坏页面的显示,可以考虑使用 转换工具 转换后再作修正;
  5. 图片上传推荐使用 S2OJ 图床,以免后续产生外链图片大量失效的情况。
@@ -494,24 +406,6 @@ $solution_view_type_form->runAtServer();
- -
-
- 提交记录可视权限 -
-
- printHTML() ?> -
-
- -
-
- 题解可视权限 -
-
- printHTML() ?> -
-
diff --git a/web/app/models/HTML.php b/web/app/models/HTML.php index a3c839b..0c78a8e 100644 --- a/web/app/models/HTML.php +++ b/web/app/models/HTML.php @@ -87,11 +87,15 @@ class HTML { } public static function tablist($tabs_info, $cur, $type = 'nav-tabs') { - $html = ''; + $html .= HTML::tag_end('ul'); return $html; } diff --git a/web/app/route.php b/web/app/route.php index 1939654..dba9979 100644 --- a/web/app/route.php +++ b/web/app/route.php @@ -25,7 +25,7 @@ Route::group( Route::any('/problem/{id}/statistics', '/problem_statistics.php'); Route::any('/problem/{id}/resources(?:/{sub_path})?', '/problem_resources.php'); Route::any('/problem/{id}/manage/statement', '/problem_statement_manage.php'); - Route::any('/problem/{id}/manage/managers', '/problem_managers_manage.php'); + Route::any('/problem/{id}/manage/permissions', '/problem_permissions_manage.php'); Route::any('/problem/{id}/manage/data', '/problem_data_manage.php'); Route::any('/download/testlib.h', '/download.php?type=testlib.h'); Route::any('/download/problem/{id}/data.zip', '/download.php?type=problem');