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

member role model follow 17.4.0 spec #1997

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 48 additions & 25 deletions member_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
101 changes: 60 additions & 41 deletions member_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
19 changes: 17 additions & 2 deletions testdata/create_member_role.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
32 changes: 30 additions & 2 deletions testdata/list_member_roles.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,52 @@
"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,
"name": "GuestVulnerabilityReader",
"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
}
]