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
eb9b599e
Commit
eb9b599e
authored
Mar 29, 2022
by
Manoj M J
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Project Member policy
parent
d80842a5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
5 deletions
+8
-5
app/policies/project_member_policy.rb
app/policies/project_member_policy.rb
+5
-2
spec/policies/project_member_policy_spec.rb
spec/policies/project_member_policy_spec.rb
+3
-3
No files found.
app/policies/project_member_policy.rb
View file @
eb9b599e
...
@@ -3,13 +3,16 @@
...
@@ -3,13 +3,16 @@
class
ProjectMemberPolicy
<
BasePolicy
class
ProjectMemberPolicy
<
BasePolicy
delegate
{
@subject
.
project
}
delegate
{
@subject
.
project
}
condition
(
:target_is_owner
,
scope: :subject
)
{
@subject
.
user
==
@subject
.
project
.
owner
}
condition
(
:target_is_holder_of_the_personal_namespace
,
scope: :subject
)
do
@subject
.
project
.
personal_namespace_holder?
(
@subject
.
user
)
end
condition
(
:target_is_self
)
{
@user
&&
@subject
.
user
==
@user
}
condition
(
:target_is_self
)
{
@user
&&
@subject
.
user
==
@user
}
condition
(
:project_bot
)
{
@subject
.
user
&
.
project_bot?
}
condition
(
:project_bot
)
{
@subject
.
user
&
.
project_bot?
}
rule
{
anonymous
}.
prevent_all
rule
{
anonymous
}.
prevent_all
rule
{
target_is_
owner
}.
policy
do
rule
{
target_is_
holder_of_the_personal_namespace
}.
policy
do
prevent
:update_project_member
prevent
:update_project_member
prevent
:destroy_project_member
prevent
:destroy_project_member
end
end
...
...
spec/policies/project_member_policy_spec.rb
View file @
eb9b599e
...
@@ -23,9 +23,9 @@ RSpec.describe ProjectMemberPolicy do
...
@@ -23,9 +23,9 @@ RSpec.describe ProjectMemberPolicy do
it
{
is_expected
.
not_to
be_allowed
(
:destroy_project_bot_member
)
}
it
{
is_expected
.
not_to
be_allowed
(
:destroy_project_bot_member
)
}
end
end
context
'when user is
project owner
'
do
context
'when user is
the holder of personal namespace in which the project resides
'
do
let
(
:
member_user
)
{
project
.
first_
owner
}
let
(
:
namespace_holder
)
{
project
.
namespace
.
owner
}
let
(
:member
)
{
project
.
members
.
find_by!
(
user:
member_us
er
)
}
let
(
:member
)
{
project
.
members
.
find_by!
(
user:
namespace_hold
er
)
}
it
{
is_expected
.
to
be_allowed
(
:read_project
)
}
it
{
is_expected
.
to
be_allowed
(
:read_project
)
}
it
{
is_expected
.
to
be_disallowed
(
:update_project_member
)
}
it
{
is_expected
.
to
be_disallowed
(
:update_project_member
)
}
...
...
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