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
356635fa
Commit
356635fa
authored
Jun 01, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract IssuesFinder.not_restricted_by_confidentiality to Issue model
parent
f8f1eb42
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
45 deletions
+46
-45
app/finders/issues_finder.rb
app/finders/issues_finder.rb
+1
-16
app/models/issue.rb
app/models/issue.rb
+15
-0
spec/finders/issues_finder_spec.rb
spec/finders/issues_finder_spec.rb
+0
-29
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+30
-0
No files found.
app/finders/issues_finder.rb
View file @
356635fa
...
...
@@ -23,7 +23,7 @@ class IssuesFinder < IssuableFinder
private
def
init_collection
Issue
sFinder
.
not_restricted_by_confidentiality
(
current_user
)
Issue
.
not_restricted_by_confidentiality
(
current_user
)
end
def
by_assignee
(
items
)
...
...
@@ -38,21 +38,6 @@ class IssuesFinder < IssuableFinder
end
end
def
self
.
not_restricted_by_confidentiality
(
user
)
return
Issue
.
where
(
'issues.confidential IS NOT TRUE'
)
if
user
.
blank?
return
Issue
.
all
if
user
.
admin_or_auditor?
Issue
.
where
(
'
issues.confidential IS NOT TRUE
OR (issues.confidential = TRUE
AND (issues.author_id = :user_id
OR EXISTS (SELECT TRUE FROM issue_assignees WHERE user_id = :user_id AND issue_id = issues.id)
OR issues.project_id IN(:project_ids)))'
,
user_id:
user
.
id
,
project_ids:
user
.
authorized_projects
(
Gitlab
::
Access
::
REPORTER
).
select
(
:id
))
end
def
item_project_ids
(
items
)
items
&
.
reorder
(
nil
)
&
.
select
(
:project_id
)
end
...
...
app/models/issue.rb
View file @
356635fa
...
...
@@ -99,6 +99,21 @@ class Issue < ActiveRecord::Base
'#'
end
def
self
.
not_restricted_by_confidentiality
(
user
)
return
where
(
'issues.confidential IS NOT TRUE'
)
if
user
.
blank?
return
all
if
user
.
admin_or_auditor?
where
(
'
issues.confidential IS NOT TRUE
OR (issues.confidential = TRUE
AND (issues.author_id = :user_id
OR EXISTS (SELECT TRUE FROM issue_assignees WHERE user_id = :user_id AND issue_id = issues.id)
OR issues.project_id IN(:project_ids)))'
,
user_id:
user
.
id
,
project_ids:
user
.
authorized_projects
(
Gitlab
::
Access
::
REPORTER
).
select
(
:id
))
end
# Pattern used to extract `#123` issue references from text
#
# This pattern supports cross-project references.
...
...
spec/finders/issues_finder_spec.rb
View file @
356635fa
...
...
@@ -290,33 +290,4 @@ describe IssuesFinder do
end
end
end
describe
'.not_restricted_by_confidentiality'
do
let
(
:authorized_user
)
{
create
(
:user
)
}
let
(
:admin_user
)
{
create
(
:admin
)
}
let
(
:auditor_user
)
{
create
(
:user
,
:auditor
)
}
let
(
:project
)
{
create
(
:empty_project
,
namespace:
authorized_user
.
namespace
)
}
let!
(
:public_issue
)
{
create
(
:issue
,
project:
project
)
}
let!
(
:confidential_issue
)
{
create
(
:issue
,
project:
project
,
confidential:
true
)
}
it
'returns non confidential issues for nil user'
do
expect
(
described_class
.
send
(
:not_restricted_by_confidentiality
,
nil
)).
to
include
(
public_issue
)
end
it
'returns non confidential issues for user not authorized for the issues projects'
do
expect
(
described_class
.
send
(
:not_restricted_by_confidentiality
,
user
)).
to
include
(
public_issue
)
end
it
'returns all issues for user authorized for the issues projects'
do
expect
(
described_class
.
send
(
:not_restricted_by_confidentiality
,
authorized_user
)).
to
include
(
public_issue
,
confidential_issue
)
end
it
'returns all issues for an admin user'
do
expect
(
described_class
.
send
(
:not_restricted_by_confidentiality
,
admin_user
)).
to
include
(
public_issue
,
confidential_issue
)
end
it
'returns all issues for an auditor user'
do
expect
(
described_class
.
send
(
:not_restricted_by_confidentiality
,
auditor_user
)).
to
include
(
public_issue
,
confidential_issue
)
end
end
end
spec/models/issue_spec.rb
View file @
356635fa
...
...
@@ -38,6 +38,36 @@ describe Issue, models: true do
end
end
describe
'.not_restricted_by_confidentiality'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:authorized_user
)
{
create
(
:user
)
}
let
(
:admin_user
)
{
create
(
:admin
)
}
let
(
:auditor_user
)
{
create
(
:user
,
:auditor
)
}
let
(
:project
)
{
create
(
:empty_project
,
namespace:
authorized_user
.
namespace
)
}
let!
(
:public_issue
)
{
create
(
:issue
,
project:
project
)
}
let!
(
:confidential_issue
)
{
create
(
:issue
,
project:
project
,
confidential:
true
)
}
it
'returns non confidential issues for nil user'
do
expect
(
described_class
.
not_restricted_by_confidentiality
(
nil
)).
to
include
(
public_issue
)
end
it
'returns non confidential issues for user not authorized for the issues projects'
do
expect
(
described_class
.
not_restricted_by_confidentiality
(
user
)).
to
include
(
public_issue
)
end
it
'returns all issues for user authorized for the issues projects'
do
expect
(
described_class
.
not_restricted_by_confidentiality
(
authorized_user
)).
to
include
(
public_issue
,
confidential_issue
)
end
it
'returns all issues for an admin user'
do
expect
(
described_class
.
not_restricted_by_confidentiality
(
admin_user
)).
to
include
(
public_issue
,
confidential_issue
)
end
it
'returns all issues for an auditor user'
do
expect
(
described_class
.
not_restricted_by_confidentiality
(
auditor_user
)).
to
include
(
public_issue
,
confidential_issue
)
end
end
describe
'#card_attributes'
do
it
'includes the author name'
do
allow
(
subject
).
to
receive
(
:author
).
and_return
(
double
(
name:
'Robert'
))
...
...
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