func (e *Engine) ApproveInvite(ctx context.Context, notifier *observer.Notifier,
	InviteID *identity.ID) (*envelope.Unsigned, error) {

	n := notifier.Notifier(3)

	invite, err := e.client.OrgInvite.Get(ctx, InviteID)
	if err != nil {
		log.Printf("could not fetch org invitation: %s", err)
		return nil, err
	}

	inviteBody := invite.Body.(*primitive.OrgInvite)

	if inviteBody.State != primitive.OrgInviteAcceptedState {
		log.Printf("invitation not in accepted state: %s", inviteBody.State)
		return nil, &apitypes.Error{
			Type: apitypes.BadRequestError,
			Err:  []string{"Invite must be accepted before it can be approved"},
		}
	}

	n.Notify(observer.Progress, "Invite retrieved", true)

	v1members, v2members, err := createKeyringMemberships(ctx, e.crypto,
		e.client, e.session, inviteBody.OrgID, inviteBody.InviteeID)
	if err != nil {
		return nil, err
	}

	n.Notify(observer.Progress, "Keyring memberships created", true)

	invite, err = e.client.OrgInvite.Approve(ctx, InviteID)
	if err != nil {
		log.Printf("could not approve org invite: %s", err)
		return nil, err
	}

	n.Notify(observer.Progress, "Invite approved", true)

	if len(v1members) != 0 {
		_, err = e.client.KeyringMember.Post(ctx, v1members)
		if err != nil {
			log.Printf("error uploading memberships: %s", err)
			return nil, err
		}
	}

	for _, member := range v2members {
		err = e.client.Keyring.Members.Post(ctx, member)
		if err != nil {
			log.Printf("error uploading memberships: %s", err)
			return nil, err
		}
	}

	return invite, nil
}
// ApproveInvite approves an invitation of a user into an organzation by
// encoding them into a Keyring.
ApproveInvite approves an invitation of a user into an organzation by
encoding them into a Keyring.
// ApproveInvite approves an invitation of a user into an organzation by // encoding them into a Keyring .
func (e *Engine) ApproveInvite(ctx context.Context, notifier *observer.Notifier,
	InviteID *identity.ID) (*envelope.Unsigned, error) {
	n := notifier.Notifier(3)
	invite, err := e.client.OrgInvite.Get(ctx, InviteID)
	if err != nil {
		log.Printf("could not fetch org invitation: %s", err)
		return nil, err
	}
	inviteBody := invite.Body.(*primitive.OrgInvite)
	if inviteBody.State != primitive.OrgInviteAcceptedState {
		log.Printf("invitation not in accepted state: %s", inviteBody.State)
		return nil, &apitypes.Error{
			Type: apitypes.BadRequestError,
			Err:  []string{"Invite must be accepted before it can be approved"},
		}
	}
	n.Notify(observer.Progress, "Invite retrieved", true)
	v1members, v2members, err := createKeyringMemberships(ctx, e.crypto,
		e.client, e.session, inviteBody.OrgID, inviteBody.InviteeID)
	if err != nil {
		return nil, err
	}
	n.Notify(observer.Progress, "Keyring memberships created", true)
	invite, err = e.client.OrgInvite.Approve(ctx, InviteID)
	if err != nil {
		log.Printf("could not approve org invite: %s", err)
		return nil, err
	}
	n.Notify(observer.Progress, "Invite approved", true)
	if len(v1members) != 0 {
		_, err = e.client.KeyringMember.Post(ctx, v1members)
		if err != nil {
			log.Printf("error uploading memberships: %s", err)
			return nil, err
		}
	}
	for _, member := range v2members {
		err = e.client.Keyring.Members.Post(ctx, member)
		if err != nil {
			log.Printf("error uploading memberships: %s", err)
			return nil, err
		}
	}
	return invite, nil
}
func ( e * Engine ) ApproveInvite ( ctx context . Context , notifier * observer . Notifier , InviteID * identity . ID ) ( * envelope . Unsigned , error ) { n := notifier . Notifier ( 3 ) invite , err := e . client . OrgInvite . Get ( ctx , InviteID ) if err != nil { log . Printf ( " " , err ) return nil , err } inviteBody := invite . Body . ( * primitive . OrgInvite ) if inviteBody . State != primitive . OrgInviteAcceptedState { log . Printf ( " " , inviteBody . State ) return nil , & apitypes . Error { Type : apitypes . BadRequestError , Err : [ ] string { " " } , } } n . Notify ( observer . Progress , " " , true ) v1members , v2members , err := createKeyringMemberships ( ctx , e . crypto , e . client , e . session , inviteBody . OrgID , inviteBody . InviteeID ) if err != nil { return nil , err } n . Notify ( observer . Progress , " " , true ) invite , err = e . client . OrgInvite . Approve ( ctx , InviteID ) if err != nil { log . Printf ( " " , err ) return nil , err } n . Notify ( observer . Progress , " " , true ) if len ( v1members ) != 0 { _ , err = e . client . KeyringMember . Post ( ctx , v1members ) if err != nil { log . Printf ( " " , err ) return nil , err } } for _ , member := range v2members { err = e . client . Keyring . Members . Post ( ctx , member ) if err != nil { log . Printf ( " " , err ) return nil , err } } return invite , nil }
ApproveInvite approves an invitation of a user into an organzation by
encoding them into a Keyring.
ApproveInvite approves an invitation of a user into an organzation by encoding them into a Keyring .