Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb1a755

Browse files
committed
add delete
1 parent dd53beb commit eb1a755

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

coderd/workspaceportsharing.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
// @Accept json
1818
// @Produce json
1919
// @Tags PortSharing
20-
// @Param request body codersdk.UpdatePortSharingLevelRequest true "Update port sharing level request"
20+
// @Param request body codersdk.UpdateWorkspaceAgentPortSharingLevelRequest true "Update port sharing level request"
2121
// @Success 200
2222
// @Router /workspaces/{workspace}/port-sharing [post]
2323
func (api *API) postWorkspacePortShareLevel(rw http.ResponseWriter, r *http.Request) {
@@ -87,6 +87,24 @@ func (api *API) postWorkspacePortShareLevel(rw http.ResponseWriter, r *http.Requ
8787
}
8888

8989
rw.WriteHeader(http.StatusOK)
90+
return
91+
}
92+
93+
if codersdk.WorkspacePortSharingLevel(psl.ShareLevel) == codersdk.WorkspaceAgentPortSharingLevelOwner {
94+
// If the port is shared, and the user is trying to set it to owner,
95+
// we need to remove the existing share record.
96+
err = api.Database.DeleteWorkspacePortShareLevel(ctx, database.DeleteWorkspacePortShareLevelParams{
97+
WorkspaceID: workspace.ID,
98+
AgentName: req.AgentName,
99+
Port: int32(req.Port),
100+
})
101+
if err != nil {
102+
httpapi.InternalServerError(rw, err)
103+
return
104+
}
105+
106+
rw.WriteHeader(http.StatusOK)
107+
return
90108
}
91109

92110
err = api.Database.UpdateWorkspacePortShareLevel(ctx, database.UpdateWorkspacePortShareLevelParams{

0 commit comments

Comments
 (0)