Commit 5fab6ac5 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch...

Merge branch '341001-discussion-proper-method-naming-for-project-user-group-namespaces' into 'master'

Convert namespace methods project?, group?, and user?

See merge request gitlab-org/gitlab!70544
parents c3def839 350b0578
...@@ -247,27 +247,27 @@ class Namespace < ApplicationRecord ...@@ -247,27 +247,27 @@ class Namespace < ApplicationRecord
end end
def kind def kind
return 'group' if group? return 'group' if group_namespace?
return 'project' if project? return 'project' if project_namespace?
'user' # defaults to user 'user' # defaults to user
end end
def group? def group_namespace?
type == Group.sti_name type == Group.sti_name
end end
def project? def project_namespace?
type == Namespaces::ProjectNamespace.sti_name type == Namespaces::ProjectNamespace.sti_name
end end
def user? def user_namespace?
# That last bit ensures we're considered a user namespace as a default # That last bit ensures we're considered a user namespace as a default
type.nil? || type == Namespaces::UserNamespace.sti_name || !(group? || project?) type.nil? || type == Namespaces::UserNamespace.sti_name || !(group_namespace? || project_namespace?)
end end
def owner_required? def owner_required?
user? user_namespace?
end end
def find_fork_of(project) def find_fork_of(project)
...@@ -314,7 +314,7 @@ class Namespace < ApplicationRecord ...@@ -314,7 +314,7 @@ class Namespace < ApplicationRecord
# that belongs to this namespace # that belongs to this namespace
def all_projects def all_projects
if Feature.enabled?(:recursive_approach_for_all_projects, default_enabled: :yaml) if Feature.enabled?(:recursive_approach_for_all_projects, default_enabled: :yaml)
namespace = user? ? self : self_and_descendant_ids namespace = user_namespace? ? self : self_and_descendant_ids
Project.where(namespace: namespace) Project.where(namespace: namespace)
else else
Project.inside_path(full_path) Project.inside_path(full_path)
...@@ -536,21 +536,21 @@ class Namespace < ApplicationRecord ...@@ -536,21 +536,21 @@ class Namespace < ApplicationRecord
def validate_parent_type def validate_parent_type
unless has_parent? unless has_parent?
if project? if project_namespace?
errors.add(:parent_id, _('must be set for a project namespace')) errors.add(:parent_id, _('must be set for a project namespace'))
end end
return return
end end
if parent.project? if parent.project_namespace?
errors.add(:parent_id, _('project namespace cannot be the parent of another namespace')) errors.add(:parent_id, _('project namespace cannot be the parent of another namespace'))
end end
if user? if user_namespace?
errors.add(:parent_id, _('cannot not be used for user namespace')) errors.add(:parent_id, _('cannot not be used for user namespace'))
elsif group? elsif group_namespace?
errors.add(:parent_id, _('user namespace cannot be the parent of another namespace')) if parent.user? errors.add(:parent_id, _('user namespace cannot be the parent of another namespace')) if parent.user_namespace?
end end
end end
......
...@@ -57,7 +57,7 @@ class Namespace::RootStorageStatistics < ApplicationRecord ...@@ -57,7 +57,7 @@ class Namespace::RootStorageStatistics < ApplicationRecord
end end
def attributes_from_personal_snippets def attributes_from_personal_snippets
return {} unless namespace.user? return {} unless namespace.user_namespace?
from_personal_snippets.take.slice(SNIPPETS_SIZE_STAT_NAME) from_personal_snippets.take.slice(SNIPPETS_SIZE_STAT_NAME)
end end
......
...@@ -99,7 +99,7 @@ module Clusters ...@@ -99,7 +99,7 @@ module Clusters
end end
def group_root_ancestor? def group_root_ancestor?
root_ancestor.group? root_ancestor.group_namespace?
end end
end end
end end
......
...@@ -59,7 +59,7 @@ module BillingPlansHelper ...@@ -59,7 +59,7 @@ module BillingPlansHelper
# This can be removed once https://gitlab.com/gitlab-org/gitlab/-/issues/298715 is complete. # This can be removed once https://gitlab.com/gitlab-org/gitlab/-/issues/298715 is complete.
return false unless current_user.last_name.present? return false unless current_user.last_name.present?
namespace.group? && (namespace.actual_plan_name == Plan::FREE || namespace.trial_active?) namespace.group_namespace? && (namespace.actual_plan_name == Plan::FREE || namespace.trial_active?)
end end
def plan_feature_list(plan) def plan_feature_list(plan)
...@@ -163,7 +163,7 @@ module BillingPlansHelper ...@@ -163,7 +163,7 @@ module BillingPlansHelper
end end
def billable_seats_href(namespace) def billable_seats_href(namespace)
return unless namespace.group? return unless namespace.group_namespace?
group_usage_quotas_path(namespace, anchor: 'seats-quota-tab') group_usage_quotas_path(namespace, anchor: 'seats-quota-tab')
end end
......
...@@ -71,7 +71,7 @@ module EE ...@@ -71,7 +71,7 @@ module EE
end end
def usage_quotas_path(namespace, *args) def usage_quotas_path(namespace, *args)
if namespace.group? if namespace.group_namespace?
group_usage_quotas_path(namespace, *args) group_usage_quotas_path(namespace, *args)
else else
profile_usage_quotas_path(*args) profile_usage_quotas_path(*args)
......
...@@ -40,7 +40,7 @@ module EE ...@@ -40,7 +40,7 @@ module EE
end end
def link_to_buy_additional_minutes_path(namespace) def link_to_buy_additional_minutes_path(namespace)
use_customer_dot_path = namespace.user? || ::Feature.disabled?(:new_route_ci_minutes_purchase, namespace, default_enabled: :yaml) use_customer_dot_path = namespace.user_namespace? || ::Feature.disabled?(:new_route_ci_minutes_purchase, namespace, default_enabled: :yaml)
return EE::SUBSCRIPTIONS_MORE_MINUTES_URL if use_customer_dot_path return EE::SUBSCRIPTIONS_MORE_MINUTES_URL if use_customer_dot_path
buy_minutes_subscriptions_path(selected_group: namespace.id) buy_minutes_subscriptions_path(selected_group: namespace.id)
......
...@@ -165,7 +165,7 @@ module EE ...@@ -165,7 +165,7 @@ module EE
def allow_filtering_by_iteration? def allow_filtering_by_iteration?
# We currently only have group-level iterations so we hide # We currently only have group-level iterations so we hide
# this filter for projects under personal namespaces # this filter for projects under personal namespaces
return false if @project && @project.namespace.user? return false if @project && @project.namespace.user_namespace?
context = @project.presence || @group.presence context = @project.presence || @group.presence
......
...@@ -92,7 +92,7 @@ module EE ...@@ -92,7 +92,7 @@ module EE
return false unless namespace.bronze_plan? return false unless namespace.bronze_plan?
return false if user_dismissed?(EOA_BRONZE_PLAN_BANNER) return false if user_dismissed?(EOA_BRONZE_PLAN_BANNER)
(namespace.group? && namespace.has_owner?(current_user.id)) || !namespace.group? (namespace.group_namespace? && namespace.has_owner?(current_user.id)) || !namespace.group_namespace?
end end
override :dismiss_two_factor_auth_recovery_settings_check override :dismiss_two_factor_auth_recovery_settings_check
......
...@@ -393,7 +393,7 @@ module EE ...@@ -393,7 +393,7 @@ module EE
end end
def free_personal? def free_personal?
user? && !paid? user_namespace? && !paid?
end end
def use_elasticsearch? def use_elasticsearch?
......
...@@ -23,7 +23,7 @@ module EE ...@@ -23,7 +23,7 @@ module EE
# the query. If this changes in the future and we add some sort of resource to # the query. If this changes in the future and we add some sort of resource to
# users that it's store in NamespaceStatistics, we will need to remove this # users that it's store in NamespaceStatistics, we will need to remove this
# guard clause. # guard clause.
return {} unless namespace.group? return {} unless namespace.group_namespace?
from_namespace_statistics.take.slice(*NAMESPACE_STATISTICS_ATTRIBUTES) from_namespace_statistics.take.slice(*NAMESPACE_STATISTICS_ATTRIBUTES)
end end
......
...@@ -14,13 +14,13 @@ class NamespaceStatistics < ApplicationRecord ...@@ -14,13 +14,13 @@ class NamespaceStatistics < ApplicationRecord
after_save :update_root_storage_statistics, if: :saved_change_to_storage_size? after_save :update_root_storage_statistics, if: :saved_change_to_storage_size?
after_destroy :update_root_storage_statistics after_destroy :update_root_storage_statistics
delegate :group?, to: :namespace delegate :group_namespace?, to: :namespace
COLUMNS_TO_REFRESH = [:wiki_size].freeze COLUMNS_TO_REFRESH = [:wiki_size].freeze
def refresh!(only: []) def refresh!(only: [])
return if Gitlab::Database.read_only? return if Gitlab::Database.read_only?
return unless group? return unless group_namespace?
COLUMNS_TO_REFRESH.each do |column| COLUMNS_TO_REFRESH.each do |column|
if only.empty? || only.include?(column) if only.empty? || only.include?(column)
...@@ -44,11 +44,11 @@ class NamespaceStatistics < ApplicationRecord ...@@ -44,11 +44,11 @@ class NamespaceStatistics < ApplicationRecord
private private
def group_wiki_available? def group_wiki_available?
group? && namespace.feature_available?(:group_wikis) group_namespace? && namespace.feature_available?(:group_wikis)
end end
def update_root_storage_statistics def update_root_storage_statistics
return unless group? return unless group_namespace?
run_after_commit do run_after_commit do
Namespaces::ScheduleAggregationWorker.perform_async(namespace.id) Namespaces::ScheduleAggregationWorker.perform_async(namespace.id)
......
...@@ -62,7 +62,7 @@ module Ci ...@@ -62,7 +62,7 @@ module Ci
end end
def owner_ids_for(namespace) def owner_ids_for(namespace)
namespace.user? ? Array(namespace.owner_id) : namespace.owner_ids namespace.user_namespace? ? Array(namespace.owner_id) : namespace.owner_ids
end end
end end
end end
......
...@@ -58,7 +58,7 @@ module Ci ...@@ -58,7 +58,7 @@ module Ci
end end
def recipients def recipients
namespace.user? ? [namespace.owner_email] : namespace.owners_emails namespace.user_namespace? ? [namespace.owner_email] : namespace.owners_emails
end end
def namespace def namespace
......
...@@ -7,7 +7,7 @@ module EE ...@@ -7,7 +7,7 @@ module EE
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepended do prepended do
with_options if: -> (issue, _) { issue.project.namespace.group? && issue.project.namespace.feature_available?(:epics) } do with_options if: -> (issue, _) { issue.project.namespace.group_namespace? && issue.project.namespace.feature_available?(:epics) } do
expose :epic_iid do |issue| expose :epic_iid do |issue|
authorized_epic_for(issue)&.iid authorized_epic_for(issue)&.iid
end end
......
...@@ -134,7 +134,7 @@ module Gitlab ...@@ -134,7 +134,7 @@ module Gitlab
plan: namespace.actual_plan_name, plan: namespace.actual_plan_name,
trial: !!namespace.trial?, trial: !!namespace.trial?,
kind: namespace.kind, kind: namespace.kind,
membersCountWithDescendants: namespace.group? ? namespace.users_with_descendants.count : nil membersCountWithDescendants: namespace.group_namespace? ? namespace.users_with_descendants.count : nil
} }
end end
......
...@@ -74,7 +74,7 @@ RSpec.describe Namespace do ...@@ -74,7 +74,7 @@ RSpec.describe Namespace do
with_them do with_them do
before do before do
allow(namespace).to receive(:user?).and_return(user) allow(namespace).to receive(:user_namespace?).and_return(user)
allow(namespace).to receive(:paid?).and_return(paid) allow(namespace).to receive(:paid?).and_return(paid)
end end
......
...@@ -6,7 +6,7 @@ module API ...@@ -6,7 +6,7 @@ module API
expose :id, :name, :path, :kind, :full_path, :parent_id, :avatar_url expose :id, :name, :path, :kind, :full_path, :parent_id, :avatar_url
expose :web_url do |namespace| expose :web_url do |namespace|
if namespace.user? if namespace.user_namespace?
Gitlab::Routing.url_helpers.user_url(namespace.owner) Gitlab::Routing.url_helpers.user_url(namespace.owner)
else else
namespace.web_url namespace.web_url
......
...@@ -175,7 +175,7 @@ RSpec.describe Namespace do ...@@ -175,7 +175,7 @@ RSpec.describe Namespace do
it 'is valid' do it 'is valid' do
expect(namespace).to be_a(Group) expect(namespace).to be_a(Group)
expect(namespace.kind).to eq('group') expect(namespace.kind).to eq('group')
expect(namespace.group?).to be_truthy expect(namespace.group_namespace?).to be_truthy
end end
end end
...@@ -186,7 +186,7 @@ RSpec.describe Namespace do ...@@ -186,7 +186,7 @@ RSpec.describe Namespace do
it 'is valid' do it 'is valid' do
expect(Namespace.find(namespace.id)).to be_a(Namespaces::ProjectNamespace) expect(Namespace.find(namespace.id)).to be_a(Namespaces::ProjectNamespace)
expect(namespace.kind).to eq('project') expect(namespace.kind).to eq('project')
expect(namespace.project?).to be_truthy expect(namespace.project_namespace?).to be_truthy
end end
end end
...@@ -198,7 +198,7 @@ RSpec.describe Namespace do ...@@ -198,7 +198,7 @@ RSpec.describe Namespace do
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68894 is ready # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68894 is ready
expect(Namespace.find(namespace.id)).to be_a(Namespace) expect(Namespace.find(namespace.id)).to be_a(Namespace)
expect(namespace.kind).to eq('user') expect(namespace.kind).to eq('user')
expect(namespace.user?).to be_truthy expect(namespace.user_namespace?).to be_truthy
end end
end end
...@@ -208,7 +208,7 @@ RSpec.describe Namespace do ...@@ -208,7 +208,7 @@ RSpec.describe Namespace do
it 'is valid' do it 'is valid' do
expect(Namespace.find(namespace.id)).to be_a(Namespace) expect(Namespace.find(namespace.id)).to be_a(Namespace)
expect(namespace.kind).to eq('user') expect(namespace.kind).to eq('user')
expect(namespace.user?).to be_truthy expect(namespace.user_namespace?).to be_truthy
end end
end end
...@@ -218,7 +218,7 @@ RSpec.describe Namespace do ...@@ -218,7 +218,7 @@ RSpec.describe Namespace do
it 'defaults to a Namespace' do it 'defaults to a Namespace' do
expect(Namespace.find(namespace.id)).to be_a(Namespace) expect(Namespace.find(namespace.id)).to be_a(Namespace)
expect(namespace.kind).to eq('user') expect(namespace.kind).to eq('user')
expect(namespace.user?).to be_truthy expect(namespace.user_namespace?).to be_truthy
end end
end end
end end
...@@ -1558,8 +1558,8 @@ RSpec.describe Namespace do ...@@ -1558,8 +1558,8 @@ RSpec.describe Namespace do
end end
end end
describe '#user?' do describe '#user_namespace?' do
subject { namespace.user? } subject { namespace.user_namespace? }
context 'when type is a user' do context 'when type is a user' do
let(:user) { create(:user) } let(:user) { create(:user) }
......
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