{"record":{"id":"d1f5247b937d5537","repo":"theonedev/onedev","slug":"import-target-already-exists-you-need-to-have-pro","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-gitea/src/main/java/io/onedev/server/plugin/imports/gitea/ImportServer.java","lineNumber":524,"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 giteaRepository : 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 = giteaRepository;\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 '\" + giteaRepository + \"' 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/\" + giteaRepository);\n\t\t\t\t\t\tJsonNode repoNode = JerseyUtils.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\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) {","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-plugin/server-plugin-import-gitea/src/main/java/io/onedev/server/plugin/imports/gitea/ImportServer.java#L506-L542","documentation":"When importing Gitea repositories, the target OneDev project is created/located via ProjectService.setup. If the project already exists and the current user lacks manage privilege on it, an UnauthorizedException is thrown rather than silently importing into someone else's project.","triggerScenarios":"Running importProjects when oneDevProjectPath already exists in OneDev and the authenticated user does not have Project Management permission over that existing project.","commonSituations":"Importing into a project path that another team already created; running the import with an account that has only read access; path collisions after a renamed/preceding import.","solutions":["Choose a different target project path for the import","Ask a project administrator to grant your account Project Management privilege on the existing project","Delete or rename the conflicting existing project if it is obsolete","Re-run the import as a user with sufficient privileges"],"exampleFix":"// before\noneDevProjectPath = \"team/api-server\"  // exists, owned by others\n// after\noneDevProjectPath = \"team/api-server-imported\"  // or get manage permission first","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 existing project \" + oneDevProjectPath);","typeGuard":null,"tryCatchPattern":"try { importServer.importProjects(...); } catch (UnauthorizedException e) { logger.error(\"Import blocked: {}\", e.getMessage()); /* choose new path or request permission */ }","preventionTips":["Check target project path existence and your permissions before importing","Use a dedicated import account with adequate privileges","Namespace target paths uniquely (e.g. suffix -import)"],"tags":["gitea","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"}