@Test public void testInvalidAccessTeacher2() { setupCurrentUser(teacher2); Set<String> ids = new HashSet<String>(Arrays.asList(studentCohortAssoc1.getEntityId())); Assert.assertFalse(validator.validate(EntityNames.STUDENT_COHORT_ASSOCIATION, ids).equals(ids)); ids = new HashSet<String>(Arrays.asList(studentCohortAssoc3.getEntityId())); Assert.assertFalse(validator.validate(EntityNames.STUDENT_COHORT_ASSOCIATION, ids).equals(ids)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery( new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.COHORT_ID)); Map<String, Set<String>> cohortIdToSca = new HashMap<String, Set<String>>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STUDENT_COHORT_ASSOCIATION, query); for (Entity sca : scas) { String cohortId = sca.getBody().get(ParameterConstants.COHORT_ID).toString(); if(!cohortIdToSca.containsKey(cohortId)) { cohortIdToSca.put(cohortId, new HashSet<String>()); } cohortIdToSca.get(cohortId).add(sca.getEntityId()); } String teacherId = SecurityUtil.getSLIPrincipal().getEntity().getEntityId(); NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, cohortIdToSca.keySet())); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, teacherId)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); Set<String> validCohortIds = new HashSet<String>(); for (Entity entity : entities) { String expireDate = (String) entity.getBody().get(ParameterConstants.END_DATE); if (expireDate == null || isLhsBeforeRhs(getNowMinusGracePeriod(), getDateTime(expireDate))) { validCohortIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } } return getValidIds(validCohortIds, cohortIdToSca); }
TeacherToStudentCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery( new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.COHORT_ID)); Map<String, Set<String>> cohortIdToSca = new HashMap<String, Set<String>>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STUDENT_COHORT_ASSOCIATION, query); for (Entity sca : scas) { String cohortId = sca.getBody().get(ParameterConstants.COHORT_ID).toString(); if(!cohortIdToSca.containsKey(cohortId)) { cohortIdToSca.put(cohortId, new HashSet<String>()); } cohortIdToSca.get(cohortId).add(sca.getEntityId()); } String teacherId = SecurityUtil.getSLIPrincipal().getEntity().getEntityId(); NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, cohortIdToSca.keySet())); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, teacherId)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); Set<String> validCohortIds = new HashSet<String>(); for (Entity entity : entities) { String expireDate = (String) entity.getBody().get(ParameterConstants.END_DATE); if (expireDate == null || isLhsBeforeRhs(getNowMinusGracePeriod(), getDateTime(expireDate))) { validCohortIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } } return getValidIds(validCohortIds, cohortIdToSca); } }
TeacherToStudentCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery( new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.COHORT_ID)); Map<String, Set<String>> cohortIdToSca = new HashMap<String, Set<String>>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STUDENT_COHORT_ASSOCIATION, query); for (Entity sca : scas) { String cohortId = sca.getBody().get(ParameterConstants.COHORT_ID).toString(); if(!cohortIdToSca.containsKey(cohortId)) { cohortIdToSca.put(cohortId, new HashSet<String>()); } cohortIdToSca.get(cohortId).add(sca.getEntityId()); } String teacherId = SecurityUtil.getSLIPrincipal().getEntity().getEntityId(); NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, cohortIdToSca.keySet())); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, teacherId)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); Set<String> validCohortIds = new HashSet<String>(); for (Entity entity : entities) { String expireDate = (String) entity.getBody().get(ParameterConstants.END_DATE); if (expireDate == null || isLhsBeforeRhs(getNowMinusGracePeriod(), getDateTime(expireDate))) { validCohortIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } } return getValidIds(validCohortIds, cohortIdToSca); }  }
TeacherToStudentCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery( new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.COHORT_ID)); Map<String, Set<String>> cohortIdToSca = new HashMap<String, Set<String>>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STUDENT_COHORT_ASSOCIATION, query); for (Entity sca : scas) { String cohortId = sca.getBody().get(ParameterConstants.COHORT_ID).toString(); if(!cohortIdToSca.containsKey(cohortId)) { cohortIdToSca.put(cohortId, new HashSet<String>()); } cohortIdToSca.get(cohortId).add(sca.getEntityId()); } String teacherId = SecurityUtil.getSLIPrincipal().getEntity().getEntityId(); NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, cohortIdToSca.keySet())); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, teacherId)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); Set<String> validCohortIds = new HashSet<String>(); for (Entity entity : entities) { String expireDate = (String) entity.getBody().get(ParameterConstants.END_DATE); if (expireDate == null || isLhsBeforeRhs(getNowMinusGracePeriod(), getDateTime(expireDate))) { validCohortIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } } return getValidIds(validCohortIds, cohortIdToSca); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToStudentCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery( new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.COHORT_ID)); Map<String, Set<String>> cohortIdToSca = new HashMap<String, Set<String>>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STUDENT_COHORT_ASSOCIATION, query); for (Entity sca : scas) { String cohortId = sca.getBody().get(ParameterConstants.COHORT_ID).toString(); if(!cohortIdToSca.containsKey(cohortId)) { cohortIdToSca.put(cohortId, new HashSet<String>()); } cohortIdToSca.get(cohortId).add(sca.getEntityId()); } String teacherId = SecurityUtil.getSLIPrincipal().getEntity().getEntityId(); NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, cohortIdToSca.keySet())); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, teacherId)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); Set<String> validCohortIds = new HashSet<String>(); for (Entity entity : entities) { String expireDate = (String) entity.getBody().get(ParameterConstants.END_DATE); if (expireDate == null || isLhsBeforeRhs(getNowMinusGracePeriod(), getDateTime(expireDate))) { validCohortIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } } return getValidIds(validCohortIds, cohortIdToSca); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }