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
Boxiang Sun
gitlab-ce
Commits
c2dd4239
Commit
c2dd4239
authored
Aug 01, 2017
by
http://jneen.net/
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
short-circuit if there is no policy, and add :read_project check
parent
488e8e79
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
12 deletions
+16
-12
app/models/notification_recipient.rb
app/models/notification_recipient.rb
+6
-3
app/services/notification_recipient_service.rb
app/services/notification_recipient_service.rb
+1
-5
lib/declarative_policy.rb
lib/declarative_policy.rb
+9
-4
No files found.
app/models/notification_recipient.rb
View file @
c2dd4239
...
...
@@ -76,10 +76,13 @@ class NotificationRecipient
end
def
has_access?
DeclarativePolicy
.
subject_scope
do
return
false
unless
user
.
can?
(
:receive_notifications
)
return
false
if
@project
&&
!
user
.
can?
(
:read_project
,
@project
)
return
true
unless
@read_ability
return
true
unless
DeclarativePolicy
.
has_policy?
(
@target
)
DeclarativePolicy
.
subject_scope
do
user
.
can?
(
@read_ability
,
@target
)
end
end
...
...
app/services/notification_recipient_service.rb
View file @
c2dd4239
...
...
@@ -308,11 +308,7 @@ module NotificationRecipientService
end
def
read_ability
@read_ability
||=
case
target
when
Commit
then
nil
else
:"read_
#{
target
.
class
.
model_name
.
name
.
underscore
}
"
end
@read_ability
||=
:"read_
#{
target
.
class
.
model_name
.
name
.
underscore
}
"
end
def
subject
...
...
lib/declarative_policy.rb
View file @
c2dd4239
...
...
@@ -28,7 +28,12 @@ module DeclarativePolicy
subject
=
find_delegate
(
subject
)
class_for_class
(
subject
.
class
)
class_for_class
(
subject
.
class
)
\
or
raise
"no policy for
#{
subject
.
class
.
name
}
"
end
def
has_policy?
(
subject
)
!
class_for_class
(
subject
.
class
).
nil?
end
private
...
...
@@ -51,9 +56,7 @@ module DeclarativePolicy
end
end
policy_class
=
subject_class
.
instance_variable_get
(
CLASS_CACHE_IVAR
)
raise
"no policy for
#{
subject
.
class
.
name
}
"
if
policy_class
.
nil?
policy_class
subject_class
.
instance_variable_get
(
CLASS_CACHE_IVAR
)
end
def
compute_class_for_class
(
subject_class
)
...
...
@@ -71,6 +74,8 @@ module DeclarativePolicy
nil
end
end
nil
end
def
find_delegate
(
subject
)
...
...
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