From f8844e567f8157a5c2c689ace8107d45ec048c1e Mon Sep 17 00:00:00 2001 From: Darby Frey Date: Wed, 6 Dec 2023 14:31:26 -0600 Subject: [PATCH 1/3] Adds API to control model registry project setting The Model Registry project setting can now be controlled via an API Changelog: added MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/139004 --- doc/api/projects.md | 2 ++ lib/api/entities/project.rb | 1 + lib/api/helpers/projects_helpers.rb | 2 ++ spec/requests/api/project_attributes.yml | 1 - spec/requests/api/projects_spec.rb | 5 +++-- spec/services/projects/update_service_spec.rb | 2 +- 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/doc/api/projects.md b/doc/api/projects.md index 5764abda7ce62a..05e9ba9d6ddbb4 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -1550,6 +1550,7 @@ curl --request POST --header "PRIVATE-TOKEN: " \ | `infrastructure_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | | `monitor_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | | `model_experiments_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | +| `model_registry_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | | `remove_source_branch_after_merge` | boolean | No | Enable `Delete source branch` option by default for all new merge requests. | | `repository_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | | `repository_storage` | string | No | Which storage shard the repository is on. _(administrator only)_ | @@ -1639,6 +1640,7 @@ POST /projects/user/:user_id | `infrastructure_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | | `monitor_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | | `model_experiments_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | +| `model_registry_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | | `remove_source_branch_after_merge` | boolean | No | Enable `Delete source branch` option by default for all new merge requests. | | `repository_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | | `repository_storage` | string | No | Which storage shard the repository is on. _(administrators only)_ | diff --git a/lib/api/entities/project.rb b/lib/api/entities/project.rb index 12e022bfb2044f..af93e09ef0dfc3 100644 --- a/lib/api/entities/project.rb +++ b/lib/api/entities/project.rb @@ -85,6 +85,7 @@ class Project < BasicProjectDetails expose(:infrastructure_access_level, documentation: { type: 'string', example: 'enabled' }) { |project, options| project_feature_string_access_level(project, :infrastructure) } expose(:monitor_access_level, documentation: { type: 'string', example: 'enabled' }) { |project, options| project_feature_string_access_level(project, :monitor) } expose(:model_experiments_access_level, documentation: { type: 'string', example: 'enabled' }) { |project, options| project_feature_string_access_level(project, :model_experiments) } + expose(:model_registry_access_level, documentation: { type: 'string', example: 'enabled' }) { |project, options| project_feature_string_access_level(project, :model_registry) } expose(:emails_disabled, documentation: { type: 'boolean' }) { |project, options| project.emails_disabled? } expose :emails_enabled, documentation: { type: 'boolean' } diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index 23e83d9d54fcc7..5eda670b832707 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -40,6 +40,7 @@ module ProjectsHelpers optional :infrastructure_access_level, type: String, values: %w[disabled private enabled], desc: 'Infrastructure access level. One of `disabled`, `private` or `enabled`' optional :monitor_access_level, type: String, values: %w[disabled private enabled], desc: 'Monitor access level. One of `disabled`, `private` or `enabled`' optional :model_experiments_access_level, type: String, values: %w[disabled private enabled], desc: 'Model experiments access level. One of `disabled`, `private` or `enabled`' + optional :model_registry_access_level, type: String, values: %w[disabled private enabled], desc: 'Model registry access level. One of `disabled`, `private` or `enabled`' optional :emails_disabled, type: Boolean, desc: 'Deprecated: Use emails_enabled instead.' optional :emails_enabled, type: Boolean, desc: 'Enable email notifications' @@ -197,6 +198,7 @@ def self.update_params_at_least_one_of :infrastructure_access_level, :monitor_access_level, :model_experiments_access_level, + :model_registry_access_level, # TODO: remove in API v5, replaced by *_access_level :issues_enabled, diff --git a/spec/requests/api/project_attributes.yml b/spec/requests/api/project_attributes.yml index ab03df84cd5b98..bab5bd2b6acf09 100644 --- a/spec/requests/api/project_attributes.yml +++ b/spec/requests/api/project_attributes.yml @@ -133,7 +133,6 @@ project_feature: - project_id - updated_at - operations_access_level - - model_registry_access_level computed_attributes: - issues_enabled - jobs_enabled diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 41ea27f95de6e5..650b21aa0e6b93 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -1313,6 +1313,7 @@ def request attrs[:merge_requests_access_level] = 'disabled' attrs[:issues_access_level] = 'disabled' attrs[:model_experiments_access_level] = 'disabled' + attrs[:model_registry_access_level] = 'disabled' end post api(path, user), params: project @@ -1323,7 +1324,7 @@ def request next if %i[ has_external_issue_tracker has_external_wiki issues_enabled merge_requests_enabled wiki_enabled storage_version container_registry_access_level releases_access_level environments_access_level feature_flags_access_level - infrastructure_access_level monitor_access_level model_experiments_access_level + infrastructure_access_level monitor_access_level model_experiments_access_level model_registry_access_level ].include?(k) expect(json_response[k.to_s]).to eq(v) @@ -3930,7 +3931,7 @@ def failure_message(diff) expect(Project.find_by(path: project[:path]).analytics_access_level).to eq(ProjectFeature::PRIVATE) end - %i[releases_access_level environments_access_level feature_flags_access_level infrastructure_access_level monitor_access_level model_experiments_access_level].each do |field| + %i[releases_access_level environments_access_level feature_flags_access_level infrastructure_access_level monitor_access_level model_experiments_access_level model_registry_access_level].each do |field| it "sets #{field}" do put api(path, user), params: { field => 'private' } diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb index c393125de3faa6..db447e78d80f1c 100644 --- a/spec/services/projects/update_service_spec.rb +++ b/spec/services/projects/update_service_spec.rb @@ -356,7 +356,7 @@ context 'when changes project features' do # Using some sample features for testing. # Not using all the features because some of them must be enabled/disabled together - %w[issues wiki forking model_experiments].each do |feature_name| + %w[issues wiki forking model_experiments model_registry].each do |feature_name| context "with feature_name:#{feature_name}" do let(:feature) { "#{feature_name}_access_level" } let(:params) do -- GitLab From ccf8fbce1b228e1f779b556af3944e134a4254fc Mon Sep 17 00:00:00 2001 From: Lorena Ciutacu Date: Thu, 7 Dec 2023 19:29:28 +0000 Subject: [PATCH 2/3] Apply 2 suggestion(s) to 1 file(s) --- doc/api/projects.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/api/projects.md b/doc/api/projects.md index 05e9ba9d6ddbb4..92b742cf687914 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -1474,7 +1474,8 @@ Refer to the [Events API documentation](events.md#list-a-projects-visible-events ## Create project -> `operations_access_level` [removed](https://gitlab.com/gitlab-org/gitlab/-/issues/385798) in GitLab 16.0. +> - `operations_access_level` [removed](https://gitlab.com/gitlab-org/gitlab/-/issues/385798) in GitLab 16.0. +> - `model_registry_access_level` [introduced](#link) in GitLab 16.7. Creates a new project owned by the authenticated user. @@ -1574,7 +1575,8 @@ curl --request POST --header "PRIVATE-TOKEN: " \ ## Create project for user -> `operations_access_level` [removed](https://gitlab.com/gitlab-org/gitlab/-/issues/385798) in GitLab 16.0. +> - `operations_access_level` [removed](https://gitlab.com/gitlab-org/gitlab/-/issues/385798) in GitLab 16.0. +> - `model_registry_access_level` [introduced](#link) in GitLab 16.7. Creates a new project owned by the specified user. Available only for administrators. -- GitLab From 6770cb77c6e22e14c35053490be65e24fd1b0505 Mon Sep 17 00:00:00 2001 From: Darby Frey Date: Thu, 7 Dec 2023 13:33:55 -0600 Subject: [PATCH 3/3] Updated project API docs --- doc/api/projects.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/api/projects.md b/doc/api/projects.md index 92b742cf687914..64e8bc7223d8fa 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -1475,7 +1475,7 @@ Refer to the [Events API documentation](events.md#list-a-projects-visible-events ## Create project > - `operations_access_level` [removed](https://gitlab.com/gitlab-org/gitlab/-/issues/385798) in GitLab 16.0. -> - `model_registry_access_level` [introduced](#link) in GitLab 16.7. +> - `model_registry_access_level` [introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/412734) in GitLab 16.7. Creates a new project owned by the authenticated user. @@ -1576,7 +1576,7 @@ curl --request POST --header "PRIVATE-TOKEN: " \ ## Create project for user > - `operations_access_level` [removed](https://gitlab.com/gitlab-org/gitlab/-/issues/385798) in GitLab 16.0. -> - `model_registry_access_level` [introduced](#link) in GitLab 16.7. +> - `model_registry_access_level` [introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/412734) in GitLab 16.7. Creates a new project owned by the specified user. Available only for administrators. @@ -1668,7 +1668,8 @@ POST /projects/user/:user_id ## Edit project -> `operations_access_level` [removed](https://gitlab.com/gitlab-org/gitlab/-/issues/385798) in GitLab 16.0. +> - `operations_access_level` [removed](https://gitlab.com/gitlab-org/gitlab/-/issues/385798) in GitLab 16.0. +> - `model_registry_access_level` [introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/412734) in GitLab 16.7. Updates an existing project. @@ -1758,6 +1759,7 @@ Supported attributes: | `feature_flags_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | | `infrastructure_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | | `monitor_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | +| `model_registry_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | | `remove_source_branch_after_merge` | boolean | No | Enable `Delete source branch` option by default for all new merge requests. | | `repository_access_level` | string | No | One of `disabled`, `private`, or `enabled`. | | `repository_storage` | string | No | Which storage shard the repository is on. _(administrators only)_ | -- GitLab