Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GitLab EE
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Privacy
Imprint
Contact
Snippets
Groups
Projects
Show more breadcrumbs
projects.thm.de
GitLab EE
Commits
90790adc
Commit
90790adc
authored
3 years ago
by
Vasilii Iakliushin
Browse files
Options
Downloads
Patches
Plain Diff
Combine the logic in GroupsFinder
parent
6bf573a4
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/finders/groups_finder.rb
+31
-3
31 additions, 3 deletions
app/finders/groups_finder.rb
app/finders/project_groups_finder.rb
+0
-56
0 additions, 56 deletions
app/finders/project_groups_finder.rb
spec/finders/project_groups_finder_spec.rb
+2
-8
2 additions, 8 deletions
spec/finders/project_groups_finder_spec.rb
with
33 additions
and
67 deletions
app/finders/groups_finder.rb
+
31
−
3
View file @
90790adc
...
...
@@ -42,8 +42,16 @@ def execute
attr_reader
:current_user
,
:params
def
project
params
[
:project
]
end
def
authorized?
true
if
project
Ability
.
allowed?
(
current_user
,
:read_project
,
project
)
else
true
end
end
def
apply_filters_on
(
item
)
...
...
@@ -54,17 +62,37 @@ def apply_filters_on(item)
item
end
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/PerceivedComplexity
def
all_groups
return
[
owned_groups
]
if
params
[
:owned
]
return
[
groups_with_min_access_level
]
if
min_access_level?
return
[
Group
.
all
]
if
current_user
&
.
can_read_all_resources?
&&
all_available?
groups
=
[]
groups
<<
Gitlab
::
ObjectHierarchy
.
new
(
groups_for_ancestors
,
groups_for_descendants
).
all_objects
if
current_user
groups
<<
Group
.
unscoped
.
public_to_user
(
current_user
)
if
include_public_groups?
groups
<<
Gitlab
::
ObjectHierarchy
.
new
(
groups_for_ancestors
,
groups_for_descendants
).
all_objects
if
current_user
&&
!
project
groups
<<
project
.
group
.
self_and_ancestors
if
project
&
.
group
if
params
[
:with_shared
]
shared_groups
=
project
.
invited_groups
if
params
[
:shared_min_access_level
]
shared_groups
=
shared_groups
.
where
(
'project_group_links.group_access >= ?'
,
params
[
:shared_min_access_level
]
)
end
groups
<<
shared_groups
end
groups
<<
Group
.
unscoped
.
public_to_user
(
current_user
)
if
include_public_groups?
&&
!
project
groups
<<
Group
.
none
if
groups
.
empty?
groups
end
# rubocop: enable Metrics/CyclomaticComplexity
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable CodeReuse/ActiveRecord
def
groups_for_ancestors
current_user
.
authorized_groups
...
...
This diff is collapsed.
Click to expand it.
app/finders/project_groups_finder.rb
deleted
100644 → 0
+
0
−
56
View file @
6bf573a4
# frozen_string_literal: true
# ProjectGroupsFinder
#
# Used to filter ancestor and shared project's Groups by a set of params
#
# Arguments:
# project
# current_user - which user is requesting groups
# params:
# with_shared: boolean (optional)
# shared_min_access_level: integer (optional)
# skip_groups: array of integers (optional)
#
class
ProjectGroupsFinder
<
GroupsFinder
def
initialize
(
project
:,
current_user:
nil
,
params:
{})
@project
=
project
super
(
current_user
,
params
)
end
private
attr_reader
:project
def
authorized?
Ability
.
allowed?
(
current_user
,
:read_project
,
project
)
end
# rubocop: disable CodeReuse/ActiveRecord
def
all_groups
groups
=
[]
groups
<<
project
.
group
.
self_and_ancestors
if
project
.
group
if
params
[
:with_shared
]
shared_groups
=
project
.
invited_groups
if
params
[
:shared_min_access_level
]
shared_groups
=
shared_groups
.
where
(
'project_group_links.group_access >= ?'
,
params
[
:shared_min_access_level
]
)
end
groups
<<
shared_groups
end
groups
<<
Group
.
none
if
groups
.
compact
.
empty?
groups
end
# rubocop: enable CodeReuse/ActiveRecord
def
apply_filters_on
(
item
)
item
=
exclude_group_ids
(
item
)
item
end
end
This diff is collapsed.
Click to expand it.
spec/finders/project_groups_finder_spec.rb
+
2
−
8
View file @
90790adc
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
RSpec
.
describe
Project
GroupsFinder
do
RSpec
.
describe
GroupsFinder
do
include
AdminModeHelper
describe
'#execute'
do
...
...
@@ -24,7 +24,7 @@
let
(
:params
)
{
{}
}
let
(
:current_user
)
{
user
}
let
(
:finder
)
{
described_class
.
new
(
project:
project
,
current_user:
current_user
,
params:
params
)
}
let
(
:finder
)
{
described_class
.
new
(
current_user
,
params
.
merge
(
project:
project
)
)
}
subject
{
finder
.
execute
}
...
...
@@ -95,11 +95,5 @@
end
end
end
describe
'Missing project'
do
let
(
:project
)
{
nil
}
it
{
is_expected
.
to
eq
([])
}
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment