Commit 7c35f5ae authored by Alexandru Croitor's avatar Alexandru Croitor

Move Multiple Issue Boards for Projects to Core

Refactor code to allow multiple issue boards management for projects
in CE
parent 9e6fd75d
...@@ -3,8 +3,9 @@ ...@@ -3,8 +3,9 @@
module BoardsResponses module BoardsResponses
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
# Overridden on EE module
def board_params def board_params
params.require(:board).permit(:name, :weight, :milestone_id, :assignee_id, label_ids: []) params.require(:board).permit(:name)
end end
def parent def parent
......
# frozen_string_literal: true
module MultipleBoardsActions
include Gitlab::Utils::StrongMemoize
extend ActiveSupport::Concern
included do
include BoardsActions
before_action :redirect_to_recent_board, only: [:index]
before_action :authenticate_user!, only: [:recent]
before_action :authorize_create_board!, only: [:create]
before_action :authorize_admin_board!, only: [:create, :update, :destroy]
end
def recent
recent_visits = ::Boards::Visits::LatestService.new(parent, current_user, count: 4).execute
recent_boards = recent_visits.map(&:board)
render json: serialize_as_json(recent_boards)
end
def create
board = Boards::CreateService.new(parent, current_user, board_params).execute
respond_to do |format|
format.json do
if board.valid?
extra_json = { board_path: board_path(board) }
render json: serialize_as_json(board).merge(extra_json)
else
render json: board.errors, status: :unprocessable_entity
end
end
end
end
def update
service = Boards::UpdateService.new(parent, current_user, board_params)
service.execute(board)
respond_to do |format|
format.json do
if board.valid?
extra_json = { board_path: board_path(board) }
render json: serialize_as_json(board).merge(extra_json)
else
render json: board.errors, status: :unprocessable_entity
end
end
end
end
def destroy
service = Boards::DestroyService.new(parent, current_user)
service.execute(board)
respond_to do |format|
format.json { head :ok }
format.html { redirect_to boards_path, status: :found }
end
end
private
def redirect_to_recent_board
return if request.format.json? || !parent.multiple_issue_boards_available?
if recently_visited = Boards::Visits::LatestService.new(parent, current_user).execute
redirect_to board_path(recently_visited.board)
end
end
def authorize_create_board!
check_multiple_group_issue_boards_available! if group?
end
def authorize_admin_board!
return render_404 unless can?(current_user, :admin_board, parent)
end
def serializer
BoardSerializer.new(current_user: current_user)
end
def serialize_as_json(resource)
serializer.represent(resource, serializer: 'board', include_full_project_path: board.group_board?)
end
end
# frozen_string_literal: true # frozen_string_literal: true
class Projects::BoardsController < Projects::ApplicationController class Projects::BoardsController < Projects::ApplicationController
include BoardsActions include MultipleBoardsActions
include IssuableCollections include IssuableCollections
before_action :check_issues_available! before_action :check_issues_available!
......
...@@ -15,7 +15,8 @@ module BoardsHelper ...@@ -15,7 +15,8 @@ module BoardsHelper
root_path: root_path, root_path: root_path,
bulk_update_path: @bulk_issues_path, bulk_update_path: @bulk_issues_path,
default_avatar: image_path(default_avatar), default_avatar: image_path(default_avatar),
time_tracking_limit_to_hours: Gitlab::CurrentSettings.time_tracking_limit_to_hours.to_s time_tracking_limit_to_hours: Gitlab::CurrentSettings.time_tracking_limit_to_hours.to_s,
recent_boards_endpoint: recent_boards_path
} }
end end
...@@ -87,8 +88,20 @@ module BoardsHelper ...@@ -87,8 +88,20 @@ module BoardsHelper
end end
def boards_link_text def boards_link_text
if current_board_parent.multiple_issue_boards_available?
s_("IssueBoards|Boards")
else
s_("IssueBoards|Board") s_("IssueBoards|Board")
end end
end
def recent_boards_path
recent_project_boards_path(@project) if current_board_parent.is_a?(Project)
end
def current_board_json
board.to_json
end
end end
BoardsHelper.prepend(EE::BoardsHelper) BoardsHelper.prepend(EE::BoardsHelper)
...@@ -1949,9 +1949,8 @@ class Project < ApplicationRecord ...@@ -1949,9 +1949,8 @@ class Project < ApplicationRecord
end end
end end
# Overridden on EE module
def multiple_issue_boards_available? def multiple_issue_boards_available?
false true
end end
def full_path_before_last_save def full_path_before_last_save
......
...@@ -196,6 +196,7 @@ class ProjectPolicy < BasePolicy ...@@ -196,6 +196,7 @@ class ProjectPolicy < BasePolicy
rule { guest & can?(:read_container_image) }.enable :build_read_container_image rule { guest & can?(:read_container_image) }.enable :build_read_container_image
rule { can?(:reporter_access) }.policy do rule { can?(:reporter_access) }.policy do
enable :admin_board
enable :download_code enable :download_code
enable :read_statistics enable :read_statistics
enable :download_wiki_code enable :download_wiki_code
...@@ -240,6 +241,7 @@ class ProjectPolicy < BasePolicy ...@@ -240,6 +241,7 @@ class ProjectPolicy < BasePolicy
rule { can?(:developer_access) & can?(:create_issue) }.enable :import_issues rule { can?(:developer_access) & can?(:create_issue) }.enable :import_issues
rule { can?(:developer_access) }.policy do rule { can?(:developer_access) }.policy do
enable :admin_board
enable :admin_merge_request enable :admin_merge_request
enable :admin_milestone enable :admin_milestone
enable :update_merge_request enable :update_merge_request
...@@ -266,6 +268,7 @@ class ProjectPolicy < BasePolicy ...@@ -266,6 +268,7 @@ class ProjectPolicy < BasePolicy
end end
rule { can?(:maintainer_access) }.policy do rule { can?(:maintainer_access) }.policy do
enable :admin_board
enable :push_to_delete_protected_branch enable :push_to_delete_protected_branch
enable :update_project_snippet enable :update_project_snippet
enable :update_environment enable :update_environment
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
class BoardSimpleEntity < Grape::Entity class BoardSimpleEntity < Grape::Entity
expose :id expose :id
expose :name
end end
BoardSimpleEntity.prepend(EE::BoardSimpleEntity) BoardSimpleEntity.prepend(EE::BoardSimpleEntity)
...@@ -9,7 +9,7 @@ module Boards ...@@ -9,7 +9,7 @@ module Boards
private private
def can_create_board? def can_create_board?
parent.boards.empty? parent.boards.empty? || parent.multiple_issue_boards_available?
end end
def create_board! def create_board!
......
# frozen_string_literal: true
module Boards
class DestroyService < Boards::BaseService
def execute(board)
return false if parent.boards.size == 1
board.destroy
end
end
end
# frozen_string_literal: true
module Boards
class UpdateService < Boards::BaseService
def execute(board)
board.update(params)
end
end
end
...@@ -165,7 +165,11 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -165,7 +165,11 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
end end
end end
resources :boards, only: [:index, :show], constraints: { id: /\d+/ } resources :boards, only: [:index, :show, :create, :update, :destroy], constraints: { id: /\d+/ } do
collection do
get :recent
end
end
resources :releases, only: [:index] resources :releases, only: [:index]
resources :forks, only: [:index, :new, :create] resources :forks, only: [:index, :new, :create]
resources :group_links, only: [:index, :create, :update, :destroy], constraints: { id: /\d+/ } resources :group_links, only: [:index, :create, :update, :destroy], constraints: { id: /\d+/ }
......
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