summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2017-02-07 08:24:57 +0100
committerZ.J. van de Weg <git@zjvandeweg.nl>2017-02-16 09:19:28 +0100
commit8ddbc43576c1cebd652d6f3541574f0176794510 (patch)
tree3dfe430f289db8a461220d26f19689013471d363
parentb4244efaf1ab955e5900e87c3ec4e9465ba38bff (diff)
downloadgitlab-ce-8ddbc43576c1cebd652d6f3541574f0176794510.tar.gz
Improve DRYness of views
-rw-r--r--app/controllers/groups_controller.rb5
-rw-r--r--app/services/groups/create_service.rb4
-rw-r--r--app/services/groups/update_service.rb5
-rw-r--r--app/views/groups/_create_chat_team.html.haml18
-rw-r--r--app/views/groups/edit.html.haml20
-rw-r--r--app/views/groups/new.html.haml17
-rw-r--r--app/workers/mattermost/create_team_worker.rb9
-rw-r--r--db/migrate/20170120131253_create_chat_teams.rb4
8 files changed, 39 insertions, 43 deletions
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index 63b37fb5eb3..b2a18f0e65d 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -29,6 +29,7 @@ class GroupsController < Groups::ApplicationController
end
def create
+ byebug
@group = Groups::CreateService.new(current_user, group_params).execute
if @group.persisted?
@@ -81,6 +82,7 @@ class GroupsController < Groups::ApplicationController
end
def update
+ byebug
if Groups::UpdateService.new(@group, current_user, group_params).execute
redirect_to edit_group_path(@group), notice: "Group '#{@group.name}' was successfully updated."
else
@@ -143,7 +145,8 @@ class GroupsController < Groups::ApplicationController
:share_with_group_lock,
:visibility_level,
:parent_id
- :create_chat_team
+ :create_chat_team,
+ :chat_team_name
]
end
diff --git a/app/services/groups/create_service.rb b/app/services/groups/create_service.rb
index aabd3c4bd05..13d1b545498 100644
--- a/app/services/groups/create_service.rb
+++ b/app/services/groups/create_service.rb
@@ -6,6 +6,7 @@ module Groups
def execute
create_chat_team = params.delete(:create_chat_team)
+ team_name = params.delete(:chat_team_name)
@group = Group.new(params)
@@ -26,7 +27,8 @@ module Groups
@group.add_owner(current_user)
if create_chat_team && Gitlab.config.mattermost.enabled
- Mattermost::CreateTeamWorker.perform_async(@group.id, current_user.id)
+ options = team_name ? { name: team_name } : {}
+ Mattermost::CreateTeamWorker.perform_async(@group.id, current_user.id, options)
end
@group
diff --git a/app/services/groups/update_service.rb b/app/services/groups/update_service.rb
index 4e878ec556a..aff42ad598c 100644
--- a/app/services/groups/update_service.rb
+++ b/app/services/groups/update_service.rb
@@ -1,6 +1,11 @@
module Groups
class UpdateService < Groups::BaseService
def execute
+ if params.delete(:create_chat_team) == '1'
+ chat_name = params[:chat_team_name]
+ options = chat_name ? { name: chat_name } : {}
+ end
+
# check that user is allowed to set specified visibility_level
new_visibility = params[:visibility_level]
if new_visibility && new_visibility.to_i != group.visibility_level
diff --git a/app/views/groups/_create_chat_team.html.haml b/app/views/groups/_create_chat_team.html.haml
new file mode 100644
index 00000000000..b2b5a2090f9
--- /dev/null
+++ b/app/views/groups/_create_chat_team.html.haml
@@ -0,0 +1,18 @@
+.form-group
+ = f.label :name, class: 'control-label' do
+ %span.mattermost-icon
+ = custom_icon('icon_mattermost')
+ Mattermost
+ .col-sm-10
+ .checkbox
+ = f.label :name do
+ = f.check_box :create_chat_team, checked: true
+ Link the group to a new Mattermost team
+
+.form-group
+ = f.label :chat_team, class: 'control-label' do
+ Chat Team name
+ .col-sm-10
+ = f.text_field :chat_team, placeholder: @group.name, class: 'form-control mattermost-team-name'
+ Leave blank to match your group name
+
diff --git a/app/views/groups/edit.html.haml b/app/views/groups/edit.html.haml
index 38d498f0343..c904b25fe94 100644
--- a/app/views/groups/edit.html.haml
+++ b/app/views/groups/edit.html.haml
@@ -22,25 +22,7 @@
= render 'shared/visibility_level', f: f, visibility_level: @group.visibility_level, can_change_visibility_level: can_change_group_visibility_level?(@group), form_model: @group
- .form-group
- = f.label :name, class: 'control-label' do
- %span.mattermost-icon
- = custom_icon('icon_mattermost')
- Mattermost
- .col-sm-10
- .checkbox
- = f.label :name do
- = f.check_box :name, checked: true
- Link the group to a new or existing Mattermost team
-
-
- - enabled = Gitlab.config.mattermost.enabled
- - if enabled
- .form-group
- .col-sm-offset-2.col-sm-10
- = f.text_field :name, placeholder: "FILL WITH TEAM NAME", class: 'form-control mattermost-team-name'
- %span.mattermost-info
- Team URL: INSERT TEAM URL
+ = render 'create_chat_team', f: f if Gitlab.config.mattermost.enabled
.form-group
.col-sm-offset-2.col-sm-10
diff --git a/app/views/groups/new.html.haml b/app/views/groups/new.html.haml
index 723071c7633..000c7af2326 100644
--- a/app/views/groups/new.html.haml
+++ b/app/views/groups/new.html.haml
@@ -16,22 +16,7 @@
= render 'shared/visibility_level', f: f, visibility_level: default_group_visibility, can_change_visibility_level: true, form_model: @group
- .form-group
- = f.label :create_chat_team, class: 'control-label' do
- %span.mattermost-icon
- = custom_icon('icon_mattermost')
- Mattermost
- .col-sm-10
- .checkbox
- = f.label :chat_team do
- = f.check_box :chat_team
- Link the group to a new or existing Mattermost team
-
-- enabled = Gitlab.config.mattermost.enabled
-- if enabled
- .form-group
- .col-sm-offset-2.col-sm-10
- = f.text_field :name, placeholder: 'Mattermost team name', class: 'form-control mattermost-team-name'
+ = render 'create_chat_team', f: f if Gitlab.config.mattermost.enabled
.form-group
.col-sm-offset-2.col-sm-10
diff --git a/app/workers/mattermost/create_team_worker.rb b/app/workers/mattermost/create_team_worker.rb
index 168bdc7454d..95b63dac8ab 100644
--- a/app/workers/mattermost/create_team_worker.rb
+++ b/app/workers/mattermost/create_team_worker.rb
@@ -7,17 +7,18 @@ module Mattermost
# Add 5 seconds so the first retry isn't 1 second later
sidekiq_retry_in do |count|
- 5 + 5 ** n
+ 5 + 5**n
end
def perform(group_id, current_user_id, options = {})
- group = Group.find(group_id)
- current_user = User.find(current_user_id)
+ group = Group.find_by(id: group_id)
+ current_user = User.find_by(id: current_user_id)
+ return unless group && current_user
# The user that creates the team will be Team Admin
response = Mattermost::Team.new(current_user).create(group, options)
- ChatTeam.create(namespace: group, name: response['name'], team_id: response['id'])
+ group.create_chat_team(name: response['name'], team_id: response['id'])
end
end
end
diff --git a/db/migrate/20170120131253_create_chat_teams.rb b/db/migrate/20170120131253_create_chat_teams.rb
index 6476c239152..8f76b43960b 100644
--- a/db/migrate/20170120131253_create_chat_teams.rb
+++ b/db/migrate/20170120131253_create_chat_teams.rb
@@ -5,13 +5,13 @@ class CreateChatTeams < ActiveRecord::Migration
def change
create_table :chat_teams do |t|
- t.integer :namespace_id, index: true
+ t.integer :group_id, index: true
t.string :team_id
t.string :name
t.timestamps null: false
end
- add_foreign_key :chat_teams, :namespaces, on_delete: :cascade
+ add_foreign_key :chat_teams, :groups, on_delete: :cascade
end
end