mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-22 14:08:42 +00:00
feat(web): add problem permissions
This commit is contained in:
parent
7fb7583574
commit
3a7e52fac1
@ -450,6 +450,7 @@ UNLOCK TABLES;
|
|||||||
CREATE TABLE `problems` (
|
CREATE TABLE `problems` (
|
||||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`title` text NOT NULL,
|
`title` text NOT NULL,
|
||||||
|
`uploader` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||||
`is_hidden` tinyint(1) NOT NULL DEFAULT '0',
|
`is_hidden` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
`submission_requirement` text,
|
`submission_requirement` text,
|
||||||
`hackable` tinyint(1) NOT NULL DEFAULT '0',
|
`hackable` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
@ -618,6 +619,7 @@ CREATE TABLE `user_info` (
|
|||||||
`usergroup` char(1) NOT NULL DEFAULT 'U',
|
`usergroup` char(1) NOT NULL DEFAULT 'U',
|
||||||
`username` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
`username` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||||
`realname` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
`realname` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||||
|
`usertype` varchar(50) NOT NULL DEFAULT 'student',
|
||||||
`email` varchar(50) NOT NULL,
|
`email` varchar(50) NOT NULL,
|
||||||
`password` char(32) NOT NULL,
|
`password` char(32) NOT NULL,
|
||||||
`svn_password` char(10) NOT NULL,
|
`svn_password` char(10) NOT NULL,
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
becomeMsgPage(UOJLocale::get('need login'));
|
becomeMsgPage(UOJLocale::get('need login'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSuperUser($myUser)) {
|
if (isSuperUser($myUser) || isProblemManager($myUser) || isProblemUploader($myUser)) {
|
||||||
$new_problem_form = new UOJForm('new_problem');
|
$new_problem_form = new UOJForm('new_problem');
|
||||||
$new_problem_form->handle = function() {
|
$new_problem_form->handle = function() {
|
||||||
DB::query("insert into problems (title, is_hidden, submission_requirement) values ('New Problem', 1, '{}')");
|
DB::query("insert into problems (title, uploader, is_hidden, submission_requirement) values ('New Problem', '{$myUser['username']}', 1, '{}')");
|
||||||
$id = DB::insert_id();
|
$id = DB::insert_id();
|
||||||
DB::query("insert into problems_contents (id, statement, statement_md) values ($id, '', '')");
|
DB::query("insert into problems_contents (id, statement, statement_md) values ($id, '', '')");
|
||||||
dataNewProblem($id);
|
dataNewProblem($id);
|
||||||
@ -189,7 +189,7 @@ $('#input-show_submit_mode').click(function() {
|
|||||||
echo '</table>';
|
echo '</table>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|
||||||
if (isSuperUser($myUser)) {
|
if (isSuperUser($myUser) || isProblemManager($myUser) || isProblemUploader($myUser)) {
|
||||||
$new_problem_form->printHTML();
|
$new_problem_form->printHTML();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +122,8 @@
|
|||||||
$options = array(
|
$options = array(
|
||||||
'banneduser' => '设为封禁用户',
|
'banneduser' => '设为封禁用户',
|
||||||
'normaluser' => '设为普通用户',
|
'normaluser' => '设为普通用户',
|
||||||
|
'problem_uploader' => '设为题目上传者',
|
||||||
|
'problem_manager' => '设为题目管理员',
|
||||||
'superuser' => '设为超级用户'
|
'superuser' => '设为超级用户'
|
||||||
);
|
);
|
||||||
$user_form->addSelect('op_type', $options, '操作类型', '');
|
$user_form->addSelect('op_type', $options, '操作类型', '');
|
||||||
@ -132,9 +134,19 @@
|
|||||||
switch ($_POST['op_type']) {
|
switch ($_POST['op_type']) {
|
||||||
case 'banneduser':
|
case 'banneduser':
|
||||||
DB::update("update user_info set usergroup = 'B' where username = '{$username}'");
|
DB::update("update user_info set usergroup = 'B' where username = '{$username}'");
|
||||||
|
DB::update("update user_info set usertype = 'banned' where username = '{$username}'");
|
||||||
break;
|
break;
|
||||||
case 'normaluser':
|
case 'normaluser':
|
||||||
DB::update("update user_info set usergroup = 'U' where username = '{$username}'");
|
DB::update("update user_info set usergroup = 'U' where username = '{$username}'");
|
||||||
|
DB::update("update user_info set usertype = 'student' where username = '{$username}'");
|
||||||
|
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}'");
|
||||||
|
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}'");
|
||||||
break;
|
break;
|
||||||
case 'superuser':
|
case 'superuser':
|
||||||
DB::update("update user_info set usergroup = 'S' where username = '{$username}'");
|
DB::update("update user_info set usergroup = 'S' where username = '{$username}'");
|
||||||
|
@ -4,7 +4,10 @@ function hasProblemPermission($user, $problem) {
|
|||||||
if ($user == null) {
|
if ($user == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (isSuperUser($user)) {
|
if (isSuperUser($user) || isProblemManager($user)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ($problem['uploader'] == $user['username']) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return DB::selectFirst("select * from problems_permissions where username = '{$user['username']}' and problem_id = {$problem['id']}") != null;
|
return DB::selectFirst("select * from problems_permissions where username = '{$user['username']}' and problem_id = {$problem['id']}") != null;
|
||||||
|
@ -129,6 +129,13 @@ function blog_name_decode($name) {
|
|||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isProblemUploader($user) {
|
||||||
|
return $user != null && $user['usertype'] == 'problem_uploader';
|
||||||
|
}
|
||||||
|
function isProblemManager($user) {
|
||||||
|
return $user != null && $user['usertype'] == 'problem_manager';
|
||||||
|
}
|
||||||
|
|
||||||
function isSuperUser($user) {
|
function isSuperUser($user) {
|
||||||
return $user != null && $user['usergroup'] == 'S';
|
return $user != null && $user['usergroup'] == 'S';
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user