Search in sources :

Example 46 with AccountAttributes

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

the class Action method authenticateAndGetNominalUser.

protected AccountAttributes authenticateAndGetNominalUser(UserType loggedInUserType) {
    String paramRequestedUserId = request.getParameter(Const.ParamsNames.USER_ID);
    AccountAttributes account = null;
    if (isMasqueradeModeRequested(loggedInUser, paramRequestedUserId)) {
        if (loggedInUserType.isAdmin) {
            // Allowing admin to masquerade as another user
            account = logic.getAccount(paramRequestedUserId);
            if (account == null) {
                // Unregistered user
                if (regkey == null) {
                    // since admin is masquerading, fabricate a regkey
                    regkey = "any-non-null-value";
                }
                account = AccountAttributes.builder().withGoogleId(paramRequestedUserId).build();
            }
            return account;
        }
        throw new UnauthorizedAccessException("User " + loggedInUserType.id + " is trying to masquerade as " + paramRequestedUserId + " without admin permission.");
    }
    account = loggedInUser;
    if (isPersistenceIssue() && isHomePage()) {
    // let the user go through as this is a persistence issue
    } else if (doesUserNeedRegistration(account) && !loggedInUserType.isAdmin) {
        if (regkey != null && student != null) {
            // TODO: encrypt the email as currently anyone with the regkey can
            // get the email because of this redirect:
            String joinUrl = Config.getAppUrl(student.getRegistrationUrl()).withParam(Const.ParamsNames.NEXT_URL, requestUrl).toString();
            setRedirectPage(joinUrl);
            return null;
        }
        throw new UnauthorizedAccessException("Unregistered user for a page that needs registration");
    }
    boolean isUserLoggedIn = account.googleId != null;
    if (isPageNotCourseJoinRelated() && doesRegkeyBelongToUnregisteredStudent() && isUserLoggedIn) {
        String redirectUrl = Config.getAppUrl(student.getRegistrationUrl()).withParam(Const.ParamsNames.NEXT_URL, requestUrl).toString();
        setRedirectPage(redirectUrl);
        return null;
    }
    return account;
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException)

Example 47 with AccountAttributes

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

the class Action method authenticateNotLoggedInUser.

protected AccountAttributes authenticateNotLoggedInUser(String email, String courseId) {
    student = logic.getStudentForRegistrationKey(regkey);
    boolean isUnknownKey = student == null;
    boolean isARegisteredUser = !isUnknownKey && student.googleId != null && !student.googleId.isEmpty();
    boolean isMissingAdditionalAuthenticationInfo = email == null || courseId == null;
    boolean isAuthenticationFailure = !isUnknownKey && (!student.email.equals(email) || !student.course.equals(courseId));
    AccountAttributes loggedInUser = null;
    if (isUnknownKey) {
        throw new UnauthorizedAccessException("Unknown Registration Key " + regkey);
    } else if (isARegisteredUser) {
        setRedirectPage(gateKeeper.getLoginUrl(requestUrl));
        return null;
    } else if (isNotLegacyLink() && isMissingAdditionalAuthenticationInfo) {
        throw new UnauthorizedAccessException("Insufficient information to authenticate user");
    } else if (isNotLegacyLink() && isAuthenticationFailure) {
        throw new UnauthorizedAccessException("Invalid email/course for given Registration Key");
    } else {
        // Unregistered and not logged in access given to page
        loggedInUser = AccountAttributes.builder().withEmail(student.email).build();
    }
    return loggedInUser;
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException)

Example 48 with AccountAttributes

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

the class AdminAccountDetailsPageAction method execute.

