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

project.rb « models « user_mentions « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4e02bf97d122ea45e0b9955244e496eecc6801d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    module UserMentions
      module Models
        # isolated Namespace model
        class Project < ActiveRecord::Base
          include Concerns::IsolatedFeatureGate
          include Gitlab::BackgroundMigration::UserMentions::Lib::Gitlab::IsolatedVisibilityLevel

          self.table_name = 'projects'
          self.inheritance_column = :_type_disabled

          belongs_to :group, -> { where(type: 'Group') }, foreign_key: 'namespace_id', class_name: "::Gitlab::BackgroundMigration::UserMentions::Models::Group"
          belongs_to :namespace, class_name: "::Gitlab::BackgroundMigration::UserMentions::Models::Namespace"
          alias_method :parent, :namespace

          # Returns a collection of projects that is either public or visible to the
          # logged in user.
          def self.public_or_visible_to_user(user = nil, min_access_level = nil)
            min_access_level = nil if user&.can_read_all_resources?

            return public_to_user unless user

            if user.is_a?(::Gitlab::BackgroundMigration::UserMentions::Models::User)
              where('EXISTS (?) OR projects.visibility_level IN (?)',
                    user.authorizations_for_projects(min_access_level: min_access_level),
                    levels_for_user(user))
            end
          end

          def grafana_integration
            nil
          end

          def default_issues_tracker?
            true # we do not care of the issue tracker type(internal or external) when parsing mentions
          end

          def visibility_level_field
            :visibility_level
          end
        end
      end
    end
  end
end