summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <zegerjan@gitlab.com>2016-03-21 14:12:52 +0100
committerZeger-Jan van de Weg <zegerjan@gitlab.com>2016-03-21 16:59:35 +0100
commit3b088fc5b53f03605484ebef1945b8839abe19de (patch)
tree1c058f36cf3610449d4636998b59128b5112131c /app/controllers
parent98fd60f50b6658d21503f548649c8db291050ab7 (diff)
downloadgitlab-ce-3b088fc5b53f03605484ebef1945b8839abe19de.tar.gz
Minor improvements on IssuableActions
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/concerns/issuable_action.rb21
-rw-r--r--app/controllers/concerns/issuable_actions.rb23
-rw-r--r--app/controllers/projects/issues_controller.rb5
-rw-r--r--app/controllers/projects/merge_requests_controller.rb5
4 files changed, 29 insertions, 25 deletions
diff --git a/app/controllers/concerns/issuable_action.rb b/app/controllers/concerns/issuable_action.rb
deleted file mode 100644
index d82f2bf9ef6..00000000000
--- a/app/controllers/concerns/issuable_action.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-module IssuableAction
- extend ActiveSupport::Concern
-
- def destroy
- issuable = @merge_request || @issue
-
- unless current_user.can?(:"remove_#{issuable.to_ability_name}", issuable)
- return access_denied!
- end
-
- issuable.destroy
-
- route = polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable.class])
- issuable_name = issuable.class.name.underscore.tr('_', ' ')
-
- respond_to do |format|
- format.html { redirect_to route, notice: "This #{issuable_name} was deleted." }
- format.json { head :ok }
- end
- end
-end
diff --git a/app/controllers/concerns/issuable_actions.rb b/app/controllers/concerns/issuable_actions.rb
new file mode 100644
index 00000000000..f40b62446e5
--- /dev/null
+++ b/app/controllers/concerns/issuable_actions.rb
@@ -0,0 +1,23 @@
+module IssuableActions
+ extend ActiveSupport::Concern
+
+ included do
+ before_action :authorize_destroy_issuable!, only: :destroy
+ end
+
+ def destroy
+ issuable.destroy
+
+ name = issuable.class.name.titleize.downcase
+ flash[:notice] = "The #{name} was successfully deleted."
+ redirect_to polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable.class])
+ end
+
+ private
+
+ def authorize_destroy_issuable!
+ unless current_user.can?(:"destroy_#{issuable.to_ability_name}", issuable)
+ return access_denied!
+ end
+ end
+end
diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb
index 75d48636da8..7c5a597cb6d 100644
--- a/app/controllers/projects/issues_controller.rb
+++ b/app/controllers/projects/issues_controller.rb
@@ -1,9 +1,9 @@
class Projects::IssuesController < Projects::ApplicationController
include ToggleSubscriptionAction
- include IssuableAction
+ include IssuableActions
before_action :module_enabled
- before_action :issue, only: [:edit, :update, :show, :destroy]
+ before_action :issue, only: [:edit, :update, :show]
# Allow read any issue
before_action :authorize_read_issue!, only: [:show]
@@ -128,6 +128,7 @@ class Projects::IssuesController < Projects::ApplicationController
end
end
alias_method :subscribable_resource, :issue
+ alias_method :issuable, :issue
def authorize_read_issue!
return render_404 unless can?(current_user, :read_issue, @issue)
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index 9cc0c8f64e3..e16acab696c 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -1,11 +1,11 @@
class Projects::MergeRequestsController < Projects::ApplicationController
include ToggleSubscriptionAction
include DiffHelper
- include IssuableAction
+ include IssuableActions
before_action :module_enabled
before_action :merge_request, only: [
- :edit, :update, :show, :destroy, :diffs, :commits, :builds, :merge, :merge_check,
+ :edit, :update, :show, :diffs, :commits, :builds, :merge, :merge_check,
:ci_status, :toggle_subscription, :cancel_merge_when_build_succeeds, :remove_wip
]
before_action :closes_issues, only: [:edit, :update, :show, :diffs, :commits, :builds]
@@ -256,6 +256,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@merge_request ||= @project.merge_requests.find_by!(iid: params[:id])
end
alias_method :subscribable_resource, :merge_request
+ alias_method :issuable, :merge_request
def closes_issues
@closes_issues ||= @merge_request.closes_issues