Class: Namespaces::ProjectNamespace

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

Constant Summary

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_DISABLED_WITH_OVERRIDE, Namespace::SR_ENABLED, Namespace::URL_MAX_LENGTH

Constants included from BlocksUnsafeSerialization

BlocksUnsafeSerialization::UnsafeSerializationError

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::PRIVATE, Gitlab::VisibilityLevel::PUBLIC

Constants included from CacheMarkdownField

CacheMarkdownField::INVALIDATED_BY

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Attribute Summary

Attributes inherited from Namespace

#emails_disabled_memoized, #root_ancestor

Attributes included from CacheMarkdownField

#skip_markdown_cache_validation

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Namespace

#actual_limits, #actual_plan, #actual_plan_name, #aggregation_scheduled?, #all_ancestors_have_runner_registration_enabled?, #all_container_repositories, #all_project_ids, #all_project_ids_except, #all_projects, #all_projects_except_soft_deleted, #all_projects_with_pages, #allow_runner_registration_token?, #any_project_has_container_registry_tags?, #any_project_with_pages_deployed?, #any_project_with_shared_runners_enabled?, #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_name, clean_path, #closest_setting, #container_repositories_size, #container_repositories_size_cache_key, #default_branch_protection, #emails_disabled?, #emails_enabled?, #enabled_git_access_protocol, #feature_available?, find_by_path_or_name, #find_fork_of, #first_auto_devops_config, #first_owner, #first_project_with_container_registry_tags, #full_path_before_last_save, #group_namespace?, #has_parent?, #human_name, #issue_repositioning_disabled?, #kind, #lfs_enabled?, #licensed_feature_available?, #multiple_issue_boards_available?, #owner_required?, #package_settings, #paid?, #prevent_delete?, #project_namespace?, #recent?, reference_pattern, reference_prefix, #refresh_project_authorizations, #root?, search, #send_update_instructions, #shared_runners, #shared_runners_setting, #shared_runners_setting_higher_than?, sti_class_for, #subgroup?, #to_param, #to_reference, #to_reference_base, top_most, #user_ids_for_project_authorizations, #user_namespace?, #visibility_level_field

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 Gitlab::Utils::Override

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

Methods included from Traversal::Linear

#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_ids, #traversal_ids=, #use_traversal_ids?

Methods included from Traversal::Recursive

#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 Storage::LegacyNamespace

#move_dir, #prepare_for_destroy

Methods included from Gitlab::ShellAdapter

#gitlab_shell

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, optimize_routable_enabled?, #owned_by?, #parent_loaded?, #route_loaded?

Methods included from Gitlab::VisibilityLevel

allowed_for?, allowed_level?, allowed_levels, 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 included from CacheMarkdownField

#attribute_invalidated?, #banzai_render_context, #cached_html_for, #cached_html_up_to_date?, #can_cache_field?, #invalidated_markdown_cache?, #latest_cached_markdown_version, #local_version, #mentionable_attributes_changed?, #mentioned_filtered_user_ids_for, #parent_user, #refresh_markdown_cache, #refresh_markdown_cache!, #rendered_field_content, #skip_project_check?, #store_mentions!, #updated_cached_html_for

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, 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 SensitiveSerializableHash

#serializable_hash

Class Method Details

.create_from_project!(project) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'app/models/namespaces/project_namespace.rb', line 25

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



21
22
23
# File 'app/models/namespaces/project_namespace.rb', line 21

def self.polymorphic_name
  'Namespaces::ProjectNamespace'
end

.sti_nameObject



17
18
19
# File 'app/models/namespaces/project_namespace.rb', line 17

def self.sti_name
  'Project'
end

Instance Method Details

#sync_attributes_from_project(project) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/namespaces/project_namespace.rb', line 35

def sync_attributes_from_project(project)
  attributes_to_sync = project
                         .changes
                         .slice(*%w[name path namespace_id namespace visibility_level shared_runners_enabled])
                         .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