zitadel/internal/v2/repository/policy/policy_org_iam.go
Fabi 65a8efeb0e
feat: New user (#1153)
* fix: use pointer in events

* fix: change user requests to command side

* fix: org policy

* fix: profile
2021-01-06 11:12:56 +01:00

79 lines
1.8 KiB
Go

package policy
import (
"encoding/json"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/v2"
"github.com/caos/zitadel/internal/eventstore/v2/repository"
)
const (
OrgIAMPolicyAddedEventType = "policy.org.iam.added"
OrgIAMPolicyChangedEventType = "policy.org.iam.changed"
)
type OrgIAMPolicyAddedEvent struct {
eventstore.BaseEvent `json:"-"`
UserLoginMustBeDomain bool `json:"userLoginMustBeDomain,omitempty"`
}
func (e *OrgIAMPolicyAddedEvent) Data() interface{} {
return e
}
func NewOrgIAMPolicyAddedEvent(
base *eventstore.BaseEvent,
userLoginMustBeDomain bool,
) *OrgIAMPolicyAddedEvent {
return &OrgIAMPolicyAddedEvent{
BaseEvent: *base,
UserLoginMustBeDomain: userLoginMustBeDomain,
}
}
func OrgIAMPolicyAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e := &OrgIAMPolicyAddedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
if err != nil {
return nil, errors.ThrowInternal(err, "POLIC-TvSmA", "unable to unmarshal policy")
}
return e, nil
}
type OrgIAMPolicyChangedEvent struct {
eventstore.BaseEvent `json:"-"`
UserLoginMustBeDomain *bool `json:"userLoginMustBeDomain,omitempty"`
}
func (e *OrgIAMPolicyChangedEvent) Data() interface{} {
return e
}
func NewOrgIAMPolicyChangedEvent(
base *eventstore.BaseEvent,
) *OrgIAMPolicyChangedEvent {
return &OrgIAMPolicyChangedEvent{
BaseEvent: *base,
}
}
func OrgIAMPolicyChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e := &OrgIAMPolicyChangedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
if err != nil {
return nil, errors.ThrowInternal(err, "POLIC-0Pl9d", "unable to unmarshal policy")
}
return e, nil
}