|
@@ -1,7 +1,12 @@
|
|
package cn.iselab.mooctest.site.web.ctrl;
|
|
package cn.iselab.mooctest.site.web.ctrl;
|
|
|
|
|
|
import cn.iselab.mooctest.site.common.constant.UrlConstants;
|
|
import cn.iselab.mooctest.site.common.constant.UrlConstants;
|
|
|
|
+import cn.iselab.mooctest.site.models.Exam;
|
|
|
|
+import cn.iselab.mooctest.site.web.data.ExamVO;
|
|
import cn.iselab.mooctest.site.web.data.SearchConditionVO;
|
|
import cn.iselab.mooctest.site.web.data.SearchConditionVO;
|
|
|
|
+import cn.iselab.mooctest.site.web.exception.HttpNotFoundException;
|
|
|
|
+import cn.iselab.mooctest.site.web.logic.ExamLogic;
|
|
|
|
+import cn.iselab.mooctest.site.web.logic.RoleLogic;
|
|
import cn.iselab.mooctest.site.web.response.ErrorResult;
|
|
import cn.iselab.mooctest.site.web.response.ErrorResult;
|
|
import cn.iselab.mooctest.site.web.response.StatusCode;
|
|
import cn.iselab.mooctest.site.web.response.StatusCode;
|
|
import cn.iselab.mooctest.site.web.response.SuccessResult;
|
|
import cn.iselab.mooctest.site.web.response.SuccessResult;
|
|
@@ -37,16 +42,60 @@ public class PaperController extends BaseSearchController{
|
|
PaperLogic paperLogic;
|
|
PaperLogic paperLogic;
|
|
@Autowired
|
|
@Autowired
|
|
DetailStatisticsLogic detailStatisticsLogic;
|
|
DetailStatisticsLogic detailStatisticsLogic;
|
|
|
|
+ @Autowired
|
|
|
|
+ RoleLogic roleLogic;
|
|
|
|
+ @Autowired
|
|
|
|
+ ExamLogic examLogic;
|
|
|
|
|
|
@RequiresPermissions("paper:view")
|
|
@RequiresPermissions("paper:view")
|
|
@RequestMapping(value = "api/paper/{paperId}", method = RequestMethod.GET)
|
|
@RequestMapping(value = "api/paper/{paperId}", method = RequestMethod.GET)
|
|
public PaperVO getPaperById(@PathVariable Long paperId, @RequestParam(value = "examId", required = false) Long examId) {
|
|
public PaperVO getPaperById(@PathVariable Long paperId, @RequestParam(value = "examId", required = false) Long examId) {
|
|
|
|
+ // 试卷应该,只有管理员或者作者可以进入。
|
|
Long userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
Long userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
- String permissionStr = userId.toString() + ":paper:view:" + paperId.toString();
|
|
|
|
- if (!SecurityUtils.getSubject().isPermitted(new PaperPermission(permissionStr))) {
|
|
|
|
|
|
+ String permissionStr = userId.toString() + ":paper:*:" + paperId.toString();
|
|
|
|
+ boolean isPaperOwner = SecurityUtils.getSubject().isPermitted(new PaperPermission(permissionStr));
|
|
|
|
+ boolean isAdmin = roleLogic.isAdmin(userId);
|
|
|
|
+ boolean isStudentFromExam = (examId != null);
|
|
|
|
+
|
|
|
|
+ // come from paper page
|
|
|
|
+ if (!isPaperOwner && !isAdmin && !isStudentFromExam) {
|
|
throw new UnauthenticatedException("forbidden");
|
|
throw new UnauthenticatedException("forbidden");
|
|
}
|
|
}
|
|
- return paperLogic.getPaperById(paperId, examId);
|
|
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ admin and owner can view any time.
|
|
|
|
+ participant only view after upcoming state.
|
|
|
|
+ */
|
|
|
|
+ if (isStudentFromExam) {
|
|
|
|
+ ExamVO exam = examLogic.getExamById(examId);
|
|
|
|
+ boolean isExamOwner = exam.getManagerId().equals(userId);
|
|
|
|
+ boolean isExamOwnerOrParticipant = examLogic.checkTaskViewPermission(userId, examId);
|
|
|
|
+ if (!isAdmin && !isExamOwner) {
|
|
|
|
+ if (exam.getStatus().equals(Exam.STATUS_UPCOMING)) {
|
|
|
|
+ throw new UnauthenticatedException("forbidden");
|
|
|
|
+ } else if (!isExamOwnerOrParticipant) {
|
|
|
|
+ throw new UnauthenticatedException("forbidden");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ PaperVO paperVO = paperLogic.getPaperById(paperId, examId);
|
|
|
|
+ if (paperVO == null) {
|
|
|
|
+ throw new HttpNotFoundException(String.format("paper %s not exists", paperId));
|
|
|
|
+ }
|
|
|
|
+ return paperVO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void foo(boolean isAdmin, ExamVO exam, boolean isExamOwner, boolean isExamOwnerOrParticipant) {
|
|
|
|
+ if (exam.getStatus().equals(Exam.STATUS_UPCOMING)) {
|
|
|
|
+ if (!isExamOwner && !isAdmin) {
|
|
|
|
+ throw new UnauthenticatedException("forbidden");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (!isExamOwner && !isAdmin && !isExamOwnerOrParticipant) {
|
|
|
|
+ throw new UnauthenticatedException("forbidden");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@RequiresPermissions("paper:create")
|
|
@RequiresPermissions("paper:create")
|