summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-12-20 19:11:53 +0100
committerKamil Trzcinski <ayufan@ayufan.eu>2016-12-20 19:11:53 +0100
commit61d09a7b15ef9ae2e23359f1afb87b0adbda4dd4 (patch)
tree1cfeb2ebdd16c9972ad296416a4db48c30cc7637 /app
parent0cf23fde7c666b64e6c18a92d29e632f51b00059 (diff)
downloadgitlab-ce-61d09a7b15ef9ae2e23359f1afb87b0adbda4dd4.tar.gz
WIP
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/mattermosts_controller.rb21
-rw-r--r--app/helpers/application_helper.rb4
-rw-r--r--app/helpers/projects_helper.rb8
-rw-r--r--app/models/project_services/mattermost_slash_commands_service.rb8
4 files changed, 17 insertions, 24 deletions
diff --git a/app/controllers/projects/mattermosts_controller.rb b/app/controllers/projects/mattermosts_controller.rb
index 0f939838306..d87dff2a80e 100644
--- a/app/controllers/projects/mattermosts_controller.rb
+++ b/app/controllers/projects/mattermosts_controller.rb
@@ -12,13 +12,17 @@ class Projects::MattermostsController < Projects::ApplicationController
end
def create
- @service.configure!(current_user, configure_params)
-
- flash[:notice] = 'This service is now configured'
- redirect_to edit_namespace_project_service_path(@project.namespace, @project, service)
- rescue => e
- flash[:alert] = e.message
- redirect_to new_namespace_project_mattermost_path(@project.namespace, @project)
+ result, message = @service.configure(current_user, configure_params)
+
+ if result
+ flash[:notice] = 'This service is now configured'
+ redirect_to edit_namespace_project_service_path(
+ @project.namespace, @project, service)
+ else
+ flash[:alert] = message || 'Failed to configure service'
+ redirect_to new_namespace_project_mattermost_path(
+ @project.namespace, @project)
+ end
end
private
@@ -31,9 +35,6 @@ class Projects::MattermostsController < Projects::ApplicationController
def teams
@teams ||= @service.list_teams(current_user)
- rescue => e
- @teams = []
- flash[:alert] = e.message
end
def service
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index adb5eeee3e4..c816b616631 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -294,8 +294,4 @@ module ApplicationHelper
def page_class
"issue-boards-page" if current_controller?(:boards)
end
-
- def pretty_url(url)
- url.gsub(/\A.*?:\/\//, '')
- end
end
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index bd2dcb08b3e..d2177f683a1 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -148,14 +148,6 @@ module ProjectsHelper
).html_safe
end
- def mattermost_teams_options(teams)
- teams_options = teams.map do |id, options|
- [options['display_name'] || options['name'], id]
- end
-
- teams_options.compact.unshift(['Select team...', '0'])
- end
-
private
def repo_children_classes(field)
diff --git a/app/models/project_services/mattermost_slash_commands_service.rb b/app/models/project_services/mattermost_slash_commands_service.rb
index 572a02b01d4..4c2b7d64f1f 100644
--- a/app/models/project_services/mattermost_slash_commands_service.rb
+++ b/app/models/project_services/mattermost_slash_commands_service.rb
@@ -19,15 +19,19 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
'mattermost_slash_commands'
end
- def configure!(user, params)
+ def configure(user, params)
token = Mattermost::Command.new(user).
create(command(params))
- update!(active: true, token: token)
+ update(active: true, token: token) if token
+ rescue => Mattermost::Error => e
+ false, e.message
end
def list_teams(user)
Mattermost::Team.new(user).all
+ rescue => Mattermost::Error => e
+ []
end
private