use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class DefaultPermissionResolver method hasWorkspaceAccess.
private boolean hasWorkspaceAccess(WorkspaceEntity workspaceEntity, UserEntity userEntity, Permission permission) {
// Workspace access as an individual
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserEntity(workspaceEntity, userEntity);
if (workspaceUserEntity != null) {
if (permissionController.hasPermission(workspaceUserEntity.getWorkspaceUserRole(), permission)) {
// TODO Override rules for workspace users
return true;
}
}
// Workspace access as a group member
List<UserGroupEntity> userGroups = userGroupEntityController.listUserGroupsByUserEntity(userEntity);
for (UserGroupEntity userGroup : userGroups) {
// TODO Override rules for user groups
if (permissionController.hasPermission(workspaceEntity, userGroup, permission)) {
return true;
}
}
return false;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class PyramusUpdater method updateInactiveWorkspaceStudents.
/**
* Updates inactive course students from Pyramus
*
* @param courseId id of course in Pyramus
* @return count of updated course students
*/
public int updateInactiveWorkspaceStudents(WorkspaceEntity workspaceEntity) {
int count = 0;
Long courseId = identifierMapper.getPyramusCourseId(workspaceEntity.getIdentifier());
CourseStudent[] nonActiveCourseStudents = pyramusClient.get().get("/courses/courses/" + courseId + "/students?filterArchived=false&activeStudents=false", CourseStudent[].class);
if (nonActiveCourseStudents != null) {
for (CourseStudent nonActiveCourseStudent : nonActiveCourseStudents) {
SchoolDataIdentifier workspaceUserIdentifier = toIdentifier(identifierMapper.getWorkspaceStudentIdentifier(nonActiveCourseStudent.getId()));
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
if (workspaceUserEntity != null) {
if (nonActiveCourseStudent.getArchived()) {
fireCourseStudentRemoved(nonActiveCourseStudent.getId(), nonActiveCourseStudent.getStudentId(), nonActiveCourseStudent.getCourseId());
count++;
} else {
fireCourseStudentUpdated(nonActiveCourseStudent, false);
count++;
}
} else {
fireCourseStudentDiscovered(nonActiveCourseStudent, false);
count++;
}
}
}
return count;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class PyramusUpdater method updateCourseStudent.
/**
* Updates course student from Pyramus
*
* @param courseStudentId id of course student in Pyramus
* @param courseId id of course in Pyramus
* @param studentId id of student in Pyramus
* @return returns whether new course student was created or not
*/
public boolean updateCourseStudent(Long courseStudentId, Long courseId, Long studentId) {
String workspaceIdentifier = identifierMapper.getWorkspaceIdentifier(courseId);
String identifier = identifierMapper.getWorkspaceStudentIdentifier(courseStudentId);
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, workspaceIdentifier);
if (workspaceEntity == null) {
updateCourse(courseId);
workspaceEntity = workspaceController.findWorkspaceEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, workspaceIdentifier);
}
if (workspaceEntity != null) {
SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(identifier, SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE);
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
CourseStudent courseStudent = pyramusClient.get().get("/courses/courses/" + courseId + "/students/" + courseStudentId, CourseStudent.class);
if (courseStudent != null && !courseStudent.getArchived()) {
boolean studentActive = isStudentActive(courseStudent.getStudentId());
if (workspaceUserEntity == null) {
fireCourseStudentDiscovered(courseStudent, studentActive);
return true;
} else {
fireCourseStudentUpdated(courseStudent, studentActive);
}
} else {
if (workspaceUserEntity != null) {
fireCourseStudentRemoved(courseStudentId, studentId, courseId);
}
}
}
return false;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class PyramusUpdater method updateActiveWorkspaceStudents.
/**
* Updates active course students from Pyramus
*
* @param courseId id of course in Pyramus
* @return count of updated course students
*/
public int updateActiveWorkspaceStudents(WorkspaceEntity workspaceEntity) {
int count = 0;
Long courseId = identifierMapper.getPyramusCourseId(workspaceEntity.getIdentifier());
CourseStudent[] courseStudents = pyramusClient.get().get("/courses/courses/" + courseId + "/students?filterArchived=false&activeStudents=true", CourseStudent[].class);
if (courseStudents != null) {
for (CourseStudent courseStudent : courseStudents) {
SchoolDataIdentifier workspaceUserIdentifier = toIdentifier(identifierMapper.getWorkspaceStudentIdentifier(courseStudent.getId()));
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
if (courseStudent.getArchived()) {
if (workspaceUserEntity != null) {
fireCourseStudentRemoved(courseStudent.getId(), courseStudent.getStudentId(), courseStudent.getCourseId());
count++;
}
} else {
if (workspaceUserEntity == null) {
fireCourseStudentDiscovered(courseStudent, true);
count++;
} else {
fireCourseStudentUpdated(courseStudent, true);
}
}
}
}
return count;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class DefaultSchoolDataWorkspaceListener method onSchoolDataWorkspaceUserRemovedEvent.
public void onSchoolDataWorkspaceUserRemovedEvent(@Observes SchoolDataWorkspaceUserRemovedEvent event) {
UserEntity userEntity = userEntityController.findUserEntityByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
if (userEntity != null) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByDataSourceAndIdentifier(event.getWorkspaceDataSource(), event.getWorkspaceIdentifier());
if (workspaceEntity != null) {
SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(event.getIdentifier(), event.getDataSource());
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(workspaceUserIdentifier);
if (workspaceUserEntity != null) {
workspaceUserEntityController.archiveWorkspaceUserEntity(workspaceUserEntity);
}
} else {
logger.warning("could not remove workspace user because workspace entity #" + event.getWorkspaceIdentifier() + '/' + event.getWorkspaceDataSource() + " could not be found");
}
} else {
logger.warning("could not remove workspace user because user entity #" + event.getUserIdentifier() + '/' + event.getUserDataSource() + " could not be found");
}
}
Aggregations