Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c77fd1d1
Commit
c77fd1d1
authored
Feb 12, 2019
by
Jarka Košanová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check if labels are available for target issuable
- labels have to be in the same project/group as an issuable
parent
40f5e1f1
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
193 additions
and
26 deletions
+193
-26
app/models/label.rb
app/models/label.rb
+4
-0
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+12
-8
app/services/labels/available_labels_service.rb
app/services/labels/available_labels_service.rb
+60
-0
ee/app/services/ee/boards/base_service.rb
ee/app/services/ee/boards/base_service.rb
+8
-13
ee/changelogs/unreleased/security-milestone-labels.yml
ee/changelogs/unreleased/security-milestone-labels.yml
+5
-0
ee/spec/controllers/projects/boards_controller_spec.rb
ee/spec/controllers/projects/boards_controller_spec.rb
+1
-1
ee/spec/services/boards/update_service_spec.rb
ee/spec/services/boards/update_service_spec.rb
+17
-4
spec/services/labels/available_labels_service_spec.rb
spec/services/labels/available_labels_service_spec.rb
+86
-0
No files found.
app/models/label.rb
View file @
c77fd1d1
...
@@ -133,6 +133,10 @@ class Label < ActiveRecord::Base
...
@@ -133,6 +133,10 @@ class Label < ActiveRecord::Base
1
1
end
end
def
self
.
by_ids
(
ids
)
where
(
id:
ids
)
end
def
open_issues_count
(
user
=
nil
)
def
open_issues_count
(
user
=
nil
)
issues_count
(
user
,
state:
'opened'
)
issues_count
(
user
,
state:
'opened'
)
end
end
...
...
app/services/issuable_base_service.rb
View file @
c77fd1d1
...
@@ -70,10 +70,14 @@ class IssuableBaseService < BaseService
...
@@ -70,10 +70,14 @@ class IssuableBaseService < BaseService
end
end
def
filter_labels
def
filter_labels
filter_labels_in_param
(
:add_label_ids
)
params
[
:add_label_ids
]
=
labels_service
.
filter_labels_ids_in_param
(
:add_label_ids
)
if
params
[
:add_label_ids
]
filter_labels_in_param
(
:remove_label_ids
)
params
[
:remove_label_ids
]
=
labels_service
.
filter_labels_ids_in_param
(
:remove_label_ids
)
if
params
[
:remove_label_ids
]
filter_labels_in_param
(
:label_ids
)
find_or_create_label_ids
if
params
[
:label_ids
]
params
[
:label_ids
]
=
labels_service
.
filter_labels_ids_in_param
(
:label_ids
)
elsif
params
[
:labels
]
params
[
:label_ids
]
=
labels_service
.
find_or_create_by_titles
.
map
(
&
:id
)
end
end
end
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
...
@@ -101,6 +105,10 @@ class IssuableBaseService < BaseService
...
@@ -101,6 +105,10 @@ class IssuableBaseService < BaseService
end
.
compact
end
.
compact
end
end
def
labels_service
@labels_service
||=
::
Labels
::
AvailableLabelsService
.
new
(
current_user
,
parent
,
params
)
end
def
process_label_ids
(
attributes
,
existing_label_ids:
nil
)
def
process_label_ids
(
attributes
,
existing_label_ids:
nil
)
label_ids
=
attributes
.
delete
(
:label_ids
)
label_ids
=
attributes
.
delete
(
:label_ids
)
add_label_ids
=
attributes
.
delete
(
:add_label_ids
)
add_label_ids
=
attributes
.
delete
(
:add_label_ids
)
...
@@ -118,10 +126,6 @@ class IssuableBaseService < BaseService
...
@@ -118,10 +126,6 @@ class IssuableBaseService < BaseService
new_label_ids
new_label_ids
end
end
def
available_labels
@available_labels
||=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
,
include_ancestor_groups:
true
).
execute
end
def
handle_quick_actions_on_create
(
issuable
)
def
handle_quick_actions_on_create
(
issuable
)
merge_quick_actions_into_params!
(
issuable
)
merge_quick_actions_into_params!
(
issuable
)
end
end
...
...
app/services/labels/available_labels_service.rb
0 → 100644
View file @
c77fd1d1
# frozen_string_literal: true
module
Labels
class
AvailableLabelsService
attr_reader
:current_user
,
:parent
,
:params
def
initialize
(
current_user
,
parent
,
params
)
@current_user
=
current_user
@parent
=
parent
@params
=
params
end
def
find_or_create_by_titles
labels
=
params
.
delete
(
:labels
)
return
[]
unless
labels
labels
=
labels
.
split
(
','
)
if
labels
.
is_a?
(
String
)
labels
.
map
do
|
label_name
|
label
=
Labels
::
FindOrCreateService
.
new
(
current_user
,
parent
,
include_ancestor_groups:
true
,
title:
label_name
.
strip
,
available_labels:
available_labels
).
execute
label
end
.
compact
end
def
filter_labels_ids_in_param
(
key
)
return
[]
if
params
[
key
].
to_a
.
empty?
# rubocop:disable CodeReuse/ActiveRecord
available_labels
.
by_ids
(
params
[
key
]).
pluck
(
:id
)
# rubocop:enable CodeReuse/ActiveRecord
end
private
def
available_labels
@available_labels
||=
LabelsFinder
.
new
(
current_user
,
finder_params
).
execute
end
def
finder_params
params
=
{
include_ancestor_groups:
true
}
case
parent
when
Group
params
[
:group_id
]
=
parent
.
id
params
[
:only_group_labels
]
=
true
when
Project
params
[
:project_id
]
=
parent
.
id
end
params
end
end
end
ee/app/services/ee/boards/base_service.rb
View file @
c77fd1d1
...
@@ -35,20 +35,15 @@ module EE
...
@@ -35,20 +35,15 @@ module EE
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
def
set_labels
def
set_labels
labels
=
params
.
delete
(
:labels
)
if
params
[
:label_ids
]
params
[
:label_ids
]
=
labels_service
.
filter_labels_ids_in_param
(
:label_ids
)
return
unless
labels
elsif
params
[
:labels
]
params
[
:label_ids
]
=
labels_service
.
find_or_create_by_titles
.
map
(
&
:id
)
params
[
:label_ids
]
=
labels
.
split
(
","
).
map
do
|
label_name
|
end
label
=
Labels
::
FindOrCreateService
.
new
(
end
current_user
,
parent
,
title:
label_name
.
strip
,
include_ancestor_groups:
true
).
execute
label
.
try
(
:id
)
def
labels_service
end
.
compact
@labels_service
||=
::
Labels
::
AvailableLabelsService
.
new
(
current_user
,
parent
,
params
)
end
end
end
end
end
end
...
...
ee/changelogs/unreleased/security-milestone-labels.yml
0 → 100644
View file @
c77fd1d1
---
title
:
Check label_ids parent when updating issue board
merge_request
:
author
:
type
:
security
ee/spec/controllers/projects/boards_controller_spec.rb
View file @
c77fd1d1
...
@@ -141,7 +141,7 @@ describe Projects::BoardsController do
...
@@ -141,7 +141,7 @@ describe Projects::BoardsController do
let
(
:board
)
{
create
(
:board
,
project:
project
,
name:
'Backend'
)
}
let
(
:board
)
{
create
(
:board
,
project:
project
,
name:
'Backend'
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:milestone
)
{
create
(
:milestone
,
project:
project
)
}
let
(
:milestone
)
{
create
(
:milestone
,
project:
project
)
}
let
(
:label
)
{
create
(
:label
)
}
let
(
:label
)
{
create
(
:label
,
project:
project
)
}
let
(
:update_params
)
do
let
(
:update_params
)
do
{
name:
'Frontend'
,
{
name:
'Frontend'
,
...
...
ee/spec/services/boards/update_service_spec.rb
View file @
c77fd1d1
...
@@ -17,7 +17,7 @@ describe Boards::UpdateService, services: true do
...
@@ -17,7 +17,7 @@ describe Boards::UpdateService, services: true do
end
end
describe
'#execute'
do
describe
'#execute'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:group
)
{
create
(
:group
)
}
let!
(
:board
)
{
create
(
:board
,
group:
group
,
name:
'Backend'
)
}
let!
(
:board
)
{
create
(
:board
,
group:
group
,
name:
'Backend'
)
}
...
@@ -44,10 +44,11 @@ describe Boards::UpdateService, services: true do
...
@@ -44,10 +44,11 @@ describe Boards::UpdateService, services: true do
it
'updates the configuration params when scoped issue board is enabled'
do
it
'updates the configuration params when scoped issue board is enabled'
do
stub_licensed_features
(
scoped_issue_board:
true
)
stub_licensed_features
(
scoped_issue_board:
true
)
assignee
=
create
(
:user
)
assignee
=
create
(
:user
)
milestone
=
create
(
:milestone
,
project:
project
)
milestone
=
create
(
:milestone
,
group:
group
)
label
=
create
(
:label
,
project:
project
)
label
=
create
(
:group_label
,
group:
board
.
group
)
user
=
create
(
:user
)
service
=
described_class
.
new
(
project
,
double
,
service
=
described_class
.
new
(
group
,
user
,
milestone_id:
milestone
.
id
,
milestone_id:
milestone
.
id
,
assignee_id:
assignee
.
id
,
assignee_id:
assignee
.
id
,
label_ids:
[
label
.
id
])
label_ids:
[
label
.
id
])
...
@@ -213,6 +214,18 @@ describe Boards::UpdateService, services: true do
...
@@ -213,6 +214,18 @@ describe Boards::UpdateService, services: true do
expect_label_assigned
(
user
,
board
,
%w{group_label project_label new_label}
,
%w{group_label project_label}
)
expect_label_assigned
(
user
,
board
,
%w{group_label project_label new_label}
,
%w{group_label project_label}
)
end
end
end
end
context
'when label_ids param is provided'
do
it
'updates using only labels accessible by the project board'
do
other_project_label
=
create
(
:label
,
title:
'other_project_label'
)
other_group_label
=
create
(
:group_label
,
title:
'other_group_label'
)
label_ids
=
[
group_label
.
id
,
label
.
id
,
other_project_label
.
id
,
other_group_label
.
id
]
described_class
.
new
(
board
.
parent
,
user
,
label_ids:
label_ids
).
execute
(
board
)
expect
(
board
.
reload
.
labels
).
to
contain_exactly
(
group_label
,
label
)
end
end
end
end
end
end
end
end
...
...
spec/services/labels/available_labels_service_spec.rb
0 → 100644
View file @
c77fd1d1
# frozen_string_literal: true
require
'spec_helper'
describe
Labels
::
AvailableLabelsService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
group:
group
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:project_label
)
{
create
(
:label
,
project:
project
)
}
let
(
:other_project_label
)
{
create
(
:label
)
}
let
(
:group_label
)
{
create
(
:group_label
,
group:
group
)
}
let
(
:other_group_label
)
{
create
(
:group_label
)
}
let
(
:labels
)
{
[
project_label
,
other_project_label
,
group_label
,
other_group_label
]
}
context
'#find_or_create_by_titles'
do
let
(
:label_titles
)
{
labels
.
map
(
&
:title
).
push
(
'non existing title'
)
}
context
'when parent is a project'
do
context
'when a user is not a project member'
do
it
'returns only relevant label ids'
do
result
=
described_class
.
new
(
user
,
project
,
labels:
label_titles
).
find_or_create_by_titles
expect
(
result
).
to
match_array
([
project_label
,
group_label
])
end
end
context
'when a user is a project member'
do
before
do
project
.
add_developer
(
user
)
end
it
'creates new labels for not found titles'
do
result
=
described_class
.
new
(
user
,
project
,
labels:
label_titles
).
find_or_create_by_titles
expect
(
result
.
count
).
to
eq
(
5
)
expect
(
result
).
to
include
(
project_label
,
group_label
)
expect
(
result
).
not_to
include
(
other_project_label
,
other_group_label
)
end
end
end
context
'when parent is a group'
do
context
'when a user is not a group member'
do
it
'returns only relevant label ids'
do
result
=
described_class
.
new
(
user
,
group
,
labels:
label_titles
).
find_or_create_by_titles
expect
(
result
).
to
match_array
([
group_label
])
end
end
context
'when a user is a group member'
do
before
do
group
.
add_developer
(
user
)
end
it
'creates new labels for not found titles'
do
result
=
described_class
.
new
(
user
,
group
,
labels:
label_titles
).
find_or_create_by_titles
expect
(
result
.
count
).
to
eq
(
5
)
expect
(
result
).
to
include
(
group_label
)
expect
(
result
).
not_to
include
(
project_label
,
other_project_label
,
other_group_label
)
end
end
end
end
context
'#filter_labels_ids_in_param'
do
let
(
:label_ids
)
{
labels
.
map
(
&
:id
).
push
(
99999
)
}
context
'when parent is a project'
do
it
'returns only relevant label ids'
do
result
=
described_class
.
new
(
user
,
project
,
ids:
label_ids
).
filter_labels_ids_in_param
(
:ids
)
expect
(
result
).
to
match_array
([
project_label
.
id
,
group_label
.
id
])
end
end
context
'when parent is a group'
do
it
'returns only relevant label ids'
do
result
=
described_class
.
new
(
user
,
group
,
ids:
label_ids
).
filter_labels_ids_in_param
(
:ids
)
expect
(
result
).
to
match_array
([
group_label
.
id
])
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment