Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: audit events for user removal from org, group and disabling org #646

Merged
merged 10 commits into from
Jun 18, 2024
1 change: 1 addition & 0 deletions core/audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const (
OrgCreatedEvent EventName = "app.organization.created"
OrgUpdatedEvent EventName = "app.organization.updated"
OrgDeletedEvent EventName = "app.organization.deleted"
OrgDisabledEvent EventName = "app.organization.disabled"
OrgMemberCreatedEvent EventName = "app.organization.member.created"
OrgMemberDeletedEvent EventName = "app.organization.member.deleted"

Expand Down
7 changes: 7 additions & 0 deletions core/group/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,5 +369,12 @@ func (s Service) Delete(ctx context.Context, id string) error {
return err
}

group, err := s.repository.GetByID(ctx, id)
anujk14 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

audit.NewLogger(ctx, group.OrganizationID).Log(audit.GroupDeletedEvent, audit.GroupTarget(id))

return s.repository.Delete(ctx, id)
}
10 changes: 9 additions & 1 deletion core/organization/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"fmt"

"github.com/raystack/frontier/core/audit"

"github.com/raystack/frontier/core/preference"

"github.com/raystack/frontier/core/policy"
Expand Down Expand Up @@ -288,6 +290,8 @@ func (s Service) RemoveUsers(ctx context.Context, orgID string, userIDs []string
}); err != nil {
err = errors.Join(err, currentErr)
}

audit.GetAuditor(ctx, orgID).Log(audit.OrgMemberDeletedEvent, audit.UserTarget(userID))
}
return err
}
Expand All @@ -297,7 +301,11 @@ func (s Service) Enable(ctx context.Context, id string) error {
}

func (s Service) Disable(ctx context.Context, id string) error {
return s.repository.SetState(ctx, id, Disabled)
err := s.repository.SetState(ctx, id, Disabled)
if err == nil {
audit.GetAuditor(ctx, id).Log(audit.OrgDisabledEvent, audit.OrgTarget(id))
}
return err
}

// DeleteModel doesn't delete the nested resource, only itself
Expand Down
1 change: 0 additions & 1 deletion internal/api/v1beta1/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ func (h Handler) RemoveOrganizationUser(ctx context.Context, request *frontierv1
logger.Error(err.Error())
return nil, grpcInternalServerError
}
audit.GetAuditor(ctx, orgResp.ID).Log(audit.OrgMemberDeletedEvent, audit.UserTarget(request.GetUserId()))
return &frontierv1beta1.RemoveOrganizationUserResponse{}, nil
}

Expand Down
Loading