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;
}
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> </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;
}
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);
}
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);
}
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;
}
Aggregations