Search in sources :

Example 11 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes in project teammates by TEAMMATES.

the class InstructorFeedbackEditCopyActionTest method testAccessControl.

@Override
@Test
protected void testAccessControl() throws Exception {
    String[] params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First feedback session", Const.ParamsNames.COURSE_ID, "idOfTypicalCourse1", Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "Session with valid name", Const.ParamsNames.COPIED_COURSES_ID, "idOfTypicalCourse2", Const.ParamsNames.COPIED_COURSES_ID, "idOfSampleCourse-demo" };
    verifyUnaccessibleWithoutViewSessionInSectionsPrivilege(params);
    FeedbackSessionAttributes fs = dataBundle.feedbackSessions.get("openSession");
    CourseAttributes course = dataBundle.courses.get("course");
    ______TS("Failure case: copying from course with insufficient permission");
    InstructorAttributes instructor = dataBundle.instructors.get("teammates.test.instructor3");
    String instructorId = instructor.googleId;
    gaeSimulation.loginAsInstructor(instructorId);
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "valid name", Const.ParamsNames.COPIED_COURSES_ID, course.getId() };
    InstructorFeedbackEditCopyAction a = getAction(params);
    try {
        a.executeAndPostProcess();
        signalFailureToDetectException();
    } catch (UnauthorizedAccessException uae) {
        String expectedString = "Course [FeedbackEditCopy.CS2104] is not accessible to instructor " + "[tmms.instr.cust@course.tmt] for privilege [canviewsessioninsection]";
        assertEquals(expectedString, uae.getMessage());
    }
    gaeSimulation.logoutUser();
    ______TS("Failure case: copying to course with insufficient permission");
    instructor = dataBundle.instructors.get("teammates.test.instructor2");
    instructorId = instructor.googleId;
    gaeSimulation.loginAsInstructor(instructorId);
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "valid name", Const.ParamsNames.COPIED_COURSES_ID, "FeedbackEditCopy.CS2107" };
    a = getAction(params);
    try {
        a.executeAndPostProcess();
        signalFailureToDetectException();
    } catch (UnauthorizedAccessException uae) {
        String expectedString = "Course [FeedbackEditCopy.CS2107] is not accessible to instructor " + "[tmms.instr@course.tmt] for privilege [canmodifysession]";
        assertEquals(expectedString, uae.getMessage());
    }
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) InstructorFeedbackEditCopyAction(teammates.ui.controller.InstructorFeedbackEditCopyAction) Test(org.testng.annotations.Test)

Example 12 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes in project teammates by TEAMMATES.

the class InstructorFeedbackEditCopyPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes instructor = dataBundle.instructors.get("teammates.test.instructor2");
    String instructorId = instructor.googleId;
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Successful case");
    String[] submissionParams = { Const.ParamsNames.COURSE_ID, "valid course id", Const.ParamsNames.FEEDBACK_SESSION_NAME, "valid fs name" };
    InstructorFeedbackEditCopyPageAction a = getAction(submissionParams);
    ShowPageResult r = getShowPageResult(a);
    assertFalse(r.isError);
    InstructorFeedbackEditCopyPageData pageData = (InstructorFeedbackEditCopyPageData) r.data;
    assertEquals(4, pageData.getCourses().size());
    List<String> idOfCourses = new ArrayList<>();
    for (CourseAttributes course : pageData.getCourses()) {
        idOfCourses.add(course.getId());
    }
    // course is archived
    assertFalse(idOfCourses.contains("FeedbackEditCopy.CS1101"));
    // instructor does not have sufficient permissions
    assertFalse(idOfCourses.contains("FeedbackEditCopy.CS2107"));
    assertTrue(idOfCourses.contains("FeedbackEditCopy.CS2102"));
    assertTrue(idOfCourses.contains("FeedbackEditCopy.CS2103"));
    assertTrue(idOfCourses.contains("FeedbackEditCopy.CS2103R"));
    assertTrue(idOfCourses.contains("FeedbackEditCopy.CS2104"));
}
Also used : InstructorFeedbackEditCopyPageData(teammates.ui.pagedata.InstructorFeedbackEditCopyPageData) ShowPageResult(teammates.ui.controller.ShowPageResult) InstructorFeedbackEditCopyPageAction(teammates.ui.controller.InstructorFeedbackEditCopyPageAction) ArrayList(java.util.ArrayList) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 13 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes in project teammates by TEAMMATES.

