Search in sources :

Example 36 with StudyUserRoleBean

use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.

the class UserAccountController method addActiveStudyRole.

private UserAccountBean addActiveStudyRole(UserAccountBean createdUserAccountBean, int studyId, Role r, UserAccountBean ownerUserAccount) {
    StudyUserRoleBean studyUserRole = new StudyUserRoleBean();
    studyUserRole.setStudyId(studyId);
    studyUserRole.setRoleName(r.getName());
    studyUserRole.setStatus(Status.AVAILABLE);
    studyUserRole.setOwner(ownerUserAccount);
    createdUserAccountBean.addRole(studyUserRole);
    //createdUserAccountBean.setAccountNonLocked(false);
    return createdUserAccountBean;
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean)

Example 37 with StudyUserRoleBean

use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.

the class UserAccountTable method showRow.

@Override
public String showRow(EntityBean e) {
    UserAccountBean u = (UserAccountBean) e;
    Status s = u.getStatus();
    // do the first row, just the "flat" properties
    String row = "<tr>\n";
    // username
    String colorOn = s.equals(Status.AVAILABLE) ? "" : "<font color='gray'>";
    String colorOff = s.equals(Status.AVAILABLE) ? "" : "</font>";
    row += "<td>" + colorOn + u.getName() + colorOff + "</td>\n";
    row += "<td>" + u.getFirstName() + "</td>\n";
    row += "<td>" + u.getLastName() + "</td>\n";
    // status
    row += "<td>" + s.getName() + "</td>\n";
    // actions
    row += "<td>";
    if (!s.equals(Status.DELETED)) {
        String confirmQuestion = "Are you sure you want to delete " + u.getName() + "?";
        String onClick = "onClick=\"return confirm('" + confirmQuestion + "');\"";
        row += "<a href='" + ViewUserAccountServlet.getLink(u.getId()) + "'>view</a>";
        row += " <a href='" + EditUserAccountServlet.getLink(u.getId()) + "'>edit</a>";
        row += " <a href='" + DeleteUserServlet.getLink(u, EntityAction.DELETE) + "'" + onClick + ">delete</a>";
    } else {
        String confirmQuestion = "Are you sure you want to restore " + u.getName() + "?";
        String onClick = "onClick=\"return confirm('" + confirmQuestion + "');\"";
        row += " <a href='" + DeleteUserServlet.getLink(u, EntityAction.RESTORE) + "'" + onClick + ">restore</a>";
    }
    row += "</td>\n";
    row += "</tr>\n";
    // do the next row, with the user's roles
    row += "<tr>\n";
    row += "<td>&nbsp;</td>\n";
    ArrayList userRoles = u.getRoles();
    // study user roles cell
    row += "<td colspan='3'>";
    if (userRoles.size() <= 0) {
        row += "<i>No roles assigned</i>";
    }
    for (int i = 0; i < userRoles.size(); i++) {
        StudyUserRoleBean sur = (StudyUserRoleBean) userRoles.get(i);
        colorOn = sur.getStatus().equals(Status.AVAILABLE) ? "" : "<font color='gray'>";
        colorOff = sur.getStatus().equals(Status.AVAILABLE) ? "" : "</font>";
        String studyName = getStudyName(sur);
        row += studyName + " - " + colorOn + sur.getRole().getDescription() + colorOff + "<br/>\n";
    }
    row += "</td>\n";
    // actions on the study user roles
    row += "<td>";
    for (int i = 0; i < userRoles.size(); i++) {
        StudyUserRoleBean sur = (StudyUserRoleBean) userRoles.get(i);
        if (!sur.getStatus().equals(Status.DELETED)) {
            String studyName = getStudyName(sur);
            String confirmQuestion = "Are you sure you want to delete the " + sur.getRole().getDescription() + " role for " + u.getName() + " in " + studyName + "?";
            row += " <a href='" + EditStudyUserRoleServlet.getLink(sur, u) + "'>edit role</a>";
            row += " <a href='" + DeleteStudyUserRoleServlet.getLink(u.getName(), sur.getStudyId(), EntityAction.DELETE) + "' onClick='return confirm(\"" + confirmQuestion + "\");'>delete role</a>";
        } else {
            String confirmQuestion = "Are you sure you want to restore the " + sur.getRole().getDescription() + " role for " + u.getName() + " in Study " + sur.getStudyId() + "?";
            row += " <a href='" + DeleteStudyUserRoleServlet.getLink(u.getName(), sur.getStudyId(), EntityAction.RESTORE) + "' onClick=\"return confirm('" + confirmQuestion + "');\">restore role</a>";
        }
        row += "<br/>\n";
    }
    row += "</td>\n";
    row += "<tr>\n";
    row += "</tr>\n";
    return row;
}
Also used : Status(org.akaza.openclinica.bean.core.Status) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) ArrayList(java.util.ArrayList)

Example 38 with StudyUserRoleBean

use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.

the class SubmitDataServletTest method test_SubmitDataServlet_MayViewData.

