BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
297dc701
Commit
297dc701
authored
Feb 02, 2017
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create MM team for GitLab group
parent
e90ec73f
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
105 additions
and
1 deletion
+105
-1
group.rb
app/models/group.rb
+1
-0
create_service.rb
app/services/groups/create_service.rb
+5
-0
new.html.haml
app/views/groups/new.html.haml
+5
-0
create_team_worker.rb
app/workers/mattermost/create_team_worker.rb
+28
-0
20170120131253_create_chat_teams.rb
db/migrate/20170120131253_create_chat_teams.rb
+17
-0
schema.rb
db/schema.rb
+11
-0
session.rb
lib/mattermost/session.rb
+1
-1
team.rb
lib/mattermost/team.rb
+5
-0
chat_team_spec.rb
spec/models/chat_team_spec.rb
+10
-0
group_spec.rb
spec/models/group_spec.rb
+1
-0
create_team_worker_spec.rb
spec/workers/mattermost/create_team_worker_spec.rb
+21
-0
No files found.
app/models/group.rb
View file @
297dc701
...
@@ -21,6 +21,7 @@ class Group < Namespace
...
@@ -21,6 +21,7 @@ class Group < Namespace
has_many
:shared_projects
,
through: :project_group_links
,
source: :project
has_many
:shared_projects
,
through: :project_group_links
,
source: :project
has_many
:notification_settings
,
dependent: :destroy
,
as: :source
has_many
:notification_settings
,
dependent: :destroy
,
as: :source
has_many
:labels
,
class_name:
'GroupLabel'
has_many
:labels
,
class_name:
'GroupLabel'
has_one
:chat_team
,
dependent: :destroy
validate
:avatar_type
,
if:
->
(
user
)
{
user
.
avatar
.
present?
&&
user
.
avatar_changed?
}
validate
:avatar_type
,
if:
->
(
user
)
{
user
.
avatar
.
present?
&&
user
.
avatar_changed?
}
validate
:visibility_level_allowed_by_projects
validate
:visibility_level_allowed_by_projects
...
...
app/services/groups/create_service.rb
View file @
297dc701
...
@@ -22,6 +22,11 @@ module Groups
...
@@ -22,6 +22,11 @@ module Groups
@group
.
name
||=
@group
.
path
.
dup
@group
.
name
||=
@group
.
path
.
dup
@group
.
save
@group
.
save
@group
.
add_owner
(
current_user
)
@group
.
add_owner
(
current_user
)
if
params
[
:create_chat_team
]
&&
Gitlab
.
config
.
mattermost
.
enabled
Mattermost
::
CreateTeamWorker
.
perform_async
(
@group
.
id
,
current_user
.
id
)
end
@group
@group
end
end
end
end
...
...
app/views/groups/new.html.haml
View file @
297dc701
...
@@ -17,6 +17,11 @@
...
@@ -17,6 +17,11 @@
=
render
'shared/visibility_level'
,
f:
f
,
visibility_level:
default_group_visibility
,
can_change_visibility_level:
true
,
form_model:
@group
=
render
'shared/visibility_level'
,
f:
f
,
visibility_level:
default_group_visibility
,
can_change_visibility_level:
true
,
form_model:
@group
.form-group
.form-group
=
f
.
label
:create_chat_team
,
"Create Mattermost Team"
,
class:
'control-label'
.col-sm-10
=
f
.
check_box
:chat_team
.form-group
.col-sm-offset-2.col-sm-10
.col-sm-offset-2.col-sm-10
=
render
'shared/group_tips'
=
render
'shared/group_tips'
...
...
app/workers/mattermost/create_team_worker.rb
0 → 100644
View file @
297dc701
module
Mattermost
class
CreateTeamWorker
include
Sidekiq
::
Worker
include
DedicatedSidekiqQueue
def
perform
(
group_id
,
current_user_id
,
options
=
{})
@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
def
team_params
{
name:
@group
.
path
[
0
..
59
],
display_name:
@group
.
name
[
0
..
59
],
type:
@group
.
public?
?
'O'
:
'I'
# Open vs Invite-only
}
end
end
end
db/migrate/20170120131253_create_chat_teams.rb
0 → 100644
View file @
297dc701
class
CreateChatTeams
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
create_table
:chat_teams
do
|
t
|
t
.
integer
:namespace_id
,
index:
true
t
.
string
:team_id
t
.
string
:name
t
.
timestamps
null:
false
end
add_foreign_key
:chat_teams
,
:namespaces
,
on_delete: :cascade
end
end
db/schema.rb
View file @
297dc701
...
@@ -171,6 +171,16 @@ ActiveRecord::Schema.define(version: 20170214111112) do
...
@@ -171,6 +171,16 @@ ActiveRecord::Schema.define(version: 20170214111112) do
add_index
"chat_names"
,
[
"service_id"
,
"team_id"
,
"chat_id"
],
name:
"index_chat_names_on_service_id_and_team_id_and_chat_id"
,
unique:
true
,
using: :btree
add_index
"chat_names"
,
[
"service_id"
,
"team_id"
,
"chat_id"
],
name:
"index_chat_names_on_service_id_and_team_id_and_chat_id"
,
unique:
true
,
using: :btree
add_index
"chat_names"
,
[
"user_id"
,
"service_id"
],
name:
"index_chat_names_on_user_id_and_service_id"
,
unique:
true
,
using: :btree
add_index
"chat_names"
,
[
"user_id"
,
"service_id"
],
name:
"index_chat_names_on_user_id_and_service_id"
,
unique:
true
,
using: :btree
create_table
"chat_teams"
,
force: :cascade
do
|
t
|
t
.
integer
"namespace_id"
t
.
string
"team_id"
t
.
string
"name"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
end
add_index
"chat_teams"
,
[
"namespace_id"
],
name:
"index_chat_teams_on_namespace_id"
,
using: :btree
create_table
"ci_application_settings"
,
force: :cascade
do
|
t
|
create_table
"ci_application_settings"
,
force: :cascade
do
|
t
|
t
.
boolean
"all_broken_builds"
t
.
boolean
"all_broken_builds"
t
.
boolean
"add_pusher"
t
.
boolean
"add_pusher"
...
@@ -1330,6 +1340,7 @@ ActiveRecord::Schema.define(version: 20170214111112) do
...
@@ -1330,6 +1340,7 @@ ActiveRecord::Schema.define(version: 20170214111112) do
add_index
"web_hooks"
,
[
"project_id"
],
name:
"index_web_hooks_on_project_id"
,
using: :btree
add_index
"web_hooks"
,
[
"project_id"
],
name:
"index_web_hooks_on_project_id"
,
using: :btree
add_foreign_key
"boards"
,
"projects"
add_foreign_key
"boards"
,
"projects"
add_foreign_key
"chat_teams"
,
"namespaces"
,
on_delete: :cascade
add_foreign_key
"issue_metrics"
,
"issues"
,
on_delete: :cascade
add_foreign_key
"issue_metrics"
,
"issues"
,
on_delete: :cascade
add_foreign_key
"label_priorities"
,
"labels"
,
on_delete: :cascade
add_foreign_key
"label_priorities"
,
"labels"
,
on_delete: :cascade
add_foreign_key
"label_priorities"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"label_priorities"
,
"projects"
,
on_delete: :cascade
...
...
lib/mattermost/session.rb
View file @
297dc701
...
@@ -153,7 +153,7 @@ module Mattermost
...
@@ -153,7 +153,7 @@ module Mattermost
yield
yield
rescue
HTTParty
::
Error
=>
e
rescue
HTTParty
::
Error
=>
e
raise
Mattermost
::
ConnectionError
.
new
(
e
.
message
)
raise
Mattermost
::
ConnectionError
.
new
(
e
.
message
)
rescue
Errno
::
ECONNREFUSED
rescue
Errno
::
ECONNREFUSED
=>
e
raise
Mattermost
::
ConnectionError
.
new
(
e
.
message
)
raise
Mattermost
::
ConnectionError
.
new
(
e
.
message
)
end
end
end
end
...
...
lib/mattermost/team.rb
View file @
297dc701
module
Mattermost
module
Mattermost
class
Team
<
Client
class
Team
<
Client
# Returns **all** teams for an admin
def
all
def
all
session_get
(
'/api/v3/teams/all'
)
session_get
(
'/api/v3/teams/all'
)
end
end
def
create
(
params
)
session_post
(
'/api/v3/teams/create'
,
body:
params
.
to_json
)
end
end
end
end
end
spec/models/chat_team_spec.rb
0 → 100644
View file @
297dc701
require
'spec_helper'
describe
ChatTeam
,
type: :model
do
# Associations
it
{
is_expected
.
to
belong_to
(
:group
)
}
# Fields
it
{
is_expected
.
to
respond_to
(
:name
)
}
it
{
is_expected
.
to
respond_to
(
:team_id
)
}
end
spec/models/group_spec.rb
View file @
297dc701
...
@@ -13,6 +13,7 @@ describe Group, models: true do
...
@@ -13,6 +13,7 @@ describe Group, models: true do
it
{
is_expected
.
to
have_many
(
:shared_projects
).
through
(
:project_group_links
)
}
it
{
is_expected
.
to
have_many
(
:shared_projects
).
through
(
:project_group_links
)
}
it
{
is_expected
.
to
have_many
(
:notification_settings
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:notification_settings
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:labels
).
class_name
(
'GroupLabel'
)
}
it
{
is_expected
.
to
have_many
(
:labels
).
class_name
(
'GroupLabel'
)
}
it
{
is_expected
.
to
have_one
(
:chat_team
)
}
describe
'#members & #requesters'
do
describe
'#members & #requesters'
do
let
(
:requester
)
{
create
(
:user
)
}
let
(
:requester
)
{
create
(
:user
)
}
...
...
spec/workers/mattermost/create_team_worker_spec.rb
0 → 100644
View file @
297dc701
require
'spec_helper'
describe
Mattermost
::
CreateTeamWorker
do
let
(
:group
)
{
create
(
:group
,
path:
'path'
,
name:
'name'
)
}
let
(
:admin
)
{
create
(
:admin
)
}
describe
'.perform'
do
subject
{
described_class
.
new
.
perform
(
group
.
id
,
admin
.
id
)
}
before
do
allow_any_instance_of
(
Mattermost
::
Team
).
to
receive
(
:create
).
with
(
name:
"path"
,
display_name:
"name"
,
type:
"O"
).
and_return
(
'name'
=>
'my team'
,
'id'
=>
'sjfkdlwkdjfwlkfjwf'
)
end
it
'creates a new chat team'
do
expect
{
subject
}.
to
change
{
ChatTeam
.
count
}.
from
(
0
).
to
(
1
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment