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
include CreatedAtFilterable
include UpdatedAtFilterable
prepend EE::Issuable
# This object is used to gather issuable meta data for displaying
# upvotes, downvotes, notes and closing merge requests count for issues and merge requests
# lists avoiding n+1 queries and improving performance.
......@@ -80,9 +82,6 @@ module Issuable
scope :opened, -> { with_state(:opened) }
scope :only_opened, -> { with_state(:opened) }
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 :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
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
# preventing errors in postgres
#
......
......@@ -10,6 +10,8 @@
module Mentionable
extend ActiveSupport::Concern
prepend EE::Mentionable
class_methods do
# Indicate which attributes of the Mentionable to search for GFM references.
def attr_mentionable(attr, options = {})
......@@ -86,12 +88,11 @@ module Mentionable
return [] unless matches_cross_reference_regex?
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
# both of the object's `hash` values to be the same, which may not be the
# case for otherwise identical Commit objects.
refs.reject { |ref| ref == local_reference }
extracted_mentionables(refs).reject { |ref| ref == local_reference }
end
# Uses regex to quickly determine if mentionables might be referenced
......@@ -134,6 +135,10 @@ module Mentionable
private
def extracted_mentionables(refs)
refs.issues + refs.merge_requests + refs.commits
end
# Returns a Hash of changed mentionable fields
#
# Preference is given to the `changes` Hash, but falls back to
......
......@@ -2,17 +2,24 @@
module Mentionable
module ReferenceRegexes
prepend EE::Mentionable::ReferenceRegexes
def self.reference_pattern(link_patterns, issue_pattern)
Regexp.union(link_patterns,
issue_pattern,
Epic.reference_pattern,
Commit.reference_pattern,
MergeRequest.reference_pattern)
*other_patterns)
end
def self.other_patterns
[
Commit.reference_pattern,
MergeRequest.reference_pattern
]
end
DEFAULT_PATTERN = begin
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)
end
......
......@@ -4,8 +4,6 @@ module ProtectedBranchAccess
extend ActiveSupport::Concern
include ProtectedRefAccess
include EE::ProtectedRefAccess # Can't use prepend. It'll override wrongly
included do
belongs_to :protected_branch
......
......@@ -2,13 +2,8 @@
module ProtectedRefAccess
extend ActiveSupport::Concern
ALLOWED_ACCESS_LEVELS = [
Gitlab::Access::MAINTAINER,
Gitlab::Access::DEVELOPER,
Gitlab::Access::NO_ACCESS,
Gitlab::Access::ADMIN
].freeze
include EE::ProtectedRefAccess::Scopes
prepend EE::ProtectedRefAccess
HUMAN_ACCESS_LEVELS = {
Gitlab::Access::MAINTAINER => "Maintainers".freeze,
......@@ -16,6 +11,16 @@ module ProtectedRefAccess
Gitlab::Access::NO_ACCESS => "No one".freeze
}.freeze
class_methods do
def allowed_access_levels
[
Gitlab::Access::MAINTAINER,
Gitlab::Access::DEVELOPER,
Gitlab::Access::NO_ACCESS
]
end
end
included do
scope :master, -> { maintainer } # @deprecated
scope :maintainer, -> { where(access_level: Gitlab::Access::MAINTAINER) }
......@@ -27,7 +32,7 @@ module ProtectedRefAccess
scope :for_group, -> { where.not(group_id: nil) }
validates :access_level, presence: true, if: :role?, inclusion: {
in: ALLOWED_ACCESS_LEVELS
in: self.allowed_access_levels
}
end
......
......@@ -4,8 +4,6 @@ module ProtectedTagAccess
extend ActiveSupport::Concern
include ProtectedRefAccess
include EE::ProtectedRefAccess # Can't use prepend. It'll override wrongly
included do
belongs_to :protected_tag
......
......@@ -5,6 +5,10 @@
class Epic < ActiveRecord::Base
prepend EE::Epic
def self.link_reference_pattern
nil
end
def self.reference_prefix
'&'
end
......
......@@ -4,7 +4,7 @@
**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
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
extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
included do
belongs_to :user
belongs_to :group
module Scopes
extend ActiveSupport::Concern
protected_type = self.parent.model_name.singular
validates :group_id, uniqueness: { scope: protected_type, allow_nil: true }
validates :user_id, uniqueness: { scope: protected_type, allow_nil: true }
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
included do
belongs_to :user
belongs_to :group
protected_type = self.parent.model_name.singular
validates :group_id, uniqueness: { scope: protected_type, allow_nil: true }
validates :user_id, uniqueness: { scope: protected_type, allow_nil: true }
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
def type
......
......@@ -3,7 +3,8 @@ module EE
class Boards < ::Grape::API
include ::API::PaginationParams
include ::API::BoardsResponses
include BoardsResponses
prepend EE::API::BoardsResponses
before { authenticate! }
......
......@@ -3,7 +3,7 @@ module EE
module BoardsResponses
extend ActiveSupport::Concern
included do
prepended do
helpers do
def create_board
forbidden! unless board_parent.multiple_issue_boards_available?
......
......@@ -3,7 +3,8 @@ module EE
class GroupBoards < ::Grape::API
include ::API::PaginationParams
include ::API::BoardsResponses
include BoardsResponses
prepend EE::API::BoardsResponses
before do
authenticate!
......
module API
class Boards < Grape::API
include BoardsResponses
include EE::API::BoardsResponses
include PaginationParams
prepend EE::API::BoardsResponses
before { authenticate! }
helpers do
......
module API
class GroupBoards < Grape::API
include BoardsResponses
include EE::API::BoardsResponses
include PaginationParams
prepend EE::API::BoardsResponses
before do
authenticate!
end
......
......@@ -44,26 +44,26 @@ module API
params do
requires :name, type: String, desc: 'The name of the protected branch'
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)'
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)'
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)'
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 :group_id, type: Integer
end
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 :group_id, type: Integer
end
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 :group_id, type: Integer
end
......
......@@ -47,7 +47,7 @@ module API
params do
requires :name, type: String, desc: 'The name of the protected tag'
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)'
end
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