diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-07-20 20:13:02 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-07-29 12:51:18 +0200 |
commit | 002ad215818450d2cbbc5fa065850a953dc7ada8 (patch) | |
tree | 9ac1703e56bd460fd24c7a5c93a5c465a83127b7 /app/models/issue.rb | |
parent | 9b0e131b83cfc44d3132bddfefb6cbd4bff7d253 (diff) | |
download | gitlab-ce-002ad215818450d2cbbc5fa065850a953dc7ada8.tar.gz |
Method for returning issues readable by a userability-batch-issue-checking
The method Ability.issues_readable_by_user takes a list of users and an
optional user and returns an Array of issues readable by said user. This
method in turn is used by
Banzai::ReferenceParser::IssueParser#nodes_visible_to_user so this
method no longer needs to get all the available abilities just to check
if a user has the "read_issue" ability.
To test this I benchmarked an issue with 222 comments on my development
environment. Using these changes the time spent in nodes_visible_to_user
was reduced from around 120 ms to around 40 ms.
Diffstat (limited to 'app/models/issue.rb')
-rw-r--r-- | app/models/issue.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index d9428ebc9fb..11f734cfc6d 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -230,6 +230,34 @@ class Issue < ActiveRecord::Base self.closed_by_merge_requests(current_user).empty? end + # Returns `true` if the current issue can be viewed by either a logged in User + # or an anonymous user. + def visible_to_user?(user = nil) + user ? readable_by?(user) : publicly_visible? + end + + # Returns `true` if the given User can read the current Issue. + def readable_by?(user) + if user.admin? + true + elsif project.owner == user + true + elsif confidential? + author == user || + assignee == user || + project.team.member?(user, Gitlab::Access::REPORTER) + else + project.public? || + project.internal? && !user.external? || + project.team.member?(user) + end + end + + # Returns `true` if this Issue is visible to everybody. + def publicly_visible? + project.public? && !confidential? + end + def overdue? due_date.try(:past?) || false end |