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
410d25c8
Commit
410d25c8
authored
Mar 16, 2015
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename table subscribe; make it polymorfic
parent
0e20dc91
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
41 additions
and
44 deletions
+41
-44
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+1
-1
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+1
-1
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+6
-5
app/models/subscribe.rb
app/models/subscribe.rb
+0
-6
app/models/subscription.rb
app/models/subscription.rb
+7
-0
app/services/notification_service.rb
app/services/notification_service.rb
+5
-5
app/views/projects/issues/_issue_context.html.haml
app/views/projects/issues/_issue_context.html.haml
+2
-2
app/views/projects/merge_requests/show/_context.html.haml
app/views/projects/merge_requests/show/_context.html.haml
+2
-2
db/migrate/20150313012111_create_subscribes_table.rb
db/migrate/20150313012111_create_subscribes_table.rb
+0
-16
db/migrate/20150313012111_create_subscriptions_table.rb
db/migrate/20150313012111_create_subscriptions_table.rb
+13
-0
db/schema.rb
db/schema.rb
+4
-6
No files found.
app/controllers/projects/issues_controller.rb
View file @
410d25c8
...
@@ -100,7 +100,7 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -100,7 +100,7 @@ class Projects::IssuesController < Projects::ApplicationController
def
set_subscription
def
set_subscription
subscribed
=
params
[
:subscription
]
==
"Subscribe"
subscribed
=
params
[
:subscription
]
==
"Subscribe"
sub
=
@issue
.
subscri
be
s
.
find_or_create_by
(
user_id:
current_user
.
id
)
sub
=
@issue
.
subscri
ption
s
.
find_or_create_by
(
user_id:
current_user
.
id
)
sub
.
update
(
subscribed:
subscribed
)
sub
.
update
(
subscribed:
subscribed
)
render
nothing:
true
render
nothing:
true
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
410d25c8
...
@@ -177,7 +177,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -177,7 +177,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def
set_subscription
def
set_subscription
subscribed
=
params
[
:subscription
]
==
"Subscribe"
subscribed
=
params
[
:subscription
]
==
"Subscribe"
sub
=
@merge_request
.
subscri
be
s
.
find_or_create_by
(
user_id:
current_user
.
id
)
sub
=
@merge_request
.
subscri
ption
s
.
find_or_create_by
(
user_id:
current_user
.
id
)
sub
.
update
(
subscribed:
subscribed
)
sub
.
update
(
subscribed:
subscribed
)
render
nothing:
true
render
nothing:
true
...
...
app/models/concerns/issuable.rb
View file @
410d25c8
...
@@ -15,7 +15,7 @@ module Issuable
...
@@ -15,7 +15,7 @@ module Issuable
has_many
:notes
,
as: :noteable
,
dependent: :destroy
has_many
:notes
,
as: :noteable
,
dependent: :destroy
has_many
:label_links
,
as: :target
,
dependent: :destroy
has_many
:label_links
,
as: :target
,
dependent: :destroy
has_many
:labels
,
through: :label_links
has_many
:labels
,
through: :label_links
has_many
:subscri
bes
,
dependent: :destroy
has_many
:subscri
ptions
,
dependent: :destroy
,
as: :subscribable
validates
:author
,
presence:
true
validates
:author
,
presence:
true
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
...
@@ -133,10 +133,11 @@ module Issuable
...
@@ -133,10 +133,11 @@ module Issuable
users
.
concat
(
mentions
.
reduce
([],
:|
)).
uniq
users
.
concat
(
mentions
.
reduce
([],
:|
)).
uniq
end
end
def
subscribe_status
(
user
)
def
subscription_status
(
user
)
subscribe
=
subscribes
.
find_by_user_id
(
user
.
id
)
subscription
=
subscriptions
.
find_by_user_id
(
user
.
id
)
if
subscribe
return
subscribe
.
subscribed
if
subscription
return
subscription
.
subscribed
end
end
participants
.
include?
(
user
)
participants
.
include?
(
user
)
...
...
app/models/subscribe.rb
deleted
100644 → 0
View file @
0e20dc91
class
Subscribe
<
ActiveRecord
::
Base
belongs_to
:user
validates
:issue_id
,
uniqueness:
{
scope: :user_id
,
allow_nil:
true
}
validates
:merge_request_id
,
uniqueness:
{
scope: :user_id
,
allow_nil:
true
}
end
app/models/subscription.rb
0 → 100644
View file @
410d25c8
class
Subscription
<
ActiveRecord
::
Base
belongs_to
:subscribable
,
polymorphic:
true
validates
:user_id
,
uniqueness:
{
scope:
[
:subscribable_id
,
:subscribable_type
]},
presence:
true
end
app/services/notification_service.rb
View file @
410d25c8
...
@@ -316,8 +316,8 @@ class NotificationService
...
@@ -316,8 +316,8 @@ class NotificationService
def
reject_unsubscribed_users
(
recipients
,
target
)
def
reject_unsubscribed_users
(
recipients
,
target
)
recipients
.
reject
do
|
user
|
recipients
.
reject
do
|
user
|
subscri
be
=
target
.
subscribe
s
.
find_by_user_id
(
user
.
id
)
subscri
ption
=
target
.
subscription
s
.
find_by_user_id
(
user
.
id
)
subscri
be
&&
!
subscribe
.
subscribed
subscri
ption
&&
!
subscription
.
subscribed
end
end
end
end
...
@@ -375,9 +375,9 @@ class NotificationService
...
@@ -375,9 +375,9 @@ class NotificationService
end
end
def
add_subscribed_users
(
recipients
,
target
)
def
add_subscribed_users
(
recipients
,
target
)
subscri
bes
=
target
.
subscribe
s
subscri
ptions
=
target
.
subscription
s
if
subscri
be
s
.
any?
if
subscri
ption
s
.
any?
recipients
.
merge
(
subscri
be
s
.
where
(
"subscribed is true"
).
map
(
&
:user
))
recipients
.
merge
(
subscri
ption
s
.
where
(
"subscribed is true"
).
map
(
&
:user
))
else
else
recipients
recipients
end
end
...
...
app/views/projects/issues/_issue_context.html.haml
View file @
410d25c8
...
@@ -33,8 +33,8 @@
...
@@ -33,8 +33,8 @@
Subscription:
Subscription:
%i
.fa.fa-spinner.fa-spin.hidden.subscription
%i
.fa.fa-spinner.fa-spin.hidden.subscription
%span
.sub_status
%span
.sub_status
=
@issue
.
subscri
be
_status
(
current_user
)
?
"subscribed"
:
"unsubscribed"
=
@issue
.
subscri
ption
_status
(
current_user
)
?
"subscribed"
:
"unsubscribed"
-
subscribe_action
=
@issue
.
subscri
be
_status
(
current_user
)
?
"Unsubscribe"
:
"Subscribe"
-
subscribe_action
=
@issue
.
subscri
ption
_status
(
current_user
)
?
"Unsubscribe"
:
"Subscribe"
%input
.btn.subscribe-button
{
:type
=>
"button"
,
:value
=>
subscribe_action
}
%input
.btn.subscribe-button
{
:type
=>
"button"
,
:value
=>
subscribe_action
}
:coffeescript
:coffeescript
...
...
app/views/projects/merge_requests/show/_context.html.haml
View file @
410d25c8
...
@@ -35,8 +35,8 @@
...
@@ -35,8 +35,8 @@
Subscription:
Subscription:
%i
.fa.fa-spinner.fa-spin.hidden.subscription
%i
.fa.fa-spinner.fa-spin.hidden.subscription
%span
.sub_status
%span
.sub_status
=
@merge_request
.
subscri
be
_status
(
current_user
)
?
"subscribed"
:
"unsubscribed"
=
@merge_request
.
subscri
ption
_status
(
current_user
)
?
"subscribed"
:
"unsubscribed"
-
subscribe_action
=
@merge_request
.
subscri
be
_status
(
current_user
)
?
"Unsubscribe"
:
"Subscribe"
-
subscribe_action
=
@merge_request
.
subscri
ption
_status
(
current_user
)
?
"Unsubscribe"
:
"Subscribe"
%input
.btn.subscribe-button
{
:type
=>
"button"
,
:value
=>
subscribe_action
}
%input
.btn.subscribe-button
{
:type
=>
"button"
,
:value
=>
subscribe_action
}
:coffeescript
:coffeescript
...
...
db/migrate/20150313012111_create_subscribes_table.rb
deleted
100644 → 0
View file @
0e20dc91
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
add_index
:subscribes
,
:user_id
add_index
:subscribes
,
:issue_id
add_index
:subscribes
,
:merge_request_id
end
end
db/migrate/20150313012111_create_subscriptions_table.rb
0 → 100644
View file @
410d25c8
class
CreateSubscriptionsTable
<
ActiveRecord
::
Migration
def
change
create_table
:subscriptions
do
|
t
|
t
.
integer
:user_id
t
.
references
:subscribable
,
polymorphic:
true
t
.
boolean
:subscribed
t
.
timestamps
end
add_index
:subscriptions
,
[
:subscribable_id
,
:subscribable_type
,
:user_id
],
unique:
true
,
name:
'subscriptions_user_id_and_ref_fields'
end
end
db/schema.rb
View file @
410d25c8
...
@@ -397,18 +397,16 @@ ActiveRecord::Schema.define(version: 20150313012111) do
...
@@ -397,18 +397,16 @@ ActiveRecord::Schema.define(version: 20150313012111) do
add_index
"snippets"
,
[
"project_id"
],
name:
"index_snippets_on_project_id"
,
using: :btree
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
add_index
"snippets"
,
[
"visibility_level"
],
name:
"index_snippets_on_visibility_level"
,
using: :btree
create_table
"subscri
be
s"
,
force:
true
do
|
t
|
create_table
"subscri
ption
s"
,
force:
true
do
|
t
|
t
.
integer
"user_id"
t
.
integer
"user_id"
t
.
integer
"
merge_request
_id"
t
.
integer
"
subscribable
_id"
t
.
integer
"issue_id
"
t
.
string
"subscribable_type
"
t
.
boolean
"subscribed"
t
.
boolean
"subscribed"
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
end
end
add_index
"subscribes"
,
[
"issue_id"
],
name:
"index_subscribes_on_issue_id"
,
using: :btree
add_index
"subscriptions"
,
[
"subscribable_id"
,
"subscribable_type"
,
"user_id"
],
name:
"subscriptions_user_id_and_ref_fields"
,
unique:
true
,
using: :btree
add_index
"subscribes"
,
[
"merge_request_id"
],
name:
"index_subscribes_on_merge_request_id"
,
using: :btree
add_index
"subscribes"
,
[
"user_id"
],
name:
"index_subscribes_on_user_id"
,
using: :btree
create_table
"taggings"
,
force:
true
do
|
t
|
create_table
"taggings"
,
force:
true
do
|
t
|
t
.
integer
"tag_id"
t
.
integer
"tag_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