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
Léo-Paul Géneau
gitlab-ce
Commits
c8b13119
Commit
c8b13119
authored
Sep 09, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix a few things after the initial improvment to Members::DestroyService
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
3158f57d
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
30 additions
and
15 deletions
+30
-15
app/controllers/concerns/membership_actions.rb
app/controllers/concerns/membership_actions.rb
+4
-3
app/controllers/groups/group_members_controller.rb
app/controllers/groups/group_members_controller.rb
+1
-1
app/controllers/projects/project_members_controller.rb
app/controllers/projects/project_members_controller.rb
+2
-1
app/services/members/authorized_destroy_service.rb
app/services/members/authorized_destroy_service.rb
+2
-0
app/services/members/destroy_service.rb
app/services/members/destroy_service.rb
+6
-5
lib/api/access_requests.rb
lib/api/access_requests.rb
+2
-1
spec/controllers/groups/group_members_controller_spec.rb
spec/controllers/groups/group_members_controller_spec.rb
+2
-2
spec/controllers/projects/project_members_controller_spec.rb
spec/controllers/projects/project_members_controller_spec.rb
+2
-2
spec/services/members/destroy_service_spec.rb
spec/services/members/destroy_service_spec.rb
+9
-0
No files found.
app/controllers/concerns/membership_actions.rb
View file @
c8b13119
...
...
@@ -15,16 +15,17 @@ module MembershipActions
end
def
leave
Members
::
DestroyService
.
new
(
membershipable
,
current_user
,
user_id:
current_user
.
id
).
execute
(
:all
)
member
=
Members
::
DestroyService
.
new
(
membershipable
,
current_user
,
user_id:
current_user
.
id
).
execute
(
:all
)
source_type
=
membershipable
.
class
.
to_s
.
humanize
(
capitalize:
false
)
notice
=
if
@
member
.
request?
if
member
.
request?
"Your access request to the
#{
source_type
}
has been withdrawn."
else
"You left the
\"
#{
membershipable
.
human_name
}
\"
#{
source_type
}
."
end
redirect_path
=
@member
.
request?
?
@
member
.
source
:
[
:dashboard
,
membershipable
.
class
.
to_s
.
tableize
]
redirect_path
=
member
.
request?
?
member
.
source
:
[
:dashboard
,
membershipable
.
class
.
to_s
.
tableize
]
redirect_to
redirect_path
,
notice:
notice
end
...
...
app/controllers/groups/group_members_controller.rb
View file @
c8b13119
...
...
@@ -40,7 +40,7 @@ class Groups::GroupMembersController < Groups::ApplicationController
end
def
destroy
Members
::
DestroyService
.
new
(
@group
,
current_user
,
user_
id:
params
[
:id
]).
execute
(
:all
)
Members
::
DestroyService
.
new
(
@group
,
current_user
,
id:
params
[
:id
]).
execute
(
:all
)
respond_to
do
|
format
|
format
.
html
{
redirect_to
group_group_members_path
(
@group
),
notice:
'User was successfully removed from group.'
}
...
...
app/controllers/projects/project_members_controller.rb
View file @
c8b13119
...
...
@@ -55,7 +55,8 @@ class Projects::ProjectMembersController < Projects::ApplicationController
end
def
destroy
Members
::
DestroyService
.
new
(
@project
,
current_user
,
user_id:
params
[
:id
]).
execute
(
:all
)
Members
::
DestroyService
.
new
(
@project
,
current_user
,
params
).
execute
(
:all
)
respond_to
do
|
format
|
format
.
html
do
...
...
app/services/members/authorized_destroy_service.rb
View file @
c8b13119
...
...
@@ -14,6 +14,8 @@ module Members
if
member
.
request?
&&
member
.
user
!=
user
notification_service
.
decline_access_request
(
member
)
end
member
end
end
end
app/services/members/destroy_service.rb
View file @
c8b13119
...
...
@@ -15,7 +15,7 @@ module Members
def
execute
(
scope
=
:members
)
raise
"scope :
#{
scope
}
is not allowed!"
unless
ALLOWED_SCOPES
.
include?
(
scope
)
member
=
find_member
(
scope
)
member
=
find_member
!
(
scope
)
raise
Gitlab
::
Access
::
AccessDeniedError
if
cannot_destroy_member?
(
member
)
...
...
@@ -24,13 +24,14 @@ module Members
private
def
find_member
(
scope
)
def
find_member!
(
scope
)
condition
=
params
[
:user_id
]
?
{
user_id:
params
[
:user_id
]
}
:
{
id:
params
[
:id
]
}
case
scope
when
:all
source
.
members
.
find_by
(
user_id:
params
[
:user_id
]
)
||
source
.
requesters
.
find_by!
(
user_id:
params
[
:user_id
]
)
source
.
members
.
find_by
(
condition
)
||
source
.
requesters
.
find_by!
(
condition
)
else
source
.
public_send
(
scope
).
find_by!
(
user_id:
params
[
:user_id
]
)
source
.
public_send
(
scope
).
find_by!
(
condition
)
end
end
...
...
lib/api/access_requests.rb
View file @
c8b13119
...
...
@@ -75,7 +75,8 @@ module API
required_attributes!
[
:user_id
]
source
=
find_source
(
source_type
,
params
[
:id
])
::
Members
::
DestroyService
.
new
(
source
,
current_user
,
declared
(
params
)).
execute
(
:requesters
)
::
Members
::
DestroyService
.
new
(
source
,
current_user
,
params
).
execute
(
:requesters
)
end
end
end
...
...
spec/controllers/groups/group_members_controller_spec.rb
View file @
c8b13119
...
...
@@ -87,10 +87,10 @@ describe Groups::GroupMembersController do
context
'when member is not found'
do
before
{
sign_in
(
user
)
}
it
'returns 40
3
'
do
it
'returns 40
4
'
do
delete
:leave
,
group_id:
group
expect
(
response
).
to
have_http_status
(
40
3
)
expect
(
response
).
to
have_http_status
(
40
4
)
end
end
...
...
spec/controllers/projects/project_members_controller_spec.rb
View file @
c8b13119
...
...
@@ -135,11 +135,11 @@ describe Projects::ProjectMembersController do
context
'when member is not found'
do
before
{
sign_in
(
user
)
}
it
'returns 40
3
'
do
it
'returns 40
4
'
do
delete
:leave
,
namespace_id:
project
.
namespace
,
project_id:
project
expect
(
response
).
to
have_http_status
(
40
3
)
expect
(
response
).
to
have_http_status
(
40
4
)
end
end
...
...
spec/services/members/destroy_service_spec.rb
View file @
c8b13119
...
...
@@ -98,6 +98,15 @@ describe Members::DestroyService, services: true do
it_behaves_like
'a service destroying a member'
do
let
(
:source
)
{
group
}
end
context
'when given a :id'
do
let
(
:params
)
{
{
id:
project
.
members
.
find_by!
(
user_id:
user
.
id
).
id
}
}
it
'destroys the member'
do
expect
{
described_class
.
new
(
project
,
user
,
params
).
execute
}.
to
change
{
project
.
members
.
count
}.
by
(
-
1
)
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