{"record":{"id":"a0256ecd8a3d9129","repo":"theonedev/onedev","slug":"import-target-already-exists-you-need-to-have-pro-a0256e","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-youtrack/src/main/java/io/onedev/server/plugin/imports/youtrack/ImportServer.java","lineNumber":1083,"sourceCode":"\t\t\t\tyouTrackProjectIds.put(projectName, projectNode.get(\"id\").asText());\n\t\t\t\tyouTrackProjectDescriptions.put(projectName, projectNode.get(\"description\").asText(null));\n\t\t\t}\n\n\t\t\tImportResult result = new ImportResult();\n\n\t\t\tfor (var youTrackProject : projects.getImportProjects()) {\n\t\t\t\tOneDev.getInstance(TransactionService.class).run(() -> {\n\t\t\t\t\tString oneDevProjectPath = youTrackProject;\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 '\" + youTrackProject + \"' 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\tString youTrackProjectId = youTrackProjectIds.get(youTrackProject);\n\t\t\t\t\tif (youTrackProjectId == null)\n\t\t\t\t\t\tthrow new ExplicitException(\"Unable to find YouTrack project: \" + youTrackProject);\n\n\t\t\t\t\tproject.setDescription(youTrackProjectDescriptions.get(youTrackProject));\n\t\t\t\t\tproject.setIssueManagement(true);\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}\n\n\t\t\t\t\tlogger.log(\"Importing issues...\");\n\t\t\t\t\tImportResult currentResult = doImportIssues(youTrackProjectId, project,\n\t\t\t\t\t\t\toption, dryRun, logger);","sourceCodeStart":1065,"sourceCodeEnd":1101,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-plugin/server-plugin-import-youtrack/src/main/java/io/onedev/server/plugin/imports/youtrack/ImportServer.java#L1065-L1101","documentation":"During a YouTrack issue import, OneDev sets up the target project at the given path. If the project already exists, the importing user must have management (admin) privilege over that existing project; otherwise an UnauthorizedException is thrown and the import is aborted. This prevents users from hijacking/overwriting projects they don't control.","triggerScenarios":"Running the YouTrack import targeting an oneDev project path that already exists (project.isNew() == false) while the current subject lacks canManageProject(project) — i.e. projectService.setup() returned an existing project not managed by the user.","commonSituations":"Re-running an import into a project path created earlier (possibly by another user); importing into an existing project where the user is a regular member or read-only; admin configured the import spec but a non-admin executes it.","solutions":["Choose a target project path that does not exist yet so a new project is created.","Ask a project admin to grant your account Manage privilege on the existing target project (Project -> People -> add with 'Manage Project').","Have a user with management privilege over the target project run the import instead.","Delete or rename the conflicting existing project if it is stale."],"exampleFix":"// before: import as user without manage privilege into existing path\n// target: myteam/existing-project\n// after: grant manage role, or use a fresh path\ntargetPath = \"myteam/existing-project-imported\";","handlingStrategy":"validation","validationCode":"// before importing, check target project state and privilege\nProject p = OneDev.getInstance(ProjectService.class).setup(subject, targetPath);\nif (!p.isNew() && !SecurityUtils.canManageProject(p)) {\n    throw new IllegalStateException(\"Need manage privilege over existing project \" + targetPath);\n}","typeGuard":null,"tryCatchPattern":"try {\n    importServer.run(spec);\n} catch (UnauthorizedException e) {\n    log.error(\"Insufficient privilege on import target: {}\", e.getMessage());\n}","preventionTips":["Verify your account has Manage Project on the target before starting an import into an existing path.","Prefer a fresh, non-existent target path for imports.","Re-run imports with the same user that created the target project."],"tags":["import","permission-denied","project-management"],"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"}