{"record":{"id":"fedaaaa7b729aceb","repo":"theonedev/onedev","slug":"import-target-already-exists-you-need-to-have-pro-fedaaa","errorCode":null,"errorMessage":"Import target already exists. You need to have project management privilege over it","messagePattern":"Import target already exists\\. You need to have project management privilege over it","errorType":"exception","errorClass":"UnauthorizedException","httpStatus":null,"severity":"error","filePath":"server-plugin/server-plugin-import-gitlab/src/main/java/io/onedev/server/plugin/imports/gitlab/ImportServer.java","lineNumber":305,"sourceCode":"\t\t\tProjectImportOption option, boolean dryRun, TaskLogger logger) {\n\t\tClient client = newClient();\n\t\ttry {\n\t\t\tMap<String, Optional<Long>> userIds = new HashMap<>();\n\t\t\tImportResult result = new ImportResult();\n\t\t\tfor (var gitLabProject: projects.getImportProjects()) {\n\t\t\t\tOneDev.getInstance(TransactionService.class).run(() -> {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tString oneDevProjectPath = gitLabProject;\n\t\t\t\t\t\tif (projects.getParentOneDevProject() != null)\n\t\t\t\t\t\t\toneDevProjectPath = projects.getParentOneDevProject() + \"/\" + oneDevProjectPath;\n\n\t\t\t\t\t\tlogger.log(\"Importing from '\" + gitLabProject + \"' to '\" + oneDevProjectPath + \"'...\");\n\n\t\t\t\t\t\tProjectService projectService = OneDev.getInstance(ProjectService.class);\n\t\t\t\t\t\tProject project = projectService.setup(SecurityUtils.getSubject(), oneDevProjectPath);\n\n\t\t\t\t\t\tif (!project.isNew() && !SecurityUtils.canManageProject(project)) {\n\t\t\t\t\t\t\tthrow new UnauthorizedException(\"Import target already exists. \" +\n\t\t\t\t\t\t\t\t\t\"You need to have project management privilege over it\");\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tString apiEndpoint = getApiEndpoint(\"/projects/\" + gitLabProject.replace(\"/\", \"%2F\"));\n\t\t\t\t\t\tJsonNode projectNode = JerseyUtils.get(client, apiEndpoint, logger);\n\n\t\t\t\t\t\tproject.setDescription(projectNode.get(\"description\").asText(null));\n\t\t\t\t\t\tproject.setIssueManagement(projectNode.get(\"issues_enabled\").asBoolean());\n\n\t\t\t\t\t\tif (project.isNew() || project.getDefaultBranch() == null) {\n\t\t\t\t\t\t\tlogger.log(\"Cloning code...\");\n\t\t\t\t\t\t\tURIBuilder builder = new URIBuilder(projectNode.get(\"http_url_to_repo\").asText());\n\t\t\t\t\t\t\tbuilder.setUserInfo(\"git\", getAccessToken());\n\n\t\t\t\t\t\t\tSecretMasker.push(new SecretMasker() {\n\n\t\t\t\t\t\t\t\t@Override\n\t\t\t\t\t\t\t\tpublic String mask(String text) {","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-plugin/server-plugin-import-gitlab/src/main/java/io/onedev/server/plugin/imports/gitlab/ImportServer.java#L287-L323","documentation":"When importing GitLab projects, the target OneDev project is created/fetched with ProjectService.setup; if it already exists and the current user lacks manage privilege over it, an UnauthorizedException is thrown to protect the existing project from unauthorized modification.","triggerScenarios":"importProjects invoked with a oneDevProjectPath that already exists in OneDev while SecurityUtils.canManageProject(project) is false for the current subject.","commonSituations":"Importing into a project path owned by someone else; using a non-admin service account; rerunning an import whose target was recreated by another user; namespace path collisions.","solutions":["Use a different oneDev project path for the import","Have an administrator grant your user Project Management privilege on the existing project","Delete/rename the pre-existing project if it is no longer needed","Re-run the import with appropriate credentials"],"exampleFix":"// before\nString oneDevProjectPath = \"group/service\"; // already exists\n// after\nString oneDevProjectPath = \"group/service-gitlab-import\";","handlingStrategy":"try-catch","validationCode":"Project existing = OneDev.getInstance(ProjectManager.class).findProjectByPath(oneDevProjectPath);\nif (existing != null && !SecurityUtils.canManageProject(existing))\n    throw new ValidationException(\"No manage privilege over \" + oneDevProjectPath);","typeGuard":null,"tryCatchPattern":"try { importServer.importProjects(...); } catch (UnauthorizedException e) { log.error(\"Import blocked: {}\", e.getMessage()); /* pick new path or obtain permission */ }","preventionTips":["Validate project path uniqueness before running the import","Grant the import account manage privileges on target namespaces","Avoid reusing paths of projects owned by others"],"tags":["gitlab","import","permissions","project"],"backgroundTag":"insufficient-permissions","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}