summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-14 12:25:38 +0200
committerDouwe Maan <douwe@gitlab.com>2015-04-14 12:25:38 +0200
commit1c0b58a7994f2942799c5ccdbdd37a48aa034f97 (patch)
treee7be01dad7807fa5177864c5ceb0f7814aa4ca30
parent1b5c483d89d9a20a92e98fc37879389ee2c8dd00 (diff)
downloadgitlab-ce-1c0b58a7994f2942799c5ccdbdd37a48aa034f97.tar.gz
Remove duplication from InvitesController.
-rw-r--r--app/controllers/invites_controller.rb47
1 files changed, 22 insertions, 25 deletions
diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb
index 00d274a7f1d..2a98fb0b48b 100644
--- a/app/controllers/invites_controller.rb
+++ b/app/controllers/invites_controller.rb
@@ -12,21 +12,9 @@ class InvitesController < ApplicationController
def accept
if member.accept_invite!(current_user)
- case member.source
- when Project
- project = member.source
- source = "project #{project.name_with_namespace}"
- path = namespace_project_path(project.namespace, project)
- when Group
- group = member.source
- source = "group #{group.name}"
- path = group_path(group)
- else
- source = "who knows what"
- path = dashboard_path
- end
-
- redirect_to path, notice: "You have been granted #{member.human_access} access to #{source}."
+ label, path = source_info(member.source)
+
+ redirect_to path, notice: "You have been granted #{member.human_access} access to #{label}."
else
redirect_to :back, alert: "The invitation could not be accepted."
end
@@ -34,16 +22,7 @@ class InvitesController < ApplicationController
def decline
if member.decline_invite!
- case member.source
- when Project
- project = member.source
- source = "project #{project.name_with_namespace}"
- when Group
- group = member.source
- source = "group #{group.name}"
- else
- source = "who knows what"
- end
+ label, _ = source_info(member.source)
path =
if current_user
@@ -81,4 +60,22 @@ class InvitesController < ApplicationController
store_location_for :user, request.fullpath
redirect_to new_user_session_path, notice: notice
end
+
+ def source_info(source)
+ case source
+ when Project
+ project = member.source
+ label = "project #{project.name_with_namespace}"
+ path = namespace_project_path(project.namespace, project)
+ when Group
+ group = member.source
+ label = "group #{group.name}"
+ path = group_path(group)
+ else
+ label = "who knows what"
+ path = dashboard_path
+ end
+
+ [label, path]
+ end
end