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

Use EE modules where needed and prepare to CE backport

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