Commit 850a2254 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'zj-delete-mm-team' into 'master'

Remove Mattermost team with GitLab group

Closes #30023

See merge request !11362
parents 3109623d d7062dd0
...@@ -3,4 +3,13 @@ class ChatTeam < ActiveRecord::Base ...@@ -3,4 +3,13 @@ class ChatTeam < ActiveRecord::Base
validates :namespace, uniqueness: true validates :namespace, uniqueness: true
belongs_to :namespace belongs_to :namespace
def remove_mattermost_team(current_user)
Mattermost::Team.new(current_user).destroy(team_id: team_id)
rescue Mattermost::ClientError => e
# Either the group is not found, or the user doesn't have the proper
# access on the mattermost instance. In the first case, we're done either way
# in the latter case, we can't recover by retrying, so we just log what happened
Rails.logger.error("Mattermost team deletion failed: #{e}")
end
end end
...@@ -21,6 +21,8 @@ module Groups ...@@ -21,6 +21,8 @@ module Groups
DestroyService.new(group, current_user).execute DestroyService.new(group, current_user).execute
end end
group.chat_team&.remove_mattermost_team(current_user)
group.really_destroy! group.really_destroy!
end end
end end
......
---
title: Remove Mattermost team when deleting a group
merge_request: 11362
author:
...@@ -24,6 +24,10 @@ module Mattermost ...@@ -24,6 +24,10 @@ module Mattermost
json_response session.post(path, options) json_response session.post(path, options)
end end
def delete(session, path, options)
json_response session.delete(path, options)
end
def session_get(path, options = {}) def session_get(path, options = {})
with_session do |session| with_session do |session|
get(session, path, options) get(session, path, options)
...@@ -36,6 +40,12 @@ module Mattermost ...@@ -36,6 +40,12 @@ module Mattermost
end end
end end
def session_delete(path, options = {})
with_session do |session|
delete(session, path, options)
end
end
def json_response(response) def json_response(response)
json_response = JSON.parse(response.body) json_response = JSON.parse(response.body)
......
...@@ -14,5 +14,12 @@ module Mattermost ...@@ -14,5 +14,12 @@ module Mattermost
type: type type: type
}.to_json) }.to_json)
end end
# The deletion is done async, so the response is fast.
# On the mattermost side, this triggers an soft deletion first, after which
# the actuall data is removed
def destroy(team_id:)
session_delete("/api/v4/teams/#{team_id}?permanent=true")
end
end end
end end
...@@ -35,6 +35,16 @@ describe Groups::DestroyService do ...@@ -35,6 +35,16 @@ describe Groups::DestroyService do
it { expect(NotificationSetting.unscoped.all).not_to include(notification_setting) } it { expect(NotificationSetting.unscoped.all).not_to include(notification_setting) }
end end
context 'mattermost team' do
let!(:chat_team) { create(:chat_team, namespace: group) }
it 'destroys the team too' do
expect_any_instance_of(Mattermost::Team).to receive(:destroy)
destroy_group(group, user, async)
end
end
context 'file system' do context 'file system' do
context 'Sidekiq inline' do context 'Sidekiq inline' do
before do before do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment