use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProjectPermission in project webanno by webanno.
the class PermissionsExporter method importData.
/**
* Create {@link ProjectPermission} from the exported {@link ExportedProjectPermission}
*
* @param aExProject
* the imported project.
* @param aProject
* the project.
* @throws IOException
* if an I/O error occurs.
*/
@Override
public void importData(ProjectImportRequest aRequest, Project aProject, ExportedProject aExProject, ZipFile aZip) throws Exception {
// permissions for other users unless permission import was requested.
for (ExportedProjectPermission importedPermission : aExProject.getProjectPermissions()) {
boolean isPermissionOfImportingUser = aRequest.getManager().map(User::getUsername).map(importedPermission.getUser()::equals).orElse(false);
if (isPermissionOfImportingUser || aRequest.isImportPermissions()) {
ProjectPermission permission = new ProjectPermission();
permission.setLevel(importedPermission.getLevel());
permission.setProject(aProject);
permission.setUser(importedPermission.getUser());
projectService.createProjectPermission(permission);
}
}
// Give all permissions to the importing user if requested
if (aRequest.getManager().isPresent()) {
User user = aRequest.getManager().get();
String username = user.getUsername();
if (!projectService.isManager(aProject, user)) {
projectService.createProjectPermission(new ProjectPermission(aProject, username, MANAGER));
}
if (!projectService.isCurator(aProject, user)) {
projectService.createProjectPermission(new ProjectPermission(aProject, username, CURATOR));
}
if (!projectService.isAnnotator(aProject, user)) {
projectService.createProjectPermission(new ProjectPermission(aProject, username, ANNOTATOR));
}
}
// Users are added without passwords and disabled.
if (aRequest.isCreateMissingUsers()) {
Set<String> users = new HashSet<>();
for (ExportedProjectPermission importedPermission : aExProject.getProjectPermissions()) {
users.add(importedPermission.getUser());
}
for (String user : users) {
if (!userService.exists(user)) {
User u = new User();
u.setUsername(user);
u.setEnabled(false);
userService.create(u);
}
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProjectPermission in project webanno by webanno.
the class PermissionsExporter method exportData.
@Override
public void exportData(ProjectExportRequest aRequest, ProjectExportTaskMonitor aMonitor, ExportedProject aExProject, File aStage) throws Exception {
Project project = aRequest.getProject();
// add project permissions to the project
List<ExportedProjectPermission> projectPermissions = new ArrayList<>();
for (User user : projectService.listProjectUsersWithPermissions(project)) {
for (ProjectPermission permission : projectService.listProjectPermissionLevel(user, project)) {
ExportedProjectPermission permissionToExport = new ExportedProjectPermission();
permissionToExport.setLevel(permission.getLevel());
permissionToExport.setUser(user.getUsername());
projectPermissions.add(permissionToExport);
}
}
aExProject.setProjectPermissions(projectPermissions);
LOG.info("Exported [{}] permissions for project [{}]", projectPermissions.size(), aRequest.getProject().getName());
}
Aggregations