mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-17 20:55:28 +00:00
chore: update find shortcut
This commit is contained in:
parent
7f29882ebf
commit
874b7768c8
@ -74,10 +74,11 @@ type ShortcutFind struct {
|
|||||||
WorkspaceID *int `json:"workspaceId"`
|
WorkspaceID *int `json:"workspaceId"`
|
||||||
|
|
||||||
// Domain specific fields
|
// Domain specific fields
|
||||||
Name *string `json:"name"`
|
Name *string
|
||||||
Link *string `json:"link"`
|
Link *string
|
||||||
Description *string `json:"description"`
|
Description *string
|
||||||
Visibility *Visibility `json:"visibility"`
|
MemberID *int
|
||||||
|
VisibilityList []Visibility
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShortcutDelete struct {
|
type ShortcutDelete struct {
|
||||||
|
@ -66,8 +66,12 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
|
|||||||
|
|
||||||
g.GET("/shortcut", func(c echo.Context) error {
|
g.GET("/shortcut", func(c echo.Context) error {
|
||||||
ctx := c.Request().Context()
|
ctx := c.Request().Context()
|
||||||
shortcutFind := &api.ShortcutFind{}
|
userID, ok := c.Get(getUserIDContextKey()).(int)
|
||||||
|
if !ok {
|
||||||
|
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||||
|
}
|
||||||
|
|
||||||
|
shortcutFind := &api.ShortcutFind{}
|
||||||
if workspaceID, err := strconv.Atoi(c.QueryParam("workspaceId")); err == nil {
|
if workspaceID, err := strconv.Atoi(c.QueryParam("workspaceId")); err == nil {
|
||||||
shortcutFind.WorkspaceID = &workspaceID
|
shortcutFind.WorkspaceID = &workspaceID
|
||||||
}
|
}
|
||||||
@ -78,10 +82,24 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
|
|||||||
shortcutFind.Link = &link
|
shortcutFind.Link = &link
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := s.Store.FindShortcutList(ctx, shortcutFind)
|
list := []*api.Shortcut{}
|
||||||
|
if shortcutFind.WorkspaceID == nil {
|
||||||
|
shortcutFind.MemberID = &userID
|
||||||
|
}
|
||||||
|
shortcutFind.VisibilityList = []api.Visibility{api.VisibilityWorkspace, api.VisibilityPublic}
|
||||||
|
visibleShortcutList, err := s.Store.FindShortcutList(ctx, shortcutFind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch shortcut list").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch shortcut list").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
list = append(list, visibleShortcutList...)
|
||||||
|
|
||||||
|
shortcutFind.VisibilityList = []api.Visibility{api.VisibilityPrivite}
|
||||||
|
shortcutFind.CreatorID = &userID
|
||||||
|
privateShortcutList, err := s.Store.FindShortcutList(ctx, shortcutFind)
|
||||||
|
if err != nil {
|
||||||
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch private shortcut list").SetInternal(err)
|
||||||
|
}
|
||||||
|
list = append(list, privateShortcutList...)
|
||||||
|
|
||||||
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
||||||
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(list)); err != nil {
|
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(list)); err != nil {
|
||||||
|
@ -125,6 +125,10 @@ func (s *Server) registerWorkspaceRoutes(g *echo.Group) {
|
|||||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if shortcut.Visibility == api.VisibilityPrivite && shortcut.CreatorID != userID {
|
||||||
|
return echo.NewHTTPError(http.StatusUnauthorized, "not shortcut owner")
|
||||||
|
}
|
||||||
|
|
||||||
workspaceUser, err := s.Store.FindWordspaceUser(ctx, &api.WorkspaceUserFind{
|
workspaceUser, err := s.Store.FindWordspaceUser(ctx, &api.WorkspaceUserFind{
|
||||||
WorkspaceID: &workspace.ID,
|
WorkspaceID: &workspace.ID,
|
||||||
UserID: &userID,
|
UserID: &userID,
|
||||||
|
@ -269,8 +269,16 @@ func findShortcutList(ctx context.Context, tx *sql.Tx, find *api.ShortcutFind) (
|
|||||||
if v := find.Description; v != nil {
|
if v := find.Description; v != nil {
|
||||||
where, args = append(where, "description = ?"), append(args, *v)
|
where, args = append(where, "description = ?"), append(args, *v)
|
||||||
}
|
}
|
||||||
if v := find.Visibility; v != nil {
|
if v := find.VisibilityList; len(v) != 0 {
|
||||||
where, args = append(where, "visibility = ?"), append(args, *v)
|
list := []string{}
|
||||||
|
for _, visibility := range v {
|
||||||
|
list = append(list, fmt.Sprintf("$%d", len(args)+1))
|
||||||
|
args = append(args, visibility)
|
||||||
|
}
|
||||||
|
where = append(where, fmt.Sprintf("visibility in (%s)", strings.Join(list, ",")))
|
||||||
|
}
|
||||||
|
if v := find.MemberID; v != nil {
|
||||||
|
where, args = append(where, "workspace_id IN (SELECT workspace_id FROM workspace_user WHERE user_id = ? )"), append(args, *v)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := tx.QueryContext(ctx, `
|
rows, err := tx.QueryContext(ctx, `
|
||||||
|
Loading…
x
Reference in New Issue
Block a user