summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-03-15 18:08:45 +0000
committerRémy Coutable <remy@rymai.me>2016-03-15 18:08:45 +0000
commitbc590ce63bd2f1af5545b648e6d028a557e7c792 (patch)
tree572c40bc0e3dc45f6970247073c4423284591c92 /app/controllers
parentac8c6f24e3070c28ab6f246599c95fd8f3b7e3a5 (diff)
parente90d6ec1d83ff86743e70931b49647eaf3e3e67a (diff)
downloadgitlab-ce-bc590ce63bd2f1af5545b648e6d028a557e7c792.tar.gz
Merge branch '12743-subscribe-to-label' into 'master'
Allow subscribing to labels This implement #12743 and supersedes !2799 (thanks @timothyandrew!). - Subscribe (and unsubscribe) for labels - When an issue/merge request is created, notify all subscribers of all its labels - When an issue/merge request is edited, notify all subscribers of all its newly-added labels ## Done - [x] Verify that a user is signed in to subscribe/unsubscribe from a label. - [x] Merge conflicts - [x] Integration tests - [x] `issuable.subscribed?` should check subscribers and participants - [x] When an issuable is relabeled, notify subscribers of the *newly added* labels only - [x] Screenshots: ### Labels page ![Screen_Shot_2016-03-07_at_19.05.44](/uploads/3e69064e9e1a06ee2e27c778776c1407/Screen_Shot_2016-03-07_at_19.05.44.png) ### HTML email ![Screen_Shot_2016-03-07_at_19.07.36](/uploads/e484e06366a738385f1f6d71b52eecf7/Screen_Shot_2016-03-07_at_19.07.36.png) ### Plain text email ![Screen_Shot_2016-03-07_at_19.07.50](/uploads/dc05f710a8f7ab5eae9f72aa2110e741/Screen_Shot_2016-03-07_at_19.07.50.png) PS: I've set the milestone to 8.6 since it's getting late for 8.5... See merge request !3115
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/concerns/toggle_subscription_action.rb17
-rw-r--r--app/controllers/projects/issues_controller.rb11
-rw-r--r--app/controllers/projects/labels_controller.rb9
-rw-r--r--app/controllers/projects/merge_requests_controller.rb10
4 files changed, 31 insertions, 16 deletions
diff --git a/app/controllers/concerns/toggle_subscription_action.rb b/app/controllers/concerns/toggle_subscription_action.rb
new file mode 100644
index 00000000000..8a43c0b93c4
--- /dev/null
+++ b/app/controllers/concerns/toggle_subscription_action.rb
@@ -0,0 +1,17 @@
+module ToggleSubscriptionAction
+ extend ActiveSupport::Concern
+
+ def toggle_subscription
+ return unless current_user
+
+ subscribable_resource.toggle_subscription(current_user)
+
+ render nothing: true
+ end
+
+ private
+
+ def subscribable_resource
+ raise NotImplementedError
+ end
+end
diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb
index 67faa1e4437..b0a03ee45cc 100644
--- a/app/controllers/projects/issues_controller.rb
+++ b/app/controllers/projects/issues_controller.rb
@@ -1,6 +1,8 @@
class Projects::IssuesController < Projects::ApplicationController
+ include ToggleSubscriptionAction
+
before_action :module_enabled
- before_action :issue, only: [:edit, :update, :show, :toggle_subscription]
+ before_action :issue, only: [:edit, :update, :show]
# Allow read any issue
before_action :authorize_read_issue!
@@ -110,12 +112,6 @@ class Projects::IssuesController < Projects::ApplicationController
redirect_back_or_default(default: { action: 'index' }, options: { notice: "#{result[:count]} issues updated" })
end
- def toggle_subscription
- @issue.toggle_subscription(current_user)
-
- render nothing: true
- end
-
def closed_by_merge_requests
@closed_by_merge_requests ||= @issue.closed_by_merge_requests(current_user)
end
@@ -129,6 +125,7 @@ class Projects::IssuesController < Projects::ApplicationController
redirect_old
end
end
+ alias_method :subscribable_resource, :issue
def authorize_update_issue!
return render_404 unless can?(current_user, :update_issue, @issue)
diff --git a/app/controllers/projects/labels_controller.rb b/app/controllers/projects/labels_controller.rb
index ecac3c395ec..40d8098690a 100644
--- a/app/controllers/projects/labels_controller.rb
+++ b/app/controllers/projects/labels_controller.rb
@@ -1,8 +1,12 @@
class Projects::LabelsController < Projects::ApplicationController
+ include ToggleSubscriptionAction
+
before_action :module_enabled
before_action :label, only: [:edit, :update, :destroy]
before_action :authorize_read_label!
- before_action :authorize_admin_labels!, except: [:index]
+ before_action :authorize_admin_labels!, only: [
+ :new, :create, :edit, :update, :generate, :destroy
+ ]
respond_to :js, :html
@@ -73,8 +77,9 @@ class Projects::LabelsController < Projects::ApplicationController
end
def label
- @label = @project.labels.find(params[:id])
+ @label ||= @project.labels.find(params[:id])
end
+ alias_method :subscribable_resource, :label
def authorize_admin_labels!
return render_404 unless can?(current_user, :admin_label, @project)
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index 03ba289eb94..61b82c9db46 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -1,10 +1,11 @@
class Projects::MergeRequestsController < Projects::ApplicationController
+ include ToggleSubscriptionAction
include DiffHelper
before_action :module_enabled
before_action :merge_request, only: [
:edit, :update, :show, :diffs, :commits, :builds, :merge, :merge_check,
- :ci_status, :toggle_subscription, :cancel_merge_when_build_succeeds
+ :ci_status, :cancel_merge_when_build_succeeds
]
before_action :closes_issues, only: [:edit, :update, :show, :diffs, :commits, :builds]
before_action :validates_merge_request, only: [:show, :diffs, :commits, :builds]
@@ -233,12 +234,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
render json: response
end
- def toggle_subscription
- @merge_request.toggle_subscription(current_user)
-
- render nothing: true
- end
-
protected
def selected_target_project
@@ -252,6 +247,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def merge_request
@merge_request ||= @project.merge_requests.find_by!(iid: params[:id])
end
+ alias_method :subscribable_resource, :merge_request
def closes_issues
@closes_issues ||= @merge_request.closes_issues