the class InstructorCourseDeleteActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    String instructorId = instructor1OfCourse1.googleId;
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Not enough parameters");
    verifyAssumptionFailure();
    ______TS("Typical case, 2 courses, redirect to homepage");
    CoursesLogic.inst().createCourseAndInstructor(instructorId, "icdct.tpa.id1", "New course", "UTC");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.NEXT_URL, Const.ActionURIs.INSTRUCTOR_HOME_PAGE };
    assertTrue(CoursesLogic.inst().isCoursePresent("icdct.tpa.id1"));
    InstructorCourseDeleteAction deleteAction = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(deleteAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals("The course idOfTypicalCourse1 has been deleted.", redirectResult.getStatusMessage());
    List<CourseAttributes> courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
    assertEquals(1, courseList.size());
    assertEquals("icdct.tpa.id1", courseList.get(0).getId());
    String expectedLogMessage = "TEAMMATESLOG|||instructorCourseDelete|||instructorCourseDelete|||true|||" + "Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||" + "instr1@course1.tmt|||Course deleted: idOfTypicalCourse1|||" + "/page/instructorCourseDelete";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, deleteAction.getLogMessage());
    ______TS("Masquerade mode, delete last course, redirect to Courses page");
    String adminUserId = "admin.user";
    gaeSimulation.loginAsAdmin(adminUserId);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, "icdct.tpa.id1", Const.ParamsNames.NEXT_URL, Const.ActionURIs.INSTRUCTOR_COURSES_PAGE };
    deleteAction = getAction(addUserIdToParams(instructorId, submissionParams));
    redirectResult = getRedirectResult(deleteAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals("The course icdct.tpa.id1 has been deleted.", redirectResult.getStatusMessage());
    courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
    assertEquals(0, courseList.size());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseDelete|||instructorCourseDelete|||true|||Instructor(M)|||" + "Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Course deleted: icdct.tpa.id1|||/page/instructorCourseDelete";
    AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, deleteAction.getLogMessage(), adminUserId);
    ______TS("Masquerade mode, delete last course, no next URL, redirect to Courses page");
    CoursesLogic.inst().createCourseAndInstructor(instructorId, "icdct.tpa.id2", "New course", "UTC");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, "icdct.tpa.id2" };
    deleteAction = getAction(addUserIdToParams(instructorId, submissionParams));
    redirectResult = getRedirectResult(deleteAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals("The course icdct.tpa.id2 has been deleted.", redirectResult.getStatusMessage());
    courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
    assertEquals(0, courseList.size());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseDelete|||instructorCourseDelete|||true|||Instructor(M)|||" + "Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Course deleted: icdct.tpa.id2|||/page/instructorCourseDelete";
    AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, deleteAction.getLogMessage(), adminUserId);
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) InstructorCourseDeleteAction(teammates.ui.controller.InstructorCourseDeleteAction) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 14 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes in project teammates by TEAMMATES.

the class BaseTestCaseWithDatastoreAccess method verifyPresentInDatastore.

protected void verifyPresentInDatastore(DataBundle data) {
    Map<String, AccountAttributes> accounts = data.accounts;
    for (AccountAttributes account : accounts.values()) {
        verifyPresentInDatastore(account);
    }
    Map<String, InstructorAttributes> instructors = data.instructors;
    for (InstructorAttributes instructor : instructors.values()) {
        verifyPresentInDatastore(instructor);
    }
    Map<String, CourseAttributes> courses = data.courses;
    for (CourseAttributes course : courses.values()) {
        verifyPresentInDatastore(course);
    }
    Map<String, StudentAttributes> students = data.students;
    for (StudentAttributes student : students.values()) {
        verifyPresentInDatastore(student);
    }
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Example 15 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes in project teammates by TEAMMATES.

the class CourseJoinAuthenticatedAbstractAction method sendCourseRegisteredEmail.

protected void sendCourseRegisteredEmail(String name, String emailAddress, boolean isInstructor, String courseId) {
    CourseAttributes course = logic.getCourse(courseId);
    EmailWrapper email = new EmailGenerator().generateUserCourseRegisteredEmail(name, emailAddress, account.googleId, isInstructor, course);
    try {
        emailSender.sendEmail(email);
    } catch (EmailSendingException e) {
        log.severe("User course register email failed to send: " + TeammatesException.toStringWithStackTrace(e));
    }
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) EmailSendingException(teammates.common.exception.EmailSendingException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Aggregations

CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)106 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)48 Test (org.testng.annotations.Test)40 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)33 ArrayList (java.util.ArrayList)31 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)19 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)16 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)15 EmailWrapper (teammates.common.util.EmailWrapper)15 HashMap (java.util.HashMap)12 InvalidParametersException (teammates.common.exception.InvalidParametersException)10 EmailGenerator (teammates.logic.api.EmailGenerator)10 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)8 StatusMessage (teammates.common.util.StatusMessage)6 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)5 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)4 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)4 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)4 InstructorCoursesPageData (teammates.ui.pagedata.InstructorCoursesPageData)4 InstructorFeedbackSessionsPageData (teammates.ui.pagedata.InstructorFeedbackSessionsPageData)4