Skip to content

Commit

Permalink
Merge pull request #76 from Interhyp/RELTEC-10390-oauth2-proxy-new
Browse files Browse the repository at this point in the history
fix(owner): stop deleting groups when patching an owner
  • Loading branch information
Roshick authored Dec 15, 2022
2 parents 7e17acf + 3ca3f32 commit a448d58
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/v1/apimodel.go

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

14 changes: 14 additions & 0 deletions docs/openapi-v3-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions internal/service/owners/owners.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions internal/service/owners/owners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,24 @@ 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 := ""

current := openapi.OwnerDto{
Contact: "contact",
ProductOwner: &productowner,
DefaultJiraProject: &jiraproject,
Groups: &groups,
TimeStamp: "timestamp",
CommitHash: "commithash",
}
Expand All @@ -77,6 +84,7 @@ func TestPatchOwner(t *testing.T) {
Contact: "contact",
ProductOwner: &productowner,
DefaultJiraProject: &jiraproject,
Groups: &groups,
TimeStamp: "timestamp.new",
CommitHash: "commithash.new",
}
Expand All @@ -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",
}
Expand All @@ -108,6 +118,7 @@ func TestPatchOwner(t *testing.T) {
Contact: "contact",
ProductOwner: &newProductowner,
DefaultJiraProject: nil,
Groups: &groups,
TimeStamp: "timestamp.new",
CommitHash: "commithash.new",
}
Expand All @@ -123,6 +134,7 @@ func TestPatchOwner(t *testing.T) {
Contact: "contact",
ProductOwner: &productowner,
DefaultJiraProject: &newJiraproject,
Groups: &groups,
TimeStamp: "timestamp.new",
CommitHash: "commithash.new",
}
Expand Down

0 comments on commit a448d58

Please sign in to comment.