Repository: xanzy/go-gitlab
Pull request #1997 (2024-08-24 11:19:11)

member role model follow 17.4.0 spec
The current definition of creating and listing member roles were not up to date with the current api. 

I've added all currently defined elements per the api spec, updated test data and simplified the tests a bit.


Patch:
diff --git a/member_roles.go b/member_roles.go
index cefb94b..c81675d 100644
--- a/member_roles.go
+++ b/member_roles.go
@@ -17,23 +17,31 @@ type MemberRolesService struct {
 //
 // GitLab API docs: https://docs.gitlab.com/ee/api/member_roles.html
 type MemberRole struct {
-	ID                       int              `json:"id"`
-	Name                     string           `json:"name"`
-	Description              string           `json:"description,omitempty"`
-	GroupId                  int              `json:"group_id"`
-	BaseAccessLevel          AccessLevelValue `json:"base_access_level"`
-	AdminCICDVariables       bool             `json:"admin_cicd_variables,omitempty"`
-	AdminMergeRequests       bool             `json:"admin_merge_request,omitempty"`
-	AdminTerraformState      bool             `json:"admin_terraform_state,omitempty"`
-	AdminVulnerability       bool             `json:"admin_vulnerability,omitempty"`
-	ReadCode                 bool             `json:"read_code,omitempty"`
-	ReadDependency           bool             `json:"read_dependency,omitempty"`
-	ReadVulnerability        bool             `json:"read_vulnerability,omitempty"`
-	AdminGroupMembers        bool             `json:"admin_group_member,omitempty"`
-	ManageProjectAccessToken bool             `json:"manage_project_access_tokens,omitempty"`
-	ArchiveProject           bool             `json:"archive_project,omitempty"`
-	RemoveProject            bool             `json:"remove_project,omitempty"`
-	ManageGroupAccesToken    bool             `json:"manage_group_access_tokens,omitempty"`
+	ID                         int              `json:"id"`
+	Name                       string           `json:"name"`
+	Description                string           `json:"description,omitempty"`
+	GroupId                    int              `json:"group_id"`
+	BaseAccessLevel            AccessLevelValue `json:"base_access_level"`
+	AdminCICDVariables         bool             `json:"admin_cicd_variables,omitempty"`
+	AdminComplianceFramework   bool             `json:"admin_compliance_framework,omitempty"`
+	AdminGroupMembers          bool             `json:"admin_group_member,omitempty"`
+	AdminMergeRequests         bool             `json:"admin_merge_request,omitempty"`
+	AdminPushRules             bool             `json:"admin_push_rules,omitempty"`
+	AdminTerraformState        bool             `json:"admin_terraform_state,omitempty"`
+	AdminVulnerability         bool             `json:"admin_vulnerability,omitempty"`
+	AdminWebHook               bool             `json:"admin_web_hook,omitempty"`
+	ArchiveProject             bool             `json:"archive_project,omitempty"`
+	ManageDeployTokens         bool             `json:"manage_deploy_tokens,omitempty"`
+	ManageGroupAccesToken      bool             `json:"manage_group_access_tokens,omitempty"`
+	ManageMergeRequestSettings bool             `json:"manage_merge_request_settings,omitempty"`
+	ManageProjectAccessToken   bool             `json:"manage_project_access_tokens,omitempty"`
+	ManageSecurityPolicyLink   bool             `json:"manage_security_policy_link,omitempty"`
+	ReadCode                   bool             `json:"read_code,omitempty"`
+	ReadRunners                bool             `json:"read_runners,omitempty"`
+	ReadDependency             bool             `json:"read_dependency,omitempty"`
+	ReadVulnerability          bool             `json:"read_vulnerability,omitempty"`
+	RemoveGroup                bool             `json:"remove_group,omitempty"`
+	RemoveProject              bool             `json:"remove_project,omitempty"`
 }
 
 // ListMemberRoles gets a list of member roles for a specified group.
@@ -66,14 +74,29 @@ func (s *MemberRolesService) ListMemberRoles(gid interface{}, options ...Request
 // GitLab API docs:
 // https://docs.gitlab.com/ee/api/member_roles.html#add-a-member-role-to-a-group
 type CreateMemberRoleOptions struct {
-	Name               *string           `url:"name,omitempty" json:"name,omitempty"`
-	BaseAccessLevel    *AccessLevelValue `url:"base_access_level,omitempty" json:"base_access_level,omitempty"`
-	Description        *string           `url:"description,omitempty" json:"description,omitempty"`
-	AdminMergeRequest  *bool             `url:"admin_merge_request,omitempty" json:"admin_merge_request,omitempty"`
-	AdminVulnerability *bool             `url:"admin_vulnerability,omitempty" json:"admin_vulnerability,omitempty"`
-	ReadCode           *bool             `url:"read_code,omitempty" json:"read_code,omitempty"`
-	ReadDependency     *bool             `url:"read_dependency,omitempty" json:"read_dependency,omitempty"`
-	ReadVulnerability  *bool             `url:"read_vulnerability,omitempty" json:"read_vulnerability,omitempty"`
+	Name                       *string           `url:"name,omitempty" json:"name,omitempty"`
+	BaseAccessLevel            *AccessLevelValue `url:"base_access_level,omitempty" json:"base_access_level,omitempty"`
+	Description                *string           `url:"description,omitempty" json:"description,omitempty"`
+	AdminCICDVariables         *bool             `url:"admin_cicd_variables" json:"admin_cicd_variables,omitempty"`
+	AdminComplianceFramework   *bool             `url:"admin_compliance_framework" json:"admin_compliance_framework,omitempty"`
+	AdminGroupMembers          *bool             `url:"admin_group_member" json:"admin_group_member,omitempty"`
+	AdminMergeRequest          *bool             `url:"admin_merge_request,omitempty" json:"admin_merge_request,omitempty"`
+	AdminPushRules             *bool             `url:"admin_push_rules" json:"admin_push_rules,omitempty"`
+	AdminTerraformState        *bool             `url:"admin_terraform_state" json:"admin_terraform_state,omitempty"`
+	AdminVulnerability         *bool             `url:"admin_vulnerability,omitempty" json:"admin_vulnerability,omitempty"`
+	AdminWebHook               *bool             `url:"admin_web_hook" json:"admin_web_hook,omitempty"`
+	ArchiveProject             *bool             `url:"archive_project" json:"archive_project,omitempty"`
+	ManageDeployTokens         *bool             `url:"manage_deploy_tokens" json:"manage_deploy_tokens,omitempty"`
+	ManageGroupAccesToken      *bool             `url:"manage_group_access_tokens" json:"manage_group_access_tokens,omitempty"`
+	ManageMergeRequestSettings *bool             `url:"manage_merge_request_settings" json:"manage_merge_request_settings,omitempty"`
+	ManageProjectAccessToken   *bool             `url:"manage_project_access_tokens" json:"manage_project_access_tokens,omitempty"`
+	ManageSecurityPolicyLink   *bool             `url:"manage_security_policy_link" json:"manage_security_policy_link,omitempty"`
+	ReadCode                   *bool             `url:"read_code,omitempty" json:"read_code,omitempty"`
+	ReadRunners                *bool             `url:"read_runners" json:"read_runners,omitempty"`
+	ReadDependency             *bool             `url:"read_dependency,omitempty" json:"read_dependency,omitempty"`
+	ReadVulnerability          *bool             `url:"read_vulnerability,omitempty" json:"read_vulnerability,omitempty"`
+	RemoveGroup                *bool             `url:"remove_group" json:"remove_group,omitempty"`
+	RemoveProject              *bool             `url:"remove_project" json:"remove_project,omitempty"`
 }
 
 // CreateMemberRole creates a new member role for a specified group.
diff --git a/projects.go b/projects.go
index a2b8e52..6df4eff 100644
--- a/projects.go
+++ b/projects.go
@@ -169,7 +169,7 @@ type Project struct {
 	MergeRequestDefaultTargetSelf            bool               `json:"mr_default_target_self"`
 	ModelExperimentsAccessLevel              AccessControlValue `json:"model_experiments_access_level"`
 	ModelRegistryAccessLevel                 AccessControlValue `json:"model_registry_access_level"`
-	PreReceiveSecretDetectionEnabled         bool              `json:"pre_receive_secret_detection_enabled"`
+	PreReceiveSecretDetectionEnabled         bool               `json:"pre_receive_secret_detection_enabled"`
 
 	// Deprecated: Use EmailsEnabled instead
 	EmailsDisabled bool `json:"emails_disabled"`


Test patch:
diff --git a/member_roles_test.go b/member_roles_test.go
index 93f0b77..894784f 100644
--- a/member_roles_test.go
+++ b/member_roles_test.go
@@ -22,30 +22,20 @@ func TestListMemberRoles(t *testing.T) {
 
 	want := []*MemberRole{
 		{
-			ID:                       1,
-			Name:                     "GuestCodeReader",
-			Description:              "A Guest user that can read code",
-			GroupId:                  1,
-			BaseAccessLevel:          10, // Guest Base Level
-			AdminMergeRequests:       false,
-			AdminVulnerability:       false,
-			ReadCode:                 true,
-			ReadDependency:           false,
-			ReadVulnerability:        false,
-			ManageProjectAccessToken: false,
+			ID:              1,
+			Name:            "GuestCodeReader",
+			Description:     "A Guest user that can read code",
+			GroupId:         1,
+			BaseAccessLevel: 10, // Guest Base Level
+			ReadCode:        true,
 		},
 		{
-			ID:                       2,
-			Name:                     "GuestVulnerabilityReader",
-			Description:              "A Guest user that can read vulnerabilities",
-			GroupId:                  1,
-			BaseAccessLevel:          10, // Guest Base Level
-			AdminMergeRequests:       false,
-			AdminVulnerability:       false,
-			ReadCode:                 false,
-			ReadDependency:           false,
-			ReadVulnerability:        true,
-			ManageProjectAccessToken: false,
+			ID:                2,
+			Name:              "GuestVulnerabilityReader",
+			Description:       "A Guest user that can read vulnerabilities",
+			GroupId:           1,
+			BaseAccessLevel:   10, // Guest Base Level
+			ReadVulnerability: true,
 		},
 	}
 
@@ -63,29 +53,58 @@ func TestCreateMemberRole(t *testing.T) {
 	})
 
 	memberRole, _, err := client.MemberRolesService.CreateMemberRole(84, &CreateMemberRoleOptions{
-		Name:               Ptr("Custom guest"),
-		BaseAccessLevel:    Ptr(GuestPermissions),
-		Description:        Ptr("a sample custom role"),
-		AdminMergeRequest:  Ptr(false),
-		AdminVulnerability: Ptr(false),
-		ReadCode:           Ptr(true),
-		ReadDependency:     Ptr(false),
-		ReadVulnerability:  Ptr(false),
+		Name:                       Ptr("Custom guest"),
+		BaseAccessLevel:            Ptr(GuestPermissions),
+		Description:                Ptr("a sample custom role"),
+		AdminCICDVariables:         Ptr(false),
+		AdminComplianceFramework:   Ptr(false),
+		AdminGroupMembers:          Ptr(false),
+		AdminMergeRequest:          Ptr(false),
+		AdminPushRules:             Ptr(false),
+		AdminTerraformState:        Ptr(false),
+		AdminVulnerability:         Ptr(false),
+		AdminWebHook:               Ptr(false),
+		ArchiveProject:             Ptr(false),
+		ManageDeployTokens:         Ptr(false),
+		ManageGroupAccesToken:      Ptr(false),
+		ManageMergeRequestSettings: Ptr(false),
+		ManageProjectAccessToken:   Ptr(false),
+		ManageSecurityPolicyLink:   Ptr(false),
+		ReadCode:                   Ptr(true),
+		ReadRunners:                Ptr(false),
+		ReadDependency:             Ptr(false),
+		ReadVulnerability:          Ptr(false),
+		RemoveGroup:                Ptr(false),
+		RemoveProject:              Ptr(false),
 	})
 	require.NoError(t, err)
 
 	want := &MemberRole{
-		ID:                       3,
-		Name:                     "Custom guest",
-		Description:              "a sample custom role",
-		BaseAccessLevel:          GuestPermissions,
-		GroupId:                  84,
-		AdminMergeRequests:       false,
-		AdminVulnerability:       false,
-		ReadCode:                 true,
-		ReadDependency:           false,
-		ReadVulnerability:        false,
-		ManageProjectAccessToken: false,
+		ID:                         3,
+		Name:                       "Custom guest",
+		Description:                "a sample custom role",
+		BaseAccessLevel:            GuestPermissions,
+		GroupId:                    84,
+		AdminCICDVariables:         false,
+		AdminComplianceFramework:   false,
+		AdminGroupMembers:          false,
+		AdminMergeRequests:         false,
+		AdminPushRules:             false,
+		AdminTerraformState:        false,
+		AdminVulnerability:         false,
+		AdminWebHook:               false,
+		ArchiveProject:             false,
+		ManageDeployTokens:         false,
+		ManageGroupAccesToken:      false,
+		ManageMergeRequestSettings: false,
+		ManageProjectAccessToken:   false,
+		ManageSecurityPolicyLink:   false,
+		ReadCode:                   true,
+		ReadRunners:                false,
+		ReadDependency:             false,
+		ReadVulnerability:          false,
+		RemoveGroup:                false,
+		RemoveProject:              false,
 	}
 
 	require.Equal(t, want, memberRole)
diff --git a/testdata/create_member_role.json b/testdata/create_member_role.json
index 0eb7bcd..ff77062 100644
--- a/testdata/create_member_role.json
+++ b/testdata/create_member_role.json
@@ -4,9 +4,24 @@
   "description": "a sample custom role",
   "group_id": 84,
   "base_access_level": 10,
-  "admin_merge_requests": false,
+  "admin_cicd_variables": false,
+  "admin_compliance_framework": false,
+  "admin_group_member": false,
+  "admin_merge_request": false,
+  "admin_push_rules": false,
+  "admin_terraform_state": false,
   "admin_vulnerability": false,
+  "admin_web_hook": false,
+  "archive_project": false,
+  "manage_deploy_tokens": false,
+  "manage_group_access_tokens": false,
+  "manage_merge_request_settings": false,
+  "manage_project_access_tokens": false,
+  "manage_security_policy_link": false,
   "read_code": true,
+  "read_runners": false,
   "read_dependency": false,
-  "read_vulnerability": false
+  "read_vulnerability": false,
+  "remove_group": false,
+  "remove_project": false
 }
diff --git a/testdata/list_member_roles.json b/testdata/list_member_roles.json
index b0843b7..850213f 100644
--- a/testdata/list_member_roles.json
+++ b/testdata/list_member_roles.json
@@ -5,12 +5,26 @@
     "description": "A Guest user that can read code",
     "group_id": 1,
     "base_access_level": 10,
+    "admin_cicd_variables": false,
+    "admin_compliance_framework": false,
+    "admin_group_member": false,
     "admin_merge_request": false,
+    "admin_push_rules": false,
+    "admin_terraform_state": false,
     "admin_vulnerability": false,
+    "admin_web_hook": false,
+    "archive_project": false,
+    "manage_deploy_tokens": false,
+    "manage_group_access_tokens": false,
+    "manage_merge_request_settings": false,
+    "manage_project_access_tokens": false,
+    "manage_security_policy_link": false,
     "read_code": true,
+    "read_runners": false,
     "read_dependency": false,
     "read_vulnerability": false,
-    "manage_project_access_token": false
+    "remove_group": false,
+    "remove_project": false
   },
   {
     "id": 2,
@@ -18,11 +32,25 @@
     "description": "A Guest user that can read vulnerabilities",
     "group_id": 1,
     "base_access_level": 10,
+    "admin_cicd_variables": false,
+    "admin_compliance_framework": false,
+    "admin_group_member": false,
     "admin_merge_request": false,
+    "admin_push_rules": false,
+    "admin_terraform_state": false,
     "admin_vulnerability": false,
+    "admin_web_hook": false,
+    "archive_project": false,
+    "manage_deploy_tokens": false,
+    "manage_group_access_tokens": false,
+    "manage_merge_request_settings": false,
+    "manage_project_access_tokens": false,
+    "manage_security_policy_link": false,
     "read_code": false,
+    "read_runners": false,
     "read_dependency": false,
     "read_vulnerability": true,
-    "manage_project_access_token": false
+    "remove_group": false,
+    "remove_project": false
   }
 ]