From c0e1eb1ee2601a087fa982d5ca7808ea78374df9 Mon Sep 17 00:00:00 2001 From: Simon Alexander Alsing Date: Sat, 24 Aug 2024 12:23:00 +0200 Subject: [PATCH 1/4] Add properties AdminComplianceFramework, AdminPushRules, AdminWebHook, ManageDeployToken, ManageMergeRequestSettings, ManageSecurityPolicyLink, ReadRunners, RemoveGroup to MemberRoles struct to comply with 17.4.0 spec --- member_roles.go | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/member_roles.go b/member_roles.go index cefb94b2c..0f0f48547 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. From 10452284305aade2dd004741e501e92499adcac4 Mon Sep 17 00:00:00 2001 From: Simon Alexander Alsing Date: Sat, 24 Aug 2024 12:56:30 +0200 Subject: [PATCH 2/4] Add properties AdminCICDVariables AdminComplianceFramework AdminGroupMembers AdminPushRules AdminTerraformState AdminWebHook ArchiveProject ManageDeployTokens ManageGroupAccesToken ManageMergeRequestSettings ManageProjectAccessToken ManageSecurityPolicyLink ReadRunners RemoveGroup RemoveProject to CreateMemberRoleOptions to align with 17.4.0 spec --- member_roles.go | 31 +++++++++++---- member_roles_test.go | 67 +++++++++++++++++++++++--------- testdata/create_member_role.json | 19 ++++++++- 3 files changed, 88 insertions(+), 29 deletions(-) diff --git a/member_roles.go b/member_roles.go index 0f0f48547..c81675d3e 100644 --- a/member_roles.go +++ b/member_roles.go @@ -74,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/member_roles_test.go b/member_roles_test.go index 93f0b7743..85b30cb7c 100644 --- a/member_roles_test.go +++ b/member_roles_test.go @@ -63,29 +63,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 0eb7bcd78..ff7706204 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 } From 7598a97d1e26e82df75e7825afff0de07a4b7575 Mon Sep 17 00:00:00 2001 From: Simon Alexander Alsing Date: Sat, 24 Aug 2024 13:14:30 +0200 Subject: [PATCH 3/4] update list member roles test with up to date data --- member_roles_test.go | 34 ++++++++++++--------------------- testdata/list_member_roles.json | 32 +++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/member_roles_test.go b/member_roles_test.go index 85b30cb7c..894784fdb 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, }, } diff --git a/testdata/list_member_roles.json b/testdata/list_member_roles.json index b0843b798..850213fa6 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 } ] From 3869a519beea7fbf13c4d62dfe370fab3f1b2b5d Mon Sep 17 00:00:00 2001 From: Simon Alexander Alsing Date: Sat, 24 Aug 2024 13:18:42 +0200 Subject: [PATCH 4/4] Fix formatting in projects.go --- projects.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects.go b/projects.go index a2b8e527e..6df4eff2b 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"`