@Override
protected ActionResult execute() {
    gateKeeper.verifyAdminPrivileges(account);
    String googleId = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_ID);
    AccountAttributes accountInformation = logic.getAccount(googleId);
    List<CourseDetailsBundle> instructorCourseList;
    try {
        instructorCourseList = new ArrayList<>(logic.getCourseSummariesForInstructor(googleId).values());
    } catch (EntityDoesNotExistException e) {
        // Not an instructor of any course
        instructorCourseList = null;
    }
    List<CourseAttributes> studentCourseList;
    try {
        studentCourseList = logic.getCoursesForStudentAccount(googleId);
    } catch (EntityDoesNotExistException e) {
        // Not a student of any course
        studentCourseList = null;
    }
    AdminAccountDetailsPageData data = new AdminAccountDetailsPageData(account, sessionToken, accountInformation, instructorCourseList, studentCourseList);
    statusToAdmin = "adminAccountDetails Page Load<br>" + "Viewing details for " + data.getAccountInformation().name + "(" + googleId + ")";
    return createShowPageResult(Const.ViewURIs.ADMIN_ACCOUNT_DETAILS, data);
}
Also used : AdminAccountDetailsPageData(teammates.ui.pagedata.AdminAccountDetailsPageData) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Example 49 with AccountAttributes

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

the class AdminAccountManagementPageAction method execute.

@Override
protected ActionResult execute() {
    gateKeeper.verifyAdminPrivileges(account);
    String instructorGoogleId = this.getRequestParamValue("googleId");
    if (instructorGoogleId == null) {
        instructorGoogleId = "";
    }
    Map<String, ArrayList<InstructorAttributes>> instructorCoursesTable = new HashMap<>();
    Map<String, AccountAttributes> instructorAccountsTable = new HashMap<>();
    List<InstructorAttributes> instructorsList = logic.getInstructorsForGoogleId(instructorGoogleId);
    AccountAttributes instructorAccount = logic.getAccount(instructorGoogleId);
    boolean isToShowAll = this.getRequestParamAsBoolean("all");
    boolean isAccountExisting = instructorAccount != null;
    if (isAccountExisting) {
        instructorAccountsTable.put(instructorAccount.googleId, instructorAccount);
        for (InstructorAttributes instructor : instructorsList) {
            ArrayList<InstructorAttributes> courseList = instructorCoursesTable.get(instructor.googleId);
            if (courseList == null) {
                courseList = new ArrayList<>();
                instructorCoursesTable.put(instructor.googleId, courseList);
            }
            courseList.add(instructor);
        }
    }
    AdminAccountManagementPageData data = new AdminAccountManagementPageData(account, sessionToken, instructorAccountsTable, instructorCoursesTable, isToShowAll);
    statusToAdmin = "Admin Account Management Page Load<br>" + "<span class=\"bold\">Total Instructors:</span> " + instructorAccountsTable.size();
    return createShowPageResult(Const.ViewURIs.ADMIN_ACCOUNT_MANAGEMENT, data);
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) AdminAccountManagementPageData(teammates.ui.pagedata.AdminAccountManagementPageData)

Example 50 with AccountAttributes

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

the class AccountsDb method createEntitiesDeferred.

@Override
public List<Account> createEntitiesDeferred(Collection<AccountAttributes> accountsToAdd) throws InvalidParametersException {
    List<StudentProfileAttributes> profilesToAdd = new LinkedList<>();
    for (AccountAttributes accountToAdd : accountsToAdd) {
        profilesToAdd.add(accountToAdd.studentProfile);
    }
    profilesDb.createEntitiesDeferred(profilesToAdd);
    return super.createEntitiesDeferred(accountsToAdd);
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) LinkedList(java.util.LinkedList)

Aggregations

AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)84 Test (org.testng.annotations.Test)53 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)28 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)16 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)15 ArrayList (java.util.ArrayList)13 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)11 HashMap (java.util.HashMap)7 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)6 InvalidParametersException (teammates.common.exception.InvalidParametersException)6 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)5 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)4 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)4 EmailWrapper (teammates.common.util.EmailWrapper)4 RedirectResult (teammates.ui.controller.RedirectResult)4 List (java.util.List)3 EmailGenerator (teammates.logic.api.EmailGenerator)3 AccountsDb (teammates.storage.api.AccountsDb)3 Account (teammates.storage.entity.Account)3 ShowPageResult (teammates.ui.controller.ShowPageResult)3