Skip to content

Commit

Permalink
feat(appeal): introduce appeal activities (#151)
Browse files Browse the repository at this point in the history
* feat(appeal): introduce appeal activities

* test: migrate audit logs in repository test

* feat: add affected_approver in audit data

* chore: remove todo

* chore: add edit appeal in activity filter

* test: fix unit test for activity

* chore: update proton commit
  • Loading branch information
rahmatrhd authored May 30, 2024
1 parent e212d92 commit e54f816
Show file tree
Hide file tree
Showing 22 changed files with 2,539 additions and 1,571 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ COMMIT := $(shell git rev-parse --short HEAD)
TAG := "$(shell git rev-list --tags --max-count=1)"
VERSION := "$(shell git describe --tags ${TAG})-next"
BUILD_DIR=dist
PROTON_COMMIT := "6fdca7f234f339540c675cc6db64f2483a6f4db5"
PROTON_COMMIT := "2f8662142874bc191fa932a28cf9e808103018cd"

.PHONY: all build clean test tidy vet proto setup format generate

Expand Down
22 changes: 22 additions & 0 deletions api/handler/v1beta1/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,28 @@ func (a *adapter) fromConditionProto(c *guardianv1beta1.Condition) *domain.Condi
}
}

func (a *adapter) ToAppealActivityProto(e *domain.Event) (*guardianv1beta1.AppealActivity, error) {
if e == nil {
return nil, nil
}

activityProto := &guardianv1beta1.AppealActivity{
AppealId: e.ParentID,
Timestamp: timestamppb.New(e.Timestamp),
Type: e.Type,
Actor: e.Actor,
}

if e.Data != nil {
data, err := structpb.NewStruct(e.Data)
if err != nil {
return nil, err
}
activityProto.Data = data
}
return activityProto, nil
}

func (a *adapter) toConditionProto(c *domain.Condition) (*guardianv1beta1.Condition, error) {
if c == nil {
return nil, nil
Expand Down
20 changes: 20 additions & 0 deletions api/handler/v1beta1/appeal.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,26 @@ func (s *GRPCServer) CancelAppeal(ctx context.Context, req *guardianv1beta1.Canc
}, nil
}

func (s *GRPCServer) ListAppealActivities(ctx context.Context, req *guardianv1beta1.ListAppealActivitiesRequest) (*guardianv1beta1.ListAppealActivitiesResponse, error) {
activities, err := s.appealService.ListActivities(ctx, req.GetAppealId())
if err != nil {
return nil, s.internalError(ctx, "failed to get appeal activities: %v", err)
}

activityProtos := make([]*guardianv1beta1.AppealActivity, 0, len(activities))
for _, a := range activities {
activityProto, err := s.adapter.ToAppealActivityProto(a)
if err != nil {
return nil, s.internalError(ctx, "failed to parse appeal activity: %v", err)
}
activityProtos = append(activityProtos, activityProto)
}

return &guardianv1beta1.ListAppealActivitiesResponse{
Activities: activityProtos,
}, nil
}

func (s *GRPCServer) listAppeals(ctx context.Context, filters *domain.ListAppealsFilter) ([]*guardianv1beta1.Appeal, int64, error) {
eg, ctx := errgroup.WithContext(ctx)
var appeals []*domain.Appeal
Expand Down
2 changes: 2 additions & 0 deletions api/handler/v1beta1/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ProtoAdapter interface {
ToActivityProto(*domain.Activity) (*guardianv1beta1.ProviderActivity, error)

ToCommentProto(*domain.Comment) *guardianv1beta1.AppealComment
ToAppealActivityProto(e *domain.Event) (*guardianv1beta1.AppealActivity, error)
}

//go:generate mockery --name=resourceService --exported --with-expecter
Expand Down Expand Up @@ -99,6 +100,7 @@ type appealService interface {
UpdateApproval(ctx context.Context, approvalAction domain.ApprovalAction) (*domain.Appeal, error)
ListComments(context.Context, domain.ListCommentsFilter) ([]*domain.Comment, error)
CreateComment(context.Context, *domain.Comment) error
ListActivities(context.Context, string) ([]*domain.Event, error)
}

//go:generate mockery --name=approvalService --exported --with-expecter
Expand Down
55 changes: 55 additions & 0 deletions api/handler/v1beta1/mocks/appealService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e54f816

Please sign in to comment.