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

Commit 3939b35

Browse files
authored
Merge pull request #1909 from PatrickRice-KSC/add-support-for-emails-enabled-to-group
Add support for EmailsEnabled to groups
2 parents f7ec87b + 48382c2 commit 3939b35

File tree

2 files changed

+126
-3
lines changed

2 files changed

+126
-3
lines changed

groups.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type Group struct {
6464
ProjectCreationLevel ProjectCreationLevelValue `json:"project_creation_level"`
6565
AutoDevopsEnabled bool `json:"auto_devops_enabled"`
6666
SubGroupCreationLevel SubGroupCreationLevelValue `json:"subgroup_creation_level"`
67-
EmailsDisabled bool `json:"emails_disabled"`
67+
EmailsEnabled bool `json:"emails_enabled"`
6868
MentionsDisabled bool `json:"mentions_disabled"`
6969
RunnersToken string `json:"runners_token"`
7070
SharedProjects []*Project `json:"shared_projects"`
@@ -87,6 +87,9 @@ type Group struct {
8787
CreatedAt *time.Time `json:"created_at"`
8888
IPRestrictionRanges string `json:"ip_restriction_ranges"`
8989
WikiAccessLevel AccessControlValue `json:"wiki_access_level"`
90+
91+
// Deprecated: Use EmailsEnabled instead
92+
EmailsDisabled bool `json:"emails_disabled"`
9093
}
9194

9295
// GroupAvatar represents a GitLab group avatar.
@@ -347,7 +350,7 @@ type CreateGroupOptions struct {
347350
ProjectCreationLevel *ProjectCreationLevelValue `url:"project_creation_level,omitempty" json:"project_creation_level,omitempty"`
348351
AutoDevopsEnabled *bool `url:"auto_devops_enabled,omitempty" json:"auto_devops_enabled,omitempty"`
349352
SubGroupCreationLevel *SubGroupCreationLevelValue `url:"subgroup_creation_level,omitempty" json:"subgroup_creation_level,omitempty"`
350-
EmailsDisabled *bool `url:"emails_disabled,omitempty" json:"emails_disabled,omitempty"`
353+
EmailsEnabled *bool `url:"emails_enabled,omitempty" json:"emails_enabled,omitempty"`
351354
MentionsDisabled *bool `url:"mentions_disabled,omitempty" json:"mentions_disabled,omitempty"`
352355
LFSEnabled *bool `url:"lfs_enabled,omitempty" json:"lfs_enabled,omitempty"`
353356
DefaultBranchProtection *int `url:"default_branch_protection,omitempty" json:"default_branch_protection"`
@@ -357,6 +360,9 @@ type CreateGroupOptions struct {
357360
ExtraSharedRunnersMinutesLimit *int `url:"extra_shared_runners_minutes_limit,omitempty" json:"extra_shared_runners_minutes_limit,omitempty"`
358361
IPRestrictionRanges *string `url:"ip_restriction_ranges,omitempty" json:"ip_restriction_ranges,omitempty"`
359362
WikiAccessLevel *AccessControlValue `url:"wiki_access_level,omitempty" json:"wiki_access_level,omitempty"`
363+
364+
// Deprecated: Use EmailsEnabled instead
365+
EmailsDisabled *bool `url:"emails_disabled,omitempty" json:"emails_disabled,omitempty"`
360366
}
361367

362368
// CreateGroup creates a new project group. Available only for users who can
@@ -473,7 +479,7 @@ type UpdateGroupOptions struct {
473479
ProjectCreationLevel *ProjectCreationLevelValue `url:"project_creation_level,omitempty" json:"project_creation_level,omitempty"`
474480
AutoDevopsEnabled *bool `url:"auto_devops_enabled,omitempty" json:"auto_devops_enabled,omitempty"`
475481
SubGroupCreationLevel *SubGroupCreationLevelValue `url:"subgroup_creation_level,omitempty" json:"subgroup_creation_level,omitempty"`
476-
EmailsDisabled *bool `url:"emails_disabled,omitempty" json:"emails_disabled,omitempty"`
482+
EmailsEnabled *bool `url:"emails_enabled,omitempty" json:"emails_enabled,omitempty"`
477483
MentionsDisabled *bool `url:"mentions_disabled,omitempty" json:"mentions_disabled,omitempty"`
478484
LFSEnabled *bool `url:"lfs_enabled,omitempty" json:"lfs_enabled,omitempty"`
479485
RequestAccessEnabled *bool `url:"request_access_enabled,omitempty" json:"request_access_enabled,omitempty"`
@@ -486,6 +492,9 @@ type UpdateGroupOptions struct {
486492
PreventSharingGroupsOutsideHierarchy *bool `url:"prevent_sharing_groups_outside_hierarchy,omitempty" json:"prevent_sharing_groups_outside_hierarchy,omitempty"`
487493
IPRestrictionRanges *string `url:"ip_restriction_ranges,omitempty" json:"ip_restriction_ranges,omitempty"`
488494
WikiAccessLevel *AccessControlValue `url:"wiki_access_level,omitempty" json:"wiki_access_level,omitempty"`
495+
496+
// Deprecated: Use EmailsEnabled instead
497+
EmailsDisabled *bool `url:"emails_disabled,omitempty" json:"emails_disabled,omitempty"`
489498
}
490499

491500
// UpdateGroup updates an existing group; only available to group owners and

groups_test.go

+114
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package gitlab
22

33
import (
4+
"encoding/json"
45
"fmt"
6+
"io"
57
"net/http"
68
"net/url"
79
"reflect"
@@ -593,3 +595,115 @@ func TestUpdateGroupWithIPRestrictionRanges(t *testing.T) {
593595
t.Errorf("Groups.UpdatedGroup returned %+v, want %+v", group, want)
594596
}
595597
}
598+
599+
func TestGetGroupWithEmailsEnabled(t *testing.T) {
600+
mux, client := setup(t)
601+
602+
mux.HandleFunc("/api/v4/groups/1",
603+
func(w http.ResponseWriter, r *http.Request) {
604+
testMethod(t, r, http.MethodGet)
605+
606+
// Modified from https://docs.gitlab.com/ee/api/groups.html#details-of-a-group
607+
fmt.Fprint(w, `
608+
{
609+
"id": 1,
610+
"name": "test",
611+
"path": "test",
612+
"emails_enabled": true,
613+
"description": "Aliquid qui quis dignissimos distinctio ut commodi voluptas est.",
614+
"visibility": "public",
615+
"avatar_url": null,
616+
"web_url": "https://gitlab.example.com/groups/test",
617+
"request_access_enabled": false,
618+
"repository_storage": "default",
619+
"full_name": "test",
620+
"full_path": "test",
621+
"runners_token": "ba324ca7b1c77fc20bb9",
622+
"file_template_project_id": 1,
623+
"parent_id": null,
624+
"enabled_git_access_protocol": "all",
625+
"created_at": "2020-01-15T12:36:29.590Z",
626+
"prevent_sharing_groups_outside_hierarchy": false,
627+
"ip_restriction_ranges": null,
628+
"math_rendering_limits_enabled": true,
629+
"lock_math_rendering_limits_enabled": false
630+
}`)
631+
})
632+
633+
group, _, err := client.Groups.GetGroup(1, &GetGroupOptions{})
634+
if err != nil {
635+
t.Errorf("Groups.UpdateGroup returned error: %v", err)
636+
}
637+
638+
if !group.EmailsEnabled {
639+
t.Fatalf("Failed to parse `emails_enabled`. Wanted true, got %v", group.EmailsEnabled)
640+
}
641+
}
642+
643+
func TestCreateGroupWithEmailsEnabled(t *testing.T) {
644+
mux, client := setup(t)
645+
646+
mux.HandleFunc("/api/v4/groups",
647+
func(w http.ResponseWriter, r *http.Request) {
648+
testMethod(t, r, http.MethodPost)
649+
650+
body, err := io.ReadAll(r.Body)
651+
if err != nil {
652+
t.Fatalf("Failed to read the request body. Error: %v", err)
653+
}
654+
655+
// unmarshal into generic JSON since we don't want to test CreateGroupOptions using itself to validate.
656+
var bodyJson map[string]interface{}
657+
err = json.Unmarshal(body, &bodyJson)
658+
if err != nil {
659+
t.Fatalf("Failed to parse the request body into JSON. Error: %v", err)
660+
}
661+
662+
if bodyJson["emails_enabled"] != true {
663+
t.Fatalf("Test failed. `emails_enabled` expected to be true, got %v", bodyJson["emails_enabled"])
664+
}
665+
666+
// Response is tested via the "GET" test, only test the actual request here.
667+
fmt.Fprint(w, `
668+
{}`)
669+
})
670+
671+
_, _, err := client.Groups.CreateGroup(&CreateGroupOptions{EmailsEnabled: Ptr(true)})
672+
if err != nil {
673+
t.Errorf("Groups.CreateGroup returned error: %v", err)
674+
}
675+
}
676+
677+
func TestUpdateGroupWithEmailsEnabled(t *testing.T) {
678+
mux, client := setup(t)
679+
680+
mux.HandleFunc("/api/v4/groups/1",
681+
func(w http.ResponseWriter, r *http.Request) {
682+
testMethod(t, r, http.MethodPut)
683+
684+
body, err := io.ReadAll(r.Body)
685+
if err != nil {
686+
t.Fatalf("Failed to read the request body. Error: %v", err)
687+
}
688+
689+
// unmarshal into generic JSON since we don't want to test UpdateGroupOptions using itself to validate.
690+
var bodyJson map[string]interface{}
691+
err = json.Unmarshal(body, &bodyJson)
692+
if err != nil {
693+
t.Fatalf("Failed to parse the request body into JSON. Error: %v", err)
694+
}
695+
696+
if bodyJson["emails_enabled"] != true {
697+
t.Fatalf("Test failed. `emails_enabled` expected to be true, got %v", bodyJson["emails_enabled"])
698+
}
699+
700+
// Response is tested via the "GET" test, only test the actual request here.
701+
fmt.Fprint(w, `
702+
{}`)
703+
})
704+
705+
_, _, err := client.Groups.UpdateGroup(1, &UpdateGroupOptions{EmailsEnabled: Ptr(true)})
706+
if err != nil {
707+
t.Errorf("Groups.UpdateGroup returned error: %v", err)
708+
}
709+
}

0 commit comments

Comments
 (0)