configstore: fix project/projectgroup rename
project: check name exists only if the name has changed projectgroup: add missing duplicate name check
This commit is contained in:
parent
25322a6d81
commit
8b7a5602e0
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue