chore: data desensitize for owner

This commit is contained in:
boojack 2022-06-22 19:16:31 +08:00
parent 1999260f9d
commit 4ce728300b
9 changed files with 50 additions and 33 deletions

View file

@ -45,7 +45,6 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(user)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode user response").SetInternal(err)
}
return nil
})
@ -113,7 +112,6 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(user)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode created user response").SetInternal(err)
}
return nil
})
}

View file

@ -32,7 +32,6 @@ func setUserSession(c echo.Context, user *api.User) error {
if err != nil {
return fmt.Errorf("failed to set session, err: %w", err)
}
return nil
}
@ -48,7 +47,6 @@ func removeUserSession(c echo.Context) error {
if err != nil {
return fmt.Errorf("failed to set session, err: %w", err)
}
return nil
}

View file

@ -30,7 +30,6 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(memo)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode memo response").SetInternal(err)
}
return nil
})
@ -56,7 +55,6 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(memo)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode memo response").SetInternal(err)
}
return nil
})
@ -96,7 +94,6 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(list)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode memo list response").SetInternal(err)
}
return nil
})
@ -135,7 +132,6 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(memo)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode memo response").SetInternal(err)
}
return nil
})
@ -161,7 +157,6 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(memo)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode memo response").SetInternal(err)
}
return nil
})
@ -181,7 +176,6 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
}
c.JSON(http.StatusOK, true)
return nil
})
@ -202,7 +196,6 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(len(memoList))); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode memo amount").SetInternal(err)
}
return nil
})
}

View file

@ -56,7 +56,6 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(resource)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode resource response").SetInternal(err)
}
return nil
})
@ -74,7 +73,51 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(list)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode resource list response").SetInternal(err)
}
return nil
})
g.GET("/resource/:resourceId", func(c echo.Context) error {
resourceID, err := strconv.Atoi(c.Param("resourceId"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("resourceId"))).SetInternal(err)
}
userID := c.Get(getUserIDContextKey()).(int)
resourceFind := &api.ResourceFind{
ID: &resourceID,
CreatorID: &userID,
}
resource, err := s.Store.FindResource(resourceFind)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch resource").SetInternal(err)
}
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(resource)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode resource response").SetInternal(err)
}
return nil
})
g.GET("/resource/:resourceId/blob", func(c echo.Context) error {
resourceID, err := strconv.Atoi(c.Param("resourceId"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("resourceId"))).SetInternal(err)
}
userID := c.Get(getUserIDContextKey()).(int)
resourceFind := &api.ResourceFind{
ID: &resourceID,
CreatorID: &userID,
}
resource, err := s.Store.FindResource(resourceFind)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch resource").SetInternal(err)
}
c.Response().Writer.WriteHeader(http.StatusOK)
c.Response().Writer.Header().Set("Content-Type", resource.Type)
c.Response().Writer.Write(resource.Blob)
return nil
})
@ -92,7 +135,6 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
}
c.JSON(http.StatusOK, true)
return nil
})
}

View file

@ -29,7 +29,6 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(shortcut)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode shortcut response").SetInternal(err)
}
return nil
})
@ -55,7 +54,6 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(shortcut)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode shortcut response").SetInternal(err)
}
return nil
})
@ -73,7 +71,6 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(list)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode shortcut list response").SetInternal(err)
}
return nil
})
@ -95,7 +92,6 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(shortcut)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode shortcut response").SetInternal(err)
}
return nil
})
@ -113,7 +109,6 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
}
c.JSON(http.StatusOK, true)
return nil
})
}

View file

@ -10,11 +10,12 @@ import (
func (s *Server) registerSystemRoutes(g *echo.Group) {
g.GET("/ping", func(c echo.Context) error {
data := s.Profile
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(s.Profile)); err != nil {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(data)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to compose system profile").SetInternal(err)
}
return nil
})
@ -28,6 +29,9 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find owner user").SetInternal(err)
}
// data desensitize
ownerUser.OpenID = ""
systemStatus := api.SystemStatus{
Owner: ownerUser,
Profile: s.Profile,
@ -37,7 +41,6 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(systemStatus)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode system status response").SetInternal(err)
}
return nil
})
}

View file

@ -47,7 +47,6 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(tagList)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode tags response").SetInternal(err)
}
return nil
})
}

View file

@ -34,7 +34,6 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(user)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode user response").SetInternal(err)
}
return nil
})
@ -48,7 +47,6 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(userList)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode user list response").SetInternal(err)
}
return nil
})
@ -72,7 +70,6 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(user)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode user response").SetInternal(err)
}
return nil
})
@ -109,7 +106,6 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(user)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode user response").SetInternal(err)
}
return nil
})
@ -158,7 +154,6 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(user)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode user response").SetInternal(err)
}
return nil
})
}

View file

@ -45,7 +45,6 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(memo)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode memo response").SetInternal(err)
}
return nil
})
@ -83,7 +82,6 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(memo)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode memo response").SetInternal(err)
}
return nil
})
@ -133,7 +131,6 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(list)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode memo list response").SetInternal(err)
}
return nil
})
@ -190,7 +187,6 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(resource)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode resource response").SetInternal(err)
}
return nil
})
@ -201,12 +197,10 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
}
filename := c.Param("filename")
resourceFind := &api.ResourceFind{
ID: &resourceID,
Filename: &filename,
}
resource, err := s.Store.FindResource(resourceFind)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch resource ID: %v", resourceID)).SetInternal(err)