fix admin training problem
This commit is contained in:
parent
71aa59310b
commit
21713e7983
|
@ -416,36 +416,6 @@ public class AdminContestController {
|
|||
}
|
||||
}
|
||||
|
||||
@PutMapping("/change-problem-auth")
|
||||
@RequiresAuthentication
|
||||
@RequiresRoles(value = {"root", "problem_admin", "admin"}, logical = Logical.OR)
|
||||
public CommonResult changeProblemAuth(@RequestBody Problem problem, HttpServletRequest request) {
|
||||
|
||||
// 普通管理员只能将题目变成隐藏题目和比赛题目
|
||||
boolean root = SecurityUtils.getSubject().hasRole("root");
|
||||
|
||||
boolean problemAdmin = SecurityUtils.getSubject().hasRole("problem_admin");
|
||||
|
||||
if (!problemAdmin && !root && problem.getAuth() == 1) {
|
||||
return CommonResult.errorResponse("修改失败!你无权限公开题目!", CommonResult.STATUS_FORBIDDEN);
|
||||
}
|
||||
|
||||
HttpSession session = request.getSession();
|
||||
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
|
||||
|
||||
UpdateWrapper<Problem> problemUpdateWrapper = new UpdateWrapper<>();
|
||||
problemUpdateWrapper.eq("id", problem.getId())
|
||||
.set("auth", problem.getAuth())
|
||||
.set("modified_user", userRolesVo.getUsername());
|
||||
|
||||
boolean result = problemService.update(problemUpdateWrapper);
|
||||
if (result) { // 更新成功
|
||||
return CommonResult.successResponse(null, "修改成功!");
|
||||
} else {
|
||||
return CommonResult.errorResponse("修改失败", CommonResult.STATUS_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/add-problem-from-public")
|
||||
@RequiresAuthentication
|
||||
@RequiresRoles(value = {"root", "admin", "problem_admin"}, logical = Logical.OR)
|
||||
|
|
|
@ -2,8 +2,10 @@ package top.hcode.hoj.controller.admin;
|
|||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
|
@ -245,5 +247,34 @@ public class AdminProblemController {
|
|||
return CommonResult.successResponse(null, "导入新题目成功!");
|
||||
}
|
||||
|
||||
@PutMapping("/change-problem-auth")
|
||||
@RequiresAuthentication
|
||||
@RequiresRoles(value = {"root", "problem_admin", "admin"}, logical = Logical.OR)
|
||||
public CommonResult changeProblemAuth(@RequestBody Problem problem, HttpServletRequest request) {
|
||||
|
||||
// 普通管理员只能将题目变成隐藏题目和比赛题目
|
||||
boolean root = SecurityUtils.getSubject().hasRole("root");
|
||||
|
||||
boolean problemAdmin = SecurityUtils.getSubject().hasRole("problem_admin");
|
||||
|
||||
if (!problemAdmin && !root && problem.getAuth() == 1) {
|
||||
return CommonResult.errorResponse("修改失败!你无权限公开题目!", CommonResult.STATUS_FORBIDDEN);
|
||||
}
|
||||
|
||||
HttpSession session = request.getSession();
|
||||
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
|
||||
|
||||
UpdateWrapper<Problem> problemUpdateWrapper = new UpdateWrapper<>();
|
||||
problemUpdateWrapper.eq("id", problem.getId())
|
||||
.set("auth", problem.getAuth())
|
||||
.set("modified_user", userRolesVo.getUsername());
|
||||
|
||||
boolean result = problemService.update(problemUpdateWrapper);
|
||||
if (result) { // 更新成功
|
||||
return CommonResult.successResponse(null, "修改成功!");
|
||||
} else {
|
||||
return CommonResult.errorResponse("修改失败", CommonResult.STATUS_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -22,7 +22,7 @@
|
|||
AND c.cid = #{cid}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY c.checked ASC,c.submit_time DESC
|
||||
ORDER BY c.checked ASC,c.submit_time ASC
|
||||
</select>
|
||||
|
||||
<select id="getOIContestRecord" resultType="top.hcode.hoj.pojo.vo.ContestRecordVo">
|
||||
|
|
|
@ -23,20 +23,17 @@
|
|||
|
||||
<select id="getTrainingProblemList" resultMap="map_TrainingProblemList">
|
||||
SELECT p.id AS pid, p.problem_id, p.title, p.difficulty, p.type
|
||||
, COALESCE(j.ac, 0) AS ac
|
||||
, COALESCE(j.total, 0) AS total
|
||||
,(SELECT COUNT(*)
|
||||
FROM judge j
|
||||
WHERE j.cid = 0 AND j.pid = p.id AND j.status = 0
|
||||
) as ac,
|
||||
(SELECT COUNT(*)
|
||||
FROM judge j
|
||||
WHERE j.cid = 0 AND j.pid = p.id
|
||||
) as total
|
||||
FROM problem p,
|
||||
(
|
||||
SELECT j.pid AS pid
|
||||
, COUNT(IF(j.status = 0, STATUS, NULL)) AS ac
|
||||
, COUNT(*) AS total
|
||||
FROM judge j
|
||||
WHERE j.cid = 0
|
||||
GROUP BY j.pid
|
||||
) j,
|
||||
training_problem tp
|
||||
where p.id = tp.pid
|
||||
and j.pid = p.id
|
||||
and p.auth = 1
|
||||
and tp.tid = #{tid}
|
||||
order by tp.`rank` asc
|
||||
|
|
|
@ -87,11 +87,10 @@ public class TrainingProblemServiceImpl extends ServiceImpl<TrainingProblemMappe
|
|||
|
||||
QueryWrapper<Problem> problemQueryWrapper = new QueryWrapper<>();
|
||||
|
||||
// 权限需要是公开的(隐藏的,比赛中不可加入!)
|
||||
problemQueryWrapper.eq("auth", 1);
|
||||
|
||||
// 逻辑判断,如果是查询已有的就应该是in,如果是查询不要重复的,使用not in
|
||||
if (queryExisted) {
|
||||
// 权限需要是公开的(隐藏的,比赛中不可加入!)
|
||||
problemQueryWrapper.eq("auth", 1);
|
||||
problemQueryWrapper.in(pidList.size() > 0, "id", pidList);
|
||||
} else {
|
||||
problemQueryWrapper.notIn(pidList.size() > 0, "id", pidList);
|
||||
|
|
|
@ -974,7 +974,11 @@ const adminApi = {
|
|||
}
|
||||
})
|
||||
},
|
||||
|
||||
admin_changeProblemAuth (data) {
|
||||
return ajax('/api/admin/problem/change-problem-auth', 'put', {
|
||||
data
|
||||
})
|
||||
},
|
||||
admin_getProblem (pid) {
|
||||
return ajax('/api/admin/problem', 'get', {
|
||||
params: {
|
||||
|
@ -1180,11 +1184,6 @@ const adminApi = {
|
|||
}
|
||||
})
|
||||
},
|
||||
admin_changeProblemPublic (data) {
|
||||
return ajax('/api/admin/contest/change-problem-auth', 'put', {
|
||||
data
|
||||
})
|
||||
},
|
||||
admin_addContestProblemFromPublic (data) {
|
||||
return ajax('/api/admin/contest/add-problem-from-public', 'post', {
|
||||
data
|
||||
|
|
|
@ -183,7 +183,7 @@
|
|||
show-overflow
|
||||
>
|
||||
</vxe-table-column>
|
||||
<vxe-table-column min-width="100" :title="$t('m.Auth')">
|
||||
<vxe-table-column min-width="120" :title="$t('m.Auth')">
|
||||
<template v-slot="{ row }">
|
||||
<el-select
|
||||
v-model="row.auth"
|
||||
|
@ -473,7 +473,7 @@ export default {
|
|||
},
|
||||
|
||||
changeProblemAuth(row) {
|
||||
api.admin_changeProblemPublic(row).then((res) => {
|
||||
api.admin_changeProblemAuth(row).then((res) => {
|
||||
myMessage.success(this.$i18n.t('m.Update_Successfully'));
|
||||
});
|
||||
},
|
||||
|
|
|
@ -62,13 +62,13 @@
|
|||
|
||||
<vxe-table-column
|
||||
field="author"
|
||||
min-width="130"
|
||||
min-width="100"
|
||||
:title="$t('m.Author')"
|
||||
show-overflow
|
||||
>
|
||||
</vxe-table-column>
|
||||
<vxe-table-column
|
||||
min-width="140"
|
||||
min-width="200"
|
||||
:title="$t('m.Training_Problem_Rank')"
|
||||
>
|
||||
<template v-slot="{ row }">
|
||||
|
@ -80,13 +80,13 @@
|
|||
></el-input-number>
|
||||
</template>
|
||||
</vxe-table-column>
|
||||
<vxe-table-column min-width="100" :title="$t('m.Auth')">
|
||||
<vxe-table-column min-width="120" :title="$t('m.Auth')">
|
||||
<template v-slot="{ row }">
|
||||
<el-select
|
||||
v-model="row.auth"
|
||||
@change="changeProblemAuth(row)"
|
||||
:disabled="!isSuperAdmin && !isProblemAdmin"
|
||||
size="small"
|
||||
:disabled="true"
|
||||
>
|
||||
<el-option
|
||||
:label="$t('m.Public_Problem')"
|
||||
|
@ -96,7 +96,6 @@
|
|||
<el-option
|
||||
:label="$t('m.Private_Problem')"
|
||||
:value="2"
|
||||
:disabled="true"
|
||||
></el-option>
|
||||
<el-option
|
||||
:label="$t('m.Contest_Problem')"
|
||||
|
@ -318,7 +317,7 @@ export default {
|
|||
});
|
||||
},
|
||||
changeProblemAuth(row) {
|
||||
api.admin_changeProblemPublic(row).then((res) => {
|
||||
api.admin_changeProblemAuth(row).then((res) => {
|
||||
myMessage.success(this.$i18n.t('m.Update_Successfully'));
|
||||
});
|
||||
},
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
<el-card shadow style="margin-top:15px;">
|
||||
<div class="contest-rank-switch">
|
||||
<span style="float:right;">
|
||||
<span>{{ $t('m.Auto_Refresh') }}(10s)</span>
|
||||
<span>{{ $t('m.Auto_Refresh') }}(30s)</span>
|
||||
<el-switch
|
||||
:disabled="contestEnded"
|
||||
@change="handleAutoRefresh"
|
||||
|
@ -512,6 +512,10 @@ export default {
|
|||
/deep/.vxe-table .vxe-header--column:not(.col--ellipsis) {
|
||||
padding: 4px 0 !important;
|
||||
}
|
||||
/deep/.vxe-table .vxe-body--column {
|
||||
padding: 4px 0 !important;
|
||||
line-height: 20px !important;
|
||||
}
|
||||
/deep/.vxe-table .vxe-body--column:not(.col--ellipsis) {
|
||||
line-height: 20px !important;
|
||||
padding: 0 !important;
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
<el-card shadow style="margin-top:15px;">
|
||||
<div class="contest-rank-switch">
|
||||
<span style="float:right;">
|
||||
<span>{{ $t('m.Auto_Refresh') }}(10s)</span>
|
||||
<span>{{ $t('m.Auto_Refresh') }}(30s)</span>
|
||||
<el-switch
|
||||
:disabled="contestEnded"
|
||||
@change="handleAutoRefresh"
|
||||
|
@ -466,6 +466,11 @@ export default {
|
|||
padding: 4px 0 !important;
|
||||
}
|
||||
|
||||
/deep/.vxe-table .vxe-body--column {
|
||||
padding: 4px 0 !important;
|
||||
line-height: 20px !important;
|
||||
}
|
||||
|
||||
/deep/.vxe-table .vxe-body--column:not(.col--ellipsis) {
|
||||
line-height: 20px !important;
|
||||
padding: 0 !important;
|
||||
|
|
|
@ -51,7 +51,7 @@ export default {
|
|||
if (status == true) {
|
||||
this.refreshFunc = setInterval(() => {
|
||||
this.getContestOutsideScoreboard()
|
||||
}, 10000)
|
||||
}, 30000)
|
||||
} else {
|
||||
clearInterval(this.refreshFunc)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue