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

Commit 24eba26

Browse files
authored
Merge pull request #2059 from jeremad/jrm/email_domains
feat: implement 'allowed_email_domains_list' group attribute
2 parents 8eaea58 + 4f7ea73 commit 24eba26

File tree

2 files changed

+60
-29
lines changed

2 files changed

+60
-29
lines changed

groups.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type Group struct {
8787
MarkedForDeletionOn *ISOTime `json:"marked_for_deletion_on"`
8888
CreatedAt *time.Time `json:"created_at"`
8989
IPRestrictionRanges string `json:"ip_restriction_ranges"`
90+
AllowedEmailDomainsList string `json:"allowed_email_domains_list"`
9091
WikiAccessLevel AccessControlValue `json:"wiki_access_level"`
9192

9293
// Deprecated: Use EmailsEnabled instead
@@ -383,7 +384,6 @@ type CreateGroupOptions struct {
383384
ParentID *int `url:"parent_id,omitempty" json:"parent_id,omitempty"`
384385
SharedRunnersMinutesLimit *int `url:"shared_runners_minutes_limit,omitempty" json:"shared_runners_minutes_limit,omitempty"`
385386
ExtraSharedRunnersMinutesLimit *int `url:"extra_shared_runners_minutes_limit,omitempty" json:"extra_shared_runners_minutes_limit,omitempty"`
386-
IPRestrictionRanges *string `url:"ip_restriction_ranges,omitempty" json:"ip_restriction_ranges,omitempty"`
387387
WikiAccessLevel *AccessControlValue `url:"wiki_access_level,omitempty" json:"wiki_access_level,omitempty"`
388388

389389
// Deprecated: Use EmailsEnabled instead
@@ -532,6 +532,7 @@ type UpdateGroupOptions struct {
532532
SharedRunnersSetting *SharedRunnersSettingValue `url:"shared_runners_setting,omitempty" json:"shared_runners_setting,omitempty"`
533533
PreventSharingGroupsOutsideHierarchy *bool `url:"prevent_sharing_groups_outside_hierarchy,omitempty" json:"prevent_sharing_groups_outside_hierarchy,omitempty"`
534534
IPRestrictionRanges *string `url:"ip_restriction_ranges,omitempty" json:"ip_restriction_ranges,omitempty"`
535+
AllowedEmailDomainsList *string `url:"allowed_email_domains_list,omitempty" json:"allowed_email_domains_list,omitempty"`
535536
WikiAccessLevel *AccessControlValue `url:"wiki_access_level,omitempty" json:"wiki_access_level,omitempty"`
536537

537538
// Deprecated: Use EmailsEnabled instead

groups_test.go

+58-28
Original file line numberDiff line numberDiff line change
@@ -783,49 +783,40 @@ func TestUnshareGroupFromGroup(t *testing.T) {
783783
}
784784
}
785785

786-
func TestCreateGroupWithIPRestrictionRanges(t *testing.T) {
786+
func TestUpdateGroupWithIPRestrictionRanges(t *testing.T) {
787787
mux, client := setup(t)
788+
const ipRange = "192.168.0.0/24"
788789

789-
mux.HandleFunc("/api/v4/groups",
790+
mux.HandleFunc("/api/v4/groups/1",
790791
func(w http.ResponseWriter, r *http.Request) {
791-
testMethod(t, r, http.MethodPost)
792-
fmt.Fprint(w, `{"id": 1, "name": "g", "path": "g", "ip_restriction_ranges" : "192.168.0.0/24"}`)
793-
})
794-
795-
opt := &CreateGroupOptions{
796-
Name: Ptr("g"),
797-
Path: Ptr("g"),
798-
IPRestrictionRanges: Ptr("192.168.0.0/24"),
799-
}
792+
testMethod(t, r, http.MethodPut)
800793

801-
group, _, err := client.Groups.CreateGroup(opt, nil)
802-
if err != nil {
803-
t.Errorf("Groups.CreateGroup returned error: %v", err)
804-
}
794+
body, err := io.ReadAll(r.Body)
795+
if err != nil {
796+
t.Fatalf("Failed to read the request body. Error: %v", err)
797+
}
805798

806-
want := &Group{ID: 1, Name: "g", Path: "g", IPRestrictionRanges: "192.168.0.0/24"}
807-
if !reflect.DeepEqual(want, group) {
808-
t.Errorf("Groups.CreateGroup returned %+v, want %+v", group, want)
809-
}
810-
}
799+
var bodyJson map[string]interface{}
800+
err = json.Unmarshal(body, &bodyJson)
801+
if err != nil {
802+
t.Fatalf("Failed to parse the request body into JSON. Error: %v", err)
803+
}
811804

812-
func TestUpdateGroupWithIPRestrictionRanges(t *testing.T) {
813-
mux, client := setup(t)
805+
if bodyJson["ip_restriction_ranges"] != ipRange {
806+
t.Fatalf("Test failed. `ip_restriction_ranges` expected to be '%v', got %v", ipRange, bodyJson["ip_restriction_ranges"])
807+
}
814808

815-
mux.HandleFunc("/api/v4/groups/1",
816-
func(w http.ResponseWriter, r *http.Request) {
817-
testMethod(t, r, http.MethodPut)
818-
fmt.Fprint(w, `{"id": 1, "ip_restriction_ranges" : "192.168.0.0/24"}`)
809+
fmt.Fprintf(w, `{"id": 1, "ip_restriction_ranges" : "%v"}`, ipRange)
819810
})
820811

821812
group, _, err := client.Groups.UpdateGroup(1, &UpdateGroupOptions{
822-
IPRestrictionRanges: Ptr("192.168.0.0/24"),
813+
IPRestrictionRanges: Ptr(ipRange),
823814
})
824815
if err != nil {
825816
t.Errorf("Groups.UpdateGroup returned error: %v", err)
826817
}
827818

828-
want := &Group{ID: 1, IPRestrictionRanges: "192.168.0.0/24"}
819+
want := &Group{ID: 1, IPRestrictionRanges: ipRange}
829820
if !reflect.DeepEqual(want, group) {
830821
t.Errorf("Groups.UpdatedGroup returned %+v, want %+v", group, want)
831822
}
@@ -1124,3 +1115,42 @@ func TestEditGroupPushRules(t *testing.T) {
11241115
t.Errorf("Groups.EditGroupPushRule returned %+v, want %+v", rule, want)
11251116
}
11261117
}
1118+
1119+
func TestUpdateGroupWithAllowedEmailDomainsList(t *testing.T) {
1120+
mux, client := setup(t)
1121+
const domain = "example.com"
1122+
1123+
mux.HandleFunc("/api/v4/groups/1",
1124+
func(w http.ResponseWriter, r *http.Request) {
1125+
testMethod(t, r, http.MethodPut)
1126+
1127+
body, err := io.ReadAll(r.Body)
1128+
if err != nil {
1129+
t.Fatalf("Failed to read the request body. Error: %v", err)
1130+
}
1131+
1132+
var bodyJson map[string]interface{}
1133+
err = json.Unmarshal(body, &bodyJson)
1134+
if err != nil {
1135+
t.Fatalf("Failed to parse the request body into JSON. Error: %v", err)
1136+
}
1137+
1138+
if bodyJson["allowed_email_domains_list"] != domain {
1139+
t.Fatalf("Test failed. `allowed_email_domains_list` expected to be '%v', got %v", domain, bodyJson["allowed_email_domains_list"])
1140+
}
1141+
1142+
fmt.Fprintf(w, `{"id": 1, "allowed_email_domains_list" : "%v"}`, domain)
1143+
})
1144+
1145+
group, _, err := client.Groups.UpdateGroup(1, &UpdateGroupOptions{
1146+
AllowedEmailDomainsList: Ptr(domain),
1147+
})
1148+
if err != nil {
1149+
t.Errorf("Groups.UpdateGroup returned error: %v", err)
1150+
}
1151+
1152+
want := &Group{ID: 1, AllowedEmailDomainsList: domain}
1153+
if !reflect.DeepEqual(want, group) {
1154+
t.Errorf("Groups.UpdatedGroup returned %+v, want %+v", group, want)
1155+
}
1156+
}

0 commit comments

Comments
 (0)