// Scenario
// Data Entry Person (site) can access Subject    
public void test_SubmitDataServlet_MayViewData() {
    UserAccountBean ub = new UserAccountBean();
    //StudyUserRoleBean currentRole = new StudyUserRoleBean();
    //currentRole.setRole(Role.COORDINATOR);
    StudyUserRoleBean studyUserRoleBeanMock = mock(StudyUserRoleBean.class);
    // Positive Testing
    when(studyUserRoleBeanMock.getRole()).thenReturn(Role.RESEARCHASSISTANT);
    boolean result1 = SubmitDataServlet.mayViewData(ub, studyUserRoleBeanMock);
    assertEquals(true, result1);
    // Positive Testing
    when(studyUserRoleBeanMock.getRole()).thenReturn(Role.RESEARCHASSISTANT2);
    boolean result2 = SubmitDataServlet.mayViewData(ub, studyUserRoleBeanMock);
    assertEquals(true, result2);
    // Negative Testing
    when(studyUserRoleBeanMock.getRole()).thenReturn(Role.ADMIN);
    boolean result3 = SubmitDataServlet.mayViewData(ub, studyUserRoleBeanMock);
    assertEquals(false, result3);
    // Negative Testing
    when(studyUserRoleBeanMock.getRole()).thenReturn(Role.INVALID);
    boolean result4 = SubmitDataServlet.mayViewData(ub, studyUserRoleBeanMock);
    assertEquals(false, result4);
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean)

Example 39 with StudyUserRoleBean

use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.

the class SubmitDataServletTest method test_SubmitDataServlet_MaySubmitData.

// Scenario
// Data Entry Person (site) can access Notes & Discrepancies
public void test_SubmitDataServlet_MaySubmitData() {
    UserAccountBean ub = new UserAccountBean();
    //StudyUserRoleBean currentRole = new StudyUserRoleBean();
    //currentRole.setRole(Role.COORDINATOR);
    StudyUserRoleBean studyUserRoleBeanMock = mock(StudyUserRoleBean.class);
    // Positive Testing
    when(studyUserRoleBeanMock.getRole()).thenReturn(Role.RESEARCHASSISTANT);
    boolean result1 = SubmitDataServlet.maySubmitData(ub, studyUserRoleBeanMock);
    assertEquals(true, result1);
    // Positive Testing
    when(studyUserRoleBeanMock.getRole()).thenReturn(Role.RESEARCHASSISTANT2);
    boolean result2 = SubmitDataServlet.maySubmitData(ub, studyUserRoleBeanMock);
    assertEquals(true, result2);
    // Negative Testing
    when(studyUserRoleBeanMock.getRole()).thenReturn(Role.ADMIN);
    boolean result3 = SubmitDataServlet.maySubmitData(ub, studyUserRoleBeanMock);
    assertEquals(false, result3);
    // Negative Testing
    when(studyUserRoleBeanMock.getRole()).thenReturn(Role.INVALID);
    boolean result4 = SubmitDataServlet.maySubmitData(ub, studyUserRoleBeanMock);
    assertEquals(false, result4);
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean)

Example 40 with StudyUserRoleBean

use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.

the class BaseVSValidatorImplementation method verifyUser.

public boolean verifyUser(UserAccountBean user, UserAccountDAO userAccountDao, int study_id, int site_id, Errors errors) {
    // TODO Auto-generated method stub
    // check for site role & user permission if ok -> return yes,
    //if no-> check for study permissions & role
    StudyUserRoleBean siteSur;
    if (site_id > -1) {
        siteSur = userAccountDao.findRoleByUserNameAndStudyId(user.getName(), site_id);
        if (siteSur.getStatus() != Status.AVAILABLE) {
            errors.reject("studyEventDefinitionRequestValidator.insufficient_permissions", "You do not have sufficient privileges to proceed with this operation.");
            return false;
        }
    }
    siteSur = userAccountDao.findRoleByUserNameAndStudyId(user.getName(), study_id);
    if (siteSur.getStatus() != Status.AVAILABLE) {
        errors.reject("studyEventDefinitionRequestValidator.insufficient_permissions", "You do not have sufficient privileges to proceed with this operation.");
        return false;
    }
    return true;
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean)

Aggregations

StudyUserRoleBean (org.akaza.openclinica.bean.login.StudyUserRoleBean)76 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)35 ArrayList (java.util.ArrayList)34 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)28 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)23 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)22 Date (java.util.Date)16 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)16 Role (org.akaza.openclinica.bean.core.Role)15 HashMap (java.util.HashMap)14 Iterator (java.util.Iterator)12 InsufficientPermissionException (org.akaza.openclinica.web.InsufficientPermissionException)10 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)9 Validator (org.akaza.openclinica.control.form.Validator)6 SimpleDateFormat (java.text.SimpleDateFormat)4 HttpSession (javax.servlet.http.HttpSession)4 DatasetBean (org.akaza.openclinica.bean.extract.DatasetBean)4 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)4 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)4 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)4