Beispiel #1
0
func Search(c *middleware.Context) {
	query := c.Query("query")
	tags := c.QueryStrings("tag")
	starred := c.Query("starred")
	limit := c.QueryInt("limit")

	if limit == 0 {
		limit = 1000
	}

	searchQuery := search.Query{
		Title:     query,
		Tags:      tags,
		UserId:    c.UserId,
		Limit:     limit,
		IsStarred: starred == "true",
		OrgId:     c.OrgId,
	}

	err := bus.Dispatch(&searchQuery)
	if err != nil {
		c.JsonApiErr(500, "Search failed", err)
		return
	}

	dashQuery := m.GetCurrentDashboardDashboard{}
	dashQuery.UserId = c.UserId
	err = bus.Dispatch(&dashQuery)
	if err != nil {
		c.JsonApiErr(500, "Get Dasboard Id failed", err)
		return
	}

	if c.OrgRole != "Admin" || !c.IsGrafanaAdmin {
		for index, hit := range searchQuery.Result {
			isDelete := true
			for _, dash := range dashQuery.Result {
				if dash.Id == hit.Id {
					isDelete = false
				}
			}
			if isDelete {
				last := index + 1
				if last > len(searchQuery.Result) {
					last = len(searchQuery.Result)
				}
				searchQuery.Result = append(searchQuery.Result[:index], searchQuery.Result[last:]...)
			}
		}
	}
	c.JSON(200, searchQuery.Result)
}
Beispiel #2
0
func GetDashboardsOfUser(query *m.GetCurrentDashboardDashboard) error {
	var sql bytes.Buffer
	query.Result = make([]*m.SystemDash, 0)
	params := make([]interface{}, 0)

	sql.WriteString("select system_dash.* from system_user right join system_dash on system_dash.system_id = system_user.system_id where user_id = ?")
	params = append(params, query.UserId)
	err := x.Sql(sql.String(), params...).Find(&query.Result)
	return err
}