Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-03-01 19:33:13 +0300
committerRémy Coutable <remy@rymai.me>2016-03-15 20:22:02 +0300
commit54ec7e959900493b6e9174bf4dfe09ed0afd1e46 (patch)
tree22b79458e9d5ad2aa8ccf7ae00935c9a14aae33c /app/models/concerns/subscribable.rb
parent0444fa560acd07255960284f19b1de6499cd5910 (diff)
Improving the original label-subscribing implementation
1. Make the "subscribed" text in Issuable sidebar reflect the labels subscription status 2. Current user mut be logged-in to toggle issue/MR/label subscription
Diffstat (limited to 'app/models/concerns/subscribable.rb')
-rw-r--r--app/models/concerns/subscribable.rb25
1 files changed, 13 insertions, 12 deletions
diff --git a/app/models/concerns/subscribable.rb b/app/models/concerns/subscribable.rb
index cab9241ac3d..d5a881b2445 100644
--- a/app/models/concerns/subscribable.rb
+++ b/app/models/concerns/subscribable.rb
@@ -13,20 +13,21 @@ module Subscribable
end
def subscribed?(user)
- subscription = subscriptions.find_by_user_id(user.id)
-
- if subscription
- return subscription.subscribed
+ if subscription = subscriptions.find_by_user_id(user.id)
+ subscription.subscribed
+ else
+ subscribed_without_subscriptions?(user)
end
+ end
- # FIXME
- # Issue/MergeRequest has participants, but Label doesn't.
- # Ideally, subscriptions should be separate from participations,
- # but that seems like a larger change with farther-reaching
- # consequences, so this is a compromise for the time being.
- if respond_to?(:participants)
- participants(user).include?(user)
- end
+ # Override this method to define custom logic to consider a subscribable as
+ # subscribed without an explicit subscription record.
+ def subscribed_without_subscriptions?(user)
+ false
+ end
+
+ def subscribers
+ subscriptions.where(subscribed: true).map(&:user)
end
def toggle_subscription(user)