1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2025-11-29 21:48:14 +02:00

Use middleware to load org (#4208)

Co-authored-by: Anbraten <6918444+anbraten@users.noreply.github.com>
Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
6543
2024-10-09 12:05:01 +02:00
committed by GitHub
parent 770ccabf54
commit 98d7b1b500
7 changed files with 142 additions and 154 deletions

View File

@@ -292,14 +292,9 @@ func PostOrgAgent(c *gin.Context) {
// @Param perPage query int false "for response pagination, max items per page" default(50)
func GetOrgAgents(c *gin.Context) {
_store := store.FromContext(c)
org := session.Org(c)
orgID, err := strconv.ParseInt(c.Param("org_id"), 10, 64)
if err != nil {
c.String(http.StatusBadRequest, "Error parsing org id. %s", err)
return
}
agents, err := _store.AgentListForOrg(orgID, session.Pagination(c))
agents, err := _store.AgentListForOrg(org.ID, session.Pagination(c))
if err != nil {
c.String(http.StatusInternalServerError, "Error getting agent list. %s", err)
return
@@ -321,12 +316,7 @@ func GetOrgAgents(c *gin.Context) {
// @Param agent body Agent true "the agent's updated data"
func PatchOrgAgent(c *gin.Context) {
_store := store.FromContext(c)
orgID, err := strconv.ParseInt(c.Param("org_id"), 10, 64)
if err != nil {
c.String(http.StatusBadRequest, "Invalid organization ID")
return
}
org := session.Org(c)
agentID, err := strconv.ParseInt(c.Param("agent_id"), 10, 64)
if err != nil {
@@ -340,7 +330,7 @@ func PatchOrgAgent(c *gin.Context) {
return
}
if agent.OrgID != orgID {
if agent.OrgID != org.ID {
c.String(http.StatusBadRequest, "Agent does not belong to this organization")
return
}
@@ -378,12 +368,7 @@ func PatchOrgAgent(c *gin.Context) {
// @Param agent_id path int true "the agent's id"
func DeleteOrgAgent(c *gin.Context) {
_store := store.FromContext(c)
orgID, err := strconv.ParseInt(c.Param("org_id"), 10, 64)
if err != nil {
c.String(http.StatusBadRequest, "Invalid organization ID")
return
}
org := session.Org(c)
agentID, err := strconv.ParseInt(c.Param("agent_id"), 10, 64)
if err != nil {
@@ -397,7 +382,7 @@ func DeleteOrgAgent(c *gin.Context) {
return
}
if agent.OrgID != orgID {
if agent.OrgID != org.ID {
c.String(http.StatusBadRequest, "Agent does not belong to this organization")
return
}