Class: Namespaces::ProjectNamespace

Inherits:
Namespace show all
Defined in:
app/models/namespaces/project_namespace.rb

Constant Summary collapse

SYNCED_ATTRIBUTES =
%w[
  name
  path
  namespace_id
  namespace
  visibility_level
  shared_runners_enabled
  organization_id
].freeze

Constants inherited from Namespace

Namespace::NUMBER_OF_ANCESTORS_ALLOWED, Namespace::SHARED_RUNNERS_SETTINGS, Namespace::SR_DISABLED_AND_OVERRIDABLE, Namespace::SR_DISABLED_AND_UNOVERRIDABLE, Namespace::SR_ENABLED, Namespace::STATISTICS_COLUMNS, Namespace::URL_MAX_LENGTH

Constants included from Cells::Claimable

Cells::Claimable::CLAIMS_BUCKET_TYPE, Cells::Claimable::CLAIMS_SOURCE_TYPE, Cells::Claimable::CLAIMS_SUBJECT_TYPE, Cells::Claimable::MissingPrimaryKeyError

Constants included from BlocksUnsafeSerialization

BlocksUnsafeSerialization::UnsafeSerializationError

Constants included from Stateful

Stateful::STATES

Constants included from Traversal::Linear

Traversal::Linear::UnboundedSearch

Constants included from Gitlab::SQL::Pattern

Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_TERM

Constants included from Gitlab::VisibilityLevel

Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::LEVELS_FOR_ADMINS, Gitlab::VisibilityLevel::PRIVATE, Gitlab::VisibilityLevel::PUBLIC

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Instance Attribute Summary

Attributes inherited from Namespace

#emails_enabled_memoized, #root_ancestor

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Namespace

#actual_limits, #actual_plan, #actual_plan_name, #aggregation_scheduled?, #all_active_project_ids, #all_ancestors_have_runner_registration_enabled?, #all_catalog_resources, #all_container_repositories, #all_project_ids_except, #all_projects_except_soft_deleted, #all_projects_with_pages, #allow_runner_registration_token?, #allowed_work_item_type?, #allowed_work_item_types, #ancestors_archived?, #any_project_has_container_registry_tags?, #any_project_with_pages_deployed?, #any_project_with_shared_runners_enabled?, #archived?, #auto_devops_enabled?, #bot_user_namespace?, by_path, #certificate_based_clusters_enabled?, #changing_allow_descendants_override_disabled_shared_runners_is_allowed, #changing_shared_runners_enabled_is_allowed, clean_path, #closest_setting, #container_repositories_size, #container_repositories_size_cache_key, #default_branch_protected?, #default_branch_protection, #default_branch_protection_settings, #emails_disabled?, #emails_enabled?, #enabled_git_access_protocol, #feature_available?, find_by_path_or_name, #find_fork_of, find_top_level, #first_auto_devops_config, #first_owner, #first_project_with_container_registry_tags, #full_path_before_last_save, gfm_autocomplete_search, #group_namespace?, #has_parent?, #human_name, #issue_repositioning_disabled?, #kind, #lfs_enabled?, #licensed_feature_available?, #linked_to_subscription?, #multiple_issue_boards_available?, #namespace_details, #owner_entity_name, #owner_required?, #package_settings, #pages_access_control_forced_by_ancestor?, #pages_access_control_forced_by_self_or_ancestor?, #pages_access_control_trie, #paid?, #pipeline_variables_default_role, #project_namespace?, #recent?, reference_pattern, reference_prefix, #refresh_project_authorizations, #root?, root_ids_for, search, #self_deletion_in_progress?, #self_or_ancestors_archived?, self_or_ancestors_archived_setting_subquery, #send_update_instructions, #shared_runners, #shared_runners_setting, #shared_runners_setting_higher_than?, sti_class_for, #subgroup?, sum_project_statistics_column, #supports_work_items?, #to_param, #to_reference, #to_reference_base, #traversal_ids_as_sql, #uploads_sharding_key, #user_ids_for_project_authorizations, #user_namespace?, #user_role, username_reserved?, username_reserved_for_organization?, #visibility_level_field, #web_url

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Methods included from Cells::Claimable

#handle_grpc_error

Methods included from Referable

#referable_inspect, #reference_link_text, #to_reference, #to_reference_base

Methods included from Ci::NamespaceSettings

#allow_stale_runner_pruning=, #allow_stale_runner_pruning?

Methods included from BlocksUnsafeSerialization

#serializable_hash

Methods included from Organizations::Isolatable

