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
d2cd9d96
Commit
d2cd9d96
authored
Aug 18, 2016
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure last group owner isn't removed on expiry
parent
396f85e4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
13 deletions
+48
-13
app/services/members/authorized_destroy_service.rb
app/services/members/authorized_destroy_service.rb
+2
-0
spec/workers/remove_expired_members_worker_spec.rb
spec/workers/remove_expired_members_worker_spec.rb
+46
-13
No files found.
app/services/members/authorized_destroy_service.rb
View file @
d2cd9d96
...
@@ -7,6 +7,8 @@ module Members
...
@@ -7,6 +7,8 @@ module Members
end
end
def
execute
def
execute
return
false
if
member
.
is_a?
(
GroupMember
)
&&
member
.
source
.
last_owner?
(
member
.
user
)
member
.
destroy
member
.
destroy
if
member
.
request?
&&
member
.
user
!=
user
if
member
.
request?
&&
member
.
user
!=
user
...
...
spec/workers/remove_expired_members_worker_spec.rb
View file @
d2cd9d96
require
'spec_helper'
require
'spec_helper'
describe
RemoveExpiredMembersWorker
do
describe
RemoveExpiredMembersWorker
do
let!
(
:worker
)
{
RemoveExpiredMembersWorker
.
new
}
let
(
:worker
)
{
RemoveExpiredMembersWorker
.
new
}
let!
(
:expired_member
)
{
create
(
:project_member
,
expires_at:
1
.
hour
.
ago
)
}
let!
(
:member_expiring_in_future
)
{
create
(
:project_member
,
expires_at:
10
.
days
.
from_now
)
}
let!
(
:non_expiring_member
)
{
create
(
:project_member
,
expires_at:
nil
)
}
describe
'#perform'
do
describe
'#perform'
do
context
'project members'
do
let!
(
:expired_project_member
)
{
create
(
:project_member
,
expires_at:
1
.
hour
.
ago
,
access_level:
GroupMember
::
DEVELOPER
)
}
let!
(
:project_member_expiring_in_future
)
{
create
(
:project_member
,
expires_at:
10
.
days
.
from_now
,
access_level:
GroupMember
::
DEVELOPER
)
}
let!
(
:non_expiring_project_member
)
{
create
(
:project_member
,
expires_at:
nil
,
access_level:
GroupMember
::
DEVELOPER
)
}
it
'removes expired members'
do
it
'removes expired members'
do
expect
{
worker
.
perform
}.
to
change
{
Member
.
count
}.
by
(
-
1
)
expect
{
worker
.
perform
}.
to
change
{
Member
.
count
}.
by
(
-
1
)
expect
(
Member
.
find_by
(
id:
expired
_member
.
id
)).
to
be_nil
expect
(
Member
.
find_by
(
id:
expired_project
_member
.
id
)).
to
be_nil
end
end
it
'leaves members who expire in the future'
do
it
'leaves members who expire in the future'
do
worker
.
perform
worker
.
perform
expect
(
member_expiring_in_future
.
reload
).
to
be_present
expect
(
project_
member_expiring_in_future
.
reload
).
to
be_present
end
end
it
'leaves members who do not expire at all'
do
it
'leaves members who do not expire at all'
do
worker
.
perform
worker
.
perform
expect
(
non_expiring_member
.
reload
).
to
be_present
expect
(
non_expiring_project_member
.
reload
).
to
be_present
end
end
context
'group members'
do
let!
(
:expired_group_member
)
{
create
(
:group_member
,
expires_at:
1
.
hour
.
ago
,
access_level:
GroupMember
::
DEVELOPER
)
}
let!
(
:group_member_expiring_in_future
)
{
create
(
:group_member
,
expires_at:
10
.
days
.
from_now
,
access_level:
GroupMember
::
DEVELOPER
)
}
let!
(
:non_expiring_group_member
)
{
create
(
:group_member
,
expires_at:
nil
,
access_level:
GroupMember
::
DEVELOPER
)
}
it
'removes expired members'
do
expect
{
worker
.
perform
}.
to
change
{
Member
.
count
}.
by
(
-
1
)
expect
(
Member
.
find_by
(
id:
expired_group_member
.
id
)).
to
be_nil
end
it
'leaves members who expire in the future'
do
worker
.
perform
expect
(
group_member_expiring_in_future
.
reload
).
to
be_present
end
it
'leaves members who do not expire at all'
do
worker
.
perform
expect
(
non_expiring_group_member
.
reload
).
to
be_present
end
end
context
'when the last group owner expires'
do
let!
(
:expired_group_owner
)
{
create
(
:group_member
,
expires_at:
1
.
hour
.
ago
,
access_level:
GroupMember
::
OWNER
)
}
it
'does not delete the owner'
do
worker
.
perform
expect
(
expired_group_owner
.
reload
).
to
be_present
end
end
end
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