Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
feat: implement 'allowed_email_domains_list' group attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremad committed Nov 15, 2024
1 parent 8eaea58 commit cfed26b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type Group struct {
MarkedForDeletionOn *ISOTime `json:"marked_for_deletion_on"`
CreatedAt *time.Time `json:"created_at"`
IPRestrictionRanges string `json:"ip_restriction_ranges"`
AllowedEmailDomainsList string `json:"allowed_email_domains_list"`
WikiAccessLevel AccessControlValue `json:"wiki_access_level"`

// Deprecated: Use EmailsEnabled instead
Expand Down Expand Up @@ -532,6 +533,7 @@ type UpdateGroupOptions struct {
SharedRunnersSetting *SharedRunnersSettingValue `url:"shared_runners_setting,omitempty" json:"shared_runners_setting,omitempty"`
PreventSharingGroupsOutsideHierarchy *bool `url:"prevent_sharing_groups_outside_hierarchy,omitempty" json:"prevent_sharing_groups_outside_hierarchy,omitempty"`
IPRestrictionRanges *string `url:"ip_restriction_ranges,omitempty" json:"ip_restriction_ranges,omitempty"`
AllowedEmailDomainsList *string `url:"allowed_email_domains_list,omitempty" json:"allowed_email_domains_list,omitempty"`
WikiAccessLevel *AccessControlValue `url:"wiki_access_level,omitempty" json:"wiki_access_level,omitempty"`

// Deprecated: Use EmailsEnabled instead
Expand Down
39 changes: 39 additions & 0 deletions groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,3 +1124,42 @@ func TestEditGroupPushRules(t *testing.T) {
t.Errorf("Groups.EditGroupPushRule returned %+v, want %+v", rule, want)
}
}

func TestUpdateGroupWithAllowedEmailDomainsList(t *testing.T) {
mux, client := setup(t)
const domain = "example.com"

mux.HandleFunc("/api/v4/groups/1",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)

body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("Failed to read the request body. Error: %v", err)
}

var bodyJson map[string]interface{}
err = json.Unmarshal(body, &bodyJson)
if err != nil {
t.Fatalf("Failed to parse the request body into JSON. Error: %v", err)
}

if bodyJson["allowed_email_domains_list"] != domain {
t.Fatalf("Test failed. `allowed_email_domains_list` expected to be '%v', got %v", domain, bodyJson["allowed_email_domains_list"])
}

fmt.Fprintf(w, `{"id": 1, "allowed_email_domains_list" : "%v"}`, domain)
})

group, _, err := client.Groups.UpdateGroup(1, &UpdateGroupOptions{
AllowedEmailDomainsList: Ptr(domain),
})
if err != nil {
t.Errorf("Groups.UpdateGroup returned error: %v", err)
}

want := &Group{ID: 1, AllowedEmailDomainsList: domain}
if !reflect.DeepEqual(want, group) {
t.Errorf("Groups.UpdatedGroup returned %+v, want %+v", group, want)
}
}

0 comments on commit cfed26b

Please sign in to comment.