summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2017-02-03 11:29:56 +0100
committerZ.J. van de Weg <git@zjvandeweg.nl>2017-02-16 09:19:02 +0100
commit1a0e54b32d43e2a3de88c20037bd167b1f8563d6 (patch)
tree21b9a0fe8cc36425b105c5065ec951ea390a177e /app
parent297dc70158f905fef4557d1ee6510bcf459a08a9 (diff)
downloadgitlab-ce-1a0e54b32d43e2a3de88c20037bd167b1f8563d6.tar.gz
Add tests for Mattermost team creation
Diffstat (limited to 'app')
-rw-r--r--app/controllers/groups_controller.rb1
-rw-r--r--app/models/chat_team.rb5
-rw-r--r--app/services/groups/create_service.rb4
-rw-r--r--app/workers/mattermost/create_team_worker.rb25
4 files changed, 19 insertions, 16 deletions
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index 7ed54479599..63b37fb5eb3 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -143,6 +143,7 @@ class GroupsController < Groups::ApplicationController
:share_with_group_lock,
:visibility_level,
:parent_id
+ :create_chat_team
]
end
diff --git a/app/models/chat_team.rb b/app/models/chat_team.rb
new file mode 100644
index 00000000000..7952141a0d6
--- /dev/null
+++ b/app/models/chat_team.rb
@@ -0,0 +1,5 @@
+class ChatTeam < ActiveRecord::Base
+ validates :team_id, presence: true
+
+ belongs_to :namespace
+end
diff --git a/app/services/groups/create_service.rb b/app/services/groups/create_service.rb
index 209fd15f481..aabd3c4bd05 100644
--- a/app/services/groups/create_service.rb
+++ b/app/services/groups/create_service.rb
@@ -5,6 +5,8 @@ module Groups
end
def execute
+ create_chat_team = params.delete(:create_chat_team)
+
@group = Group.new(params)
unless Gitlab::VisibilityLevel.allowed_for?(current_user, params[:visibility_level])
@@ -23,7 +25,7 @@ module Groups
@group.save
@group.add_owner(current_user)
- if params[:create_chat_team] && Gitlab.config.mattermost.enabled
+ if create_chat_team && Gitlab.config.mattermost.enabled
Mattermost::CreateTeamWorker.perform_async(@group.id, current_user.id)
end
diff --git a/app/workers/mattermost/create_team_worker.rb b/app/workers/mattermost/create_team_worker.rb
index 69486569cbf..168bdc7454d 100644
--- a/app/workers/mattermost/create_team_worker.rb
+++ b/app/workers/mattermost/create_team_worker.rb
@@ -3,26 +3,21 @@ module Mattermost
include Sidekiq::Worker
include DedicatedSidekiqQueue
+ sidekiq_options retry: 5
+
+ # Add 5 seconds so the first retry isn't 1 second later
+ sidekiq_retry_in do |count|
+ 5 + 5 ** n
+ end
+
def perform(group_id, current_user_id, options = {})
- @group = Group.find(group_id)
+ group = Group.find(group_id)
current_user = User.find(current_user_id)
- options = team_params.merge(options)
-
# The user that creates the team will be Team Admin
- response = Mattermost::Team.new(current_user).create(options)
-
- ChatTeam.create!(namespace: @group, name: response['name'], team_id: response['id'])
- end
-
- private
+ response = Mattermost::Team.new(current_user).create(group, options)
- def team_params
- {
- name: @group.path[0..59],
- display_name: @group.name[0..59],
- type: @group.public? ? 'O' : 'I' # Open vs Invite-only
- }
+ ChatTeam.create(namespace: group, name: response['name'], team_id: response['id'])
end
end
end