Commit 631d9284 authored by Felipe Artur's avatar Felipe Artur

Allow to add labels on group boards and serveral code improvements

parent 26ee6f34
......@@ -6,7 +6,8 @@ const Api = {
namespacesPath: '/api/:version/namespaces.json',
groupProjectsPath: '/api/:version/groups/:id/projects.json',
projectsPath: '/api/:version/projects.json?simple=true',
labelsPath: '/:namespace_path/:project_path/labels',
projectLabelsPath: '/:namespace_path/:project_path/labels',
groupLabelsPath: '/groups/:namespace_path/labels',
licensePath: '/api/:version/templates/licenses/:key',
gitignorePath: '/api/:version/templates/gitignores/:key',
gitlabCiYmlPath: '/api/:version/templates/gitlab_ci_ymls/:key',
......@@ -67,9 +68,16 @@ const Api = {
},
newLabel(namespacePath, projectPath, data, callback) {
const url = Api.buildUrl(Api.labelsPath)
.replace(':namespace_path', namespacePath)
.replace(':project_path', projectPath);
var url = ""
if (projectPath) {
url = Api.buildUrl(Api.projectLabelsPath)
.replace(':namespace_path', namespacePath)
.replace(':project_path', projectPath);
} else {
url = Api.buildUrl(Api.groupLabelsPath).replace(':namespace_path', namespacePath)
}
return $.ajax({
url,
type: 'POST',
......
......@@ -26,7 +26,7 @@ gl.issueBoards.newListDropdownInit = () => {
$this.glDropdown({
data(term, callback) {
$.get($this.attr('data-labels'))
$.get($this.attr('data-list-labels-path'))
.then((resp) => {
callback(resp);
});
......
......@@ -18,7 +18,7 @@ module Boards
end
def create
service = Boards::Issues::CreateService.new(board_parent, current_user, issue_params)
service = Boards::Issues::CreateService.new(project, current_user, issue_params)
issue = service.execute
if issue.valid?
......@@ -62,6 +62,11 @@ module Boards
end
end
def project
@project ||=
board.is_group_board? ? Project.find(params[:project_id]) : board.parent
end
def move_params
params.permit(:board_id, :id, :from_list_id, :to_list_id, :move_before_iid, :move_after_iid)
end
......
......@@ -18,7 +18,7 @@ module BoardsResponses
end
def authorize_create_issue
authorize_action_for!(board.parent, :admin_issue)
authorize_action_for!(project, :admin_issue)
end
def authorize_admin_list
......
......@@ -20,5 +20,7 @@ class Groups::BoardsController < Groups::ApplicationController
def assign_endpoint_vars
@boards_endpoint = group_boards_path(group)
@issues_path = issues_group_path(group)
@namespace_path = group.path
@labels_endpoint = group_labels_path(group)
end
end
......@@ -34,10 +34,18 @@ class Groups::LabelsController < Groups::ApplicationController
def create
@label = Labels::CreateService.new(label_params).execute(group: group)
if @label.valid?
redirect_to group_labels_path(@group)
else
render :new
respond_to do |format|
format.html do
if @label.valid?
redirect_to group_labels_path(@group)
else
render :new
end
end
format.json do
render json: LabelSerializer.new.represent_appearance(@label)
end
end
end
......
......@@ -23,7 +23,9 @@ 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)
@bulk_issues_path = bulk_update_project_issues_path(project)
@namespace_path = project.namespace.path
@labels_endpoint = project_labels_path(project)
end
def authorize_read_board!
......
......@@ -55,14 +55,13 @@ module BoardsHelper
end
def board_list_data
namespace_path = current_board_parent.try(:path) || current_board_parent.namespace.try(:path)
{
toggle: "dropdown",
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
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)
}
end
......
......@@ -362,4 +362,12 @@ module IssuablesHelper
params[:format] = :json if issuable.is_a?(Issue)
end
end
def labels_path
if @project
project_labels_path(@project)
elsif @group
group_labels_path(@group)
end
end
end
......@@ -122,12 +122,12 @@ module LabelsHelper
end
def labels_filter_path(only_group_labels = false)
return group_labels_path(@group, :json, only_group_labels: only_group_labels) if @group
project = @target_project || @project
if project
project_labels_path(project, :json)
elsif @group
group_labels_path(@group, :json, only_group_labels: only_group_labels)
else
dashboard_labels_path(:json)
end
......
......@@ -11,8 +11,8 @@ module EE
enable :admin_board
end
rule { public_group } .enable :read_board
rule { guest } .enable :read_board
rule { public_group }.enable :read_board
rule { guest }.enable :read_board
rule { ldap_synced }.prevent :admin_group_member
......
......@@ -8,7 +8,7 @@ module Boards
private
def board
@board ||= project.boards.find(params.delete(:board_id))
@board ||= parent.boards.find(params.delete(:board_id))
end
def list
......@@ -16,7 +16,7 @@ module Boards
end
def create_issue(params)
::Issues::CreateService.new(project, current_user, params).execute
::Issues::CreateService.new(parent, current_user, params).execute
end
end
end
......
......@@ -20,7 +20,7 @@
%a.dropdown-toggle-page{ href: "#" }
Create new label
%li
= link_to labels_filter_path, :"data-is-link" => true do
= link_to labels_path, :"data-is-link" => true do
- if show_create && can?(current_user, :admin_label, current_board_parent)
Manage labels
- else
......
......@@ -122,7 +122,7 @@
Add list
.dropdown-menu.dropdown-menu-paging.dropdown-menu-align-right.dropdown-menu-issues-board-new.dropdown-menu-selectable
= render partial: "shared/issuable/label_page_default", locals: { show_footer: true, show_create: true, show_boards_content: true, title: "Add list" }
- if can?(current_user, :admin_label,board.parent)
- if can?(current_user, :admin_label, board.parent)
= render partial: "shared/issuable/label_page_create"
= dropdown_loading
- if @project
......
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