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
f53683e6
Commit
f53683e6
authored
Mar 16, 2015
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix specs
parent
410d25c8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
12 deletions
+22
-12
app/models/subscription.rb
app/models/subscription.rb
+2
-1
app/services/notification_service.rb
app/services/notification_service.rb
+19
-10
db/schema.rb
db/schema.rb
+1
-1
No files found.
app/models/subscription.rb
View file @
f53683e6
class
Subscription
<
ActiveRecord
::
Base
belongs_to
:user
belongs_to
:subscribable
,
polymorphic:
true
validates
:user_id
,
uniqueness:
{
scope:
[
:subscribable_id
,
:subscribable_type
]},
uniqueness:
{
scope:
[
:subscribable_id
,
:subscribable_type
]
},
presence:
true
end
app/services/notification_service.rb
View file @
f53683e6
...
...
@@ -151,6 +151,10 @@ class NotificationService
# Reject mutes users
recipients
=
reject_muted_users
(
recipients
,
note
.
project
)
recipients
=
add_subscribed_users
(
recipients
,
note
.
noteable
)
recipients
=
reject_unsubscribed_users
(
recipients
,
note
.
noteable
)
# Reject author
recipients
.
delete
(
note
.
author
)
...
...
@@ -315,12 +319,26 @@ class NotificationService
end
def
reject_unsubscribed_users
(
recipients
,
target
)
return
recipients
unless
target
.
respond_to?
:subscriptions
recipients
.
reject
do
|
user
|
subscription
=
target
.
subscriptions
.
find_by_user_id
(
user
.
id
)
subscription
&&
!
subscription
.
subscribed
end
end
def
add_subscribed_users
(
recipients
,
target
)
return
recipients
unless
target
.
respond_to?
:subscriptions
subscriptions
=
target
.
subscriptions
if
subscriptions
.
any?
recipients
+
subscriptions
.
where
(
"subscribed is true"
).
map
(
&
:user
)
else
recipients
end
end
def
new_resource_email
(
target
,
project
,
method
)
recipients
=
build_recipients
(
target
,
project
)
recipients
.
delete
(
target
.
author
)
...
...
@@ -368,21 +386,12 @@ class NotificationService
recipients
=
reject_muted_users
(
recipients
,
project
)
recipients
=
reject_mention_users
(
recipients
,
project
)
recipients
=
add_subscribed_users
(
recipients
,
projec
t
)
recipients
=
add_subscribed_users
(
recipients
,
targe
t
)
recipients
=
recipients
.
concat
(
project_watchers
(
project
)).
uniq
recipients
=
reject_unsubscribed_users
(
recipients
,
target
)
recipients
end
def
add_subscribed_users
(
recipients
,
target
)
subscriptions
=
target
.
subscriptions
if
subscriptions
.
any?
recipients
.
merge
(
subscriptions
.
where
(
"subscribed is true"
).
map
(
&
:user
))
else
recipients
end
end
def
mailer
Notify
.
delay
end
...
...
db/schema.rb
View file @
f53683e6
...
...
@@ -334,12 +334,12 @@ ActiveRecord::Schema.define(version: 20150313012111) do
t
.
string
"import_url"
t
.
integer
"visibility_level"
,
default:
0
,
null:
false
t
.
boolean
"archived"
,
default:
false
,
null:
false
t
.
string
"avatar"
t
.
string
"import_status"
t
.
float
"repository_size"
,
default:
0.0
t
.
integer
"star_count"
,
default:
0
,
null:
false
t
.
string
"import_type"
t
.
string
"import_source"
t
.
string
"avatar"
end
add_index
"projects"
,
[
"created_at"
,
"id"
],
name:
"index_projects_on_created_at_and_id"
,
using: :btree
...
...
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