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
baf47a0b
Commit
baf47a0b
authored
8 years ago
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove project_labels from Projects::ApplicationController
parent
cf14482a
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
88 additions
and
48 deletions
+88
-48
app/controllers/concerns/issuable_actions.rb
app/controllers/concerns/issuable_actions.rb
+5
-0
app/controllers/projects/application_controller.rb
app/controllers/projects/application_controller.rb
+0
-4
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+1
-5
app/controllers/projects/labels_controller.rb
app/controllers/projects/labels_controller.rb
+16
-12
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+0
-1
app/views/projects/labels/destroy.js.haml
app/views/projects/labels/destroy.js.haml
+1
-1
app/views/projects/labels/index.html.haml
app/views/projects/labels/index.html.haml
+5
-5
spec/controllers/projects/labels_controller_spec.rb
spec/controllers/projects/labels_controller_spec.rb
+60
-20
No files found.
app/controllers/concerns/issuable_actions.rb
View file @
baf47a0b
...
@@ -2,6 +2,7 @@ module IssuableActions
...
@@ -2,6 +2,7 @@ module IssuableActions
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
included
do
included
do
before_action
:labels
,
only:
[
:new
,
:edit
]
before_action
:authorize_destroy_issuable!
,
only: :destroy
before_action
:authorize_destroy_issuable!
,
only: :destroy
before_action
:authorize_admin_issuable!
,
only: :bulk_update
before_action
:authorize_admin_issuable!
,
only: :bulk_update
end
end
...
@@ -25,6 +26,10 @@ module IssuableActions
...
@@ -25,6 +26,10 @@ module IssuableActions
private
private
def
labels
@labels
||=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
).
execute
end
def
authorize_destroy_issuable!
def
authorize_destroy_issuable!
unless
can?
(
current_user
,
:"destroy_
#{
issuable
.
to_ability_name
}
"
,
issuable
)
unless
can?
(
current_user
,
:"destroy_
#{
issuable
.
to_ability_name
}
"
,
issuable
)
return
access_denied!
return
access_denied!
...
...
This diff is collapsed.
Click to expand it.
app/controllers/projects/application_controller.rb
View file @
baf47a0b
...
@@ -44,10 +44,6 @@ class Projects::ApplicationController < ApplicationController
...
@@ -44,10 +44,6 @@ class Projects::ApplicationController < ApplicationController
@project
@project
end
end
def
project_labels
@project_labels
||=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
).
execute
end
def
repository
def
repository
@repository
||=
project
.
repository
@repository
||=
project
.
repository
end
end
...
...
This diff is collapsed.
Click to expand it.
app/controllers/projects/issues_controller.rb
View file @
baf47a0b
...
@@ -48,14 +48,10 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -48,14 +48,10 @@ class Projects::IssuesController < Projects::ApplicationController
)
)
@issue
=
@noteable
=
@project
.
issues
.
new
(
issue_params
)
@issue
=
@noteable
=
@project
.
issues
.
new
(
issue_params
)
@labels
=
project_labels
respond_with
(
@issue
)
respond_with
(
@issue
)
end
end
def
edit
def
edit
@labels
=
project_labels
respond_with
(
@issue
)
respond_with
(
@issue
)
end
end
...
...
This diff is collapsed.
Click to expand it.
app/controllers/projects/labels_controller.rb
View file @
baf47a0b
...
@@ -3,23 +3,23 @@ class Projects::LabelsController < Projects::ApplicationController
...
@@ -3,23 +3,23 @@ class Projects::LabelsController < Projects::ApplicationController
before_action
:module_enabled
before_action
:module_enabled
before_action
:label
,
only:
[
:edit
,
:update
,
:destroy
]
before_action
:label
,
only:
[
:edit
,
:update
,
:destroy
]
before_action
:labels
,
only:
[
:index
]
before_action
:authorize_read_label!
before_action
:authorize_read_label!
before_action
:authorize_admin_labels!
,
only:
[
before_action
:authorize_admin_labels!
,
only:
[
:new
,
:create
,
:edit
,
:update
,
:new
,
:create
,
:edit
,
:update
,
:generate
,
:destroy
,
:remove_priority
,
:set_priorities
:generate
,
:destroy
,
:remove_priority
,
]
:set_priorities
]
respond_to
:js
,
:html
respond_to
:js
,
:html
def
index
def
index
@project_labels
=
project_labels
@prioritized_labels
=
@labels
.
prioritized
@prioritized_labels
=
project_labels
.
prioritized
@group_labels
=
@project
.
group
.
labels
.
unprioritized
if
@project
.
group
.
present?
@group_labels
=
@project
.
group
.
labels
.
unprioritized
if
@project
.
group
.
present?
@labels
=
@project
.
labels
.
unprioritized
.
page
(
params
[
:page
])
@
project_
labels
=
@project
.
labels
.
unprioritized
.
page
(
params
[
:page
])
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
format
.
html
format
.
json
do
format
.
json
do
render
json:
@
project_
labels
render
json:
@labels
end
end
end
end
end
end
...
@@ -38,7 +38,7 @@ class Projects::LabelsController < Projects::ApplicationController
...
@@ -38,7 +38,7 @@ class Projects::LabelsController < Projects::ApplicationController
end
end
else
else
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
{
render
'new'
}
format
.
html
{
render
:new
}
format
.
json
{
render
json:
{
message:
@label
.
errors
.
messages
},
status:
400
}
format
.
json
{
render
json:
{
message:
@label
.
errors
.
messages
},
status:
400
}
end
end
end
end
...
@@ -51,7 +51,7 @@ class Projects::LabelsController < Projects::ApplicationController
...
@@ -51,7 +51,7 @@ class Projects::LabelsController < Projects::ApplicationController
if
@label
.
update_attributes
(
label_params
)
if
@label
.
update_attributes
(
label_params
)
redirect_to
namespace_project_labels_path
(
@project
.
namespace
,
@project
)
redirect_to
namespace_project_labels_path
(
@project
.
namespace
,
@project
)
else
else
render
'edit'
render
:edit
end
end
end
end
...
@@ -70,7 +70,7 @@ class Projects::LabelsController < Projects::ApplicationController
...
@@ -70,7 +70,7 @@ class Projects::LabelsController < Projects::ApplicationController
def
destroy
def
destroy
@label
.
destroy
@label
.
destroy
@
project_labels
=
project_
labels
@
labels
=
labels
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
do
format
.
html
do
...
@@ -83,7 +83,7 @@ class Projects::LabelsController < Projects::ApplicationController
...
@@ -83,7 +83,7 @@ class Projects::LabelsController < Projects::ApplicationController
def
remove_priority
def
remove_priority
respond_to
do
|
format
|
respond_to
do
|
format
|
label
=
project_
labels
.
find
(
params
[
:id
])
label
=
labels
.
find
(
params
[
:id
])
if
label
.
update_attribute
(
:priority
,
nil
)
if
label
.
update_attribute
(
:priority
,
nil
)
format
.
json
{
render
json:
label
}
format
.
json
{
render
json:
label
}
...
@@ -97,7 +97,7 @@ class Projects::LabelsController < Projects::ApplicationController
...
@@ -97,7 +97,7 @@ class Projects::LabelsController < Projects::ApplicationController
def
set_priorities
def
set_priorities
Label
.
transaction
do
Label
.
transaction
do
params
[
:label_ids
].
each_with_index
do
|
label_id
,
index
|
params
[
:label_ids
].
each_with_index
do
|
label_id
,
index
|
label
=
project_
labels
.
find_by_id
(
label_id
)
label
=
labels
.
find_by_id
(
label_id
)
label
.
update_attribute
(
:priority
,
index
)
if
label
label
.
update_attribute
(
:priority
,
index
)
if
label
end
end
end
end
...
@@ -124,6 +124,10 @@ class Projects::LabelsController < Projects::ApplicationController
...
@@ -124,6 +124,10 @@ class Projects::LabelsController < Projects::ApplicationController
end
end
alias_method
:subscribable_resource
,
:label
alias_method
:subscribable_resource
,
:label
def
labels
@labels
||=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
).
execute
end
def
authorize_admin_labels!
def
authorize_admin_labels!
return
render_404
unless
can?
(
current_user
,
:admin_label
,
@project
)
return
render_404
unless
can?
(
current_user
,
:admin_label
,
@project
)
end
end
...
...
This diff is collapsed.
Click to expand it.
app/controllers/projects/merge_requests_controller.rb
View file @
baf47a0b
...
@@ -263,7 +263,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -263,7 +263,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@source_project
=
@merge_request
.
source_project
@source_project
=
@merge_request
.
source_project
@target_project
=
@merge_request
.
target_project
@target_project
=
@merge_request
.
target_project
@target_branches
=
@merge_request
.
target_project
.
repository
.
branch_names
@target_branches
=
@merge_request
.
target_project
.
repository
.
branch_names
@labels
=
project_labels
end
end
def
update
def
update
...
...
This diff is collapsed.
Click to expand it.
app/views/projects/labels/destroy.js.haml
View file @
baf47a0b
-
if
@
project_labels
.
none
?
-
if
@
labels
.
empty
?
$('.labels').load(document.URL + ' .nothing-here-block').hide().fadeIn(1000)
$('.labels').load(document.URL + ' .nothing-here-block').hide().fadeIn(1000)
This diff is collapsed.
Click to expand it.
app/views/projects/labels/index.html.haml
View file @
baf47a0b
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
New label
New label
.labels
.labels
-
unless
@
project_
labels
.
empty?
-
unless
@labels
.
empty?
-# Only show it in the first page
-# Only show it in the first page
-
hide
=
params
[
:page
].
present?
&&
params
[
:page
]
!=
'1'
-
hide
=
params
[
:page
].
present?
&&
params
[
:page
]
!=
'1'
-
if
can?
(
current_user
,
:admin_label
,
@project
)
-
if
can?
(
current_user
,
:admin_label
,
@project
)
...
@@ -39,10 +39,10 @@
...
@@ -39,10 +39,10 @@
=
icon
(
'bookmark'
)
=
icon
(
'bookmark'
)
Project Labels
Project Labels
%ul
.content-list.manage-labels-list.js-project-labels
%ul
.content-list.manage-labels-list.js-project-labels
%p
.empty-message
{
class:
(
'hidden'
unless
@labels
.
empty?
)
}
No project labels
%p
.empty-message
{
class:
(
'hidden'
unless
@
project_
labels
.
empty?
)
}
No project labels
-
if
@labels
.
present?
-
if
@
project_
labels
.
present?
=
render
@labels
=
render
@
project_
labels
=
paginate
@labels
,
theme:
'gitlab'
=
paginate
@
project_
labels
,
theme:
'gitlab'
-
else
-
else
.nothing-here-block
.nothing-here-block
-
if
can?
(
current_user
,
:admin_label
,
@project
)
-
if
can?
(
current_user
,
:admin_label
,
@project
)
...
...
This diff is collapsed.
Click to expand it.
spec/controllers/projects/labels_controller_spec.rb
View file @
baf47a0b
require
'spec_helper'
require
'spec_helper'
describe
Projects
::
LabelsController
do
describe
Projects
::
LabelsController
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
group
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
before
do
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user
,
:master
]
sign_in
(
user
)
sign_in
(
user
)
end
end
describe
'GET #index'
do
describe
'GET #index'
do
def
create_label
(
attributes
)
let!
(
:label_1
)
{
create
(
:label
,
project:
project
,
priority:
1
,
title:
'Label 1'
)
}
create
(
:label
,
attributes
.
merge
(
project:
project
))
let!
(
:label_2
)
{
create
(
:label
,
project:
project
,
priority:
3
,
title:
'Label 2'
)
}
end
let!
(
:label_3
)
{
create
(
:label
,
project:
project
,
priority:
1
,
title:
'Label 3'
)
}
let!
(
:label_4
)
{
create
(
:label
,
project:
project
,
priority:
nil
,
title:
'Label 4'
)
}
before
do
let!
(
:label_5
)
{
create
(
:label
,
project:
project
,
priority:
nil
,
title:
'Label 5'
)
}
15
.
times
{
|
i
|
create_label
(
priority:
(
i
%
3
)
+
1
,
title:
"label
#{
15
-
i
}
"
)
}
5
.
times
{
|
i
|
create_label
(
title:
"label
#{
100
-
i
}
"
)
}
get
:index
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
let!
(
:group_label_1
)
{
create
(
:group_label
,
group:
group
,
priority:
3
,
title:
'Group Label 1'
)
}
end
let!
(
:group_label_2
)
{
create
(
:group_label
,
group:
group
,
priority:
1
,
title:
'Group Label 2'
)
}
let!
(
:group_label_3
)
{
create
(
:group_label
,
group:
group
,
priority:
nil
,
title:
'Group Label 3'
)
}
let!
(
:group_label_4
)
{
create
(
:group_label
,
group:
group
,
priority:
nil
,
title:
'Group Label 4'
)
}
context
'@prioritized_labels'
do
context
'@prioritized_labels'
do
let
(
:prioritized_labels
)
{
assigns
(
:prioritized_labels
)
}
before
do
list_labels
end
it
'contains only prioritized labels'
do
it
'contains only prioritized labels'
do
expect
(
prioritized_labels
).
to
all
(
have_attributes
(
priority:
a_value
>
0
))
expect
(
assigns
(
:prioritized_labels
)
).
to
all
(
have_attributes
(
priority:
a_value
>
0
))
end
end
it
'is sorted by priority, then label title'
do
it
'is sorted by priority, then label title'
do
priorities_and_titles
=
prioritized_labels
.
pluck
(
:priority
,
:title
)
expect
(
assigns
(
:prioritized_labels
)).
to
match_array
[
group_label_2
,
label_1
,
label_3
,
group_label_1
,
label_2
]
expect
(
priorities_and_titles
.
sort
).
to
eq
(
priorities_and_titles
)
end
end
end
end
context
'@labels'
do
context
'@group_labels'
do
let
(
:labels
)
{
assigns
(
:labels
)
}
it
'contains only group labels'
do
list_labels
expect
(
assigns
(
:group_labels
)).
to
all
(
have_attributes
(
group_id:
a_value
>
0
))
end
it
'contains only unprioritized labels'
do
it
'contains only unprioritized labels'
do
expect
(
labels
).
to
all
(
have_attributes
(
priority:
nil
))
list_labels
expect
(
assigns
(
:group_labels
)).
to
all
(
have_attributes
(
priority:
nil
))
end
end
it
'is sorted by label title'
do
it
'is sorted by label title'
do
titles
=
labels
.
pluck
(
:title
)
list_labels
expect
(
assigns
(
:group_labels
)).
to
match_array
[
group_label_3
,
group_label_4
]
end
it
'is nil when project does not belong to a group'
do
project
.
update
(
namespace:
create
(
:namespace
))
list_labels
expect
(
titles
.
sort
).
to
eq
(
titles
)
expect
(
assigns
(
:group_labels
)).
to
be_nil
end
end
end
end
context
'@project_labels'
do
before
do
list_labels
end
it
'contains only project labels'
do
list_labels
expect
(
assigns
(
:project_labels
)).
to
all
(
have_attributes
(
project_id:
a_value
>
0
))
end
it
'contains only unprioritized labels'
do
expect
(
assigns
(
:project_labels
)).
to
all
(
have_attributes
(
priority:
nil
))
end
it
'is sorted by label title'
do
expect
(
assigns
(
:project_labels
)).
to
match_array
[
label_4
,
label_5
]
end
end
def
list_labels
get
:index
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
end
end
end
end
end
This diff is collapsed.
Click to expand it.
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