Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
38175209
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,发现更多精彩内容 >>
提交
38175209
编写于
10月 24, 2012
作者:
V
Valery Sizov
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'feature/import_team_from_other_project' of dev.gitlabhq.com:gitlabhq
上级
a7efeb37
6f4576b7
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
131 addition
and
3 deletion
+131
-3
app/controllers/team_members_controller.rb
app/controllers/team_members_controller.rb
+8
-0
app/models/users_project.rb
app/models/users_project.rb
+29
-0
app/views/team_members/import.html.haml
app/views/team_members/import.html.haml
+17
-0
app/views/team_members/index.html.haml
app/views/team_members/index.html.haml
+7
-2
config/routes.rb
config/routes.rb
+10
-1
features/project/team_management.feature
features/project/team_management.feature
+7
-0
features/steps/project/project_team_management.rb
features/steps/project/project_team_management.rb
+20
-0
spec/models/users_project_spec.rb
spec/models/users_project_spec.rb
+33
-0
未找到文件。
app/controllers/team_members_controller.rb
浏览文件 @
38175209
...
...
@@ -43,4 +43,12 @@ class TeamMembersController < ProjectResourceController
format
.
js
{
render
nothing:
true
}
end
end
def
apply_import
giver
=
Project
.
find
(
params
[
:source_project_id
])
status
=
UsersProject
.
import_team
(
giver
,
project
)
notice
=
status
?
"Succesfully imported"
:
"Import failed"
redirect_to
project_team_members_path
(
project
),
notice:
notice
end
end
app/models/users_project.rb
浏览文件 @
38175209
...
...
@@ -21,6 +21,35 @@ class UsersProject < ActiveRecord::Base
delegate
:name
,
:email
,
to: :user
,
prefix:
true
class
<<
self
def
import_team
(
source_project
,
target_project
)
UsersProject
.
without_repository_callback
do
UsersProject
.
transaction
do
team
=
source_project
.
users_projects
.
all
team
.
each
do
|
tm
|
# Skip if user already present in team
next
if
target_project
.
users
.
include?
(
tm
.
user
)
new_tm
=
tm
.
dup
new_tm
.
id
=
nil
new_tm
.
project_id
=
target_project
.
id
new_tm
.
save
end
end
end
target_project
.
update_repository
true
rescue
false
end
def
without_repository_callback
UsersProject
.
skip_callback
(
:destroy
,
:after
,
:update_repository
)
yield
UsersProject
.
set_callback
(
:destroy
,
:after
,
:update_repository
)
end
def
bulk_delete
(
project
,
user_ids
)
UsersProject
.
transaction
do
UsersProject
.
where
(
:user_id
=>
user_ids
,
:project_id
=>
project
.
id
).
each
do
|
users_project
|
...
...
app/views/team_members/import.html.haml
0 → 100644
浏览文件 @
38175209
=
render
"projects/project_head"
%h3
.page_title
=
"Import team from another project"
%hr
%p
.slead
Read more about team import
#{
link_to
"here"
,
'#'
,
class:
'vlink'
}
.
=
form_tag
apply_import_project_team_members_path
(
@project
),
method:
'post'
do
%p
.slead
Choose project you want to use as team source:
.padded
=
label_tag
:source_project_id
,
"Project"
.input
=
select_tag
(
:source_project_id
,
options_from_collection_for_select
(
current_user
.
projects
,
:id
,
:name
),
prompt:
"Select project"
,
class:
"chosen xxlarge"
,
required:
true
)
.actions
=
submit_tag
'Import'
,
class:
"btn save-btn"
=
link_to
"Cancel"
,
project_team_index_path
(
@project
),
class:
"btn cancel-btn"
app/views/team_members/index.html.haml
浏览文件 @
38175209
...
...
@@ -5,9 +5,14 @@
-
if
can?
current_user
,
:admin_team_member
,
@project
%p
.slead
=
link_to
new_project_team_member_path
(
@project
),
class:
"btn small right"
,
title:
"New Team Member"
do
New Team Member
Read more about project permissions
%strong
=
link_to
"here"
,
help_permissions_path
,
class:
"vlink"
%span
.right
=
link_to
import_project_team_members_path
(
@project
),
class:
"btn small grouped"
,
title:
"Import team from another project"
do
Import team from another project
=
link_to
new_project_team_member_path
(
@project
),
class:
"btn success small grouped"
,
title:
"New Team Member"
do
New Team Member
.clearfix
=
render
partial:
"team_members/team"
,
locals:
{
project:
@project
}
config/routes.rb
浏览文件 @
38175209
...
...
@@ -188,7 +188,6 @@ Gitlab::Application.routes.draw do
:via
=>
[
:get
,
:post
],
constraints:
{
from:
/.+/
,
to:
/.+/
}
resources
:team
,
controller:
'team_members'
,
only:
[
:index
]
resources
:team_members
resources
:milestones
resources
:labels
,
only:
[
:index
]
resources
:issues
do
...
...
@@ -199,6 +198,16 @@ Gitlab::Application.routes.draw do
end
end
resources
:team_members
do
collection
do
# Used for import team
# from another project
get
:import
post
:apply_import
end
end
resources
:notes
,
only:
[
:index
,
:create
,
:destroy
]
do
collection
do
post
:preview
...
...
features/project/team_management.feature
浏览文件 @
38175209
...
...
@@ -32,3 +32,10 @@ Feature: Project Team management
And
I click link
"Remove from team"
Then
I visit project
"Shop"
team page
And
I should not see
"Sam"
in team list
Scenario
:
Import team from another project
Given
I own project
"Website"
And
"Mike"
is
"Website"
reporter
And
I click link
"Import team from another project"
When
I submit
"Website"
project for import team
Then
I should see
"Mike"
in team list as
"Reporter"
features/steps/project/project_team_management.rb
浏览文件 @
38175209
...
...
@@ -86,4 +86,24 @@ class ProjectTeamManagement < Spinach::FeatureSteps
project
=
Project
.
find_by_name
(
"Shop"
)
project
.
add_access
(
user
,
:write
)
end
Given
'I own project "Website"'
do
@project
=
Factory
:project
,
:name
=>
"Website"
@project
.
add_access
(
@user
,
:admin
)
end
And
'"Mike" is "Website" reporter'
do
user
=
User
.
find_by_name
(
"Mike"
)
project
=
Project
.
find_by_name
(
"Website"
)
project
.
add_access
(
user
,
:read
)
end
And
'I click link "Import team from another project"'
do
click_link
"Import team from another project"
end
When
'I submit "Website" project for import team'
do
select
'Website'
,
from:
'source_project_id'
click_button
'Import'
end
end
spec/models/users_project_spec.rb
浏览文件 @
38175209
...
...
@@ -35,4 +35,37 @@ describe UsersProject do
it
{
should
respond_to
(
:user_name
)
}
it
{
should
respond_to
(
:user_email
)
}
end
describe
:import_team
do
before
do
@abilities
=
Six
.
new
@abilities
<<
Ability
@project_1
=
create
:project
@project_2
=
create
:project
@user_1
=
create
:user
@user_2
=
create
:user
@project_1
.
add_access
@user_1
,
:write
@project_2
.
add_access
@user_2
,
:read
@status
=
UsersProject
.
import_team
(
@project_1
,
@project_2
)
end
it
{
@status
.
should
be_true
}
describe
'project 2 should get user 1 as developer. user_2 should not be changed'
do
it
{
@project_2
.
users
.
should
include
(
@user_1
)
}
it
{
@project_2
.
users
.
should
include
(
@user_2
)
}
it
{
@abilities
.
allowed?
(
@user_1
,
:write_project
,
@project_2
).
should
be_true
}
it
{
@abilities
.
allowed?
(
@user_2
,
:read_project
,
@project_2
).
should
be_true
}
end
describe
'project 1 should not be changed'
do
it
{
@project_1
.
users
.
should
include
(
@user_1
)
}
it
{
@project_1
.
users
.
should_not
include
(
@user_2
)
}
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录