-
Notifications
You must be signed in to change notification settings - Fork 0
/
invite.go
49 lines (39 loc) · 1.37 KB
/
invite.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
package cloudymsgraph
import (
"context"
"github.com/appliedres/cloudy"
cloudymodels "github.com/appliedres/cloudy/models"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
)
func init() {
cloudy.InviteProviders.Register(MsGraphName, &MsGraphInviteManagerFactory{})
}
type MsGraphInviteManagerFactory struct {
MsGraph
}
func NewMsGraphInviteManager(ctx context.Context, cfg *MsGraphConfig) (*MsGraphInviteManager, error) {
gm := &MsGraphInviteManager{
MsGraph: &MsGraph{},
}
err := gm.Configure(cfg)
return gm, err
}
func (ms *MsGraphInviteManagerFactory) Create(cfg interface{}) (cloudy.InviteManager, error) {
return NewMsGraphInviteManager(context.Background(), cfg.(*MsGraphConfig))
}
func (ms *MsGraphInviteManagerFactory) FromEnv(env *cloudy.Environment) (interface{}, error) {
cfg := fromEnvironment(env)
return cfg, nil
}
type MsGraphInviteManager struct {
*MsGraph
}
func (im *MsGraphInviteManager) CreateInvitation(ctx context.Context, user *cloudymodels.User, emailInvite bool, inviteRedirectUrl string) error {
requestBody := graphmodels.NewInvitation()
requestBody.SetInvitedUserEmailAddress(&user.Email)
requestBody.SetInvitedUserDisplayName(&user.DisplayName)
requestBody.SetSendInvitationMessage(&emailInvite)
requestBody.SetInviteRedirectUrl(&inviteRedirectUrl)
_, err := im.Client.Invitations().Post(ctx, requestBody, nil)
return err
}