public boolean hasRightsOnProject(User user, Project project) { if (user.getUserType() == UserType.ADMIN || user.getUserType() == UserType.SYSTEM) { return true; } for (User authorizedUser : project.getHasAuthorizedUsers()) { if (authorizedUser == user) { return true; } } return false; }
public boolean hasRightsOnProjectOrSubProjects(User user, Project project) { if (user.getUserType() == UserType.ADMIN || user.getUserType() == UserType.SYSTEM) { return true; } if (hasRightsOnProject(user, project)) { return true; } for (Project subProject : project.getSubProjects()) { if (hasRightsOnProjectOrSubProjects(user, subProject)) { return true; } } return false; }
public boolean hasRightsOnProjectOrSuperProjects(User user, Project project) { if (user.getUserType() == UserType.ADMIN || user.getUserType() == UserType.SYSTEM) { return true; } if (hasRightsOnProject(user, project)) { return true; } if (project.getParent() != null) { if (hasRightsOnProjectOrSuperProjects(user, project.getParent())) { return true; } } return false; }
public void update() { try { serverInfo.setVersion( bimServer .getSConverter() .convertFromSObject(bimServer.getVersionChecker().getLocalVersion(), null)); } catch (BimserverDatabaseException e) { LOGGER.error("", e); } if (bimServer.getDatabase().getMigrator().migrationRequired()) { setServerState(ServerState.MIGRATION_REQUIRED); if (bimServer.getConfig().isAutoMigrate()) { try { bimServer.getDatabase().getMigrator().migrate(); setServerState(ServerState.RUNNING); } catch (MigrationException | InconsistentModelsException e) { LOGGER.error("", e); } } } else if (bimServer.getDatabase().getMigrator().migrationImpossible()) { setServerState(ServerState.MIGRATION_IMPOSSIBLE); } else { DatabaseSession session = bimServer.getDatabase().createSession(); try { boolean adminFound = false; ServerSettings settings = bimServer.getServerSettingsCache().getServerSettings(); IfcModelInterface users = session.getAllOfType(StorePackage.eINSTANCE.getUser(), Query.getDefault()); for (IdEObject idEObject : users.getValues()) { if (idEObject instanceof User) { User user = (User) idEObject; if (user.getUserType() == UserType.ADMIN) { adminFound = true; break; } } } if (settings.getSiteAddress().isEmpty() || settings.getSmtpServer().isEmpty() || !adminFound) { setServerState(ServerState.NOT_SETUP); } else { setServerState(ServerState.RUNNING); } } catch (BimserverDatabaseException e) { LOGGER.error("", e); } finally { session.close(); } } }
@Override public Set<User> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException { User actingUser = getUserByUoid(authorization.getUoid()); Condition condition = new IsOfTypeCondition(StorePackage.eINSTANCE.getUser()); condition = condition.and( new Not( new AttributeCondition( StorePackage.eINSTANCE.getUser_UserType(), new EnumLiteral(UserType.SYSTEM)))); if (actingUser.getUserType() != UserType.ADMIN) { condition = condition.and( new AttributeCondition( StorePackage.eINSTANCE.getUser_State(), new EnumLiteral(ObjectState.ACTIVE))); } return CollectionUtils.mapToSet( getDatabaseSession().query(condition, User.class, OldQuery.getDefault())); }
@Override public Project execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException { User actingUser = getUserByUoid(owningUoid); String trimmedName = name.trim(); if (trimmedName.equals("")) { throw new UserException("Invalid project name"); } final Project project = StoreFactory.eINSTANCE.createProject(); Project parentProject = null; if (parentPoid != -1) { parentProject = getProjectByPoid(parentPoid); project.setParent(parentProject); parentProject.getSubProjects().add(project); getDatabaseSession().store(parentProject); } if (actingUser.getUserType() != UserType.SYSTEM) { if (parentPoid == -1 && actingUser.getUserType() != UserType.ADMIN && !bimServer.getSettingsManager().getSettings().isAllowUsersToCreateTopLevelProjects()) { throw new UserException("Only administrators can create new projects"); } } if (project.getParent() == null) { for (Project p : getProjectsByName(trimmedName)) { if (p.getParent() == null) { throw new UserException("Project name must be unique"); } } } else { Project parent = project.getParent(); for (Project subProject : parent.getSubProjects()) { if (subProject != project && subProject.getName().equals(trimmedName)) { throw new UserException( "Project name must be unique within parent project (" + parent.getName() + ")"); } } project.setClashDetectionSettings(parent.getClashDetectionSettings()); project.setGeoTag(parent.getGeoTag()); } final NewProjectAdded newProjectAdded = LogFactory.eINSTANCE.createNewProjectAdded(); newProjectAdded.setDate(new Date()); newProjectAdded.setExecutor(actingUser); newProjectAdded.setParentProject(parentProject); newProjectAdded.setProject(project); newProjectAdded.setAccessMethod(getAccessMethod()); getDatabaseSession() .addPostCommitAction( new PostCommitAction() { @Override public void execute() throws UserException { NewProjectNotification newProjectNotification = StoreFactory.eINSTANCE.createNewProjectNotification(); newProjectNotification.setProject(project); bimServer.getNotificationsManager().notify(newProjectNotification); } }); project.setId(getDatabaseSession().newPid()); project.setName(trimmedName); // project.getHasAuthorizedUsers().add(getAdminUser()); project.getHasAuthorizedUsers().add(actingUser); project.setCreatedBy(actingUser); project.setCreatedDate(new Date()); project.setDescription(""); project.setExportLengthMeasurePrefix(SIPrefix.METER); if (project.getParent() == null) { GeoTag geoTag = StoreFactory.eINSTANCE.createGeoTag(); geoTag.setEnabled(false); project.setGeoTag(geoTag); ClashDetectionSettings clashDetectionSettings = StoreFactory.eINSTANCE.createClashDetectionSettings(); clashDetectionSettings.setEnabled(false); project.setClashDetectionSettings(clashDetectionSettings); getDatabaseSession().store(geoTag); getDatabaseSession().store(clashDetectionSettings); } else { ClashDetectionSettings clashDetectionSettings = parentProject.getClashDetectionSettings(); project.setClashDetectionSettings(clashDetectionSettings); getDatabaseSession().store(clashDetectionSettings); GeoTag geoTag = parentProject.getGeoTag(); project.setGeoTag(geoTag); getDatabaseSession().store(geoTag); } getDatabaseSession().store(project); getDatabaseSession().store(actingUser); getDatabaseSession().store(newProjectAdded); return project; }