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
Jérome Perrin
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
...
@@ -3,7 +3,7 @@ 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
: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_read_label!
before_action
:authorize_admin_labels!
,
only:
[
:new
,
:create
,
:edit
,
:update
,
before_action
:authorize_admin_labels!
,
only:
[
:new
,
:create
,
:edit
,
:update
,
:generate
,
:destroy
,
:remove_priority
,
:generate
,
:destroy
,
:remove_priority
,
...
@@ -123,7 +123,10 @@ class Projects::LabelsController < Projects::ApplicationController
...
@@ -123,7 +123,10 @@ class Projects::LabelsController < Projects::ApplicationController
def
label
def
label
@label
||=
@project
.
labels
.
find
(
params
[
:id
])
@label
||=
@project
.
labels
.
find
(
params
[
:id
])
end
end
alias_method
:subscribable_resource
,
:label
def
subscribable_resource
@available_labels
.
find
(
params
[
:id
])
end
def
subscribable_project
def
subscribable_project
@project
@project
...
...
app/helpers/labels_helper.rb
View file @
4a29fde5
...
@@ -68,11 +68,9 @@ module LabelsHelper
...
@@ -68,11 +68,9 @@ module LabelsHelper
end
end
end
end
def
toggle_subscription_data
(
label
)
def
toggle_subscription_data
(
label
,
project
)
return
unless
label
.
is_a?
(
ProjectLabel
)
{
{
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
end
...
@@ -149,17 +147,11 @@ module LabelsHelper
...
@@ -149,17 +147,11 @@ module LabelsHelper
end
end
def
label_subscription_status
(
label
,
project
)
def
label_subscription_status
(
label
,
project
)
case
label
label
.
subscribed?
(
current_user
,
project
)
?
'subscribed'
:
'unsubscribed'
when
GroupLabel
then
'Subscribing to group labels is currently not supported.'
when
ProjectLabel
then
label
.
subscribed?
(
current_user
,
project
)
?
'subscribed'
:
'unsubscribed'
end
end
end
def
label_subscription_toggle_button_text
(
label
,
project
)
def
label_subscription_toggle_button_text
(
label
,
project
)
case
label
label
.
subscribed?
(
current_user
,
project
)
?
'Unsubscribe'
:
'Subscribe'
when
GroupLabel
then
'Subscribing to group labels is currently not supported.'
when
ProjectLabel
then
label
.
subscribed?
(
current_user
,
project
)
?
'Unsubscribe'
:
'Subscribe'
end
end
end
def
label_deletion_confirm_text
(
label
)
def
label_deletion_confirm_text
(
label
)
...
...
app/views/shared/_label.html.haml
View file @
4a29fde5
...
@@ -18,8 +18,8 @@
...
@@ -18,8 +18,8 @@
%li
%li
=
link_to_label
(
label
,
subject:
subject
)
do
=
link_to_label
(
label
,
subject:
subject
)
do
=
pluralize
open_issues_count
,
'open issue'
=
pluralize
open_issues_count
,
'open issue'
-
if
current_user
-
if
current_user
&&
defined?
(
@project
)
%li
.label-subscription
{
data:
toggle_subscription_data
(
label
)
}
%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
)
}
}
%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
)
%span
=
label_subscription_toggle_button_text
(
label
,
@project
)
-
if
can?
(
current_user
,
:admin_label
,
label
)
-
if
can?
(
current_user
,
:admin_label
,
label
)
...
@@ -34,11 +34,11 @@
...
@@ -34,11 +34,11 @@
=
link_to_label
(
label
,
subject:
subject
,
css_class:
'btn btn-transparent btn-action'
)
do
=
link_to_label
(
label
,
subject:
subject
,
css_class:
'btn btn-transparent btn-action'
)
do
=
pluralize
open_issues_count
,
'open issue'
=
pluralize
open_issues_count
,
'open issue'
-
if
current_user
-
if
current_user
&&
defined?
(
@project
)
.label-subscription.inline
{
data:
toggle_subscription_data
(
label
)
}
.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
)
}
}
%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
)
%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'
)
=
icon
(
'spinner spin'
,
class:
'label-subscribe-button-loading'
)
-
if
can?
(
current_user
,
:admin_label
,
label
)
-
if
can?
(
current_user
,
:admin_label
,
label
)
...
@@ -49,6 +49,6 @@
...
@@ -49,6 +49,6 @@
%span
.sr-only
Delete
%span
.sr-only
Delete
=
icon
(
'trash-o'
)
=
icon
(
'trash-o'
)
-
if
current_user
&&
label
.
is_a?
(
ProjectLabel
)
-
if
current_user
&&
defined?
(
@project
)
:javascript
:javascript
new
Subscription
(
'
##{dom_id(label)} .label-subscription
'
);
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
...
@@ -72,14 +72,8 @@ describe Projects::LabelsController do
end
end
describe
'POST #generate'
do
describe
'POST #generate'
do
let
(
:admin
)
{
create
(
:admin
)
}
before
do
sign_in
(
admin
)
end
context
'personal project'
do
context
'personal project'
do
let
(
:personal_project
)
{
create
(
:empty_project
)
}
let
(
:personal_project
)
{
create
(
:empty_project
,
namespace:
user
.
namespace
)
}
it
'creates labels'
do
it
'creates labels'
do
post
:generate
,
namespace_id:
personal_project
.
namespace
.
to_param
,
project_id:
personal_project
.
to_param
post
:generate
,
namespace_id:
personal_project
.
namespace
.
to_param
,
project_id:
personal_project
.
to_param
...
@@ -96,4 +90,22 @@ describe Projects::LabelsController do
...
@@ -96,4 +90,22 @@ describe Projects::LabelsController do
end
end
end
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
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