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:
Simone Gotti 2019-07-08 18:12:42 +02:00
parent 25322a6d81
commit 8b7a5602e0
2 changed files with 24 additions and 9 deletions

View File

@ -197,18 +197,21 @@ func (h *ActionHandler) UpdateProject(ctx context.Context, req *UpdateProjectReq
return util.NewErrBadRequest(errors.Errorf("changing project parent isn't supported")) 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 { if err != nil {
return err return err
} }
pp := path.Join(groupPath, req.Project.Name)
if p.Name != req.Project.Name {
// check duplicate project name // check duplicate project name
ap, err := h.readDB.GetProjectByName(tx, req.Project.Parent.ID, req.Project.Name) ap, err := h.readDB.GetProjectByName(tx, req.Project.Parent.ID, req.Project.Name)
if err != nil { if err != nil {
return err return err
} }
if ap != nil { if ap != nil {
return util.NewErrBadRequest(errors.Errorf("project with name %q, path %q already exists", p.Name, pp)) 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 // changegroup is the project path. Use "projectpath" prefix as it must

View File

@ -226,10 +226,22 @@ func (h *ActionHandler) UpdateProjectGroup(ctx context.Context, req *UpdateProje
req.ProjectGroup.Name = "" req.ProjectGroup.Name = ""
} }
pgp, err := h.readDB.GetProjectGroupPath(tx, pg) pgPath, err := h.readDB.GetProjectGroupPath(tx, pg)
if err != nil { if err != nil {
return err 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 // changegroup is the project group path. Use "projectpath" prefix as it must
// cover both projects and projectgroups // cover both projects and projectgroups