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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
27a19c51
Commit
27a19c51
authored
Dec 28, 2018
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out group labels entity
parent
70ed87ba
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
41 deletions
+31
-41
app/models/group_label.rb
app/models/group_label.rb
+0
-4
lib/api/entities.rb
lib/api/entities.rb
+7
-5
lib/api/group_labels.rb
lib/api/group_labels.rb
+8
-12
lib/api/labels.rb
lib/api/labels.rb
+8
-11
lib/api/subscriptions.rb
lib/api/subscriptions.rb
+8
-9
No files found.
app/models/group_label.rb
View file @
27a19c51
...
...
@@ -10,8 +10,4 @@ class GroupLabel < Label
def
subject_foreign_key
'group_id'
end
def
priority
(
parent
)
nil
end
end
lib/api/entities.rb
View file @
27a19c51
...
...
@@ -1006,7 +1006,7 @@ module API
expose
:id
,
:name
,
:color
,
:description
end
class
Label
<
LabelBasic
class
Group
Label
<
LabelBasic
expose
:open_issues_count
do
|
label
,
options
|
label
.
open_issues_count
(
options
[
:current_user
])
end
...
...
@@ -1019,15 +1019,17 @@ module API
label
.
open_merge_requests_count
(
options
[
:current_user
])
end
expose
:priority
do
|
label
,
options
|
label
.
priority
(
options
[
:project
])
end
expose
:subscribed
do
|
label
,
options
|
label
.
subscribed?
(
options
[
:current_user
],
options
[
:project
])
end
end
class
ProjectLabel
<
GroupLabel
expose
:priority
do
|
label
,
options
|
label
.
priority
(
options
[
:project
])
end
end
class
List
<
Grape
::
Entity
expose
:id
expose
:label
,
using:
Entities
::
LabelBasic
...
...
lib/api/group_labels.rb
View file @
27a19c51
...
...
@@ -12,7 +12,7 @@ module API
resource
:groups
,
requirements:
API
::
NAMESPACE_OR_PROJECT_REQUIREMENTS
do
desc
'Get all labels of the group'
do
detail
'This feature was added in GitLab 11.7'
success
Entities
::
Label
success
Entities
::
Group
Label
end
params
do
use
:pagination
...
...
@@ -20,12 +20,12 @@ module API
get
':id/labels'
do
group_labels
=
available_labels_for
(
user_group
)
present
paginate
(
group_labels
),
with:
Entities
::
Label
,
current_user:
current_user
,
parent:
user_group
present
paginate
(
group_labels
),
with:
Entities
::
Group
Label
,
current_user:
current_user
,
parent:
user_group
end
desc
'Create a new label'
do
detail
'This feature was added in GitLab 11.7'
success
Entities
::
Label
success
Entities
::
Group
Label
end
params
do
requires
:name
,
type:
String
,
desc:
'The name of the label to be created'
...
...
@@ -41,7 +41,7 @@ module API
label
=
::
Labels
::
CreateService
.
new
(
declared_params
(
include_missing:
false
)).
execute
(
group:
user_group
)
if
label
.
persisted?
present
label
,
with:
Entities
::
Label
,
current_user:
current_user
,
parent:
user_group
present
label
,
with:
Entities
::
Group
Label
,
current_user:
current_user
,
parent:
user_group
else
render_validation_error!
(
label
)
end
...
...
@@ -49,7 +49,7 @@ module API
desc
'Delete an existing label'
do
detail
'This feature was added in GitLab 11.7'
success
Entities
::
Label
success
Entities
::
Group
Label
end
params
do
requires
:name
,
type:
String
,
desc:
'The name of the label to be deleted'
...
...
@@ -64,7 +64,7 @@ module API
desc
'Update an existing label. At least one optional parameter is required.'
do
detail
'This feature was added in GitLab 11.7'
success
Entities
::
Label
success
Entities
::
Group
Label
end
params
do
requires
:name
,
type:
String
,
desc:
'The name of the label to be updated'
...
...
@@ -78,14 +78,10 @@ module API
label
=
find_label
(
user_group
,
params
[
:name
])
label_params
=
declared_params
(
include_missing:
false
)
# Rename new name to the actual label attribute name
label_params
[
:name
]
=
label_params
.
delete
(
:new_name
)
if
label_params
.
key?
(
:new_name
)
label
=
::
Labels
::
UpdateService
.
new
(
label_params
).
execute
(
label
)
label
=
::
Labels
::
UpdateService
.
new
(
declared_params
(
include_missing:
false
)).
execute
(
label
)
render_validation_error!
(
label
)
unless
label
.
valid?
present
label
,
with:
Entities
::
Label
,
current_user:
current_user
,
parent:
user_group
present
label
,
with:
Entities
::
Group
Label
,
current_user:
current_user
,
parent:
user_group
end
end
end
...
...
lib/api/labels.rb
View file @
27a19c51
...
...
@@ -11,17 +11,17 @@ module API
end
resource
:projects
,
requirements:
API
::
NAMESPACE_OR_PROJECT_REQUIREMENTS
do
desc
'Get all labels of the project'
do
success
Entities
::
Label
success
Entities
::
Project
Label
end
params
do
use
:pagination
end
get
':id/labels'
do
present
paginate
(
available_labels_for
(
user_project
)),
with:
Entities
::
Label
,
current_user:
current_user
,
project:
user_project
present
paginate
(
available_labels_for
(
user_project
)),
with:
Entities
::
Project
Label
,
current_user:
current_user
,
project:
user_project
end
desc
'Create a new label'
do
success
Entities
::
Label
success
Entities
::
Project
Label
end
params
do
requires
:name
,
type:
String
,
desc:
'The name of the label to be created'
...
...
@@ -41,7 +41,7 @@ module API
if
label
.
valid?
label
.
prioritize!
(
user_project
,
priority
)
if
priority
present
label
,
with:
Entities
::
Label
,
current_user:
current_user
,
project:
user_project
present
label
,
with:
Entities
::
Project
Label
,
current_user:
current_user
,
project:
user_project
else
render_validation_error!
(
label
)
end
...
...
@@ -49,7 +49,7 @@ module API
# rubocop: enable CodeReuse/ActiveRecord
desc
'Delete an existing label'
do
success
Entities
::
Label
success
Entities
::
Project
Label
end
params
do
requires
:name
,
type:
String
,
desc:
'The name of the label to be deleted'
...
...
@@ -66,7 +66,7 @@ module API
# rubocop: enable CodeReuse/ActiveRecord
desc
'Update an existing label. At least one optional parameter is required.'
do
success
Entities
::
Label
success
Entities
::
Project
Label
end
params
do
requires
:name
,
type:
String
,
desc:
'The name of the label to be updated'
...
...
@@ -85,11 +85,8 @@ module API
update_priority
=
params
.
key?
(
:priority
)
priority
=
params
.
delete
(
:priority
)
label_params
=
declared_params
(
include_missing:
false
)
# Rename new name to the actual label attribute name
label_params
[
:name
]
=
label_params
.
delete
(
:new_name
)
if
label_params
.
key?
(
:new_name
)
label
=
::
Labels
::
UpdateService
.
new
(
label_params
).
execute
(
label
)
label
=
::
Labels
::
UpdateService
.
new
(
declared_params
(
include_missing:
false
)
).
execute
(
label
)
render_validation_error!
(
label
)
unless
label
.
valid?
if
update_priority
...
...
@@ -100,7 +97,7 @@ module API
end
end
present
label
,
with:
Entities
::
Label
,
current_user:
current_user
,
project:
user_project
present
label
,
with:
Entities
::
Project
Label
,
current_user:
current_user
,
project:
user_project
end
# rubocop: enable CodeReuse/ActiveRecord
end
...
...
lib/api/subscriptions.rb
View file @
27a19c51
...
...
@@ -5,15 +5,14 @@ module API
before
{
authenticate!
}
subscribables
=
[
{
type:
'merge_requests'
,
source:
Project
,
finder:
->
(
id
)
{
find_merge_request_with_access
(
id
,
:update_merge_request
)
},
parent_resource:
->
{
user_project
}
},
{
type:
'issues'
,
source:
Project
,
finder:
->
(
id
)
{
find_project_issue
(
id
)
},
parent_resource:
->
{
user_project
}
},
{
type:
'labels'
,
source:
Project
,
finder:
->
(
id
)
{
find_label
(
user_project
,
id
)
},
parent_resource:
->
{
user_project
}
},
{
type:
'labels'
,
source:
Group
,
finder:
->
(
id
)
{
find_label
(
user_group
,
id
)
},
parent_resource:
->
{
nil
}
}
{
type:
'merge_requests'
,
entity:
Entities
::
MergeRequest
,
source:
Project
,
finder:
->
(
id
)
{
find_merge_request_with_access
(
id
,
:update_merge_request
)
},
parent_resource:
->
{
user_project
}
},
{
type:
'issues'
,
entity:
Entities
::
Issue
,
source:
Project
,
finder:
->
(
id
)
{
find_project_issue
(
id
)
},
parent_resource:
->
{
user_project
}
},
{
type:
'labels'
,
entity:
Entities
::
ProjectLabel
,
source:
Project
,
finder:
->
(
id
)
{
find_label
(
user_project
,
id
)
},
parent_resource:
->
{
user_project
}
},
{
type:
'labels'
,
entity:
Entities
::
GroupLabel
,
source:
Group
,
finder:
->
(
id
)
{
find_label
(
user_group
,
id
)
},
parent_resource:
->
{
nil
}
}
]
subscribables
.
each
do
|
subscribable
|
source_type
=
subscribable
[
:source
].
name
.
underscore
entity_class
=
Entities
.
const_get
(
subscribable
[
:type
].
singularize
.
camelcase
)
params
do
requires
:id
,
type:
String
,
desc:
"The
#{
source_type
}
ID"
...
...
@@ -21,7 +20,7 @@ module API
end
resource
source_type
.
pluralize
,
requirements:
API
::
NAMESPACE_OR_PROJECT_REQUIREMENTS
do
desc
'Subscribe to a resource'
do
success
entity_class
success
subscribable
[
:entity
]
end
post
":id/
#{
subscribable
[
:type
]
}
/:subscribable_id/subscribe"
do
parent
=
instance_exec
(
&
subscribable
[
:parent_resource
])
...
...
@@ -31,12 +30,12 @@ module API
not_modified!
else
resource
.
subscribe
(
current_user
,
parent
)
present
resource
,
with:
entity_class
,
current_user:
current_user
,
project:
parent
present
resource
,
with:
subscribable
[
:entity
]
,
current_user:
current_user
,
project:
parent
end
end
desc
'Unsubscribe from a resource'
do
success
entity_class
success
subscribable
[
:entity
]
end
post
":id/
#{
subscribable
[
:type
]
}
/:subscribable_id/unsubscribe"
do
parent
=
instance_exec
(
&
subscribable
[
:parent_resource
])
...
...
@@ -46,7 +45,7 @@ module API
not_modified!
else
resource
.
unsubscribe
(
current_user
,
parent
)
present
resource
,
with:
entity_class
,
current_user:
current_user
,
project:
parent
present
resource
,
with:
subscribable
[
:entity
]
,
current_user:
current_user
,
project:
parent
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