Returns organizations the parameterized user has access to. @Summary Get organizations by user @ID get-organizations-by-user @Security CoderSessionToken @Produce json @Tags Users @Param user path string true "User ID, name, or me" @Success 200 {array} codersdk.Organization @Router /api/v2/users/{us
(rw http.ResponseWriter, r *http.Request)
| 1851 | // @Success 200 {array} codersdk.Organization |
| 1852 | // @Router /api/v2/users/{user}/organizations [get] |
| 1853 | func (api *API) organizationsByUser(rw http.ResponseWriter, r *http.Request) { |
| 1854 | ctx := r.Context() |
| 1855 | user := httpmw.UserParam(r) |
| 1856 | |
| 1857 | organizations, err := api.Database.GetOrganizationsByUserID(ctx, database.GetOrganizationsByUserIDParams{ |
| 1858 | UserID: user.ID, |
| 1859 | Deleted: sql.NullBool{Bool: false, Valid: true}, |
| 1860 | }) |
| 1861 | if errors.Is(err, sql.ErrNoRows) { |
| 1862 | err = nil |
| 1863 | organizations = []database.Organization{} |
| 1864 | } |
| 1865 | if err != nil { |
| 1866 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 1867 | Message: "Internal error fetching user's organizations.", |
| 1868 | Detail: err.Error(), |
| 1869 | }) |
| 1870 | return |
| 1871 | } |
| 1872 | |
| 1873 | // Only return orgs the user can read. |
| 1874 | organizations, err = AuthorizeFilter(api.HTTPAuth, r, policy.ActionRead, organizations) |
| 1875 | if err != nil { |
| 1876 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 1877 | Message: "Internal error fetching organizations.", |
| 1878 | Detail: err.Error(), |
| 1879 | }) |
| 1880 | return |
| 1881 | } |
| 1882 | |
| 1883 | httpapi.Write(ctx, rw, http.StatusOK, slice.List(organizations, db2sdk.Organization)) |
| 1884 | } |
| 1885 | |
| 1886 | // @Summary Get organization by user and organization name |
| 1887 | // @ID get-organization-by-user-and-organization-name |
nothing calls this directly
no test coverage detected