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
4a29fde5
Commit
4a29fde5
authored
Nov 01, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow users to subscribe to group labels at project-level
parent
b34c063e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
27 deletions
+34
-27
app/controllers/projects/labels_controller.rb
app/controllers/projects/labels_controller.rb
+5
-2
app/helpers/labels_helper.rb
app/helpers/labels_helper.rb
+4
-12
app/views/shared/_label.html.haml
app/views/shared/_label.html.haml
+6
-6
spec/controllers/projects/labels_controller_spec.rb
spec/controllers/projects/labels_controller_spec.rb
+19
-7
No files found.
app/controllers/projects/labels_controller.rb
View file @
4a29fde5
...
...
@@ -3,7 +3,7 @@ class Projects::LabelsController < Projects::ApplicationController
before_action
:module_enabled
before_action
:label
,
only:
[
:edit
,
:update
,
:destroy
]
before_action
:find_labels
,
only:
[
:index
,
:set_priorities
,
:remove_priority
]
before_action
:find_labels
,
only:
[
:index
,
:set_priorities
,
:remove_priority
,
:toggle_subscription
]
before_action
:authorize_read_label!
before_action
:authorize_admin_labels!
,
only:
[
:new
,
:create
,
:edit
,
:update
,
:generate
,
:destroy
,
:remove_priority
,
...
...
@@ -123,7 +123,10 @@ class Projects::LabelsController < Projects::ApplicationController
def
label
@label
||=
@project
.
labels
.
find
(
params
[
:id
])
end
alias_method
:subscribable_resource
,
:label
def
subscribable_resource
@available_labels
.
find
(
params
[
:id
])
end
def
subscribable_project
@project
...
...
app/helpers/labels_helper.rb
View file @
4a29fde5
...
...
@@ -68,11 +68,9 @@ module LabelsHelper
end
end
def
toggle_subscription_data
(
label
)
return
unless
label
.
is_a?
(
ProjectLabel
)
def
toggle_subscription_data
(
label
,
project
)
{
url:
toggle_subscription_namespace_project_label_path
(
label
.
project
.
namespace
,
label
.
project
,
label
)
url:
toggle_subscription_namespace_project_label_path
(
project
.
namespace
,
project
,
label
)
}
end
...
...
@@ -149,17 +147,11 @@ module LabelsHelper
end
def
label_subscription_status
(
label
,
project
)
case
label
when
GroupLabel
then
'Subscribing to group labels is currently not supported.'
when
ProjectLabel
then
label
.
subscribed?
(
current_user
,
project
)
?
'subscribed'
:
'unsubscribed'
end
label
.
subscribed?
(
current_user
,
project
)
?
'subscribed'
:
'unsubscribed'
end
def
label_subscription_toggle_button_text
(
label
,
project
)
case
label
when
GroupLabel
then
'Subscribing to group labels is currently not supported.'
when
ProjectLabel
then
label
.
subscribed?
(
current_user
,
project
)
?
'Unsubscribe'
:
'Subscribe'
end
label
.
subscribed?
(
current_user
,
project
)
?
'Unsubscribe'
:
'Subscribe'
end
def
label_deletion_confirm_text
(
label
)
...
...
app/views/shared/_label.html.haml
View file @
4a29fde5
...
...
@@ -18,8 +18,8 @@
%li
=
link_to_label
(
label
,
subject:
subject
)
do
=
pluralize
open_issues_count
,
'open issue'
-
if
current_user
%li
.label-subscription
{
data:
toggle_subscription_data
(
label
)
}
-
if
current_user
&&
defined?
(
@project
)
%li
.label-subscription
{
data:
toggle_subscription_data
(
label
,
@project
)
}
%a
.js-subscribe-button.label-subscribe-button.subscription-status
{
role:
"button"
,
href:
"#"
,
data:
{
toggle:
"tooltip"
,
status:
label_subscription_status
(
label
,
@project
)
}
}
%span
=
label_subscription_toggle_button_text
(
label
,
@project
)
-
if
can?
(
current_user
,
:admin_label
,
label
)
...
...
@@ -34,11 +34,11 @@
=
link_to_label
(
label
,
subject:
subject
,
css_class:
'btn btn-transparent btn-action'
)
do
=
pluralize
open_issues_count
,
'open issue'
-
if
current_user
.label-subscription.inline
{
data:
toggle_subscription_data
(
label
)
}
-
if
current_user
&&
defined?
(
@project
)
.label-subscription.inline
{
data:
toggle_subscription_data
(
label
,
@project
)
}
%button
.js-subscribe-button.label-subscribe-button.btn.btn-transparent.btn-action.subscription-status
{
type:
"button"
,
title:
label_subscription_toggle_button_text
(
label
,
@project
),
data:
{
toggle:
"tooltip"
,
status:
label_subscription_status
(
label
,
@project
)
}
}
%span
.sr-only
=
label_subscription_toggle_button_text
(
label
,
@project
)
=
icon
(
'eye'
,
class:
'label-subscribe-button-icon'
,
disabled:
label
.
is_a?
(
GroupLabel
)
)
=
icon
(
'eye'
,
class:
'label-subscribe-button-icon'
)
=
icon
(
'spinner spin'
,
class:
'label-subscribe-button-loading'
)
-
if
can?
(
current_user
,
:admin_label
,
label
)
...
...
@@ -49,6 +49,6 @@
%span
.sr-only
Delete
=
icon
(
'trash-o'
)
-
if
current_user
&&
label
.
is_a?
(
ProjectLabel
)
-
if
current_user
&&
defined?
(
@project
)
:javascript
new
Subscription
(
'
##{dom_id(label)} .label-subscription
'
);
spec/controllers/projects/labels_controller_spec.rb
View file @
4a29fde5
...
...
@@ -72,14 +72,8 @@ describe Projects::LabelsController do
end
describe
'POST #generate'
do
let
(
:admin
)
{
create
(
:admin
)
}
before
do
sign_in
(
admin
)
end
context
'personal project'
do
let
(
:personal_project
)
{
create
(
:empty_project
)
}
let
(
:personal_project
)
{
create
(
:empty_project
,
namespace:
user
.
namespace
)
}
it
'creates labels'
do
post
:generate
,
namespace_id:
personal_project
.
namespace
.
to_param
,
project_id:
personal_project
.
to_param
...
...
@@ -96,4 +90,22 @@ describe Projects::LabelsController do
end
end
end
describe
'POST #toggle_subscription'
do
it
'allows user to toggle subscription on project labels'
do
label
=
create
(
:label
,
project:
project
)
post
:toggle_subscription
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
id:
label
.
id
expect
(
response
).
to
have_http_status
(
200
)
end
it
'allows user to toggle subscription on group labels'
do
group_label
=
create
(
:group_label
,
group:
group
)
post
:toggle_subscription
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
id:
group_label
.
id
expect
(
response
).
to
have_http_status
(
200
)
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