-
Notifications
You must be signed in to change notification settings - Fork 2
/
app_data.go
61 lines (50 loc) · 1.53 KB
/
app_data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package page
import (
"context"
"net/http"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
)
type AppData struct {
Page string
Path string
Query string
Localizer Localizer
Lang localize.Lang
CookieConsentSet bool
CanGoBack bool
SessionID string
RumConfig RumConfig
StaticHash string
Paths AppPaths
LpaID string
CsrfToken string
ActorTypes actor.Types
ActorType actor.Type
AttorneyID string
OneloginURL string
AppPublicURL string
}
func (d AppData) Redirect(w http.ResponseWriter, r *http.Request, url string) error {
http.Redirect(w, r, d.Lang.URL(url), http.StatusFound)
return nil
}
func ContextWithAppData(ctx context.Context, appData AppData) context.Context {
return context.WithValue(ctx, contextKey("appData"), appData)
}
func AppDataFromContext(ctx context.Context) AppData {
appData, _ := ctx.Value(contextKey("appData")).(AppData)
return appData
}
func (d AppData) IsDonor() bool {
return d.ActorType == actor.TypeDonor
}
func (d AppData) IsCertificateProvider() bool {
return d.ActorType == actor.TypeCertificateProvider
}
func (d AppData) IsReplacementAttorney() bool {
return d.ActorType == actor.TypeReplacementAttorney
}
func (d AppData) IsTrustCorporation() bool {
return (d.ActorType == actor.TypeAttorney || d.ActorType == actor.TypeReplacementAttorney) && d.AttorneyID == ""
}