-
Notifications
You must be signed in to change notification settings - Fork 1
/
current_user.go
41 lines (33 loc) · 1.38 KB
/
current_user.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
package resolvers
import (
"context"
"github.com/cmsgov/mint-app/pkg/appcontext"
"github.com/cmsgov/mint-app/pkg/authentication"
"github.com/cmsgov/mint-app/pkg/flags"
"github.com/cmsgov/mint-app/pkg/graph/model"
"github.com/cmsgov/mint-app/pkg/models"
"github.com/cmsgov/mint-app/pkg/notifications"
"github.com/cmsgov/mint-app/pkg/sqlutils"
ldclient "github.com/launchdarkly/go-server-sdk/v6"
)
// CurrentUserLaunchDarklySettingsGet returns the launch darkly settings for the current user
func CurrentUserLaunchDarklySettingsGet(ctx context.Context, ldClient *ldclient.LDClient) (*model.LaunchDarklySettings, error) {
ldContext := flags.Principal(ctx)
userKey := ldContext.Key()
signedHash := ldClient.SecureModeHash(ldContext)
LaunchDarkly := model.LaunchDarklySettings{
UserKey: userKey,
SignedHash: signedHash,
}
return &LaunchDarkly, nil
}
// CurrentUserAccountGet Gets the account of the current user in the database
func CurrentUserAccountGet(ctx context.Context) (*authentication.UserAccount, error) {
princ := appcontext.Principal(ctx)
return princ.Account(), nil
}
// CurrentUserNotificationsGet returns the notifications for the Current User
func CurrentUserNotificationsGet(ctx context.Context, np sqlutils.NamedPreparer) (*models.UserNotifications, error) {
princ := appcontext.Principal(ctx)
return notifications.UserNotificationCollectionGetByUser(ctx, np, princ)
}