Commit 65db35d1 authored by Felipe Artur's avatar Felipe Artur

Use EE modules where needed and prepare to CE backport

parent bbe9ee48
module Boards module Boards
class IssuesController < Boards::ApplicationController class IssuesController < Boards::ApplicationController
include BoardsResponses include EE::BoardsResponses
before_action :authorize_read_issue, only: [:index] before_action :authorize_read_issue, only: [:index]
before_action :authorize_create_issue, only: [:create] before_action :authorize_create_issue, only: [:create]
...@@ -72,9 +72,9 @@ module Boards ...@@ -72,9 +72,9 @@ module Boards
end end
def issue_params def issue_params
params.require(:issue). params.require(:issue)
permit(:title, :milestone_id, :project_id). .permit(:title, :milestone_id, :project_id)
merge(board_id: params[:board_id], list_id: params[:list_id], request: request) .merge(board_id: params[:board_id], list_id: params[:list_id], request: request)
end end
def serialize_as_json(resource) def serialize_as_json(resource)
......
module Boards module Boards
class ListsController < Boards::ApplicationController class ListsController < Boards::ApplicationController
include BoardsResponses include EE::BoardsResponses
before_action :authorize_admin_list, only: [:create, :update, :destroy, :generate] before_action :authorize_admin_list, only: [:create, :update, :destroy, :generate]
before_action :authorize_read_list, only: [:index] before_action :authorize_read_list, only: [:index]
......
module BoardsResponses
# Shared authorizations between projects and groups which
# have different policies.
def authorize_read_list
ability = board.is_group_board? ? :read_group : :read_list
authorize_action_for!(board.parent, ability)
end
def authorize_read_issue
ability = board.is_group_board? ? :read_group : :read_issue
authorize_action_for!(board.parent, ability)
end
def authorize_update_issue
authorize_action_for!(issue, :admin_issue)
end
def authorize_create_issue
authorize_action_for!(project, :admin_issue)
end
def authorize_admin_list
authorize_action_for!(board.parent, :admin_list)
end
def authorize_action_for!(resource, ability)
return render_403 unless can?(current_user, ability, resource)
end
def respond_with_boards
respond_with(@boards)
end
def respond_with_board
respond_with(@board)
end
def respond_with(resource)
respond_to do |format|
format.html
format.json do
render json: serialize_as_json(resource)
end
end
end
end
module EE
module BoardsResponses
# Shared authorizations between projects and groups which
# have different policies.
def authorize_read_list
ability = board.is_group_board? ? :read_group : :read_list
authorize_action_for!(board.parent, ability)
end
def authorize_read_issue
ability = board.is_group_board? ? :read_group : :read_issue
authorize_action_for!(board.parent, ability)
end
def authorize_update_issue
authorize_action_for!(issue, :admin_issue)
end
def authorize_create_issue
authorize_action_for!(project, :admin_issue)
end
def authorize_admin_list
authorize_action_for!(board.parent, :admin_list)
end
def authorize_action_for!(resource, ability)
return render_403 unless can?(current_user, ability, resource)
end
def respond_with_boards
respond_with(@boards)
end
def respond_with_board
respond_with(@board)
end
def respond_with(resource)
respond_to do |format|
format.html
format.json do
render json: serialize_as_json(resource)
end
end
end
end
end
class Groups::BoardsController < Groups::ApplicationController class Groups::BoardsController < Groups::ApplicationController
prepend EE::Boards::BoardsController prepend EE::Boards::BoardsController
include BoardsResponses include EE::BoardsResponses
before_action :check_group_issue_boards_available! before_action :check_group_issue_boards_available!
before_action :assign_endpoint_vars before_action :assign_endpoint_vars
......
class Projects::BoardsController < Projects::ApplicationController class Projects::BoardsController < Projects::ApplicationController
prepend EE::Boards::BoardsController prepend EE::Boards::BoardsController
include IssuableCollections include IssuableCollections
include BoardsResponses include EE::BoardsResponses
before_action :authorize_read_board!, only: [:index, :show] before_action :authorize_read_board!, only: [:index, :show]
before_action :assign_endpoint_vars before_action :assign_endpoint_vars
......
...@@ -2,7 +2,7 @@ module BoardsHelper ...@@ -2,7 +2,7 @@ module BoardsHelper
prepend EE::BoardsHelper prepend EE::BoardsHelper
def board def board
@board ||= @board || @boards.first @board ||= @board || @boards.first
end end
def board_data def board_data
...@@ -20,9 +20,7 @@ module BoardsHelper ...@@ -20,9 +20,7 @@ module BoardsHelper
end end
def build_issue_link_base def build_issue_link_base
return project_issues_path(@project) unless @board.is_group_board? project_issues_path(@project)
"/#{@board.group.path}/:project_path/issues"
end end
def current_board_json def current_board_json
...@@ -37,11 +35,7 @@ module BoardsHelper ...@@ -37,11 +35,7 @@ module BoardsHelper
end end
def board_base_url def board_base_url
if @project project_boards_path(@project)
project_boards_path(@project)
elsif @group
group_boards_path(@group)
end
end end
def multiple_boards_available? def multiple_boards_available?
...@@ -49,17 +43,11 @@ module BoardsHelper ...@@ -49,17 +43,11 @@ module BoardsHelper
end end
def board_path(board) def board_path(board)
@board_path ||= begin @board_path ||= project_board_path(current_board_parent, board)
if board.is_group_board?
group_board_path(current_board_parent, board)
else
project_board_path(current_board_parent, board)
end
end
end end
def current_board_parent def current_board_parent
@current_board_parent ||= @project || @group @current_board_parent ||= @project
end end
def can_admin_issue? def can_admin_issue?
...@@ -72,8 +60,7 @@ module BoardsHelper ...@@ -72,8 +60,7 @@ module BoardsHelper
list_labels_path: labels_filter_path(true), list_labels_path: labels_filter_path(true),
labels_endpoint: @labels_endpoint, labels_endpoint: @labels_endpoint,
namespace_path: @namespace_path, namespace_path: @namespace_path,
project_path: @project&.try(:path), project_path: @project&.try(:path)
group_path: @group&.try(:path)
} }
end end
...@@ -86,7 +73,6 @@ module BoardsHelper ...@@ -86,7 +73,6 @@ module BoardsHelper
first_user: current_user&.username, first_user: current_user&.username,
current_user: 'true', current_user: 'true',
project_id: @project&.try(:id), project_id: @project&.try(:id),
group_id: @group&.try(:id),
null_user: 'true', null_user: 'true',
multi_select: 'true', multi_select: 'true',
'dropdown-header': dropdown_options[:data][:'dropdown-header'], 'dropdown-header': dropdown_options[:data][:'dropdown-header'],
......
...@@ -4,5 +4,41 @@ module EE ...@@ -4,5 +4,41 @@ module EE
parent = @group || @project parent = @group || @project
super.merge(focus_mode_available: parent.feature_available?(:issue_board_focus_mode).to_s) super.merge(focus_mode_available: parent.feature_available?(:issue_board_focus_mode).to_s)
end end
def build_issue_link_base
return super unless @board.is_group_board?
"/#{@board.group.path}/:project_path/issues"
end
def board_base_url
return group_boards_path(@group) if @group
end
def board_path(board)
@board_path ||= begin
if board.is_group_board?
group_board_path(current_board_parent, board)
else
super(board)
end
end
end
def current_board_parent
@current_board_parent ||= @group || super
end
def can_admin_issue?
can?(current_user, :admin_issue, current_board_parent)
end
def board_list_data
super.merge(group_path: @group&.path)
end
def board_sidebar_user_data
super.merge(group_id: @group&.path)
end
end end
end end
module EE
module LabelsHelper
def labels_filter_path(only_group_labels = false)
end
end
end
...@@ -7,6 +7,8 @@ module EE ...@@ -7,6 +7,8 @@ module EE
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
has_many :boards
state_machine :ldap_sync_status, namespace: :ldap_sync, initial: :ready do state_machine :ldap_sync_status, namespace: :ldap_sync, initial: :ready do
state :ready state :ready
state :started state :started
......
module EE
module Label
extend ActiveSupport::Concern
prepended do
scope :on_group_boards, ->(group_id) { with_lists_and_board.where(boards: { group_id: group_id }) }
end
end
end
...@@ -22,7 +22,6 @@ class Group < Namespace ...@@ -22,7 +22,6 @@ class Group < Namespace
has_many :requesters, -> { where.not(requested_at: nil) }, dependent: :destroy, as: :source, class_name: 'GroupMember' # rubocop:disable Cop/ActiveRecordDependent has_many :requesters, -> { where.not(requested_at: nil) }, dependent: :destroy, as: :source, class_name: 'GroupMember' # rubocop:disable Cop/ActiveRecordDependent
has_many :boards
has_many :milestones has_many :milestones
has_many :project_group_links, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :project_group_links, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :shared_projects, through: :project_group_links, source: :project has_many :shared_projects, through: :project_group_links, source: :project
......
...@@ -3,6 +3,9 @@ class Label < ActiveRecord::Base ...@@ -3,6 +3,9 @@ class Label < ActiveRecord::Base
include Referable include Referable
include Subscribable include Subscribable
# EE specific
prepend EE::Label
# Represents a "No Label" state used for filtering Issues and Merge # Represents a "No Label" state used for filtering Issues and Merge
# Requests that have no label assigned. # Requests that have no label assigned.
LabelStruct = Struct.new(:title, :name) LabelStruct = Struct.new(:title, :name)
...@@ -36,7 +39,6 @@ class Label < ActiveRecord::Base ...@@ -36,7 +39,6 @@ class Label < ActiveRecord::Base
scope :with_title, ->(title) { where(title: title) } scope :with_title, ->(title) { where(title: title) }
scope :with_lists_and_board, -> { joins(lists: :board).merge(List.movable) } scope :with_lists_and_board, -> { joins(lists: :board).merge(List.movable) }
scope :on_project_boards, ->(project_id) { with_lists_and_board.where(boards: { project_id: project_id }) } scope :on_project_boards, ->(project_id) { with_lists_and_board.where(boards: { project_id: project_id }) }
scope :on_group_boards, ->(group_id) { with_lists_and_board.where(boards: { group_id: group_id }) }
def self.prioritized(project) def self.prioritized(project)
joins(:priorities) joins(:priorities)
......
module Boards module Boards
module Issues module Issues
class ListService < BaseService class ListService < BaseService
prepend EE::Boards::Issues::ListService
def execute def execute
issues = IssuesFinder.new(current_user, filter_params).execute issues = IssuesFinder.new(current_user, filter_params).execute
issues = without_board_labels(issues) unless movable_list? || closed_list? issues = without_board_labels(issues) unless movable_list? || closed_list?
...@@ -45,8 +47,7 @@ module Boards ...@@ -45,8 +47,7 @@ module Boards
end end
def set_parent def set_parent
param_key = parent.is_a?(Group) ? :group_id : :project_id params[:project_id] = @parent.id
params[param_key] = parent.id
end end
def set_state def set_state
......
module EE
module Boards
module Issues
module ListService
def set_parent
if @parent.is_a?(Group)
params[:group_id] = @parent.id
else
super
end
end
end
end
end
end
...@@ -10,7 +10,7 @@ FactoryGirl.define do ...@@ -10,7 +10,7 @@ FactoryGirl.define do
parent nil parent nil
end end
after(:build) do |board, evaluator| after(:build, :stub) do |board, evaluator|
if evaluator.group if evaluator.group
board.group = evaluator.group board.group = evaluator.group
elsif evaluator.group_id elsif evaluator.group_id
......
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