Class: Organizations::Organization
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Organizations::Organization
- Includes:
- Cells::Claimable, FeatureGate, Gitlab::SQL::Pattern, Gitlab::Utils::StrongMemoize, Gitlab::VisibilityLevel, Isolatable
- Defined in:
- app/models/organizations/organization.rb
Constant Summary collapse
- DEFAULT_ORGANIZATION_ID =
1
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 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
Constants included from HasCheckConstraints
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
Constants included from ResetOnColumnErrors
ResetOnColumnErrors::MAX_RESET_PERIOD
Class Method Summary collapse
- .default?(id) ⇒ Boolean
- .default_organization ⇒ Object
- .search(query, use_minimum_char_limit: true) ⇒ Object
Instance Method Summary collapse
- #add_owner(user) ⇒ Object
- #default? ⇒ Boolean
-
#full_path ⇒ Object
Deprecated, use root_path instead.
- #inspect ⇒ Object
- #organization_detail ⇒ Object
- #owner?(user) ⇒ Boolean
- #owner_user_ids ⇒ Object
-
#root_path ⇒ Object
Root path in the context of this organization instance.
-
#scoped_paths? ⇒ Boolean
For example: scoped path - /o/my-org/my-group/my-project unscoped path - /my-group/my-project.
- #to_param ⇒ Object
- #user?(user) ⇒ Boolean
-
#visibility_level_field ⇒ Object
Required for Gitlab::VisibilityLevel module.
- #web_url(only_path: nil) ⇒ Object
Methods included from Cells::Claimable
Methods included from Isolatable
#isolated?, #mark_as_isolated!, #mark_as_not_isolated!, #not_isolated?
Methods included from FeatureGate
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
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 Sharding
Methods included from ResetOnColumnErrors
#reset_on_union_error, #reset_on_unknown_attribute_error
Methods included from Gitlab::SensitiveSerializableHash
Class Method Details
.default?(id) ⇒ Boolean
80 81 82 |
# File 'app/models/organizations/organization.rb', line 80 def self.default?(id) id == DEFAULT_ORGANIZATION_ID end |
.default_organization ⇒ Object
76 77 78 |
# File 'app/models/organizations/organization.rb', line 76 def self.default_organization find_by(id: DEFAULT_ORGANIZATION_ID) end |
.search(query, use_minimum_char_limit: true) ⇒ Object
72 73 74 |
# File 'app/models/organizations/organization.rb', line 72 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
116 117 118 |
# File 'app/models/organizations/organization.rb', line 116 def add_owner(user) organization_users.owners.create(user: user) end |
#default? ⇒ Boolean
93 94 95 |
# File 'app/models/organizations/organization.rb', line 93 def default? self.class.default?(id) end |
#full_path ⇒ Object
Deprecated, use root_path instead. Will be removed in future commit.
144 145 146 147 148 |
# File 'app/models/organizations/organization.rb', line 144 def full_path return '' unless scoped_paths? "/o/#{path}" end |
#inspect ⇒ Object
131 132 133 |
# File 'app/models/organizations/organization.rb', line 131 def inspect "#<#{self.class.name} id:#{id} path:#{path}>" end |
#organization_detail ⇒ Object
89 90 91 |
# File 'app/models/organizations/organization.rb', line 89 def organization_detail super.presence || build_organization_detail end |
#owner?(user) ⇒ Boolean
112 113 114 |
# File 'app/models/organizations/organization.rb', line 112 def owner?(user) organization_users.owners.exists?(user: user) end |
#owner_user_ids ⇒ Object
101 102 103 104 105 |
# File 'app/models/organizations/organization.rb', line 101 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 |
#root_path ⇒ Object
Root path in the context of this organization instance.
136 137 138 139 140 |
# File 'app/models/organizations/organization.rb', line 136 def root_path return organization_root_path(self) if scoped_paths? unscoped_root_path end |
#scoped_paths? ⇒ Boolean
For example: scoped path - /o/my-org/my-group/my-project unscoped path - /my-group/my-project
127 128 129 |
# File 'app/models/organizations/organization.rb', line 127 def scoped_paths? Feature.enabled?(:organization_scoped_paths, self) && !default? end |
#to_param ⇒ Object
97 98 99 |
# File 'app/models/organizations/organization.rb', line 97 def to_param path end |
#user?(user) ⇒ Boolean
108 109 110 |
# File 'app/models/organizations/organization.rb', line 108 def user?(user) organization_users.exists?(user: user) end |
#visibility_level_field ⇒ Object
Required for Gitlab::VisibilityLevel module
85 86 87 |
# File 'app/models/organizations/organization.rb', line 85 def visibility_level_field :visibility_level end |
#web_url(only_path: nil) ⇒ Object
120 121 122 |
# File 'app/models/organizations/organization.rb', line 120 def web_url(only_path: nil) Gitlab::UrlBuilder.build(self, only_path: only_path) end |