当前位置: 首页>>代码示例>>Java>>正文


Java Restrict类代码示例

本文整理汇总了Java中be.objectify.deadbolt.java.actions.Restrict的典型用法代码示例。如果您正苦于以下问题:Java Restrict类的具体用法?Java Restrict怎么用?Java Restrict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Restrict类属于be.objectify.deadbolt.java.actions包,在下文中一共展示了Restrict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: insertComment

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result insertComment(Long eid, Long cid) {
    Exam exam = Ebean.find(Exam.class, eid);
    if (exam == null) {
        return notFound("sitnet_error_exam_not_found");
    }
    if (exam.hasState(Exam.State.ABORTED, Exam.State.GRADED_LOGGED, Exam.State.ARCHIVED)) {
        return forbidden();
    }
    Comment comment = bindForm(Comment.class);
    AppUtil.setCreator(comment, getLoggedUser());
    comment.save();

    exam.setExamFeedback(comment);
    exam.save();

    return ok(comment);
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:19,代码来源:ReviewController.java

示例2: downloadQuestionAttachment

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN"), @Group("STUDENT")})
public Result downloadQuestionAttachment(Long id) {
    User user = getLoggedUser();
    Question question;
    if (user.hasRole("STUDENT", getSession())) {
        question = Ebean.find(Question.class).where()
                .idEq(id)
                .eq("examSectionQuestions.examSection.exam.creator", getLoggedUser())
                .findUnique();
    } else {
        question = Ebean.find(Question.class, id);
    }
    if (question == null || question.getAttachment() == null) {
        return notFound();
    }
    return serveAttachment(question.getAttachment());
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:18,代码来源:AttachmentController.java

示例3: deleteQuestionAnswerAttachment

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict({@Group("ADMIN"), @Group("STUDENT")})
public Result deleteQuestionAnswerAttachment(Long qid, String hash) {
    User user = getLoggedUser();
    ExamSectionQuestion question;
    if (user.hasRole("STUDENT", getSession())) {
        question = Ebean.find(ExamSectionQuestion.class).where()
                .idEq(qid)
                .eq("examSection.exam.creator", getLoggedUser())
                .findUnique();
    } else {
        question = Ebean.find(ExamSectionQuestion.class, qid);
    }
    if (question != null && question.getEssayAnswer() != null && question.getEssayAnswer().getAttachment() != null) {
        EssayAnswer answer = question.getEssayAnswer();
        Attachment aa = answer.getAttachment();
        answer.setAttachment(null);
        answer.save();
        AppUtil.removeAttachmentFile(aa.getFilePath());
        aa.delete();
        return ok(answer);
    }
    return notFound();
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:24,代码来源:AttachmentController.java

示例4: insertExamOwner

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result insertExamOwner(Long eid, Long uid) {

    final User owner = Ebean.find(User.class, uid);
    final Exam exam = Ebean.find(Exam.class, eid);
    if (exam == null) {
        return notFound();
    }
    User user = getLoggedUser();
    if (!user.hasRole(Role.Name.ADMIN.toString(), getSession()) && !exam.isOwnedOrCreatedBy(user)) {
        return forbidden("sitnet_error_access_forbidden");
    }
    if (owner != null) {
        exam.getExamOwners().add(owner);
        exam.update();
        return ok();
    }
    return notFound();
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:20,代码来源:ExamOwnerController.java

示例5: removeExamOwner

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result removeExamOwner(Long eid, Long uid) {

    final User owner = Ebean.find(User.class, uid);
    final Exam exam = Ebean.find(Exam.class, eid);
    if (exam == null) {
        return notFound();
    }
    User user = getLoggedUser();
    if (!user.hasRole(Role.Name.ADMIN.toString(), getSession()) && !exam.isOwnedOrCreatedBy(user)) {
        return forbidden("sitnet_error_access_forbidden");
    }
    if (owner != null) {
        exam.getExamOwners().remove(owner);
        exam.update();
        return ok();
    }
    return notFound();
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:20,代码来源:ExamOwnerController.java

示例6: insertSection

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result insertSection(Long id) {
    Exam exam = Ebean.find(Exam.class, id);
    if (exam == null) {
        return notFound();
    }
    User user = getLoggedUser();
    if (exam.isOwnedOrCreatedBy(user) || user.hasRole("ADMIN", getSession())) {
        ExamSection section = new ExamSection();
        section.setLotteryItemCount(1);
        section.setExam(exam);
        section.setSectionQuestions(Collections.emptySet());
        section.setSequenceNumber(exam.getExamSections().size());
        section.setExpanded(true);
        AppUtil.setCreator(section, user);
        section.save();
        return ok(section, PathProperties.parse("(*, sectionQuestions(*))"));
    } else {
        return forbidden("sitnet_error_access_forbidden");
    }
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:22,代码来源:ExamSectionController.java

示例7: insertQuestion

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result insertQuestion(Long eid, Long sid, Integer seq, Long qid) {
    Exam exam = Ebean.find(Exam.class, eid);
    ExamSection section = Ebean.find(ExamSection.class, sid);
    Question question = Ebean.find(Question.class, qid);
    if (exam == null || section == null || question == null) {
        return notFound();
    }
    if (exam.getAutoEvaluationConfig() != null && question.getType() == Question.Type.EssayQuestion) {
        return forbidden("sitnet_error_autoevaluation_essay_question");
    }
    User user = getLoggedUser();
    if (!exam.isOwnedOrCreatedBy(user) && !user.hasRole("ADMIN", getSession())) {
        return forbidden("sitnet_error_access_forbidden");
    }
    // TODO: response payload should be trimmed down (use path properties)
    return insertQuestion(exam, section, question, user, seq)
            .orElse(ok(Json.toJson(section)));
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:20,代码来源:ExamSectionController.java

示例8: listNoShows

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result listNoShows(Long eid) {
    List<ExamEnrolment> enrolments = Ebean.find(ExamEnrolment.class)
            .fetch("exam", "id, name, state, gradedTime, customCredit, trialCount")
            .fetch("exam.executionType")
            .fetch("reservation")
            .fetch("user", "id, firstName, lastName, email, userIdentifier")
            .fetch("exam.course", "code, credits")
            .fetch("exam.grade", "id, name")
            .where()
            .eq("exam.id", eid)
            .eq("reservation.noShow", true)
            .orderBy("reservation.endAt")
            .findList();
    if (enrolments == null) {
        return notFound();
    } else {
        return ok(enrolments);
    }
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:21,代码来源:ReviewController.java

示例9: updateUndistributedExamQuestion

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result updateUndistributedExamQuestion(Long esqId) {
    User user = getLoggedUser();
    ExpressionList<ExamSectionQuestion> query = Ebean.find(ExamSectionQuestion.class).where().idEq(esqId);
    if (user.hasRole("TEACHER", getSession())) {
        query = query.eq("examSection.exam.examOwners", user);
    }
    ExamSectionQuestion examSectionQuestion = query.findUnique();
    if (examSectionQuestion == null) {
        return forbidden("sitnet_error_access_forbidden");
    }
    Question question = Ebean.find(Question.class, examSectionQuestion.getQuestion().getId());
    if (question == null) {
        return notFound();
    }
    updateExamQuestion(examSectionQuestion, question);
    examSectionQuestion.update();
    return ok(examSectionQuestion);
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:20,代码来源:ExamSectionController.java

示例10: removeStudentEnrolment

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict({@Group("ADMIN"), @Group("TEACHER")})
public Result removeStudentEnrolment(Long id) {
    User user = getLoggedUser();
    ExamEnrolment enrolment = Ebean.find(ExamEnrolment.class).where()
            .idEq(id)
            .ne("exam.executionType.type", ExamExecutionType.Type.PUBLIC.toString())
            .isNull("reservation")
            .disjunction()
            .eq("exam.state", Exam.State.DRAFT)
            .eq("exam.state", Exam.State.SAVED)
            .endJunction()
            .disjunction()
            .eq("exam.examOwners", user)
            .eq("exam.creator", user)
            .endJunction()
            .findUnique();
    if (enrolment == null) {
        return forbidden("sitnet_not_possible_to_remove_participant");
    }
    enrolment.delete();
    return ok();
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:23,代码来源:EnrolmentController.java

示例11: activateExamRoom

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict(@Group({"ADMIN"}))
public CompletionStage<Result> activateExamRoom(Long id) throws MalformedURLException {

    ExamRoom room = Ebean.find(ExamRoom.class, id);
    if (room == null) {
        return wrapAsPromise(notFound());
    }
    room.setState(ExamRoom.State.ACTIVE.toString());
    room.update();

    if (room.getExternalRef() != null && IOP_ACTIVATED) {
        return externalApi.activateFacility(room.getId())
                .thenApplyAsync(response -> ok(Json.toJson(room)));
    } else {
        return wrapAsPromise(ok(Json.toJson(room)));
    }
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:18,代码来源:RoomController.java

示例12: addRole

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict({@Group("ADMIN")})
public Result addRole(Long uid, String roleName) {
    User user = Ebean.find(User.class, uid);
    if (user == null) {
        return notFound("sitnet_user_not_found");
    }
    if (user.getRoles().stream().noneMatch((r) -> r.getName().equals(roleName))) {
        Role role = Ebean.find(Role.class).where().eq("name", roleName).findUnique();
        if (role == null) {
            return notFound("sitnet_role_not_found");
        }
        user.getRoles().add(role);
        user.update();
    }
    return ok();
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:17,代码来源:UserController.java

示例13: getUsersByRole

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result getUsersByRole(String role) {

    List<User> users = Ebean.find(User.class)
            .where()
            .eq("roles.name", role)
            .orderBy("lastName")
            .findList();

    ArrayNode array = JsonNodeFactory.instance.arrayNode();
    for (User u : users) {
        ObjectNode part = Json.newObject();
        part.put("id", u.getId());
        part.put("name", String.format("%s %s", u.getFirstName(), u.getLastName()));
        array.add(part);
    }

    return ok(Json.toJson(array));
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:20,代码来源:UserController.java

示例14: updateAssessmentInfo

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict({@Group("TEACHER")})
public Result updateAssessmentInfo(Long id) {
    String info = request().body().asJson().get("assessmentInfo").asText();
    Optional<Exam>  option = Ebean.find(Exam.class).fetch("parent.creator")
            .where()
            .idEq(id)
            .eq("state", Exam.State.GRADED_LOGGED)
            .findOneOrEmpty();
    if (!option.isPresent()) {
        return notFound("sitnet_exam_not_found");
    }
    Exam exam = option.get();
    if (exam.getState() != Exam.State.GRADED_LOGGED || !isAllowedToModify(exam, getLoggedUser(), exam.getState())) {
        return forbidden("You are not allowed to modify this object");
    }
    exam.setAssessmentInfo(info);
    exam.update();
    return ok();
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:20,代码来源:ReviewController.java

示例15: getParticipationsForExamAndUser

import be.objectify.deadbolt.java.actions.Restrict; //导入依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result getParticipationsForExamAndUser(Long eid, Long uid) {
    List<ExamParticipation> participations = Ebean.find(ExamParticipation.class)
            .fetch("exam", "id, state")
            .fetch("exam.grade", "id, name")
            .where()
            .eq("user.id", uid)
            .eq("exam.parent.id", eid)
            .disjunction()
            .eq("exam.state", Exam.State.ABORTED)
            .eq("exam.state", Exam.State.GRADED)
            .eq("exam.state", Exam.State.GRADED_LOGGED)
            .eq("exam.state", Exam.State.ARCHIVED)
            .endJunction()
            .findList();
    return ok(participations);
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:18,代码来源:ReviewController.java


注:本文中的be.objectify.deadbolt.java.actions.Restrict类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。