mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-07 07:16:54 +00:00
fix: set correct owner on project grants
This commit is contained in:
@@ -125,7 +125,18 @@ func scanToSequence(rows *sql.Rows, sequences []*latestSequence) error {
|
||||
return nil
|
||||
}
|
||||
sequence.sequence = currentSequence
|
||||
if sequence.aggregate.ResourceOwner == "" {
|
||||
if resourceOwner != "" && sequence.aggregate.ResourceOwner != "" && sequence.aggregate.ResourceOwner != resourceOwner {
|
||||
logging.WithFields(
|
||||
"current_sequence", sequence.sequence,
|
||||
"instance_id", sequence.aggregate.InstanceID,
|
||||
"agg_type", sequence.aggregate.Type,
|
||||
"agg_id", sequence.aggregate.ID,
|
||||
"current_owner", resourceOwner,
|
||||
"provided_owner", sequence.aggregate.ResourceOwner,
|
||||
).Info("would have set wrong resource owner")
|
||||
}
|
||||
// set resource owner from previous events
|
||||
if resourceOwner != "" {
|
||||
sequence.aggregate.ResourceOwner = resourceOwner
|
||||
}
|
||||
|
||||
|
||||
@@ -93,6 +93,10 @@ func (p *projectGrantProjection) Reducers() []handler.AggregateReducer {
|
||||
Event: project.ProjectRemovedType,
|
||||
Reduce: p.reduceProjectRemoved,
|
||||
},
|
||||
{
|
||||
Event: project.ProjectOwnerCorrected,
|
||||
Reduce: p.reduceOwnerCorrected,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -269,3 +273,16 @@ func (p *projectGrantProjection) reduceOwnerRemoved(event eventstore.Event) (*ha
|
||||
),
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *projectGrantProjection) reduceOwnerCorrected(event eventstore.Event) (*handler.Statement, error) {
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(ProjectGrantColumnResourceOwner, event.Aggregate().ResourceOwner),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ProjectGrantColumnInstanceID, event.Aggregate().InstanceID),
|
||||
handler.NewCond(ProjectGrantColumnProjectID, event.Aggregate().ID),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
40
internal/repository/owner/owner_corrected.go
Normal file
40
internal/repository/owner/owner_corrected.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package owner
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
)
|
||||
|
||||
const OwnerCorrectedType = ".owner.corrected"
|
||||
|
||||
type Corrected struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
PreviousOwners map[uint32]string `json:"previousOwners,omitempty"`
|
||||
}
|
||||
|
||||
var _ eventstore.Command = (*Corrected)(nil)
|
||||
|
||||
func (e *Corrected) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *Corrected) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewCorrected(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
previousOwners map[uint32]string,
|
||||
) *Corrected {
|
||||
return &Corrected{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
aggregate,
|
||||
eventstore.EventType(aggregate.Type+OwnerCorrectedType),
|
||||
),
|
||||
PreviousOwners: previousOwners,
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ const (
|
||||
ProjectDeactivatedType = projectEventTypePrefix + "deactivated"
|
||||
ProjectReactivatedType = projectEventTypePrefix + "reactivated"
|
||||
ProjectRemovedType = projectEventTypePrefix + "removed"
|
||||
ProjectOwnerCorrected = projectEventTypePrefix + "owner.corrected"
|
||||
|
||||
ProjectSearchType = "project"
|
||||
ProjectObjectRevision = uint8(1)
|
||||
|
||||
Reference in New Issue
Block a user