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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
014aca53
Commit
014aca53
authored
Apr 17, 2017
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unassign all Issues and Merge Requests when member leaves team
parent
c3bb21ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
1 deletion
+68
-1
app/services/members/authorized_destroy_service.rb
app/services/members/authorized_destroy_service.rb
+22
-1
spec/services/members/authorized_destroy_service_spec.rb
spec/services/members/authorized_destroy_service_spec.rb
+46
-0
No files found.
app/services/members/authorized_destroy_service.rb
View file @
014aca53
...
@@ -9,7 +9,11 @@ module Members
...
@@ -9,7 +9,11 @@ module Members
def
execute
def
execute
return
false
if
member
.
is_a?
(
GroupMember
)
&&
member
.
source
.
last_owner?
(
member
.
user
)
return
false
if
member
.
is_a?
(
GroupMember
)
&&
member
.
source
.
last_owner?
(
member
.
user
)
member
.
destroy
Member
.
transaction
do
unassign_issues_and_merge_requests
(
member
)
member
.
destroy
end
if
member
.
request?
&&
member
.
user
!=
user
if
member
.
request?
&&
member
.
user
!=
user
notification_service
.
decline_access_request
(
member
)
notification_service
.
decline_access_request
(
member
)
...
@@ -17,5 +21,22 @@ module Members
...
@@ -17,5 +21,22 @@ module Members
member
member
end
end
private
def
unassign_issues_and_merge_requests
(
member
)
if
member
.
is_a?
(
GroupMember
)
IssuesFinder
.
new
(
user
,
group_id:
member
.
source_id
,
assignee_id:
member
.
user_id
).
execute
.
update_all
(
assignee_id:
nil
)
MergeRequestsFinder
.
new
(
user
,
group_id:
member
.
source_id
,
assignee_id:
member
.
user_id
).
execute
.
update_all
(
assignee_id:
nil
)
else
project
=
member
.
source
project
.
issues
.
opened
.
assigned_to
(
member
.
user
).
update_all
(
assignee_id:
nil
)
project
.
merge_requests
.
opened
.
assigned_to
(
member
.
user
).
update_all
(
assignee_id:
nil
)
end
end
end
end
end
end
spec/services/members/authorized_destroy_service_spec.rb
0 → 100644
View file @
014aca53
require
'spec_helper'
describe
Members
::
AuthorizedDestroyService
,
services:
true
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:member_user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
)
}
let
(
:group
)
{
create
(
:group
,
:public
)
}
let
(
:group_project
)
{
create
(
:empty_project
,
:public
,
group:
group
)
}
def
number_of_assigned_issuables
(
user
)
user
.
assigned_issues
.
count
+
user
.
assigned_merge_requests
.
count
end
context
'Group member'
do
it
"unassigns issues and merge requests"
do
group
.
add_developer
(
member_user
)
issue
=
create
:issue
,
project:
group_project
,
assignee:
member_user
create
:issue
,
assignee:
member_user
merge_request
=
create
:merge_request
,
target_project:
group_project
,
source_project:
group_project
,
assignee:
member_user
create
:merge_request
,
target_project:
project
,
source_project:
project
,
assignee:
member_user
member
=
group
.
members
.
find_by
(
user_id:
member_user
.
id
)
expect
{
described_class
.
new
(
member
,
member_user
).
execute
}
.
to
change
{
number_of_assigned_issuables
(
member_user
)
}.
from
(
4
).
to
(
2
)
expect
(
issue
.
reload
.
assignee_id
).
to
be_nil
expect
(
merge_request
.
reload
.
assignee_id
).
to
be_nil
end
end
context
'Project member'
do
it
"unassigns issues and merge requests"
do
project
.
team
<<
[
member_user
,
:developer
]
create
:issue
,
project:
project
,
assignee:
member_user
create
:merge_request
,
target_project:
project
,
source_project:
project
,
assignee:
member_user
member
=
project
.
members
.
find_by
(
user_id:
member_user
.
id
)
expect
{
described_class
.
new
(
member
,
member_user
).
execute
}
.
to
change
{
number_of_assigned_issuables
(
member_user
)
}.
from
(
2
).
to
(
0
)
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