Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
52c4a786
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,发现更多精彩内容 >>
提交
52c4a786
编写于
3月 01, 2017
作者:
Z
Z.J. van de Weg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve UX
上级
f6247600
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
47 addition
and
52 deletion
+47
-52
app/controllers/groups_controller.rb
app/controllers/groups_controller.rb
+7
-1
app/models/group.rb
app/models/group.rb
+10
-0
app/services/groups/base_service.rb
app/services/groups/base_service.rb
+0
-6
app/services/groups/create_service.rb
app/services/groups/create_service.rb
+11
-1
app/services/groups/update_service.rb
app/services/groups/update_service.rb
+0
-14
app/services/mattermost/create_team_service.rb
app/services/mattermost/create_team_service.rb
+2
-3
db/migrate/20170120131253_create_chat_teams.rb
db/migrate/20170120131253_create_chat_teams.rb
+3
-1
db/schema.rb
db/schema.rb
+8
-6
lib/mattermost/team.rb
lib/mattermost/team.rb
+6
-14
spec/services/groups/create_service_spec.rb
spec/services/groups/create_service_spec.rb
+0
-6
未找到文件。
app/controllers/groups_controller.rb
浏览文件 @
52c4a786
...
...
@@ -32,7 +32,13 @@ class GroupsController < Groups::ApplicationController
@group
=
Groups
::
CreateService
.
new
(
current_user
,
group_params
).
execute
if
@group
.
persisted?
redirect_to
@group
,
notice:
"Group '
#{
@group
.
name
}
' was successfully created."
notice
=
if
@group
.
chat_team
.
present?
"Group '
#{
@group
.
name
}
' and its Mattermost team were successfully created."
else
"Group '
#{
@group
.
name
}
' was successfully created."
end
redirect_to
@group
,
notice:
notice
else
render
action:
"new"
end
...
...
app/models/group.rb
浏览文件 @
52c4a786
...
...
@@ -212,4 +212,14 @@ class Group < Namespace
def
users_with_parents
User
.
where
(
id:
members_with_parents
.
select
(
:user_id
))
end
def
mattermost_team_params
max_length
=
59
{
name:
path
[
0
..
max_length
],
display_name:
name
[
0
..
max_length
],
type:
public
?
?
'O'
:
'I'
# Open vs Invite-only
}
end
end
app/services/groups/base_service.rb
浏览文件 @
52c4a786
...
...
@@ -5,11 +5,5 @@ module Groups
def
initialize
(
group
,
user
,
params
=
{})
@group
,
@current_user
,
@params
=
group
,
user
,
params
.
dup
end
private
def
create_chat_team?
@chat_team
==
true
&&
Gitlab
.
config
.
mattermost
.
enabled
end
end
end
app/services/groups/create_service.rb
浏览文件 @
52c4a786
...
...
@@ -23,7 +23,11 @@ module Groups
@group
.
name
||=
@group
.
path
.
dup
if
create_chat_team?
Mattermost
::
CreateTeamService
.
new
(
@group
,
current_user
).
execute
begin
response
=
Mattermost
::
CreateTeamService
.
new
(
@group
,
current_user
).
execute
@group
.
build_chat_team
(
name:
response
[
'name'
],
team_id:
response
[
'id'
])
end
return
@group
if
@group
.
errors
.
any?
end
...
...
@@ -32,5 +36,11 @@ module Groups
@group
.
add_owner
(
current_user
)
@group
end
private
def
create_chat_team?
Gitlab
.
config
.
mattermost
.
enabled
&&
@chat_team
&&
group
.
chat_team
.
nil?
end
end
end
app/services/groups/update_service.rb
浏览文件 @
52c4a786
module
Groups
class
UpdateService
<
Groups
::
BaseService
def
execute
@chat_team
=
params
.
delete
(
:create_chat_team
)
# 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
...
...
@@ -16,12 +14,6 @@ module Groups
group
.
assign_attributes
(
params
)
if
create_chat_team?
Mattermost
::
CreateTeamService
.
new
(
group
,
current_user
).
execute
return
group
if
group
.
errors
.
any?
end
begin
group
.
save
rescue
Gitlab
::
UpdatePathError
=>
e
...
...
@@ -30,11 +22,5 @@ module Groups
false
end
end
private
def
create_chat_team?
super
&&
group
.
chat_team
.
nil?
end
end
end
app/services/mattermost/create_team_service.rb
浏览文件 @
52c4a786
...
...
@@ -6,10 +6,9 @@ module Mattermost
def
execute
# The user that creates the team will be Team Admin
response
=
Mattermost
::
Team
.
new
(
current_user
).
create
(
@group
)
@group
.
build_chat_team
(
name:
response
[
'name'
],
team_id:
response
[
'id'
])
Mattermost
::
Team
.
new
(
current_user
).
create
(
@group
.
mattermost_team_params
)
rescue
Mattermost
::
ClientError
=>
e
@group
.
errors
.
add
(
:
cha
t_team
,
e
.
message
)
@group
.
errors
.
add
(
:
mattermos
t_team
,
e
.
message
)
end
end
end
db/migrate/20170120131253_create_chat_teams.rb
浏览文件 @
52c4a786
...
...
@@ -4,6 +4,8 @@ class CreateChatTeams < ActiveRecord::Migration
DOWNTIME
=
true
DOWNTIME_REASON
=
"Adding a foreign key"
disable_ddl_transaction!
def
change
create_table
:chat_teams
do
|
t
|
t
.
integer
:namespace_id
,
index:
true
...
...
@@ -13,6 +15,6 @@ class CreateChatTeams < ActiveRecord::Migration
t
.
timestamps
null:
false
end
add_concurrent_foreign_key
:chat_teams
,
:namespaces
,
on_delete: :cascade
add_concurrent_foreign_key
:chat_teams
,
:namespaces
,
column: :namespace_id
end
end
db/schema.rb
浏览文件 @
52c4a786
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2017021
6141440
)
do
ActiveRecord
::
Schema
.
define
(
version:
2017021
7151947
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -61,7 +61,6 @@ ActiveRecord::Schema.define(version: 20170216141440) do
t
.
boolean
"shared_runners_enabled"
,
default:
true
,
null:
false
t
.
integer
"max_artifacts_size"
,
default:
100
,
null:
false
t
.
string
"runners_registration_token"
t
.
integer
"max_pages_size"
,
default:
100
,
null:
false
t
.
boolean
"require_two_factor_authentication"
,
default:
false
t
.
integer
"two_factor_grace_period"
,
default:
48
t
.
boolean
"metrics_enabled"
,
default:
false
...
...
@@ -110,7 +109,9 @@ ActiveRecord::Schema.define(version: 20170216141440) do
t
.
boolean
"html_emails_enabled"
,
default:
true
t
.
string
"plantuml_url"
t
.
boolean
"plantuml_enabled"
t
.
integer
"max_pages_size"
,
default:
100
,
null:
false
t
.
integer
"terminal_max_session_time"
,
default:
0
,
null:
false
t
.
string
"default_artifacts_expire_in"
,
default:
"0"
,
null:
false
end
create_table
"audit_events"
,
force: :cascade
do
|
t
|
...
...
@@ -698,7 +699,7 @@ ActiveRecord::Schema.define(version: 20170216141440) do
t
.
integer
"updated_by_id"
t
.
text
"merge_error"
t
.
text
"merge_params"
t
.
boolean
"merge_when_
build
_succeeds"
,
default:
false
,
null:
false
t
.
boolean
"merge_when_
pipeline
_succeeds"
,
default:
false
,
null:
false
t
.
integer
"merge_user_id"
t
.
string
"merge_commit_sha"
t
.
datetime
"deleted_at"
...
...
@@ -765,8 +766,8 @@ ActiveRecord::Schema.define(version: 20170216141440) do
t
.
integer
"visibility_level"
,
default:
20
,
null:
false
t
.
boolean
"request_access_enabled"
,
default:
false
,
null:
false
t
.
datetime
"deleted_at"
t
.
text
"description_html"
t
.
boolean
"lfs_enabled"
t
.
text
"description_html"
t
.
integer
"parent_id"
end
...
...
@@ -981,7 +982,7 @@ ActiveRecord::Schema.define(version: 20170216141440) do
t
.
boolean
"last_repository_check_failed"
t
.
datetime
"last_repository_check_at"
t
.
boolean
"container_registry_enabled"
t
.
boolean
"only_allow_merge_if_
build
_succeeds"
,
default:
false
,
null:
false
t
.
boolean
"only_allow_merge_if_
pipeline
_succeeds"
,
default:
false
,
null:
false
t
.
boolean
"has_external_issue_tracker"
t
.
string
"repository_storage"
,
default:
"default"
,
null:
false
t
.
boolean
"request_access_enabled"
,
default:
false
,
null:
false
...
...
@@ -1291,6 +1292,7 @@ ActiveRecord::Schema.define(version: 20170216141440) do
t
.
string
"organization"
t
.
boolean
"authorized_projects_populated"
t
.
boolean
"notified_of_own_activity"
,
default:
false
,
null:
false
t
.
boolean
"ghost"
end
add_index
"users"
,
[
"admin"
],
name:
"index_users_on_admin"
,
using: :btree
...
...
@@ -1341,7 +1343,7 @@ ActiveRecord::Schema.define(version: 20170216141440) 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
"chat_teams"
,
"namespaces"
,
name:
"fk_3b543909cb"
,
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/team.rb
浏览文件 @
52c4a786
...
...
@@ -7,20 +7,12 @@ module Mattermost
# Creates a team on the linked Mattermost instance, the team admin will be the
# `current_user` passed to the Mattermost::Client instance
def
create
(
group
)
session_post
(
'/api/v3/teams/create'
,
body:
new_team_params
(
group
).
to_json
)
end
private
MATTERMOST_TEAM_LENGTH_MAX
=
59
def
new_team_params
(
group
)
{
name:
group
.
path
[
0
..
MATTERMOST_TEAM_LENGTH_MAX
],
display_name:
group
.
name
[
0
..
MATTERMOST_TEAM_LENGTH_MAX
],
type:
group
.
public?
?
'O'
:
'I'
# Open vs Invite-only
}
def
create
(
name
:,
display_name
:,
type
:)
session_post
(
'/api/v3/teams/create'
,
body:
{
name:
name
,
display_name:
display_name
,
type:
type
}.
to_json
)
end
end
end
spec/services/groups/create_service_spec.rb
浏览文件 @
52c4a786
...
...
@@ -47,12 +47,6 @@ describe Groups::CreateService, '#execute', services: true do
Settings
.
mattermost
[
'enabled'
]
=
true
end
it
'triggers the service'
do
expect_any_instance_of
(
Mattermost
::
CreateTeamService
).
to
receive
(
:execute
)
subject
end
it
'create the chat team with the group'
do
allow_any_instance_of
(
Mattermost
::
Team
).
to
receive
(
:create
)
.
and_return
({
'name'
=>
'tanuki'
,
'id'
=>
'lskdjfwlekfjsdifjj'
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录