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
iv
gitlab-ce
Commits
9698b36c
Commit
9698b36c
authored
Mar 15, 2015
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Subscription
parent
606d24ff
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
127 additions
and
3 deletions
+127
-3
app/assets/javascripts/subscription.js.coffee
app/assets/javascripts/subscription.js.coffee
+18
-0
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+10
-1
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+10
-1
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+10
-0
app/models/subscribe.rb
app/models/subscribe.rb
+3
-0
app/services/notification_service.rb
app/services/notification_service.rb
+18
-0
app/views/projects/issues/_issue_context.html.haml
app/views/projects/issues/_issue_context.html.haml
+16
-0
app/views/projects/merge_requests/show/_context.html.haml
app/views/projects/merge_requests/show/_context.html.haml
+16
-0
config/routes.rb
config/routes.rb
+4
-0
db/migrate/20150313012111_create_subscribes_table.rb
db/migrate/20150313012111_create_subscribes_table.rb
+12
-0
db/schema.rb
db/schema.rb
+10
-1
No files found.
app/assets/javascripts/subscription.js.coffee
0 → 100644
View file @
9698b36c
class
@
Subscription
constructor
:
(
url
)
->
$
(
".subscribe-button"
).
click
(
event
)
=>
self
=
@
btn
=
$
(
event
.
currentTarget
)
action
=
btn
.
prop
(
"value"
)
current_status
=
$
(
".sub_status"
).
text
().
trim
()
$
(
".fa-spinner.subscription"
).
removeClass
(
"hidden"
)
$
(
".sub_status"
).
empty
()
$
.
post
url
,
subscription
:
action
,
=>
$
(
".fa-spinner.subscription"
).
addClass
(
"hidden"
)
status
=
if
current_status
==
"subscribed"
then
"unsubscribed"
else
"subscribed"
$
(
".sub_status"
).
text
(
status
)
action
=
if
status
==
"subscribed"
then
"Unsubscribe"
else
"Subscribe"
btn
.
prop
(
"value"
,
action
)
app/controllers/projects/issues_controller.rb
View file @
9698b36c
class
Projects::IssuesController
<
Projects
::
ApplicationController
before_filter
:module_enabled
before_filter
:issue
,
only:
[
:edit
,
:update
,
:show
]
before_filter
:issue
,
only:
[
:edit
,
:update
,
:show
,
:set_subscription
]
# Allow read any issue
before_filter
:authorize_read_issue!
...
...
@@ -97,6 +97,15 @@ class Projects::IssuesController < Projects::ApplicationController
redirect_to
:back
,
notice:
"
#{
result
[
:count
]
}
issues updated"
end
def
set_subscription
subscribed
=
params
[
:subscription
]
==
"Subscribe"
sub
=
@issue
.
subscribes
.
find_or_create_by
(
user_id:
current_user
.
id
)
sub
.
update
(
subscribed:
subscribed
)
render
nothing:
true
end
protected
def
issue
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
9698b36c
...
...
@@ -2,7 +2,7 @@ require 'gitlab/satellite/satellite'
class
Projects::MergeRequestsController
<
Projects
::
ApplicationController
before_filter
:module_enabled
before_filter
:merge_request
,
only:
[
:edit
,
:update
,
:show
,
:diffs
,
:automerge
,
:automerge_check
,
:ci_status
]
before_filter
:merge_request
,
only:
[
:edit
,
:update
,
:show
,
:diffs
,
:automerge
,
:automerge_check
,
:ci_status
,
:set_subscription
]
before_filter
:closes_issues
,
only:
[
:edit
,
:update
,
:show
,
:diffs
]
before_filter
:validates_merge_request
,
only:
[
:show
,
:diffs
]
before_filter
:define_show_vars
,
only:
[
:show
,
:diffs
]
...
...
@@ -174,6 +174,15 @@ class Projects::MergeRequestsController < Projects::ApplicationController
render
json:
response
end
def
set_subscription
subscribed
=
params
[
:subscription
]
==
"Subscribe"
sub
=
@merge_request
.
subscribes
.
find_or_create_by
(
user_id:
current_user
.
id
)
sub
.
update
(
subscribed:
subscribed
)
render
nothing:
true
end
protected
def
selected_target_project
...
...
app/models/concerns/issuable.rb
View file @
9698b36c
...
...
@@ -15,6 +15,7 @@ module Issuable
has_many
:notes
,
as: :noteable
,
dependent: :destroy
has_many
:label_links
,
as: :target
,
dependent: :destroy
has_many
:labels
,
through: :label_links
has_many
:subscribes
,
dependent: :destroy
validates
:author
,
presence:
true
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
...
...
@@ -132,6 +133,15 @@ module Issuable
users
.
concat
(
mentions
.
reduce
([],
:|
)).
uniq
end
def
subscribe_status
(
user
)
sub
=
subscribes
.
find_by_user_id
(
user
.
id
)
if
sub
return
sub
.
subscribed
end
participants
.
include?
(
user
)
end
def
to_hook_data
(
user
)
{
object_kind:
self
.
class
.
name
.
underscore
,
...
...
app/models/subscribe.rb
0 → 100644
View file @
9698b36c
class
Subscribe
<
ActiveRecord
::
Base
belongs_to
:user
end
app/services/notification_service.rb
View file @
9698b36c
...
...
@@ -314,6 +314,13 @@ class NotificationService
end
end
def
reject_unsubscribed_users
(
recipients
,
target
)
recipients
.
reject
do
|
user
|
subscribe
=
target
.
subscribes
.
find_by_user_id
(
user
.
id
)
subscribe
&&
!
subscribe
.
subscribed
end
end
def
new_resource_email
(
target
,
project
,
method
)
recipients
=
build_recipients
(
target
,
project
)
recipients
.
delete
(
target
.
author
)
...
...
@@ -361,10 +368,21 @@ class NotificationService
recipients
=
reject_muted_users
(
recipients
,
project
)
recipients
=
reject_mention_users
(
recipients
,
project
)
recipients
=
add_subscribers
(
recipients
,
project
)
recipients
=
recipients
.
concat
(
project_watchers
(
project
)).
uniq
recipients
=
reject_unsubscribed_users
(
recipients
,
target
)
recipients
end
def
add_subscribers
(
recipients
,
target
)
subs
=
target
.
subscribes
if
subs
.
any?
recipients
.
merge
(
subs
.
where
(
"subscribed is true"
).
map
(
&
:user
))
else
recipients
end
end
def
mailer
Notify
.
delay
end
...
...
app/views/projects/issues/_issue_context.html.haml
View file @
9698b36c
...
...
@@ -26,3 +26,19 @@
=
f
.
select
(
:milestone_id
,
milestone_options
(
@issue
),
{
include_blank:
"Select milestone"
},
{
class:
'select2 select2-compact js-select2 js-milestone'
})
=
hidden_field_tag
:issue_context
=
f
.
submit
class:
'btn'
%div
.prepend-top-20.clearfix
.issuable-context-title
%label
Subscription:
%i
.fa.fa-spinner.fa-spin.hidden.subscription
%span
.sub_status
=
@issue
.
subscribe_status
(
current_user
)
?
"subscribed"
:
"unsubscribed"
-
subscribe_action
=
@issue
.
subscribe_status
(
current_user
)
?
"Unsubscribe"
:
"Subscribe"
%input
.btn.subscribe-button
{
:type
=>
"button"
,
:value
=>
subscribe_action
}
:coffeescript
$ ->
new Subscription("
#{
set_subscription_namespace_project_issue_path
(
@issue
.
project
.
namespace
,
@project
,
@issue
)
}
")
\ No newline at end of file
app/views/projects/merge_requests/show/_context.html.haml
View file @
9698b36c
...
...
@@ -28,3 +28,19 @@
=
f
.
select
(
:milestone_id
,
milestone_options
(
@merge_request
),
{
include_blank:
"Select milestone"
},
{
class:
'select2 select2-compact js-select2 js-milestone'
})
=
hidden_field_tag
:merge_request_context
=
f
.
submit
class:
'btn'
%div
.prepend-top-20.clearfix
.issuable-context-title
%label
Subscription:
%i
.fa.fa-spinner.fa-spin.hidden.subscription
%span
.sub_status
=
@merge_request
.
subscribe_status
(
current_user
)
?
"subscribed"
:
"unsubscribed"
-
subscribe_action
=
@merge_request
.
subscribe_status
(
current_user
)
?
"Unsubscribe"
:
"Subscribe"
%input
.btn.subscribe-button
{
:type
=>
"button"
,
:value
=>
subscribe_action
}
:coffeescript
$ ->
new Subscription("
#{
set_subscription_namespace_project_issue_path
(
@merge_request
.
project
.
namespace
,
@project
,
@merge_request
)
}
")
\ No newline at end of file
config/routes.rb
View file @
9698b36c
...
...
@@ -406,6 +406,7 @@ Gitlab::Application.routes.draw do
post
:automerge
get
:automerge_check
get
:ci_status
post
:set_subscription
end
collection
do
...
...
@@ -440,6 +441,9 @@ Gitlab::Application.routes.draw do
end
resources
:issues
,
constraints:
{
id:
/\d+/
},
except:
[
:destroy
]
do
member
do
post
:set_subscription
end
collection
do
post
:bulk_update
end
...
...
db/migrate/20150313012111_create_subscribes_table.rb
0 → 100644
View file @
9698b36c
class
CreateSubscribesTable
<
ActiveRecord
::
Migration
def
change
create_table
:subscribes
do
|
t
|
t
.
integer
:user_id
t
.
integer
:merge_request_id
t
.
integer
:issue_id
t
.
boolean
:subscribed
t
.
timestamps
end
end
end
db/schema.rb
View file @
9698b36c
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201503
06023112
)
do
ActiveRecord
::
Schema
.
define
(
version:
201503
13012111
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -397,6 +397,15 @@ ActiveRecord::Schema.define(version: 20150306023112) do
add_index
"snippets"
,
[
"project_id"
],
name:
"index_snippets_on_project_id"
,
using: :btree
add_index
"snippets"
,
[
"visibility_level"
],
name:
"index_snippets_on_visibility_level"
,
using: :btree
create_table
"subscribes"
,
force:
true
do
|
t
|
t
.
integer
"user_id"
t
.
integer
"merge_request_id"
t
.
integer
"issue_id"
t
.
boolean
"subscribed"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
end
create_table
"taggings"
,
force:
true
do
|
t
|
t
.
integer
"tag_id"
t
.
integer
"taggable_id"
...
...
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