Cookies: Provide a mechanism for per user control over cookies (#61566)
This commit is contained in:
@@ -7,9 +7,16 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
var ErrPrefNotFound = errors.New("preference not found")
|
||||
var ErrUnknownCookieType = errutil.NewBase(
|
||||
errutil.StatusBadRequest,
|
||||
"preferences.unknownCookieType",
|
||||
errutil.WithPublicMessage("Got an unknown cookie preference type. Expected a set containing one or more of 'functional', 'performance', or 'analytics'}"),
|
||||
)
|
||||
|
||||
type Preference struct {
|
||||
ID int64 `xorm:"pk autoincr 'id'" db:"id"`
|
||||
@@ -27,6 +34,15 @@ type Preference struct {
|
||||
JSONData *PreferenceJSONData `xorm:"json_data" db:"json_data"`
|
||||
}
|
||||
|
||||
func (p Preference) Cookies(typ string) bool {
|
||||
if p.JSONData == nil || p.JSONData.CookiePreferences == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
_, ok := p.JSONData.CookiePreferences[typ]
|
||||
return ok
|
||||
}
|
||||
|
||||
type GetPreferenceWithDefaultsQuery struct {
|
||||
Teams []int64
|
||||
OrgID int64
|
||||
@@ -44,13 +60,14 @@ type SavePreferenceCommand struct {
|
||||
OrgID int64
|
||||
TeamID int64
|
||||
|
||||
HomeDashboardID int64 `json:"homeDashboardId,omitempty"`
|
||||
HomeDashboardUID *string `json:"homeDashboardUID,omitempty"`
|
||||
Timezone string `json:"timezone,omitempty"`
|
||||
WeekStart string `json:"weekStart,omitempty"`
|
||||
Theme string `json:"theme,omitempty"`
|
||||
Language string `json:"language,omitempty"`
|
||||
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
|
||||
HomeDashboardID int64 `json:"homeDashboardId,omitempty"`
|
||||
HomeDashboardUID *string `json:"homeDashboardUID,omitempty"`
|
||||
Timezone string `json:"timezone,omitempty"`
|
||||
WeekStart string `json:"weekStart,omitempty"`
|
||||
Theme string `json:"theme,omitempty"`
|
||||
Language string `json:"language,omitempty"`
|
||||
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
|
||||
CookiePreferences []CookieType `json:"cookiePreferences,omitempty"`
|
||||
}
|
||||
|
||||
type PatchPreferenceCommand struct {
|
||||
@@ -58,18 +75,20 @@ type PatchPreferenceCommand struct {
|
||||
OrgID int64
|
||||
TeamID int64
|
||||
|
||||
HomeDashboardID *int64 `json:"homeDashboardId,omitempty"`
|
||||
HomeDashboardUID *string `json:"homeDashboardUID,omitempty"`
|
||||
Timezone *string `json:"timezone,omitempty"`
|
||||
WeekStart *string `json:"weekStart,omitempty"`
|
||||
Theme *string `json:"theme,omitempty"`
|
||||
Language *string `json:"language,omitempty"`
|
||||
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
|
||||
HomeDashboardID *int64 `json:"homeDashboardId,omitempty"`
|
||||
HomeDashboardUID *string `json:"homeDashboardUID,omitempty"`
|
||||
Timezone *string `json:"timezone,omitempty"`
|
||||
WeekStart *string `json:"weekStart,omitempty"`
|
||||
Theme *string `json:"theme,omitempty"`
|
||||
Language *string `json:"language,omitempty"`
|
||||
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
|
||||
CookiePreferences []CookieType `json:"cookiePreferences,omitempty"`
|
||||
}
|
||||
|
||||
type PreferenceJSONData struct {
|
||||
Language string `json:"language"`
|
||||
QueryHistory QueryHistoryPreference `json:"queryHistory"`
|
||||
Language string `json:"language"`
|
||||
QueryHistory QueryHistoryPreference `json:"queryHistory"`
|
||||
CookiePreferences map[string]struct{} `json:"cookiePreferences"`
|
||||
}
|
||||
|
||||
type QueryHistoryPreference struct {
|
||||
@@ -112,3 +131,7 @@ func (j *PreferenceJSONData) ToDB() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (p Preference) TableName() string { return "preferences" }
|
||||
|
||||
// swagger:model
|
||||
// Enum: analytics,performance,functional
|
||||
type CookieType string
|
||||
|
||||
Reference in New Issue
Block a user