Class: Organizations::Organization

Inherits:
ApplicationRecord show all
Includes:
FeatureGate, Gitlab::SQL::Pattern, Gitlab::Utils::StrongMemoize, Gitlab::VisibilityLevel
Defined in:
app/models/organizations/organization.rb

Constant Summary collapse

DEFAULT_ORGANIZATION_ID =
1

Constants included from Gitlab::VisibilityLevel

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

Constants included from Gitlab::SQL::Pattern

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

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FeatureGate

#flipper_id

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 included from Gitlab::SQL::Pattern

split_query_to_search_terms

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!, sharding_keys, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.default?(id) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'app/models/organizations/organization.rb', line 66

def self.default?(id)
  id == DEFAULT_ORGANIZATION_ID
end

.default_organizationObject



62
63
64
# File 'app/models/organizations/organization.rb', line 62

def self.default_organization
  find_by(id: DEFAULT_ORGANIZATION_ID)
end

.search(query, use_minimum_char_limit: true) ⇒ Object



58
59
60
# File 'app/models/organizations/organization.rb', line 58

def self.search(query, use_minimum_char_limit: true)
  fuzzy_search(query, [:name, :path], use_minimum_char_limit: use_minimum_char_limit)
end

Instance Method Details

#add_owner(user) ⇒ Object



102
103
104
# File 'app/models/organizations/organization.rb', line 102

def add_owner(user)
  organization_users.owners.create(user: user)
end

#default?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/models/organizations/organization.rb', line 79

def default?
  self.class.default?(id)
end

#full_pathObject



121
122
123
124
125
# File 'app/models/organizations/organization.rb', line 121

def full_path
  return '' unless scoped_paths?

  "/o/#{path}"
end

#inspectObject



117
118
119
# File 'app/models/organizations/organization.rb', line 117

def inspect
  "#<#{self.class.name} id:#{id} path:#{path}>"
end

#organization_detailObject



75
76
77
# File 'app/models/organizations/organization.rb', line 75

def organization_detail
  super.presence || build_organization_detail
end

#owner?(user) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'app/models/organizations/organization.rb', line 98

def owner?(user)
  organization_users.owners.exists?(user: user)
end

#owner_user_idsObject



87
88
89
90
91
# File 'app/models/organizations/organization.rb', line 87

def owner_user_ids
  # rubocop:disable Database/AvoidUsingPluckWithoutLimit -- few owners, and not used with IN clause
  organization_users.owners.pluck(:user_id)
  # rubocop:enable Database/AvoidUsingPluckWithoutLimit
end

#scoped_paths?Boolean

For example: scoped path - /o/my-org/my-group/my-project unscoped path - /my-group/my-project

Returns:

  • (Boolean)


113
114
115
# File 'app/models/organizations/organization.rb', line 113

def scoped_paths?
  Feature.enabled?(:organization_scoped_paths, self) && !default?
end

#to_paramObject



83
84
85
# File 'app/models/organizations/organization.rb', line 83

def to_param
  path
end

#user?(user) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'app/models/organizations/organization.rb', line 94

def user?(user)
  organization_users.exists?(user: user)
end

#visibility_level_fieldObject

Required for Gitlab::VisibilityLevel module



71
72
73
# File 'app/models/organizations/organization.rb', line 71

def visibility_level_field
  :visibility_level
end

#web_url(only_path: nil) ⇒ Object



106
107
108
# File 'app/models/organizations/organization.rb', line 106

def web_url(only_path: nil)
  Gitlab::UrlBuilder.build(self, only_path: only_path)
end