Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
gitlab-ce
Commits
b7a9e41b
Commit
b7a9e41b
authored
Oct 24, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle perfomance issue with team import. Model specs
parent
fd0aca12
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
11 deletions
+57
-11
app/models/users_project.rb
app/models/users_project.rb
+24
-11
spec/models/users_project_spec.rb
spec/models/users_project_spec.rb
+33
-0
No files found.
app/models/users_project.rb
View file @
b7a9e41b
...
@@ -22,6 +22,7 @@ class UsersProject < ActiveRecord::Base
...
@@ -22,6 +22,7 @@ class UsersProject < ActiveRecord::Base
class
<<
self
class
<<
self
def
import_team
(
source_project
,
target_project
)
def
import_team
(
source_project
,
target_project
)
UsersProject
.
without_repository_callback
do
UsersProject
.
transaction
do
UsersProject
.
transaction
do
team
=
source_project
.
users_projects
.
all
team
=
source_project
.
users_projects
.
all
...
@@ -37,6 +38,18 @@ class UsersProject < ActiveRecord::Base
...
@@ -37,6 +38,18 @@ class UsersProject < ActiveRecord::Base
end
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
)
def
bulk_delete
(
project
,
user_ids
)
UsersProject
.
transaction
do
UsersProject
.
transaction
do
UsersProject
.
where
(
:user_id
=>
user_ids
,
:project_id
=>
project
.
id
).
each
do
|
users_project
|
UsersProject
.
where
(
:user_id
=>
user_ids
,
:project_id
=>
project
.
id
).
each
do
|
users_project
|
...
...
spec/models/users_project_spec.rb
View file @
b7a9e41b
...
@@ -35,4 +35,37 @@ describe UsersProject do
...
@@ -35,4 +35,37 @@ describe UsersProject do
it
{
should
respond_to
(
:user_name
)
}
it
{
should
respond_to
(
:user_name
)
}
it
{
should
respond_to
(
:user_email
)
}
it
{
should
respond_to
(
:user_email
)
}
end
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
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