#isolated?, #mark_as_isolated!, #mark_as_not_isolated!, #not_isolated?

Methods included from AdjournedDeletable

#ancestor_scheduled_for_deletion?, #deletion_adjourned_period, #deletion_in_progress_or_scheduled_in_hierarchy_chain?, #first_scheduled_for_deletion_in_hierarchy_chain, #scheduled_for_deletion_in_hierarchy_chain?, #self_deletion_in_progress?, #self_deletion_scheduled?, #self_deletion_scheduled_deletion_created_on

Methods included from Traversal::Cached

#all_project_ids, #all_unarchived_project_ids, #descendant_ids, #self_and_descendant_ids

Methods included from Traversal::Linear

#all_project_ids, #ancestor_ids, #ancestors, #ancestors_upto, #descendants, #parent=, #parent_id=, #root_ancestor, #self_and_ancestor_ids, #self_and_ancestors, #self_and_descendant_ids, #self_and_descendants, #self_and_hierarchy, #traversal_path, #use_traversal_ids?

Methods included from Traversal::Recursive

#all_project_ids, #all_unarchived_project_ids, #ancestor_ids, #ancestors, #ancestors_upto, #descendants, #object_hierarchy, #root_ancestor, #self_and_ancestor_ids, #self_and_ancestors, #self_and_descendant_ids, #self_and_descendants, #self_and_hierarchy

Methods included from FeatureGate

#flipper_id

Methods included from Gitlab::SQL::Pattern

split_query_to_search_terms

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods included from Routable

#build_full_path, find_by_full_path, #full_name, #full_path, #full_path_components, #owned_by?

Methods included from Gitlab::VisibilityLevel

allowed_for?, allowed_level?, allowed_levels, allowed_levels_for_user, closest_allowed_level, #internal?, level_name, level_value, levels_for_user, non_restricted_level?, options, #private?, #public?, public_visibility_restricted?, restricted_level?, string_level, string_options, string_values, valid_level?, #visibility, #visibility=, #visibility_attribute_present?, #visibility_attribute_value, #visibility_level_attributes, #visibility_level_previous_changes, #visibility_level_value

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from Organizations::Sharding

#sharding_organization

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.create_from_project!(project) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'app/models/namespaces/project_namespace.rb', line 42

def self.create_from_project!(project)
  return unless project.new_record?
  return unless project.namespace

  proj_namespace = project.project_namespace || project.build_project_namespace
  project.project_namespace.sync_attributes_from_project(project)
  proj_namespace.save!
  proj_namespace
end

.polymorphic_nameObject



38
39
40
# File 'app/models/namespaces/project_namespace.rb', line 38

def self.polymorphic_name
  'Namespaces::ProjectNamespace'
end

.sti_nameObject



34
35
36
# File 'app/models/namespaces/project_namespace.rb', line 34

def self.sti_name
  'Project'
end

Instance Method Details

#all_projectsObject

It’s always 1 project but it has to be an AR relation



83
84
85
# File 'app/models/namespaces/project_namespace.rb', line 83

def all_projects
  Project.where(id: project.id)
end

#max_member_access_for_user(user) ⇒ Object



87
88
89
# File 'app/models/namespaces/project_namespace.rb', line 87

def max_member_access_for_user(user)
  project.max_member_access_for_user(user)
end

#owner_entityObject



53
54
55
# File 'app/models/namespaces/project_namespace.rb', line 53

def owner_entity
  project
end

#sync_attributes_from_project(project) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/namespaces/project_namespace.rb', line 57

def sync_attributes_from_project(project)
  attributes_to_sync = project
                         .changes
                         .slice(*SYNCED_ATTRIBUTES)
                         .transform_values { |val| val[1] }

  # if visibility_level is not set explicitly for project, it defaults to 0,
  # but for namespace visibility_level defaults to 20,
  # so it gets out of sync right away if we do not set it explicitly when creating the project namespace
  attributes_to_sync['visibility_level'] ||= project.visibility_level if project.new_record?

  # when a project is associated with a group while the group is created we need to ensure we associate the new
  # group with the project namespace as well.
  # E.g.
  # project = create(:project) <- project is saved
  # create(:group, projects: [project]) <- associate project with a group that is not yet created.
  if attributes_to_sync.has_key?('namespace_id') &&
      attributes_to_sync['namespace_id'].blank? &&
      project.namespace.present?
    attributes_to_sync['parent'] = project.namespace
  end

  assign_attributes(attributes_to_sync)
end