Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ae1aee24
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ae1aee24
编写于
2月 02, 2017
作者:
Z
Z.J. van de Weg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Create MM team for GitLab group
上级
40a82435
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
105 addition
and
1 deletion
+105
-1
app/models/group.rb
app/models/group.rb
+1
-0
app/services/groups/create_service.rb
app/services/groups/create_service.rb
+5
-0
app/views/groups/new.html.haml
app/views/groups/new.html.haml
+5
-0
app/workers/mattermost/create_team_worker.rb
app/workers/mattermost/create_team_worker.rb
+28
-0
db/migrate/20170120131253_create_chat_teams.rb
db/migrate/20170120131253_create_chat_teams.rb
+17
-0
db/schema.rb
db/schema.rb
+11
-0
lib/mattermost/session.rb
lib/mattermost/session.rb
+1
-1
lib/mattermost/team.rb
lib/mattermost/team.rb
+5
-0
spec/models/chat_team_spec.rb
spec/models/chat_team_spec.rb
+10
-0
spec/models/group_spec.rb
spec/models/group_spec.rb
+1
-0
spec/workers/mattermost/create_team_worker_spec.rb
spec/workers/mattermost/create_team_worker_spec.rb
+21
-0
未找到文件。
app/models/group.rb
浏览文件 @
ae1aee24
...
...
@@ -21,6 +21,7 @@ class Group < Namespace
has_many
:shared_projects
,
through: :project_group_links
,
source: :project
has_many
:notification_settings
,
dependent: :destroy
,
as: :source
has_many
:labels
,
class_name:
'GroupLabel'
has_one
:chat_team
,
dependent: :destroy
validate
:avatar_type
,
if:
->
(
user
)
{
user
.
avatar
.
present?
&&
user
.
avatar_changed?
}
validate
:visibility_level_allowed_by_projects
...
...
app/services/groups/create_service.rb
浏览文件 @
ae1aee24
...
...
@@ -22,6 +22,11 @@ module Groups
@group
.
name
||=
@group
.
path
.
dup
@group
.
save
@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
end
end
...
...
app/views/groups/new.html.haml
浏览文件 @
ae1aee24
...
...
@@ -16,6 +16,11 @@
=
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
,
"Create Mattermost Team"
,
class:
'control-label'
.col-sm-10
=
f
.
check_box
:chat_team
.form-group
.col-sm-offset-2.col-sm-10
=
render
'shared/group_tips'
...
...
app/workers/mattermost/create_team_worker.rb
0 → 100644
浏览文件 @
ae1aee24
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
浏览文件 @
ae1aee24
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
浏览文件 @
ae1aee24
...
...
@@ -169,6 +169,16 @@ ActiveRecord::Schema.define(version: 20170130204620) 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"
,
[
"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
|
t
.
boolean
"all_broken_builds"
t
.
boolean
"add_pusher"
...
...
@@ -1307,6 +1317,7 @@ ActiveRecord::Schema.define(version: 20170130204620) do
add_index
"web_hooks"
,
[
"project_id"
],
name:
"index_web_hooks_on_project_id"
,
using: :btree
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
"label_priorities"
,
"labels"
,
on_delete: :cascade
add_foreign_key
"label_priorities"
,
"projects"
,
on_delete: :cascade
...
...
lib/mattermost/session.rb
浏览文件 @
ae1aee24
...
...
@@ -153,7 +153,7 @@ module Mattermost
yield
rescue
HTTParty
::
Error
=>
e
raise
Mattermost
::
ConnectionError
.
new
(
e
.
message
)
rescue
Errno
::
ECONNREFUSED
rescue
Errno
::
ECONNREFUSED
=>
e
raise
Mattermost
::
ConnectionError
.
new
(
e
.
message
)
end
end
...
...
lib/mattermost/team.rb
浏览文件 @
ae1aee24
module
Mattermost
class
Team
<
Client
# Returns **all** teams for an admin
def
all
session_get
(
'/api/v3/teams/all'
)
end
def
create
(
params
)
session_post
(
'/api/v3/teams/create'
,
body:
params
.
to_json
)
end
end
end
spec/models/chat_team_spec.rb
0 → 100644
浏览文件 @
ae1aee24
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
浏览文件 @
ae1aee24
...
...
@@ -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
(
:notification_settings
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:labels
).
class_name
(
'GroupLabel'
)
}
it
{
is_expected
.
to
have_one
(
:chat_team
)
}
describe
'#members & #requesters'
do
let
(
:requester
)
{
create
(
:user
)
}
...
...
spec/workers/mattermost/create_team_worker_spec.rb
0 → 100644
浏览文件 @
ae1aee24
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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录