diff --git a/internal/services/configstore/action/project.go b/internal/services/configstore/action/project.go index 55f4301..4730570 100644 --- a/internal/services/configstore/action/project.go +++ b/internal/services/configstore/action/project.go @@ -197,18 +197,21 @@ func (h *ActionHandler) UpdateProject(ctx context.Context, req *UpdateProjectReq return util.NewErrBadRequest(errors.Errorf("changing project parent isn't supported")) } - pp, err := h.readDB.GetProjectPath(tx, p) + groupPath, err := h.readDB.GetProjectGroupPath(tx, group) if err != nil { return err } + pp := path.Join(groupPath, req.Project.Name) - // check duplicate project name - ap, err := h.readDB.GetProjectByName(tx, req.Project.Parent.ID, req.Project.Name) - if err != nil { - return err - } - if ap != nil { - return util.NewErrBadRequest(errors.Errorf("project with name %q, path %q already exists", p.Name, pp)) + if p.Name != req.Project.Name { + // check duplicate project name + ap, err := h.readDB.GetProjectByName(tx, req.Project.Parent.ID, req.Project.Name) + if err != nil { + return err + } + if ap != nil { + return util.NewErrBadRequest(errors.Errorf("project with name %q, path %q already exists", req.Project.Name, pp)) + } } // changegroup is the project path. Use "projectpath" prefix as it must diff --git a/internal/services/configstore/action/projectgroup.go b/internal/services/configstore/action/projectgroup.go index 5b3362d..c807270 100644 --- a/internal/services/configstore/action/projectgroup.go +++ b/internal/services/configstore/action/projectgroup.go @@ -226,10 +226,22 @@ func (h *ActionHandler) UpdateProjectGroup(ctx context.Context, req *UpdateProje req.ProjectGroup.Name = "" } - pgp, err := h.readDB.GetProjectGroupPath(tx, pg) + pgPath, err := h.readDB.GetProjectGroupPath(tx, pg) if err != nil { return err } + pgp := path.Join(path.Dir(pgPath), req.ProjectGroup.Name) + + if pg.Name != req.ProjectGroup.Name { + // check duplicate project group name + ap, err := h.readDB.GetProjectGroupByName(tx, req.ProjectGroup.Parent.ID, req.ProjectGroup.Name) + if err != nil { + return err + } + if ap != nil { + return util.NewErrBadRequest(errors.Errorf("project group with name %q, path %q already exists", req.ProjectGroup.Name, pgp)) + } + } // changegroup is the project group path. Use "projectpath" prefix as it must // cover both projects and projectgroups