{"record":{"id":"1dad367adfa9deec","repo":"theonedev/onedev","slug":"import-target-already-exists-you-need-to-have-pro-1dad36","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-jiracloud/src/main/java/io/onedev/server/plugin/imports/jiracloud/ImportServer.java","lineNumber":367,"sourceCode":"\tTaskResult importProjects(ImportProjects projects, ImportOption 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\tMap<String, JsonNode> projectNodes = getProjectNodes(logger);\n\t\t\tImportResult result = new ImportResult();\n\t\t\tfor (var jiraProject: projects.getImportProjects()) {\n\t\t\t\tOneDev.getInstance(TransactionService.class).run(() -> {\n\t\t\t\t\tString oneDevProjectPath = jiraProject;\n\t\t\t\t\tif (projects.getParentOneDevProject() != null)\n\t\t\t\t\t\toneDevProjectPath = projects.getParentOneDevProject() + \"/\" + oneDevProjectPath;\n\n\t\t\t\t\tlogger.log(\"Importing from '\" + jiraProject + \"' to '\" + oneDevProjectPath + \"'...\");\n\n\t\t\t\t\tProjectService projectService = OneDev.getInstance(ProjectService.class);\n\t\t\t\t\tProject project = projectService.setup(SecurityUtils.getSubject(), oneDevProjectPath);\n\n\t\t\t\t\tif (!project.isNew() && !SecurityUtils.canManageProject(project)) {\n\t\t\t\t\t\tthrow new UnauthorizedException(\"Import target already exists. \" +\n\t\t\t\t\t\t\t\t\"You need to have project management privilege over it\");\n\t\t\t\t\t}\n\n\t\t\t\t\tJsonNode projectNode = projectNodes.get(jiraProject);\n\t\t\t\t\tif (projectNode == null)\n\t\t\t\t\t\tthrow new ExplicitException(\"Unable to find project: \" + jiraProject);\n\n\t\t\t\t\tString apiEndpoint = getApiEndpoint(\"/project/\" + projectNode.get(\"id\").asText());\n\n\t\t\t\t\t// Get more detail project information\n\t\t\t\t\tprojectNode = JerseyUtils.get(client, apiEndpoint, logger);\n\n\t\t\t\t\tproject.setDescription(projectNode.get(\"description\").asText(null));\n\n\t\t\t\t\tif (!dryRun && project.isNew()) {\n\t\t\t\t\t\tprojectService.create(SecurityUtils.getUser(), project);\n\t\t\t\t\t\tOneDev.getInstance(AuditService.class).audit(project, \"created project\", null, VersionedXmlDoc.fromBean(project).toXML());\n\t\t\t\t\t}","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-plugin/server-plugin-import-jiracloud/src/main/java/io/onedev/server/plugin/imports/jiracloud/ImportServer.java#L349-L385","documentation":"Thrown as an UnauthorizedException by the Jira Cloud import's importProjects() when the target OneDev project path already exists (ProjectService.setup returned an existing project) but the current user lacks manage privilege over that project. Importing would write content into a project the user does not control, so the operation is refused before any data is read from Jira.","triggerScenarios":"Calling the Jira Cloud import (doImport -> importProjects) with a oneDevProjectPath that already exists in OneDev while the authenticated subject fails SecurityUtils.canManageProject(project). Happens for every Jira project mapped to an existing path without Project Manage permission.","commonSituations":"Re-running an import into a project created by another user or an earlier import; overlapping project path that collides with an existing project; running the import with a non-admin account that can create projects but cannot manage the pre-existing target.","solutions":["Grant the importing user Project Manage privilege over the existing target project, then re-run the import.","Choose a different target project path in the import mapping so ProjectService.setup creates a new project the user owns.","Delete or rename the conflicting existing project if it is a stale artifact from a previous import attempt.","Run the import as a project/server administrator who has manage rights over the existing path."],"exampleFix":"// before: importing into existing project without manage rights\noneDevProjectPath = \"team/legacy\"   // exists, user has only READ access\n// after: grant manage permission or use fresh path\noneDevProjectPath = \"team/legacy-import\"  // new project created and owned by importer","handlingStrategy":"try-catch","validationCode":"Project p = OneDev.getInstance(ProjectService.class).find(oneDevProjectPath);\nif (p != null && !SecurityUtils.canManageProject(p))\n    throw new IllegalStateException(\"No manage privilege over \" + oneDevProjectPath);","typeGuard":null,"tryCatchPattern":"try { importServer.doImport(...) } catch (UnauthorizedException e) { logger.error(\"Grant manage privilege or pick another target path: \" + e.getMessage()); }","preventionTips":["Grant the importing user manage rights over pre-existing targets before importing.","Use unique target paths per import run.","Run imports with an account holding sufficient project privileges."],"tags":["import","jira-cloud","authorization","permissions"],"backgroundTag":"permission-denied","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}