Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-04-05 03:16:56 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-04-05 03:16:56 +0300
commit92a2c36b8cbbe4a7c0991312c28aa088a15201e6 (patch)
treec7545328646a92d8ddbf0798bd6f86301deb8fe7
parent269e52662aceba62b91424e87f4def90ecc81e6c (diff)
Add latest changes from gitlab-org/gitlab@master
-rw-r--r--GITALY_SERVER_VERSION2
-rw-r--r--app/controllers/projects/cluster_agents_controller.rb10
-rw-r--r--app/finders/clusters/agent_tokens_finder.rb6
-rw-r--r--app/finders/clusters/agents_finder.rb2
-rw-r--r--app/graphql/resolvers/kas/agent_configurations_resolver.rb2
-rw-r--r--app/graphql/types/clusters/agent_activity_event_type.rb2
-rw-r--r--app/graphql/types/clusters/agent_token_type.rb2
-rw-r--r--app/graphql/types/clusters/agent_type.rb2
-rw-r--r--app/policies/group_policy.rb3
-rw-r--r--app/policies/project_policy.rb3
-rw-r--r--db/migrate/20230330101438_create_fk_ml_candidate_params_on_candidate_id.rb29
-rw-r--r--db/migrate/20230330101439_validate_fk_ml_candidate_params_on_candidate_id.rb13
-rw-r--r--db/migrate/20230330101440_remove_old_fk_ml_candidate_params_on_candidate_id.rb21
-rw-r--r--db/migrate/20230330101441_create_fk_ml_candidate_metrics_on_candidate_id.rb29
-rw-r--r--db/migrate/20230330101442_validate_fk_ml_candidate_metrics_on_candidate_id.rb13
-rw-r--r--db/migrate/20230330101443_remove_old_fk_ml_candidate_metrics_on_candidate_id.rb21
-rw-r--r--db/post_migrate/20230224144233_migrate_evidences_from_raw_metadata.rb11
-rw-r--r--db/post_migrate/20230330103104_reschedule_migrate_evidences.rb30
-rw-r--r--db/schema_migrations/202303301014381
-rw-r--r--db/schema_migrations/202303301014391
-rw-r--r--db/schema_migrations/202303301014401
-rw-r--r--db/schema_migrations/202303301014411
-rw-r--r--db/schema_migrations/202303301014421
-rw-r--r--db/schema_migrations/202303301014431
-rw-r--r--db/schema_migrations/202303301031041
-rw-r--r--db/structure.sql12
-rw-r--r--lib/api/clusters/agents.rb2
-rw-r--r--lib/bulk_imports/projects/graphql/get_project_query.rb1
-rw-r--r--lib/bulk_imports/projects/transformers/project_attributes_transformer.rb2
-rw-r--r--lib/gitlab/background_migration/migrate_evidences_for_vulnerability_findings.rb13
-rw-r--r--lib/sidebars/projects/menus/infrastructure_menu.rb2
-rw-r--r--spec/graphql/types/clusters/agent_activity_event_type_spec.rb2
-rw-r--r--spec/graphql/types/clusters/agent_token_type_spec.rb2
-rw-r--r--spec/graphql/types/clusters/agent_type_spec.rb2
-rw-r--r--spec/lib/bulk_imports/projects/transformers/project_attributes_transformer_spec.rb13
-rw-r--r--spec/lib/gitlab/background_migration/migrate_evidences_for_vulnerability_findings_spec.rb27
-rw-r--r--spec/migrations/20230224144233_migrate_evidences_from_raw_metadata_spec.rb8
-rw-r--r--spec/migrations/20230330103104_reschedule_migrate_evidences_spec.rb31
-rw-r--r--spec/models/ml/candidate_spec.rb14
39 files changed, 250 insertions, 89 deletions
diff --git a/GITALY_SERVER_VERSION b/GITALY_SERVER_VERSION
index fab6581e358..4f42e4f877a 100644
--- a/GITALY_SERVER_VERSION
+++ b/GITALY_SERVER_VERSION
@@ -1 +1 @@
-3fd0240c8d286bab982fbb5b75dd34eb64e260b5
+d642d1ef77564b21d24a0be42c1c12ed62d03b2b
diff --git a/app/controllers/projects/cluster_agents_controller.rb b/app/controllers/projects/cluster_agents_controller.rb
index e0c9763abb6..9bc03640811 100644
--- a/app/controllers/projects/cluster_agents_controller.rb
+++ b/app/controllers/projects/cluster_agents_controller.rb
@@ -3,7 +3,7 @@
class Projects::ClusterAgentsController < Projects::ApplicationController
include KasCookie
- before_action :authorize_can_read_cluster_agent!
+ before_action :authorize_read_cluster_agent!
before_action :set_kas_cookie, only: [:show], if: -> { current_user }
feature_category :kubernetes_management
@@ -12,14 +12,6 @@ class Projects::ClusterAgentsController < Projects::ApplicationController
def show
@agent_name = params[:name]
end
-
- private
-
- def authorize_can_read_cluster_agent!
- return if can?(current_user, :read_cluster, project)
-
- access_denied!
- end
end
Projects::ClusterAgentsController.prepend_mod_with('Projects::ClusterAgentsController')
diff --git a/app/finders/clusters/agent_tokens_finder.rb b/app/finders/clusters/agent_tokens_finder.rb
index 72692777bc6..0e777564db5 100644
--- a/app/finders/clusters/agent_tokens_finder.rb
+++ b/app/finders/clusters/agent_tokens_finder.rb
@@ -11,7 +11,7 @@ module Clusters
end
def execute
- return ::Clusters::AgentToken.none unless can_read_cluster_agents?
+ return ::Clusters::AgentToken.none unless can_read_cluster_agent?
agent.agent_tokens.then { |agent_tokens| by_status(agent_tokens) }
end
@@ -24,8 +24,8 @@ module Clusters
params[:status].present? ? agent_tokens.with_status(params[:status]) : agent_tokens
end
- def can_read_cluster_agents?
- current_user&.can?(:read_cluster, agent&.project)
+ def can_read_cluster_agent?
+ current_user&.can?(:read_cluster_agent, agent)
end
end
end
diff --git a/app/finders/clusters/agents_finder.rb b/app/finders/clusters/agents_finder.rb
index 14277db3f85..0cdebe93f32 100644
--- a/app/finders/clusters/agents_finder.rb
+++ b/app/finders/clusters/agents_finder.rb
@@ -29,7 +29,7 @@ module Clusters
end
def can_read_cluster_agents?
- current_user&.can?(:read_cluster, object)
+ current_user&.can?(:read_cluster_agent, object)
end
end
end
diff --git a/app/graphql/resolvers/kas/agent_configurations_resolver.rb b/app/graphql/resolvers/kas/agent_configurations_resolver.rb
index 9db104287a6..74c5cbe55f1 100644
--- a/app/graphql/resolvers/kas/agent_configurations_resolver.rb
+++ b/app/graphql/resolvers/kas/agent_configurations_resolver.rb
@@ -21,7 +21,7 @@ module Resolvers
private
def can_read_agent_configuration?
- current_user.can?(:read_cluster, project)
+ current_user.can?(:read_cluster_agent, project)
end
def kas_client
diff --git a/app/graphql/types/clusters/agent_activity_event_type.rb b/app/graphql/types/clusters/agent_activity_event_type.rb
index 3484acfe25e..1d0ec7c4959 100644
--- a/app/graphql/types/clusters/agent_activity_event_type.rb
+++ b/app/graphql/types/clusters/agent_activity_event_type.rb
@@ -5,7 +5,7 @@ module Types
class AgentActivityEventType < BaseObject
graphql_name 'ClusterAgentActivityEvent'
- authorize :read_cluster
+ authorize :read_cluster_agent
connection_type_class(Types::CountableConnectionType)
diff --git a/app/graphql/types/clusters/agent_token_type.rb b/app/graphql/types/clusters/agent_token_type.rb
index 24489707698..720ee2f685b 100644
--- a/app/graphql/types/clusters/agent_token_type.rb
+++ b/app/graphql/types/clusters/agent_token_type.rb
@@ -5,7 +5,7 @@ module Types
class AgentTokenType < BaseObject
graphql_name 'ClusterAgentToken'
- authorize :read_cluster
+ authorize :read_cluster_agent
connection_type_class(Types::CountableConnectionType)
diff --git a/app/graphql/types/clusters/agent_type.rb b/app/graphql/types/clusters/agent_type.rb
index 5d7b8815cde..317a1aab628 100644
--- a/app/graphql/types/clusters/agent_type.rb
+++ b/app/graphql/types/clusters/agent_type.rb
@@ -5,7 +5,7 @@ module Types
class AgentType < BaseObject
graphql_name 'ClusterAgent'
- authorize :read_cluster
+ authorize :read_cluster_agent
connection_type_class(Types::CountableConnectionType)
diff --git a/app/policies/group_policy.rb b/app/policies/group_policy.rb
index ee1140b8405..5d4f8478377 100644
--- a/app/policies/group_policy.rb
+++ b/app/policies/group_policy.rb
@@ -165,7 +165,8 @@ class GroupPolicy < Namespaces::GroupProjectNamespaceSharedPolicy
enable :developer_access
enable :admin_crm_organization
enable :admin_crm_contact
- enable :read_cluster
+ enable :read_cluster # Deprecated as certificate-based cluster integration (`Clusters::Cluster`).
+ enable :read_cluster_agent
enable :read_group_all_available_runners
enable :use_k8s_proxies
end
diff --git a/app/policies/project_policy.rb b/app/policies/project_policy.rb
index d6d0eefe3cd..95cdbd65055 100644
--- a/app/policies/project_policy.rb
+++ b/app/policies/project_policy.rb
@@ -461,7 +461,8 @@ class ProjectPolicy < BasePolicy
enable :destroy_environment
enable :create_deployment
enable :update_deployment
- enable :read_cluster
+ enable :read_cluster # Deprecated as certificate-based cluster integration (`Clusters::Cluster`).
+ enable :read_cluster_agent
enable :use_k8s_proxies
enable :create_release
enable :update_release
diff --git a/db/migrate/20230330101438_create_fk_ml_candidate_params_on_candidate_id.rb b/db/migrate/20230330101438_create_fk_ml_candidate_params_on_candidate_id.rb
new file mode 100644
index 00000000000..8273ffc27e2
--- /dev/null
+++ b/db/migrate/20230330101438_create_fk_ml_candidate_params_on_candidate_id.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class CreateFkMlCandidateParamsOnCandidateId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ NEW_CONSTRAINT_NAME = 'fk_ml_candidate_params_on_candidate_id'
+
+ def up
+ add_concurrent_foreign_key(
+ :ml_candidate_params,
+ :ml_candidates,
+ column: :candidate_id,
+ on_delete: :cascade,
+ validate: false,
+ name: NEW_CONSTRAINT_NAME
+ )
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists(
+ :ml_candidate_params,
+ column: :candidate_id,
+ on_delete: :cascade,
+ name: NEW_CONSTRAINT_NAME
+ )
+ end
+ end
+end
diff --git a/db/migrate/20230330101439_validate_fk_ml_candidate_params_on_candidate_id.rb b/db/migrate/20230330101439_validate_fk_ml_candidate_params_on_candidate_id.rb
new file mode 100644
index 00000000000..912380ac3b7
--- /dev/null
+++ b/db/migrate/20230330101439_validate_fk_ml_candidate_params_on_candidate_id.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class ValidateFkMlCandidateParamsOnCandidateId < Gitlab::Database::Migration[2.1]
+ NEW_CONSTRAINT_NAME = 'fk_ml_candidate_params_on_candidate_id'
+
+ def up
+ validate_foreign_key(:ml_candidate_params, :candidate_id, name: NEW_CONSTRAINT_NAME)
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/migrate/20230330101440_remove_old_fk_ml_candidate_params_on_candidate_id.rb b/db/migrate/20230330101440_remove_old_fk_ml_candidate_params_on_candidate_id.rb
new file mode 100644
index 00000000000..8e143cd3ed2
--- /dev/null
+++ b/db/migrate/20230330101440_remove_old_fk_ml_candidate_params_on_candidate_id.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class RemoveOldFkMlCandidateParamsOnCandidateId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ OLD_CONSTRAINT_NAME = 'fk_rails_d4a51d1185'
+
+ def up
+ remove_foreign_key_if_exists(:ml_candidate_params, column: :candidate_id, name: OLD_CONSTRAINT_NAME)
+ end
+
+ def down
+ add_concurrent_foreign_key(
+ :ml_candidate_params,
+ :ml_candidates,
+ column: :candidate_id,
+ validate: false,
+ name: OLD_CONSTRAINT_NAME
+ )
+ end
+end
diff --git a/db/migrate/20230330101441_create_fk_ml_candidate_metrics_on_candidate_id.rb b/db/migrate/20230330101441_create_fk_ml_candidate_metrics_on_candidate_id.rb
new file mode 100644
index 00000000000..0ef0075127d
--- /dev/null
+++ b/db/migrate/20230330101441_create_fk_ml_candidate_metrics_on_candidate_id.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class CreateFkMlCandidateMetricsOnCandidateId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ NEW_CONSTRAINT_NAME = 'fk_ml_candidate_metrics_on_candidate_id'
+
+ def up
+ add_concurrent_foreign_key(
+ :ml_candidate_metrics,
+ :ml_candidates,
+ column: :candidate_id,
+ on_delete: :cascade,
+ validate: false,
+ name: NEW_CONSTRAINT_NAME
+ )
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists(
+ :ml_candidate_metrics,
+ column: :candidate_id,
+ on_delete: :cascade,
+ name: NEW_CONSTRAINT_NAME
+ )
+ end
+ end
+end
diff --git a/db/migrate/20230330101442_validate_fk_ml_candidate_metrics_on_candidate_id.rb b/db/migrate/20230330101442_validate_fk_ml_candidate_metrics_on_candidate_id.rb
new file mode 100644
index 00000000000..5180c6582cf
--- /dev/null
+++ b/db/migrate/20230330101442_validate_fk_ml_candidate_metrics_on_candidate_id.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class ValidateFkMlCandidateMetricsOnCandidateId < Gitlab::Database::Migration[2.1]
+ NEW_CONSTRAINT_NAME = 'fk_ml_candidate_metrics_on_candidate_id'
+
+ def up
+ validate_foreign_key(:ml_candidate_metrics, :candidate_id, name: NEW_CONSTRAINT_NAME)
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/migrate/20230330101443_remove_old_fk_ml_candidate_metrics_on_candidate_id.rb b/db/migrate/20230330101443_remove_old_fk_ml_candidate_metrics_on_candidate_id.rb
new file mode 100644
index 00000000000..2e9153cb9d9
--- /dev/null
+++ b/db/migrate/20230330101443_remove_old_fk_ml_candidate_metrics_on_candidate_id.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class RemoveOldFkMlCandidateMetricsOnCandidateId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ OLD_CONSTRAINT_NAME = 'fk_rails_efb613a25a'
+
+ def up
+ remove_foreign_key_if_exists(:ml_candidate_metrics, column: :candidate_id, name: OLD_CONSTRAINT_NAME)
+ end
+
+ def down
+ add_concurrent_foreign_key(
+ :ml_candidate_metrics,
+ :ml_candidates,
+ column: :candidate_id,
+ validate: false,
+ name: OLD_CONSTRAINT_NAME
+ )
+ end
+end
diff --git a/db/post_migrate/20230224144233_migrate_evidences_from_raw_metadata.rb b/db/post_migrate/20230224144233_migrate_evidences_from_raw_metadata.rb
index 5d72a46f3c4..7c2a43443df 100644
--- a/db/post_migrate/20230224144233_migrate_evidences_from_raw_metadata.rb
+++ b/db/post_migrate/20230224144233_migrate_evidences_from_raw_metadata.rb
@@ -9,17 +9,10 @@ class MigrateEvidencesFromRawMetadata < Gitlab::Database::Migration[2.1]
BATCH_SIZE = 10000
def up
- queue_batched_background_migration(
- MIGRATION,
- :vulnerability_occurrences,
- :id,
- job_interval: DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
+ # no-op as it has been rescheduled via db/post_migrate/20230330103104_reschedule_migrate_evidences.rb
end
def down
- delete_batched_background_migration(MIGRATION, :vulnerability_occurrences, :id, [])
+ # no-op as it has been rescheduled via db/post_migrate/20230330103104_reschedule_migrate_evidences.rb
end
end
diff --git a/db/post_migrate/20230330103104_reschedule_migrate_evidences.rb b/db/post_migrate/20230330103104_reschedule_migrate_evidences.rb
new file mode 100644
index 00000000000..1b59b9a4344
--- /dev/null
+++ b/db/post_migrate/20230330103104_reschedule_migrate_evidences.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+# rubocop:disable BackgroundMigration/MissingDictionaryFile
+
+class RescheduleMigrateEvidences < Gitlab::Database::Migration[2.1]
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MIGRATION = 'MigrateEvidencesForVulnerabilityFindings'
+ DELAY_INTERVAL = 2.minutes
+ SUB_BATCH_SIZE = 500
+ BATCH_SIZE = 10000
+
+ def up
+ delete_batched_background_migration(MIGRATION, :vulnerability_occurrences, :id, [])
+
+ queue_batched_background_migration(
+ MIGRATION,
+ :vulnerability_occurrences,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :vulnerability_occurrences, :id, [])
+ end
+end
+# rubocop:enable BackgroundMigration/MissingDictionaryFile
diff --git a/db/schema_migrations/20230330101438 b/db/schema_migrations/20230330101438
new file mode 100644
index 00000000000..0e479e7b28f
--- /dev/null
+++ b/db/schema_migrations/20230330101438
@@ -0,0 +1 @@
+ff2658630f5877b94536653994d211344210e10c0d3ef19d6052ca606bf8ea56 \ No newline at end of file
diff --git a/db/schema_migrations/20230330101439 b/db/schema_migrations/20230330101439
new file mode 100644
index 00000000000..64ccb9de3ee
--- /dev/null
+++ b/db/schema_migrations/20230330101439
@@ -0,0 +1 @@
+b388e3de152fda4ec4590fad5ffd503df85e474e807232e2afdacd51a4eebef9 \ No newline at end of file
diff --git a/db/schema_migrations/20230330101440 b/db/schema_migrations/20230330101440
new file mode 100644
index 00000000000..470fc0189d2
--- /dev/null
+++ b/db/schema_migrations/20230330101440
@@ -0,0 +1 @@
+f20a1df2650018debf7b84f90c0459e4fac7120c90aa23f184bbb5a96ab6e62c \ No newline at end of file
diff --git a/db/schema_migrations/20230330101441 b/db/schema_migrations/20230330101441
new file mode 100644
index 00000000000..fb69231b91a
--- /dev/null
+++ b/db/schema_migrations/20230330101441
@@ -0,0 +1 @@
+29c035a58df131daff23434a57999f04fbafde5a661e35bdc8556238c5822b5c \ No newline at end of file
diff --git a/db/schema_migrations/20230330101442 b/db/schema_migrations/20230330101442
new file mode 100644
index 00000000000..ba0def5c784
--- /dev/null
+++ b/db/schema_migrations/20230330101442
@@ -0,0 +1 @@
+f2037e8c082b2355c7b004bc2f006f99f738c48e277b0013872c77d1347a0d14 \ No newline at end of file
diff --git a/db/schema_migrations/20230330101443 b/db/schema_migrations/20230330101443
new file mode 100644
index 00000000000..4c0c0bc4b0a
--- /dev/null
+++ b/db/schema_migrations/20230330101443
@@ -0,0 +1 @@
+75bbf5ead4cec9bd425d056c9bbdc0e090721caa74c143533a30afedf90047ca \ No newline at end of file
diff --git a/db/schema_migrations/20230330103104 b/db/schema_migrations/20230330103104
new file mode 100644
index 00000000000..804fb366310
--- /dev/null
+++ b/db/schema_migrations/20230330103104
@@ -0,0 +1 @@
+e52fa4a4736346c3c03e9386be1f25cf8a2cf006c63432181afcf27473dce90a \ No newline at end of file
diff --git a/db/structure.sql b/db/structure.sql
index 8b02dc32711..98b006c0ac3 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -35231,6 +35231,12 @@ ALTER TABLE ONLY geo_event_log
ALTER TABLE ONLY issue_user_mentions
ADD CONSTRAINT fk_issue_user_mentions_note_id_convert_to_bigint FOREIGN KEY (note_id_convert_to_bigint) REFERENCES notes(id) ON DELETE CASCADE NOT VALID;
+ALTER TABLE ONLY ml_candidate_metrics
+ ADD CONSTRAINT fk_ml_candidate_metrics_on_candidate_id FOREIGN KEY (candidate_id) REFERENCES ml_candidates(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY ml_candidate_params
+ ADD CONSTRAINT fk_ml_candidate_params_on_candidate_id FOREIGN KEY (candidate_id) REFERENCES ml_candidates(id) ON DELETE CASCADE;
+
ALTER TABLE ONLY note_diff_files
ADD CONSTRAINT fk_note_diff_files_diff_note_id_convert_to_bigint FOREIGN KEY (diff_note_id_convert_to_bigint) REFERENCES notes(id) ON DELETE CASCADE NOT VALID;
@@ -36683,9 +36689,6 @@ ALTER TABLE ONLY alert_management_alert_assignees
ALTER TABLE ONLY geo_hashed_storage_attachments_events
ADD CONSTRAINT fk_rails_d496b088e9 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
-ALTER TABLE ONLY ml_candidate_params
- ADD CONSTRAINT fk_rails_d4a51d1185 FOREIGN KEY (candidate_id) REFERENCES ml_candidates(id);
-
ALTER TABLE ONLY packages_rpm_repository_files
ADD CONSTRAINT fk_rails_d545cfaed2 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
@@ -36863,9 +36866,6 @@ ALTER TABLE ONLY project_relation_exports
ALTER TABLE ONLY label_priorities
ADD CONSTRAINT fk_rails_ef916d14fa FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
-ALTER TABLE ONLY ml_candidate_metrics
- ADD CONSTRAINT fk_rails_efb613a25a FOREIGN KEY (candidate_id) REFERENCES ml_candidates(id);
-
ALTER TABLE ONLY fork_network_members
ADD CONSTRAINT fk_rails_efccadc4ec FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
diff --git a/lib/api/clusters/agents.rb b/lib/api/clusters/agents.rb
index 62d4fb009c6..c5ddecc8e93 100644
--- a/lib/api/clusters/agents.rb
+++ b/lib/api/clusters/agents.rb
@@ -23,7 +23,7 @@ module API
use :pagination
end
get ':id/cluster_agents' do
- not_found!('ClusterAgents') unless can?(current_user, :read_cluster, user_project)
+ not_found!('ClusterAgents') unless can?(current_user, :read_cluster_agent, user_project)
agents = ::Clusters::AgentsFinder.new(user_project, current_user).execute
diff --git a/lib/bulk_imports/projects/graphql/get_project_query.rb b/lib/bulk_imports/projects/graphql/get_project_query.rb
index a2d7094d570..a2cba2fcfc0 100644
--- a/lib/bulk_imports/projects/graphql/get_project_query.rb
+++ b/lib/bulk_imports/projects/graphql/get_project_query.rb
@@ -11,6 +11,7 @@ module BulkImports
query($full_path: ID!) {
project(fullPath: $full_path) {
id
+ name
visibility
created_at: createdAt
}
diff --git a/lib/bulk_imports/projects/transformers/project_attributes_transformer.rb b/lib/bulk_imports/projects/transformers/project_attributes_transformer.rb
index d36b0af8829..72b32ad5b3b 100644
--- a/lib/bulk_imports/projects/transformers/project_attributes_transformer.rb
+++ b/lib/bulk_imports/projects/transformers/project_attributes_transformer.rb
@@ -16,7 +16,7 @@ module BulkImports
namespace = Namespace.find_by_full_path(entity.destination_namespace)
path = normalize_path(entity.destination_slug)
- project[:name] = uniquify(namespace, entity.destination_slug, :name)
+ project[:name] = uniquify(namespace, data['name'], :name)
project[:path] = uniquify(namespace, path, :path)
project[:created_at] = data['created_at']
project[:import_type] = PROJECT_IMPORT_TYPE
diff --git a/lib/gitlab/background_migration/migrate_evidences_for_vulnerability_findings.rb b/lib/gitlab/background_migration/migrate_evidences_for_vulnerability_findings.rb
index 78a93b49c49..95e65d80a7a 100644
--- a/lib/gitlab/background_migration/migrate_evidences_for_vulnerability_findings.rb
+++ b/lib/gitlab/background_migration/migrate_evidences_for_vulnerability_findings.rb
@@ -41,14 +41,7 @@ module Gitlab
build_evidence(finding, evidence)
end.compact
- begin
- create_evidences(attrs) if attrs.present?
- rescue StandardError => e
- logger.error(
- message: e.message,
- class: self.class.name
- )
- end
+ create_evidences(attrs) if attrs.present?
end
def build_evidence(finding, evidence)
@@ -72,10 +65,6 @@ module Gitlab
rescue JSON::ParserError
nil
end
-
- def logger
- @logger ||= ::Gitlab::AppLogger
- end
end
end
end
diff --git a/lib/sidebars/projects/menus/infrastructure_menu.rb b/lib/sidebars/projects/menus/infrastructure_menu.rb
index a7cd920a74c..704b311a647 100644
--- a/lib/sidebars/projects/menus/infrastructure_menu.rb
+++ b/lib/sidebars/projects/menus/infrastructure_menu.rb
@@ -45,7 +45,7 @@ module Sidebars
end
def kubernetes_menu_item
- unless can?(context.current_user, :read_cluster, context.project)
+ unless can?(context.current_user, :read_cluster_agent, context.project)
return ::Sidebars::NilMenuItem.new(item_id: :kubernetes)
end
diff --git a/spec/graphql/types/clusters/agent_activity_event_type_spec.rb b/spec/graphql/types/clusters/agent_activity_event_type_spec.rb
index cae75485846..f89bd877920 100644
--- a/spec/graphql/types/clusters/agent_activity_event_type_spec.rb
+++ b/spec/graphql/types/clusters/agent_activity_event_type_spec.rb
@@ -6,6 +6,6 @@ RSpec.describe GitlabSchema.types['ClusterAgentActivityEvent'] do
let(:fields) { %i[recorded_at kind level user agent_token] }
it { expect(described_class.graphql_name).to eq('ClusterAgentActivityEvent') }
- it { expect(described_class).to require_graphql_authorizations(:read_cluster) }
+ it { expect(described_class).to require_graphql_authorizations(:read_cluster_agent) }
it { expect(described_class).to have_graphql_fields(fields) }
end
diff --git a/spec/graphql/types/clusters/agent_token_type_spec.rb b/spec/graphql/types/clusters/agent_token_type_spec.rb
index 1ca6d690c80..e04b33f92f8 100644
--- a/spec/graphql/types/clusters/agent_token_type_spec.rb
+++ b/spec/graphql/types/clusters/agent_token_type_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe GitlabSchema.types['ClusterAgentToken'] do
it { expect(described_class.graphql_name).to eq('ClusterAgentToken') }
- it { expect(described_class).to require_graphql_authorizations(:read_cluster) }
+ it { expect(described_class).to require_graphql_authorizations(:read_cluster_agent) }
it { expect(described_class).to have_graphql_fields(fields) }
end
diff --git a/spec/graphql/types/clusters/agent_type_spec.rb b/spec/graphql/types/clusters/agent_type_spec.rb
index bb1006c55c0..4bae0ea5602 100644
--- a/spec/graphql/types/clusters/agent_type_spec.rb
+++ b/spec/graphql/types/clusters/agent_type_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe GitlabSchema.types['ClusterAgent'] do
it { expect(described_class.graphql_name).to eq('ClusterAgent') }
- it { expect(described_class).to require_graphql_authorizations(:read_cluster) }
+ it { expect(described_class).to require_graphql_authorizations(:read_cluster_agent) }
it { expect(described_class).to include_graphql_fields(*fields) }
end
diff --git a/spec/lib/bulk_imports/projects/transformers/project_attributes_transformer_spec.rb b/spec/lib/bulk_imports/projects/transformers/project_attributes_transformer_spec.rb
index d64a0114f7b..40ad4ee8be5 100644
--- a/spec/lib/bulk_imports/projects/transformers/project_attributes_transformer_spec.rb
+++ b/spec/lib/bulk_imports/projects/transformers/project_attributes_transformer_spec.rb
@@ -5,7 +5,6 @@ require 'spec_helper'
RSpec.describe BulkImports::Projects::Transformers::ProjectAttributesTransformer, feature_category: :importers do
describe '#transform' do
let_it_be(:user) { create(:user) }
- let_it_be(:project) { create(:project, name: 'My Source Project') }
let_it_be(:bulk_import) { create(:bulk_import, user: user) }
let(:entity) do
@@ -25,6 +24,7 @@ RSpec.describe BulkImports::Projects::Transformers::ProjectAttributesTransformer
let(:context) { BulkImports::Pipeline::Context.new(tracker) }
let(:data) do
{
+ 'name' => 'My Project',
'visibility' => 'private',
'created_at' => '2016-11-18T09:29:42.634Z'
}
@@ -32,8 +32,9 @@ RSpec.describe BulkImports::Projects::Transformers::ProjectAttributesTransformer
subject(:transformed_data) { described_class.new.transform(context, data) }
- it 'transforms name to destination slug' do
- expect(transformed_data[:name]).to eq(entity.destination_slug)
+ it 'uniquifies project name' do
+ create(:project, group: destination_group, name: 'My Project')
+ expect(transformed_data[:name]).to eq('My Project_1')
end
it 'adds path as normalized name' do
@@ -110,6 +111,12 @@ RSpec.describe BulkImports::Projects::Transformers::ProjectAttributesTransformer
end
it 'makes the name unique by appending a counter' do
+ data = {
+ 'visibility' => 'private',
+ 'created_at' => '2016-11-18T09:29:42.634Z',
+ 'name' => 'Destination-Project-Name'
+ }
+
transformed_data = described_class.new.transform(context, data)
expect(transformed_data['name']).to eq('Destination-Project-Name_2')
end
diff --git a/spec/lib/gitlab/background_migration/migrate_evidences_for_vulnerability_findings_spec.rb b/spec/lib/gitlab/background_migration/migrate_evidences_for_vulnerability_findings_spec.rb
index b70044ab2a4..28e16a5820d 100644
--- a/spec/lib/gitlab/background_migration/migrate_evidences_for_vulnerability_findings_spec.rb
+++ b/spec/lib/gitlab/background_migration/migrate_evidences_for_vulnerability_findings_spec.rb
@@ -38,8 +38,6 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateEvidencesForVulnerabilityFind
end
it 'does not create any evidence' do
- expect(Gitlab::AppLogger).not_to receive(:error)
-
expect { perform_migration }.not_to change { vulnerability_finding_evidences.count }
end
end
@@ -50,8 +48,6 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateEvidencesForVulnerabilityFind
end
it 'does not create any evidence' do
- expect(Gitlab::AppLogger).not_to receive(:error)
-
expect { perform_migration }.not_to change { vulnerability_finding_evidences.count }
end
end
@@ -61,32 +57,15 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateEvidencesForVulnerabilityFind
let!(:finding2) { create_finding!(project1.id, scanner1.id, { evidence: evidence_hash }) }
it 'creates new evidence for each finding' do
- expect(Gitlab::AppLogger).not_to receive(:error)
-
expect { perform_migration }.to change { vulnerability_finding_evidences.count }.by(2)
end
- context 'when create throws exception StandardError' do
- before do
- allow(migration).to receive(:create_evidences).and_raise(StandardError)
- end
-
- it 'logs StandardError' do
- expect(Gitlab::AppLogger).to receive(:error).with({
- class: described_class.name, message: StandardError.to_s
- })
- expect { perform_migration }.not_to change { vulnerability_finding_evidences.count }
- end
- end
-
context 'when parse throws exception JSON::ParserError' do
before do
allow(Gitlab::Json).to receive(:parse).and_raise(JSON::ParserError)
end
- it 'does not log this error nor create new records' do
- expect(Gitlab::AppLogger).not_to receive(:error)
-
+ it 'does not create new records' do
expect { perform_migration }.not_to change { vulnerability_finding_evidences.count }
end
end
@@ -100,8 +79,6 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateEvidencesForVulnerabilityFind
end
it 'does not create new evidence' do
- expect(Gitlab::AppLogger).not_to receive(:error)
-
expect { perform_migration }.not_to change { vulnerability_finding_evidences.count }
end
@@ -109,8 +86,6 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateEvidencesForVulnerabilityFind
let!(:finding3) { create_finding!(project1.id, scanner1.id, { evidence: { url: 'http://secondary.com' } }) }
it 'creates a new evidence only to the non-existing evidence' do
- expect(Gitlab::AppLogger).not_to receive(:error)
-
expect { perform_migration }.to change { vulnerability_finding_evidences.count }.by(1)
end
end
diff --git a/spec/migrations/20230224144233_migrate_evidences_from_raw_metadata_spec.rb b/spec/migrations/20230224144233_migrate_evidences_from_raw_metadata_spec.rb
index 9b38557c8c3..6610f70be2b 100644
--- a/spec/migrations/20230224144233_migrate_evidences_from_raw_metadata_spec.rb
+++ b/spec/migrations/20230224144233_migrate_evidences_from_raw_metadata_spec.rb
@@ -10,13 +10,7 @@ RSpec.describe MigrateEvidencesFromRawMetadata, :migration, feature_category: :v
it 'schedules a batched background migration' do
migrate!
- expect(migration).to have_scheduled_batched_migration(
- table_name: :vulnerability_occurrences,
- column_name: :id,
- interval: described_class::DELAY_INTERVAL,
- batch_size: described_class::BATCH_SIZE,
- sub_batch_size: described_class::SUB_BATCH_SIZE
- )
+ expect(migration).not_to have_scheduled_batched_migration
end
end
diff --git a/spec/migrations/20230330103104_reschedule_migrate_evidences_spec.rb b/spec/migrations/20230330103104_reschedule_migrate_evidences_spec.rb
new file mode 100644
index 00000000000..4f490ec90cb
--- /dev/null
+++ b/spec/migrations/20230330103104_reschedule_migrate_evidences_spec.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe RescheduleMigrateEvidences, :migration, feature_category: :vulnerability_management do
+ let(:migration) { described_class::MIGRATION }
+
+ describe '#up' do
+ it 'schedules a batched background migration' do
+ migrate!
+
+ expect(migration).to have_scheduled_batched_migration(
+ table_name: :vulnerability_occurrences,
+ column_name: :id,
+ interval: described_class::DELAY_INTERVAL,
+ batch_size: described_class::BATCH_SIZE,
+ sub_batch_size: described_class::SUB_BATCH_SIZE
+ )
+ end
+ end
+
+ describe '#down' do
+ it 'deletes all batched migration records' do
+ migrate!
+ schema_migrate_down!
+
+ expect(migration).not_to have_scheduled_batched_migration
+ end
+ end
+end
diff --git a/spec/models/ml/candidate_spec.rb b/spec/models/ml/candidate_spec.rb
index 610501f1ca3..063b57788ce 100644
--- a/spec/models/ml/candidate_spec.rb
+++ b/spec/models/ml/candidate_spec.rb
@@ -34,6 +34,20 @@ RSpec.describe Ml::Candidate, factory_default: :keep, feature_category: :mlops d
it { expect(described_class.new.eid).to be_present }
end
+ describe '.destroy' do
+ let_it_be(:candidate_to_destroy) do
+ create(:ml_candidates, :with_metrics_and_params, :with_metadata, :with_artifact)
+ end
+
+ it 'destroys metrics, params and metadata, but not the artifact', :aggregate_failures do
+ expect { candidate_to_destroy.destroy! }
+ .to change { Ml::CandidateMetadata.count }.by(-2)
+ .and change { Ml::CandidateParam.count }.by(-2)
+ .and change { Ml::CandidateMetric.count }.by(-2)
+ .and not_change { Packages::Package.count }
+ end
+ end
+
describe '.artifact_root' do
subject { candidate.artifact_root }