Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/organizations')
-rw-r--r--app/models/organizations/organization.rb10
-rw-r--r--app/models/organizations/organization_detail.rb2
-rw-r--r--app/models/organizations/organization_user.rb12
3 files changed, 21 insertions, 3 deletions
diff --git a/app/models/organizations/organization.rb b/app/models/organizations/organization.rb
index 764378a5d19..df6f0109d57 100644
--- a/app/models/organizations/organization.rb
+++ b/app/models/organizations/organization.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module Organizations
- class Organization < ApplicationRecord
+ class Organization < MainClusterwide::ApplicationRecord
DEFAULT_ORGANIZATION_ID = 1
scope :without_default, -> { where.not(id: DEFAULT_ORGANIZATION_ID) }
@@ -16,6 +16,8 @@ module Organizations
has_one :organization_detail, inverse_of: :organization, autosave: true
has_many :organization_users, inverse_of: :organization
+ # if considering disable_joins on the below see:
+ # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/140343#note_1705047949
has_many :users, through: :organization_users, inverse_of: :organizations
validates :name,
@@ -28,7 +30,7 @@ module Organizations
'organizations/path': true,
length: { minimum: 2, maximum: 255 }
- delegate :description, :avatar, :avatar_url, to: :organization_detail
+ delegate :description, :description_html, :avatar, :avatar_url, :remove_avatar!, to: :organization_detail
accepts_nested_attributes_for :organization_detail
@@ -52,6 +54,10 @@ module Organizations
organization_users.exists?(user: user)
end
+ def owner?(user)
+ organization_users.owners.exists?(user: user)
+ end
+
def web_url(only_path: nil)
Gitlab::UrlBuilder.build(self, only_path: only_path)
end
diff --git a/app/models/organizations/organization_detail.rb b/app/models/organizations/organization_detail.rb
index b69ec5eae76..018e7579c5b 100644
--- a/app/models/organizations/organization_detail.rb
+++ b/app/models/organizations/organization_detail.rb
@@ -6,7 +6,7 @@ module Organizations
include Avatarable
include WithUploads
- cache_markdown_field :description
+ cache_markdown_field :description, pipeline: :description
belongs_to :organization, inverse_of: :organization_detail
diff --git a/app/models/organizations/organization_user.rb b/app/models/organizations/organization_user.rb
index 5aa1133b017..9e06870dcc6 100644
--- a/app/models/organizations/organization_user.rb
+++ b/app/models/organizations/organization_user.rb
@@ -4,5 +4,17 @@ module Organizations
class OrganizationUser < ApplicationRecord
belongs_to :organization, inverse_of: :organization_users, optional: false
belongs_to :user, inverse_of: :organization_users, optional: false
+
+ validates :user, uniqueness: { scope: :organization_id }
+ validates :access_level, presence: true
+
+ enum access_level: {
+ # Until we develop more access_levels, we really don't know if the default access_level will be what we think of
+ # as a guest. For now, we'll set to same value as guest, but call it default to denote the current ambivalence.
+ default: Gitlab::Access::GUEST,
+ owner: Gitlab::Access::OWNER
+ }
+
+ scope :owners, -> { where(access_level: Gitlab::Access::OWNER) }
end
end