Commit 4804df2e authored by Brett Walker's avatar Brett Walker

Address reviewer comments

particuarly adding TODO comments where
code is temporary.
parent e358cac8
......@@ -101,6 +101,8 @@ class Namespace < ApplicationRecord
saved_change_to_name? || saved_change_to_path? || saved_change_to_parent_id?
}
# TODO: change to `type: Namespaces::UserNamespace.sti_name` when
# working on issue https://gitlab.com/gitlab-org/gitlab/-/issues/341070
scope :user_namespaces, -> { where(type: [nil, Namespaces::UserNamespace.sti_name]) }
scope :sort_by_type, -> { order(Gitlab::Database.nulls_first_order(:type)) }
scope :include_route, -> { includes(:route) }
......
# frozen_string_literal: true
# TODO: currently not created/mapped in the database, will be done in another issue
# https://gitlab.com/gitlab-org/gitlab/-/issues/337102
# https://gitlab.com/gitlab-org/gitlab/-/issues/341070
module Namespaces
class UserNamespace < Namespace
def self.sti_name
......
......@@ -112,6 +112,8 @@ class User < ApplicationRecord
#
# Namespace for personal projects
# TODO: change to `type: Namespaces::UserNamespace.sti_name` when
# working on issue https://gitlab.com/gitlab-org/gitlab/-/issues/341070
has_one :namespace, -> { where(type: [nil, Namespaces::UserNamespace.sti_name]) }, dependent: :destroy, foreign_key: :owner_id, inverse_of: :owner, autosave: true # rubocop:disable Cop/ActiveRecordDependent
# Profile
......
......@@ -452,6 +452,8 @@ module EE
end
end
# TODO: change to `type: ::Namespaces::UserNamespace.sti_name` when
# working on issue https://gitlab.com/gitlab-org/gitlab/-/issues/341070
def namespace_union_for_owned(select = :id)
::Gitlab::SQL::Union.new([
::Namespace.select(select).where(type: [nil, ::Namespaces::UserNamespace.sti_name], owner: self),
......@@ -459,6 +461,8 @@ module EE
]).to_sql
end
# TODO: change to `type: ::Namespaces::UserNamespace.sti_name` when
# working on issue https://gitlab.com/gitlab-org/gitlab/-/issues/341070
def namespace_union_for_reporter_developer_maintainer_owned(select = :id)
::Gitlab::SQL::Union.new([
::Namespace.select(select).where(type: [nil, ::Namespaces::UserNamespace.sti_name], owner: self),
......
......@@ -1343,6 +1343,8 @@ RSpec.describe User do
let_it_be(:free_group) { create(:group_with_plan, plan: :free_plan) }
let_it_be(:group_without_plan) { create(:group) }
# TODO: this `where/when` can be removed in issue https://gitlab.com/gitlab-org/gitlab/-/issues/341070
# At that point we only need to check `user_namespace`
where(namespace_type: [:namespace, :user_namespace])
with_them do
......
......@@ -178,7 +178,7 @@ RSpec.describe Namespace do
context 'creating a Group' do
let(:namespace_type) { group_sti_name }
it 'is valid' do
it 'is the correct type of namespace' do
expect(namespace).to be_a(Group)
expect(namespace.kind).to eq('group')
expect(namespace.group_namespace?).to be_truthy
......@@ -189,7 +189,7 @@ RSpec.describe Namespace do
let(:namespace_type) { project_sti_name }
let(:parent) { create(:group) }
it 'is valid' do
it 'is the correct type of namespace' do
expect(Namespace.find(namespace.id)).to be_a(Namespaces::ProjectNamespace)
expect(namespace.kind).to eq('project')
expect(namespace.project_namespace?).to be_truthy
......@@ -199,7 +199,7 @@ RSpec.describe Namespace do
context 'creating a UserNamespace' do
let(:namespace_type) { user_sti_name }
it 'is valid' do
it 'is the correct type of namespace' do
expect(Namespace.find(namespace.id)).to be_a(Namespaces::UserNamespace)
expect(namespace.kind).to eq('user')
expect(namespace.user_namespace?).to be_truthy
......@@ -209,7 +209,7 @@ RSpec.describe Namespace do
context 'creating a default Namespace' do
let(:namespace_type) { nil }
it 'is valid' do
it 'is the correct type of namespace' do
expect(Namespace.find(namespace.id)).to be_a(Namespace)
expect(namespace.kind).to eq('user')
expect(namespace.user_namespace?).to be_truthy
......
......@@ -2544,6 +2544,8 @@ RSpec.describe User do
describe '.find_by_full_path' do
using RSpec::Parameterized::TableSyntax
# TODO: this `where/when` can be removed in issue https://gitlab.com/gitlab-org/gitlab/-/issues/341070
# At that point we only need to check `user_namespace`
where(namespace_type: [:namespace, :user_namespace])
with_them do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment