Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2024-07-27 12:09:41 +00:00
parent 4f1e897426
commit 26f28dfd16
8 changed files with 46 additions and 20 deletions

View File

@ -137,6 +137,12 @@ class ApplicationRecord < ActiveRecord::Base
!not_null_check?(column_name)
end
def require_organization?
return false unless Feature.enabled?(:require_organization, Feature.current_request)
Gitlab::SafeRequestStore.fetch(:require_organization) { true } # rubocop:disable Style/RedundantFetchBlock -- This fetch has a different interface
end
def readable_by?(user)
Ability.allowed?(user, "read_#{to_ability_name}".to_sym, self)
end

View File

@ -722,12 +722,6 @@ class Namespace < ApplicationRecord
:active_pages_deployments)
end
def require_organization?
return false unless Feature.enabled?(:require_organization, Feature.current_request)
Gitlab::SafeRequestStore.fetch(:require_organization) { true } # rubocop:disable Style/RedundantFetchBlock -- This fetch has a different interface
end
private
def cross_namespace_reference?(from)

View File

@ -616,8 +616,8 @@ class Project < ApplicationRecord
if: :path_changed?
validates :project_feature, presence: true
validates :namespace, presence: true
validates :organization, presence: true, if: :require_organization?
validates :project_namespace, presence: true, on: :create, if: -> { self.namespace }
validates :project_namespace, presence: true, on: :update, if: -> { self.project_namespace_id_changed?(to: nil) }
validates :name, uniqueness: { scope: :namespace_id }

View File

@ -64,7 +64,10 @@ module ServicePing
URI.join(base_url, path),
body: Gitlab::Json.dump(payload),
allow_local_requests: true,
headers: { 'Content-type' => 'application/json' }
headers: {
'Content-type' => 'application/json',
'Accept' => 'application/json'
}
)
end

View File

@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Groups::Registry::RepositoriesController do
RSpec.describe Groups::Registry::RepositoriesController, feature_category: :container_registry do
let_it_be(:user) { create(:user) }
let_it_be(:guest) { create(:user) }
let_it_be(:group, reload: true) { create(:group) }

View File

@ -707,10 +707,19 @@ RSpec.describe Project, factory_default: :keep, feature_category: :groups_and_pr
it { is_expected.not_to allow_value('/test/foo').for(:ci_config_path) }
it { is_expected.to validate_presence_of(:creator) }
it { is_expected.to validate_presence_of(:namespace) }
it { is_expected.to validate_presence_of(:organization) }
it { is_expected.to validate_presence_of(:repository_storage) }
it { is_expected.to validate_numericality_of(:max_artifacts_size).only_integer.is_greater_than(0) }
it { is_expected.to validate_length_of(:suggestion_commit_message).is_at_most(255) }
context 'when require_organization feature is disabled' do
before do
stub_feature_flags(require_organization: false)
end
it { is_expected.not_to validate_presence_of(:organization) }
end
it 'validates name is case-sensitively unique within the scope of namespace_id' do
project = create(:project)

View File

@ -392,18 +392,22 @@ RSpec.describe ResourceAccessTokens::CreateService, feature_category: :system_ac
end
end
context 'when resource organization is not set', :enable_admin_mode do
let_it_be(:resource) { create(:project, :private, organization_id: nil) }
let_it_be(:default_organization) { Organizations::Organization.default_organization }
let(:user) { create(:admin) }
context 'when require_organization feature is disabled' do
before_all do
stub_feature_flags(require_organization: false)
end
it 'uses database default' do
response = subject
context 'when resource organization is not set', :enable_admin_mode do
let_it_be(:resource) { create(:project, :private, organization_id: nil) }
let_it_be(:default_organization) { Organizations::Organization.default_organization }
let(:user) { create(:admin) }
access_token = response.payload[:access_token]
expect(access_token.user.namespace.organization).to eq(
default_organization
)
it 'uses database default' do
response = subject
access_token = response.payload[:access_token]
expect(access_token.user.namespace.organization).to eq(default_organization)
end
end
end
end

View File

@ -126,7 +126,17 @@ RSpec.describe ServicePing::SubmitService, feature_category: :service_ping do
error_response = stub_response(body: nil, url: service_ping_errors_url, status: 201)
metadata_response = stub_response(body: nil, url: service_ping_metadata_url, status: 201)
expect(Gitlab::HTTP).to receive(:post).twice.and_call_original
expect(Gitlab::HTTP).to receive(:post)
.with(
anything,
hash_including(
headers: {
'Content-type' => 'application/json',
'Accept' => 'application/json'
}
)
).twice
.and_call_original
subject.execute