Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: don't expose projectID in respositoryCreate since it should be part of request URL (#561)

Danny Xue714604b98eb
diff --git a/api/repository.go b/api/repository.go
index a988146bf3..e0c99d7ee7 100644
--- a/api/repository.go
+++ b/api/repository.go
@@ -53,7 +53,7 @@ type RepositoryCreate struct {
// Related fields
VCSID int `jsonapi:"attr,vcsId"`
- ProjectID int `jsonapi:"attr,projectId"`
+ ProjectID int
// Domain specific fields
Name string `jsonapi:"attr,name"`
diff --git a/frontend/src/components/RepositorySetupWizard.vue b/frontend/src/components/RepositorySetupWizard.vue
index 551f262243..953f6b3a67 100644
--- a/frontend/src/components/RepositorySetupWizard.vue
+++ b/frontend/src/components/RepositorySetupWizard.vue
@@ -147,7 +147,6 @@ export default {
const createFunc = () => {
const repositoryCreate: RepositoryCreate = {
vcsId: state.config.vcs.id,
- projectId: props.project.id,
name: state.config.repositoryInfo.name,
fullPath: state.config.repositoryInfo.fullPath,
webUrl: state.config.repositoryInfo.webUrl,
@@ -161,7 +160,10 @@ export default {
refreshToken: state.config.token.refreshToken,
};
store
- .dispatch("repository/createRepository", repositoryCreate)
+ .dispatch("repository/createRepository", {
+ projectId: props.project.id,
+ repositoryCreate,
+ })
.then(() => {
allowFinishCallback();
emit("finish");
diff --git a/frontend/src/store/modules/repository.ts b/frontend/src/store/modules/repository.ts
index e4aff1d007..eb73391bfe 100644
--- a/frontend/src/store/modules/repository.ts
+++ b/frontend/src/store/modules/repository.ts
@@ -82,28 +82,28 @@ const getters = {
const actions = {
async createRepository(
{ dispatch, commit, rootGetters }: any,
- repositoryCreate: RepositoryCreate
+ {
+ projectId,
+ repositoryCreate,
+ }: { projectId: ProjectId; repositoryCreate: RepositoryCreate }
): Promise<Repository> {
const data = (
- await axios.post(
- `/api/project/${repositoryCreate.projectId}/repository`,
- {
- data: {
- type: "RepositoryCreate",
- attributes: repositoryCreate,
- },
- }
- )
+ await axios.post(`/api/project/${projectId}/repository`, {
+ data: {
+ type: "RepositoryCreate",
+ attributes: repositoryCreate,
+ },
+ })
).data;
const createdRepository = convert(data.data, data.included, rootGetters);
commit("setRepositoryByProjectId", {
- projectId: repositoryCreate.projectId,
+ projectId: projectId,
repository: createdRepository,
});
// Refetch the project as the project workflow type has been updated to "VCS"
- dispatch("project/fetchProjectById", repositoryCreate.projectId, {
+ dispatch("project/fetchProjectById", projectId, {
root: true,
});
diff --git a/frontend/src/types/repository.ts b/frontend/src/types/repository.ts
index 3884a3ff33..d7bbaf94cb 100644
--- a/frontend/src/types/repository.ts
+++ b/frontend/src/types/repository.ts
@@ -35,7 +35,6 @@ export type Repository = {
export type RepositoryCreate = {
// Related fields
vcsId: VCSId;
- projectId: ProjectId;
// Domain specific fields
name: string;
diff --git a/server/project.go b/server/project.go
index 1df4870b21..d85b2a894d 100644
--- a/server/project.go
+++ b/server/project.go
@@ -160,7 +160,14 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
// When we link the repository with the project, we will also change the project workflow type to VCS
g.POST("/project/:projectID/repository", func(c echo.Context) error {
ctx := context.Background()
- repositoryCreate := &api.RepositoryCreate{}
+ projectID, err := strconv.Atoi(c.Param("projectID"))
+ if err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("projectID"))).SetInternal(err)
+ }
+ repositoryCreate := &api.RepositoryCreate{
+ ProjectID: projectID,
+ CreatorID: c.Get(getPrincipalIDContextKey()).(int),
+ }
if err := jsonapi.UnmarshalPayload(c.Request().Body, repositoryCreate); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted create linked repository request").SetInternal(err)
}
@@ -222,7 +229,6 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
}
repositoryCreate.ExternalWebhookID = webhookID
- repositoryCreate.CreatorID = c.Get(getPrincipalIDContextKey()).(int)
// Remove enclosing /
repositoryCreate.BaseDirectory = strings.Trim(repositoryCreate.BaseDirectory, "/")
repository, err := s.RepositoryService.CreateRepository(ctx, repositoryCreate)
@@ -287,7 +293,6 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Project ID is not a number: %s", c.Param("projectID"))).SetInternal(err)
}
-
repositoryPatch := &api.RepositoryPatch{
UpdaterID: c.Get(getPrincipalIDContextKey()).(int),
}