{"record":{"id":"673f0085a6d0603c","repo":"theonedev/onedev","slug":"import-target-already-exists-you-need-to-have-pro-673f00","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-github/src/main/java/io/onedev/server/plugin/imports/github/ImportServer.java","lineNumber":575,"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 gitHubRepository: repositories.getImportRepositories()) {\n\t\t\t\tOneDev.getInstance(TransactionService.class).run(() -> {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tString oneDevProjectPath = gitHubRepository;\n\t\t\t\t\t\tif (repositories.getParentOneDevProject() != null)\n\t\t\t\t\t\t\toneDevProjectPath = repositories.getParentOneDevProject() + \"/\" + oneDevProjectPath;\n\n\t\t\t\t\t\tlogger.log(\"Importing from '\" + gitHubRepository + \"' 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(\"/repos/\" + gitHubRepository);\n\t\t\t\t\t\tJsonNode repoNode = get(client, apiEndpoint, logger);\n\n\t\t\t\t\t\tproject.setDescription(repoNode.get(\"description\").asText(null));\n\t\t\t\t\t\tproject.setIssueManagement(repoNode.get(\"has_issues\").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(repoNode.get(\"clone_url\").asText());\n\t\t\t\t\t\t\tbuilder.setUserInfo(\"git\", getAccessToken());\n\n\t\t\t\t\t\t\tSecretMasker.push(text -> Strings.CS.replace(text, getAccessToken(), \"******\"));\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tif (dryRun) {\n\t\t\t\t\t\t\t\t\tnew LsRemoteCommand(builder.build().toString()).refs(\"HEAD\").quiet(true).run();","sourceCodeStart":557,"sourceCodeEnd":593,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-plugin/server-plugin-import-github/src/main/java/io/onedev/server/plugin/imports/github/ImportServer.java#L557-L593","documentation":"During GitHub repository import, the target OneDev project is set up via ProjectService.setup. If the project already exists and the current user cannot manage it, an UnauthorizedException is thrown so the import never writes into a project the user does not control.","triggerScenarios":"Running ImportServer's importProjects for oneDevProjectPath that already exists in OneDev while the authenticated user lacks Project Management privilege on it.","commonSituations":"Target path already created by another team; import account with insufficient role; rerunning an import after ownership changed; path naming collisions.","solutions":["Pick a unique target project path that does not already exist","Get Project Management permission granted on the existing project","Remove or archive the existing conflicting project if appropriate","Run the import with an account that has administration rights"],"exampleFix":"// before\ntargetProjectPath = \"apps/web\"; // exists, no manage rights\n// after\ntargetProjectPath = \"apps/web-github-import\"; // or grant manage permission","handlingStrategy":"try-catch","validationCode":"Project existing = OneDev.getInstance(ProjectManager.class).findProjectByPath(oneDevProjectPath);\nif (existing != null && !SecurityUtils.canManageProject(existing))\n    throw new ValidationException(\"Cannot manage existing project: \" + oneDevProjectPath);","typeGuard":null,"tryCatchPattern":"try { importServer.importProjects(...); } catch (UnauthorizedException e) { logger.error(\"{} - choose a different path or request manage privilege\", e.getMessage()); }","preventionTips":["Pre-check target path and permissions before import","Use unique target paths per import source","Ensure the importing account has Project Management rights"],"tags":["github","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"}