From 3ca3f32d64353bbed16ff87cd9409bd19d295bb8 Mon Sep 17 00:00:00 2001 From: Roshick Date: Thu, 15 Dec 2022 14:18:22 +0100 Subject: [PATCH] fix(owner): stop deleting groups when patching an owner --- api/v1/apimodel.go | 2 ++ docs/openapi-v3-spec.json | 14 ++++++++++++++ internal/service/owners/owners.go | 12 ++++++++++++ internal/service/owners/owners_test.go | 12 ++++++++++++ 4 files changed, 40 insertions(+) diff --git a/api/v1/apimodel.go b/api/v1/apimodel.go index 8a475b5..541634c 100644 --- a/api/v1/apimodel.go +++ b/api/v1/apimodel.go @@ -63,6 +63,8 @@ type OwnerPatchDto struct { Contact *string `json:"contact,omitempty"` // The product owner of this owner space ProductOwner *string `json:"productOwner,omitempty"` + // Map of string (group name e.g. some-owner) of strings (list of usernames), one username for each group is required. + Groups *map[string][]string `json:"groups,omitempty" yaml:"groups,omitempty"` // A list of users that are allowed to promote services in this owner space Promoters []string `json:"promoters,omitempty"` // The default jira project that is used by this owner space diff --git a/docs/openapi-v3-spec.json b/docs/openapi-v3-spec.json index 60431c2..c6a6aa3 100644 --- a/docs/openapi-v3-spec.json +++ b/docs/openapi-v3-spec.json @@ -2006,6 +2006,20 @@ "description": "The product owner of this owner space", "example": "kschlangenheld" }, + "groups": { + "type": "object", + "description": "Map of string (group name e.g. some-owner) of strings (list of usernames), one username for each group is required.", + "example": { + "some-owner": { + } + }, + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } + }, "promoters": { "type": "array", "description": "A list of users that are allowed to promote services in this owner space", diff --git a/internal/service/owners/owners.go b/internal/service/owners/owners.go index 677640a..7694569 100644 --- a/internal/service/owners/owners.go +++ b/internal/service/owners/owners.go @@ -259,6 +259,7 @@ func patchOwner(current openapi.OwnerDto, patch openapi.OwnerPatchDto) openapi.O ProductOwner: patchStringPtr(patch.ProductOwner, current.ProductOwner), DefaultJiraProject: patchStringPtr(patch.DefaultJiraProject, current.DefaultJiraProject), Promoters: patchStringArray(patch.Promoters, current.Promoters), + Groups: patchStringToStringArrayMapPtr(patch.Groups, current.Groups), TimeStamp: patch.TimeStamp, CommitHash: patch.CommitHash, JiraIssue: patch.JiraIssue, @@ -294,6 +295,17 @@ func patchStringArray(patch []string, original []string) []string { } } +func patchStringToStringArrayMapPtr(patch *map[string][]string, original *map[string][]string) *map[string][]string { + if patch == nil { + return original + } + if len(*patch) == 0 { + return original + } else { + return patch + } +} + func (s *Impl) DeleteOwner(ctx context.Context, ownerAlias string, deletionInfo openapi.DeletionDto) error { if err := s.validateDeletionDto(ctx, deletionInfo); err != nil { return err diff --git a/internal/service/owners/owners_test.go b/internal/service/owners/owners_test.go index ee6cf30..e695113 100644 --- a/internal/service/owners/owners_test.go +++ b/internal/service/owners/owners_test.go @@ -53,10 +53,16 @@ func TestPatchOwner(t *testing.T) { productowner := "productowner" jiraproject := "jira" + groups := map[string][]string{ + "group0": {"user1", "user2"}, + } newProductowner := "productowner.new" newJiraproject := "jira.new" newContact := "contact.new" + newGroups := map[string][]string{ + "group1": {"user1"}, + } emptyJiraproject := "" @@ -64,6 +70,7 @@ func TestPatchOwner(t *testing.T) { Contact: "contact", ProductOwner: &productowner, DefaultJiraProject: &jiraproject, + Groups: &groups, TimeStamp: "timestamp", CommitHash: "commithash", } @@ -77,6 +84,7 @@ func TestPatchOwner(t *testing.T) { Contact: "contact", ProductOwner: &productowner, DefaultJiraProject: &jiraproject, + Groups: &groups, TimeStamp: "timestamp.new", CommitHash: "commithash.new", } @@ -86,12 +94,14 @@ func TestPatchOwner(t *testing.T) { Contact: &newContact, TimeStamp: "timestamp.new", CommitHash: "commithash.new", + Groups: &newGroups, } actual1 := patchOwner(current, patch1) expected1 := openapi.OwnerDto{ Contact: "contact.new", ProductOwner: &productowner, DefaultJiraProject: &jiraproject, + Groups: &newGroups, TimeStamp: "timestamp.new", CommitHash: "commithash.new", } @@ -108,6 +118,7 @@ func TestPatchOwner(t *testing.T) { Contact: "contact", ProductOwner: &newProductowner, DefaultJiraProject: nil, + Groups: &groups, TimeStamp: "timestamp.new", CommitHash: "commithash.new", } @@ -123,6 +134,7 @@ func TestPatchOwner(t *testing.T) { Contact: "contact", ProductOwner: &productowner, DefaultJiraProject: &newJiraproject, + Groups: &groups, TimeStamp: "timestamp.new", CommitHash: "commithash.new", }