Commit 6e9f841a authored by Felipe Artur's avatar Felipe Artur

Code improvements plus changelog

parent 215c15bf
......@@ -19,4 +19,3 @@ module Boards
end
end
end
module Boards
class IssuesController < Boards::ApplicationController
include BoardsAuthorizations
include BoardsResponses
before_action :authorize_read_issue!, only: [:index]
before_action :authorize_create_issue!, only: [:create]
before_action :authorize_update_issue!, only: [:update]
before_action :authorize_read_issue, only: [:index]
before_action :authorize_create_issue, only: [:create]
before_action :authorize_update_issue, only: [:update]
def index
issues = Boards::Issues::ListService.new(board_parent, current_user, filter_params).execute
......@@ -83,4 +83,3 @@ module Boards
end
end
end
module Boards
class ListsController < Boards::ApplicationController
include BoardsAuthorizations
include BoardsResponses
before_action :authorize_admin_list!, only: [:create, :update, :destroy, :generate]
before_action :authorize_read_list!, only: [:index]
before_action :authorize_admin_list, only: [:create, :update, :destroy, :generate]
before_action :authorize_read_list, only: [:index]
def index
lists = Boards::Lists::ListService.new(board.parent, current_user).execute(board)
......@@ -12,7 +12,7 @@ module Boards
end
def create
list = ::Boards::Lists::CreateService.new(board.parent, current_user, list_params).execute(board)
list = Boards::Lists::CreateService.new(board.parent, current_user, list_params).execute(board)
if list.valid?
render json: serialize_as_json(list)
......
module BoardsAuthorizations
# Shared authorizations between projects and groups which
# have different policies.
def authorize_read_list!
ability = board.is_group_board? ? :read_group : :read_list
return render_403 unless action_allowed_for?(board.parent, ability)
end
def authorize_read_issue!
ability = board.is_group_board? ? :read_group : :read_issue
return render_403 unless action_allowed_for?(board.parent, ability)
end
def authorize_update_issue!
return render_403 unless action_allowed_for?(issue, :admin_issue)
end
def authorize_create_issue!
return render_403 unless action_allowed_for?(board.parent, :admin_issue)
end
def authorize_admin_list!
return render_403 unless action_allowed_for?(board.parent, :admin_list)
end
def action_allowed_for?(resource, ability)
can?(current_user, ability, resource)
end
end
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!(board.parent, :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
......@@ -66,7 +66,7 @@ module EE
end
def boards_path
if parent.is_a?(Group)
if @group
group_boards_path(parent)
else
project_boards_path(parent)
......
class Groups::BoardsController < Groups::ApplicationController
prepend EE::Boards::BoardsController
include BoardsResponses
before_action :check_group_issue_boards_available!
before_action :assign_endpoint_vars
......@@ -7,28 +8,17 @@ class Groups::BoardsController < Groups::ApplicationController
def index
@boards = Boards::ListService.new(group, current_user).execute
respond_to do |format|
format.html
format.json do
render json: serialize_as_json(@boards)
end
end
respond_with_boards
end
def show
@board = group.boards.find(params[:id])
respond_to do |format|
format.html
format.json do
render json: serialize_as_json(@board)
end
end
respond_with_board
end
def assign_endpoint_vars
@boards_endpoint = group_boards_path(group)
@issues_path = issues_group_path(group)
@bulk_issues_path = ""
end
end
......@@ -15,10 +15,10 @@ class Groups::LabelsController < Groups::ApplicationController
format.json do
available_labels =
if params[:group_labels_only]
LabelsFinder.new(current_user, group_id: @group.id).execute
else
if params[:only_group_labels]
group.labels
else
LabelsFinder.new(current_user, group_id: @group.id).execute
end
render json: LabelSerializer.new.represent_appearance(available_labels)
......
class Projects::BoardsController < Projects::ApplicationController
prepend EE::Boards::BoardsController
include IssuableCollections
include BoardsResponses
before_action :authorize_read_board!, only: [:index, :show]
before_action :assign_endpoint_vars
......@@ -8,23 +9,13 @@ class Projects::BoardsController < Projects::ApplicationController
def index
@boards = Boards::ListService.new(project, current_user).execute
respond_to do |format|
format.html
format.json do
render json: serialize_as_json(@boards)
end
end
respond_with_boards
end
def show
@board = project.boards.find(params[:id])
respond_to do |format|
format.html
format.json do
render json: serialize_as_json(@board)
end
end
respond_with_boards
end
private
......@@ -32,7 +23,6 @@ class Projects::BoardsController < Projects::ApplicationController
def assign_endpoint_vars
@boards_endpoint = project_boards_path(project)
@issues_path = project_issues_path(project)
@bulk_issues_path = bulk_update_project_issues_path(@project)
end
......
......@@ -59,7 +59,7 @@ module BoardsHelper
{
toggle: "dropdown",
labels: labels_filter_path(only_group_labels: true),
labels: labels_filter_path(true),
namespace_path: namespace_path,
project_path: @project&.try(:path), # Change this one on JS to use a single property: parent_path
group_path: @group&.try(:path) # Same here
......
---
title: Add group issue boards
merge_request:
author:
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