summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-11-04 16:19:08 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-11-17 15:10:13 -0200
commit0c052f116c9e093936847280e833ca8985d2d94c (patch)
tree6b8d52bd8b3ac075c7abf223571cfe14345bffc3 /app
parentb3249bc28faecd1774558ec6f8ecc32f89c416ae (diff)
downloadgitlab-ce-0c052f116c9e093936847280e833ca8985d2d94c.tar.gz
Remove default value for `project` argument on subscribable concern
Diffstat (limited to 'app')
-rw-r--r--app/controllers/sent_notifications_controller.rb2
-rw-r--r--app/models/concerns/subscribable.rb32
-rw-r--r--app/models/issue.rb2
-rw-r--r--app/services/issuable_base_service.rb4
-rw-r--r--app/services/slash_commands/interpret_service.rb4
-rw-r--r--app/views/shared/issuable/_sidebar.html.haml2
6 files changed, 22 insertions, 24 deletions
diff --git a/app/controllers/sent_notifications_controller.rb b/app/controllers/sent_notifications_controller.rb
index 3085ff33aba..04c36b3ebfe 100644
--- a/app/controllers/sent_notifications_controller.rb
+++ b/app/controllers/sent_notifications_controller.rb
@@ -12,7 +12,7 @@ class SentNotificationsController < ApplicationController
def unsubscribe_and_redirect
noteable = @sent_notification.noteable
- noteable.unsubscribe(@sent_notification.recipient)
+ noteable.unsubscribe(@sent_notification.recipient, @sent_notification.project)
flash[:notice] = "You have been unsubscribed from this thread."
diff --git a/app/models/concerns/subscribable.rb b/app/models/concerns/subscribable.rb
index 2210a210f33..5f2725a6d7f 100644
--- a/app/models/concerns/subscribable.rb
+++ b/app/models/concerns/subscribable.rb
@@ -12,45 +12,43 @@ module Subscribable
has_many :subscriptions, dependent: :destroy, as: :subscribable
end
- def subscribed?(user, to_project = nil)
- if subscription = subscriptions.find_by(user: user, project: (to_project || project))
+ def subscribed?(user, project)
+ if subscription = subscriptions.find_by(user: user, project: project)
subscription.subscribed
else
- subscribed_without_subscriptions?(user, to_project)
+ subscribed_without_subscriptions?(user, project)
end
end
# Override this method to define custom logic to consider a subscribable as
# subscribed without an explicit subscription record.
- def subscribed_without_subscriptions?(user, to_project = nil)
+ def subscribed_without_subscriptions?(user, project)
false
end
- def subscribers(to_project = nil)
- subscriptions.where(project: (to_project || project), subscribed: true).map(&:user)
+ def subscribers(project)
+ subscriptions.where(project: project, subscribed: true).map(&:user)
end
- def toggle_subscription(user, to_project = nil)
- subscribed = subscribed?(user, (to_project || project))
-
- find_or_initialize_subscription(user, to_project).
- update(subscribed: !subscribed)
+ def toggle_subscription(user, project)
+ find_or_initialize_subscription(user, project).
+ update(subscribed: !subscribed?(user, project))
end
- def subscribe(user, to_project = nil)
- find_or_initialize_subscription(user, to_project).
+ def subscribe(user, project)
+ find_or_initialize_subscription(user, project).
update(subscribed: true)
end
- def unsubscribe(user, to_project = nil)
- find_or_initialize_subscription(user, to_project).
+ def unsubscribe(user, project)
+ find_or_initialize_subscription(user, project).
update(subscribed: false)
end
private
- def find_or_initialize_subscription(user, to_project = nil)
+ def find_or_initialize_subscription(user, project)
subscriptions.
- find_or_initialize_by(user_id: user.id, project_id: (to_project || project).id)
+ find_or_initialize_by(user_id: user.id, project_id: project.id)
end
end
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 4a4017003d8..6e8f5d3c422 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -266,7 +266,7 @@ class Issue < ActiveRecord::Base
def as_json(options = {})
super(options).tap do |json|
- json[:subscribed] = subscribed?(options[:user]) if options.has_key?(:user) && options[:user]
+ json[:subscribed] = subscribed?(options[:user], project) if options.has_key?(:user) && options[:user]
if options.has_key?(:labels)
json[:labels] = labels.as_json(
diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb
index bb92cd80cc9..575795788de 100644
--- a/app/services/issuable_base_service.rb
+++ b/app/services/issuable_base_service.rb
@@ -212,9 +212,9 @@ class IssuableBaseService < BaseService
def change_subscription(issuable)
case params.delete(:subscription_event)
when 'subscribe'
- issuable.subscribe(current_user)
+ issuable.subscribe(current_user, project)
when 'unsubscribe'
- issuable.unsubscribe(current_user)
+ issuable.unsubscribe(current_user, project)
end
end
diff --git a/app/services/slash_commands/interpret_service.rb b/app/services/slash_commands/interpret_service.rb
index 5a81194a5f4..d75c5b1800e 100644
--- a/app/services/slash_commands/interpret_service.rb
+++ b/app/services/slash_commands/interpret_service.rb
@@ -193,7 +193,7 @@ module SlashCommands
desc 'Subscribe'
condition do
issuable.persisted? &&
- !issuable.subscribed?(current_user)
+ !issuable.subscribed?(current_user, project)
end
command :subscribe do
@updates[:subscription_event] = 'subscribe'
@@ -202,7 +202,7 @@ module SlashCommands
desc 'Unsubscribe'
condition do
issuable.persisted? &&
- issuable.subscribed?(current_user)
+ issuable.subscribed?(current_user, project)
end
command :unsubscribe do
@updates[:subscription_event] = 'unsubscribe'
diff --git a/app/views/shared/issuable/_sidebar.html.haml b/app/views/shared/issuable/_sidebar.html.haml
index 7363ead09ff..f166fac105d 100644
--- a/app/views/shared/issuable/_sidebar.html.haml
+++ b/app/views/shared/issuable/_sidebar.html.haml
@@ -140,7 +140,7 @@
= render "shared/issuable/participants", participants: issuable.participants(current_user)
- if current_user
- - subscribed = issuable.subscribed?(current_user)
+ - subscribed = issuable.subscribed?(current_user, @project)
.block.light.subscription{data: {url: toggle_subscription_path(issuable)}}
.sidebar-collapsed-icon
= icon('rss')