Commit 8c7c6613 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'remove-ee-specific-lines-from-plan-concerns' into 'master'

Remove EE-specific lines from Plan concerns

Closes #6122

See merge request gitlab-org/gitlab-ee!7202
parents 51e7a93f a7cebd8b
...@@ -23,6 +23,8 @@ module Issuable ...@@ -23,6 +23,8 @@ module Issuable
include CreatedAtFilterable include CreatedAtFilterable
include UpdatedAtFilterable include UpdatedAtFilterable
prepend EE::Issuable
# This object is used to gather issuable meta data for displaying # This object is used to gather issuable meta data for displaying
# upvotes, downvotes, notes and closing merge requests count for issues and merge requests # upvotes, downvotes, notes and closing merge requests count for issues and merge requests
# lists avoiding n+1 queries and improving performance. # lists avoiding n+1 queries and improving performance.
...@@ -80,9 +82,6 @@ module Issuable ...@@ -80,9 +82,6 @@ module Issuable
scope :opened, -> { with_state(:opened) } scope :opened, -> { with_state(:opened) }
scope :only_opened, -> { with_state(:opened) } scope :only_opened, -> { with_state(:opened) }
scope :closed, -> { with_state(:closed) } scope :closed, -> { with_state(:closed) }
scope :order_milestone_due_desc, -> { outer_join_milestone.reorder('milestones.due_date IS NULL ASC, milestones.due_date DESC, milestones.id DESC') }
scope :order_milestone_due_asc, -> { outer_join_milestone.reorder('milestones.due_date IS NULL ASC, milestones.due_date ASC, milestones.id ASC') }
scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) }
scope :left_joins_milestones, -> { joins("LEFT OUTER JOIN milestones ON #{table_name}.milestone_id = milestones.id") } scope :left_joins_milestones, -> { joins("LEFT OUTER JOIN milestones ON #{table_name}.milestone_id = milestones.id") }
scope :order_milestone_due_desc, -> { left_joins_milestones.reorder('milestones.due_date IS NULL, milestones.id IS NULL, milestones.due_date DESC') } scope :order_milestone_due_desc, -> { left_joins_milestones.reorder('milestones.due_date IS NULL, milestones.id IS NULL, milestones.due_date DESC') }
...@@ -207,17 +206,6 @@ module Issuable ...@@ -207,17 +206,6 @@ module Issuable
end end
end end
def labels_hash
issue_labels = Hash.new { |h, k| h[k] = [] }
relation = unscoped.where(id: self.select(:id)).eager_load(:labels)
relation.pluck(:id, 'labels.title').each do |issue_id, label|
issue_labels[issue_id] << label
end
issue_labels
end
# Includes table keys in group by clause when sorting # Includes table keys in group by clause when sorting
# preventing errors in postgres # preventing errors in postgres
# #
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
module Mentionable module Mentionable
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepend EE::Mentionable
class_methods do class_methods do
# Indicate which attributes of the Mentionable to search for GFM references. # Indicate which attributes of the Mentionable to search for GFM references.
def attr_mentionable(attr, options = {}) def attr_mentionable(attr, options = {})
...@@ -86,12 +88,11 @@ module Mentionable ...@@ -86,12 +88,11 @@ module Mentionable
return [] unless matches_cross_reference_regex? return [] unless matches_cross_reference_regex?
refs = all_references(current_user) refs = all_references(current_user)
refs = (refs.issues + refs.merge_requests + refs.commits + refs.epics)
# We're using this method instead of Array diffing because that requires # We're using this method instead of Array diffing because that requires
# both of the object's `hash` values to be the same, which may not be the # both of the object's `hash` values to be the same, which may not be the
# case for otherwise identical Commit objects. # case for otherwise identical Commit objects.
refs.reject { |ref| ref == local_reference } extracted_mentionables(refs).reject { |ref| ref == local_reference }
end end
# Uses regex to quickly determine if mentionables might be referenced # Uses regex to quickly determine if mentionables might be referenced
...@@ -134,6 +135,10 @@ module Mentionable ...@@ -134,6 +135,10 @@ module Mentionable
private private
def extracted_mentionables(refs)
refs.issues + refs.merge_requests + refs.commits
end
# Returns a Hash of changed mentionable fields # Returns a Hash of changed mentionable fields
# #
# Preference is given to the `changes` Hash, but falls back to # Preference is given to the `changes` Hash, but falls back to
......
...@@ -2,17 +2,24 @@ ...@@ -2,17 +2,24 @@
module Mentionable module Mentionable
module ReferenceRegexes module ReferenceRegexes
prepend EE::Mentionable::ReferenceRegexes
def self.reference_pattern(link_patterns, issue_pattern) def self.reference_pattern(link_patterns, issue_pattern)
Regexp.union(link_patterns, Regexp.union(link_patterns,
issue_pattern, issue_pattern,
Epic.reference_pattern, *other_patterns)
Commit.reference_pattern, end
MergeRequest.reference_pattern)
def self.other_patterns
[
Commit.reference_pattern,
MergeRequest.reference_pattern
]
end end
DEFAULT_PATTERN = begin DEFAULT_PATTERN = begin
issue_pattern = Issue.reference_pattern issue_pattern = Issue.reference_pattern
link_patterns = Regexp.union([Issue, Commit, MergeRequest, Epic].map(&:link_reference_pattern)) link_patterns = Regexp.union([Issue, Commit, MergeRequest, Epic].map(&:link_reference_pattern).compact)
reference_pattern(link_patterns, issue_pattern) reference_pattern(link_patterns, issue_pattern)
end end
......
...@@ -4,8 +4,6 @@ module ProtectedBranchAccess ...@@ -4,8 +4,6 @@ module ProtectedBranchAccess
extend ActiveSupport::Concern extend ActiveSupport::Concern
include ProtectedRefAccess include ProtectedRefAccess
include EE::ProtectedRefAccess # Can't use prepend. It'll override wrongly
included do included do
belongs_to :protected_branch belongs_to :protected_branch
......
...@@ -2,13 +2,8 @@ ...@@ -2,13 +2,8 @@
module ProtectedRefAccess module ProtectedRefAccess
extend ActiveSupport::Concern extend ActiveSupport::Concern
include EE::ProtectedRefAccess::Scopes
ALLOWED_ACCESS_LEVELS = [ prepend EE::ProtectedRefAccess
Gitlab::Access::MAINTAINER,
Gitlab::Access::DEVELOPER,
Gitlab::Access::NO_ACCESS,
Gitlab::Access::ADMIN
].freeze
HUMAN_ACCESS_LEVELS = { HUMAN_ACCESS_LEVELS = {
Gitlab::Access::MAINTAINER => "Maintainers".freeze, Gitlab::Access::MAINTAINER => "Maintainers".freeze,
...@@ -16,6 +11,16 @@ module ProtectedRefAccess ...@@ -16,6 +11,16 @@ module ProtectedRefAccess
Gitlab::Access::NO_ACCESS => "No one".freeze Gitlab::Access::NO_ACCESS => "No one".freeze
}.freeze }.freeze
class_methods do
def allowed_access_levels
[
Gitlab::Access::MAINTAINER,
Gitlab::Access::DEVELOPER,
Gitlab::Access::NO_ACCESS
]
end
end
included do included do
scope :master, -> { maintainer } # @deprecated scope :master, -> { maintainer } # @deprecated
scope :maintainer, -> { where(access_level: Gitlab::Access::MAINTAINER) } scope :maintainer, -> { where(access_level: Gitlab::Access::MAINTAINER) }
...@@ -27,7 +32,7 @@ module ProtectedRefAccess ...@@ -27,7 +32,7 @@ module ProtectedRefAccess
scope :for_group, -> { where.not(group_id: nil) } scope :for_group, -> { where.not(group_id: nil) }
validates :access_level, presence: true, if: :role?, inclusion: { validates :access_level, presence: true, if: :role?, inclusion: {
in: ALLOWED_ACCESS_LEVELS in: self.allowed_access_levels
} }
end end
......
...@@ -4,8 +4,6 @@ module ProtectedTagAccess ...@@ -4,8 +4,6 @@ module ProtectedTagAccess
extend ActiveSupport::Concern extend ActiveSupport::Concern
include ProtectedRefAccess include ProtectedRefAccess
include EE::ProtectedRefAccess # Can't use prepend. It'll override wrongly
included do included do
belongs_to :protected_tag belongs_to :protected_tag
......
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
class Epic < ActiveRecord::Base class Epic < ActiveRecord::Base
prepend EE::Epic prepend EE::Epic
def self.link_reference_pattern
nil
end
def self.reference_prefix def self.reference_prefix
'&' '&'
end end
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
**Valid access levels** **Valid access levels**
The access levels are defined in the `ProtectedRefAccess::ALLOWED_ACCESS_LEVELS` constant. Currently, these levels are recognized: The access levels are defined in the `ProtectedRefAccess.allowed_access_levels` method. Currently, these levels are recognized:
``` ```
0 => No access 0 => No access
30 => Developer access 30 => Developer access
......
# frozen_string_literal: true
module EE
module Issuable
extend ActiveSupport::Concern
class_methods do
def labels_hash
issue_labels = Hash.new { |h, k| h[k] = [] }
relation = unscoped.where(id: self.select(:id)).eager_load(:labels)
relation.pluck(:id, 'labels.title').each do |issue_id, label|
issue_labels[issue_id] << label
end
issue_labels
end
end
end
end
# frozen_string_literal: true
module EE
module Mentionable
extend ::Gitlab::Utils::Override
private
override :extracted_mentionables
def extracted_mentionables(refs)
super.concat(
refs.epics
)
end
end
end
# frozen_string_literal: true
module EE
module Mentionable
module ReferenceRegexes
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :other_patterns
def other_patterns
super.unshift(
::Epic.reference_pattern
)
end
end
end
end
end
...@@ -10,18 +10,33 @@ module EE ...@@ -10,18 +10,33 @@ module EE
extend ActiveSupport::Concern extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
included do module Scopes
belongs_to :user extend ActiveSupport::Concern
belongs_to :group
protected_type = self.parent.model_name.singular included do
validates :group_id, uniqueness: { scope: protected_type, allow_nil: true } belongs_to :user
validates :user_id, uniqueness: { scope: protected_type, allow_nil: true } belongs_to :group
validates :access_level, uniqueness: { scope: protected_type, if: :role?,
conditions: -> { where(user_id: nil, group_id: nil) } } protected_type = self.parent.model_name.singular
validates :group, :user, validates :group_id, uniqueness: { scope: protected_type, allow_nil: true }
absence: true, validates :user_id, uniqueness: { scope: protected_type, allow_nil: true }
unless: :protected_refs_for_users_required_and_available validates :access_level, uniqueness: { scope: protected_type, if: :role?,
conditions: -> { where(user_id: nil, group_id: nil) } }
validates :group, :user,
absence: true,
unless: :protected_refs_for_users_required_and_available
end
end
class_methods do
# We can't specify `override` here:
# https://gitlab.com/gitlab-org/gitlab-ce/issues/50911
def allowed_access_levels
[
*super,
::Gitlab::Access::ADMIN
]
end
end end
def type def type
......
...@@ -3,7 +3,8 @@ module EE ...@@ -3,7 +3,8 @@ module EE
class Boards < ::Grape::API class Boards < ::Grape::API
include ::API::PaginationParams include ::API::PaginationParams
include ::API::BoardsResponses include ::API::BoardsResponses
include BoardsResponses
prepend EE::API::BoardsResponses
before { authenticate! } before { authenticate! }
......
...@@ -3,7 +3,7 @@ module EE ...@@ -3,7 +3,7 @@ module EE
module BoardsResponses module BoardsResponses
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do prepended do
helpers do helpers do
def create_board def create_board
forbidden! unless board_parent.multiple_issue_boards_available? forbidden! unless board_parent.multiple_issue_boards_available?
......
...@@ -3,7 +3,8 @@ module EE ...@@ -3,7 +3,8 @@ module EE
class GroupBoards < ::Grape::API class GroupBoards < ::Grape::API
include ::API::PaginationParams include ::API::PaginationParams
include ::API::BoardsResponses include ::API::BoardsResponses
include BoardsResponses
prepend EE::API::BoardsResponses
before do before do
authenticate! authenticate!
......
module API module API
class Boards < Grape::API class Boards < Grape::API
include BoardsResponses include BoardsResponses
include EE::API::BoardsResponses
include PaginationParams include PaginationParams
prepend EE::API::BoardsResponses
before { authenticate! } before { authenticate! }
helpers do helpers do
......
module API module API
class GroupBoards < Grape::API class GroupBoards < Grape::API
include BoardsResponses include BoardsResponses
include EE::API::BoardsResponses
include PaginationParams include PaginationParams
prepend EE::API::BoardsResponses
before do before do
authenticate! authenticate!
end end
......
...@@ -44,26 +44,26 @@ module API ...@@ -44,26 +44,26 @@ module API
params do params do
requires :name, type: String, desc: 'The name of the protected branch' requires :name, type: String, desc: 'The name of the protected branch'
optional :push_access_level, type: Integer, optional :push_access_level, type: Integer,
values: ProtectedRefAccess::ALLOWED_ACCESS_LEVELS, values: ProtectedBranch::PushAccessLevel.allowed_access_levels,
desc: 'Access levels allowed to push (defaults: `40`, maintainer access level)' desc: 'Access levels allowed to push (defaults: `40`, maintainer access level)'
optional :merge_access_level, type: Integer, optional :merge_access_level, type: Integer,
values: ProtectedRefAccess::ALLOWED_ACCESS_LEVELS, values: ProtectedBranch::MergeAccessLevel.allowed_access_levels,
desc: 'Access levels allowed to merge (defaults: `40`, maintainer access level)' desc: 'Access levels allowed to merge (defaults: `40`, maintainer access level)'
optional :unprotect_access_level, type: Integer, optional :unprotect_access_level, type: Integer,
values: ProtectedRefAccess::ALLOWED_ACCESS_LEVELS, values: ProtectedBranch::UnprotectAccessLevel.allowed_access_levels,
desc: 'Access levels allowed to unprotect (defaults: `40`, maintainer access level)' desc: 'Access levels allowed to unprotect (defaults: `40`, maintainer access level)'
optional :allowed_to_push, type: Array, desc: 'An array of users/groups allowed to push' do optional :allowed_to_push, type: Array, desc: 'An array of users/groups allowed to push' do
optional :access_level, type: Integer, values: ProtectedRefAccess::ALLOWED_ACCESS_LEVELS optional :access_level, type: Integer, values: ProtectedBranch::PushAccessLevel.allowed_access_levels
optional :user_id, type: Integer optional :user_id, type: Integer
optional :group_id, type: Integer optional :group_id, type: Integer
end end
optional :allowed_to_merge, type: Array, desc: 'An array of users/groups allowed to merge' do optional :allowed_to_merge, type: Array, desc: 'An array of users/groups allowed to merge' do
optional :access_level, type: Integer, values: ProtectedRefAccess::ALLOWED_ACCESS_LEVELS optional :access_level, type: Integer, values: ProtectedBranch::MergeAccessLevel.allowed_access_levels
optional :user_id, type: Integer optional :user_id, type: Integer
optional :group_id, type: Integer optional :group_id, type: Integer
end end
optional :allowed_to_unprotect, type: Array, desc: 'An array of users/groups allowed to unprotect' do optional :allowed_to_unprotect, type: Array, desc: 'An array of users/groups allowed to unprotect' do
optional :access_level, type: Integer, values: ProtectedRefAccess::ALLOWED_ACCESS_LEVELS optional :access_level, type: Integer, values: ProtectedBranch::UnprotectAccessLevel.allowed_access_levels
optional :user_id, type: Integer optional :user_id, type: Integer
optional :group_id, type: Integer optional :group_id, type: Integer
end end
......
...@@ -47,7 +47,7 @@ module API ...@@ -47,7 +47,7 @@ module API
params do params do
requires :name, type: String, desc: 'The name of the protected tag' requires :name, type: String, desc: 'The name of the protected tag'
optional :create_access_level, type: Integer, default: Gitlab::Access::MAINTAINER, optional :create_access_level, type: Integer, default: Gitlab::Access::MAINTAINER,
values: ProtectedRefAccess::ALLOWED_ACCESS_LEVELS, values: ProtectedTag::CreateAccessLevel.allowed_access_levels,
desc: 'Access levels allowed to create (defaults: `40`, maintainer access level)' desc: 'Access levels allowed to create (defaults: `40`, maintainer access level)'
end end
post ':id/protected_tags' do post ':id/protected_tags' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment