diff options
author | Robert Speicher <robert@gitlab.com> | 2016-05-31 22:35:13 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-05-31 22:35:13 +0300 |
commit | 613bcdc6262f30156bc240e532c781f1d0681b9f (patch) | |
tree | 31c70a4a39abb01eefa0f088fd88937e5647e876 /app | |
parent | ef4fedc18f5e2475aa36cc4327a76a496567c6fc (diff) | |
parent | 9154586ce5c46dfac83a1ed1e4beac1940913f16 (diff) |
Merge branch 'data_leak' into 'master'
Confidential notes data leak
Fixes part of https://gitlab.com/gitlab-org/gitlab-ee/issues/575
See merge request !1967
Diffstat (limited to 'app')
-rw-r--r-- | app/models/note.rb | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/app/models/note.rb b/app/models/note.rb index 5f669c02e8b..052239af43c 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -84,14 +84,30 @@ class Note < ActiveRecord::Base # # This method uses ILIKE on PostgreSQL and LIKE on MySQL. # - # query - The search query as a String. + # query - The search query as a String. + # as_user - Limit results to those viewable by a specific user # # Returns an ActiveRecord::Relation. - def search(query) + def search(query, as_user: nil) table = arel_table pattern = "%#{query}%" - where(table[:note].matches(pattern)) + found_notes = joins('LEFT JOIN issues ON issues.id = noteable_id'). + where(table[:note].matches(pattern)) + + if as_user + found_notes.where(' + issues.confidential IS NULL + OR issues.confidential IS FALSE + OR (issues.confidential IS TRUE + AND (issues.author_id = :user_id + OR issues.assignee_id = :user_id + OR issues.project_id IN(:project_ids)))', + user_id: as_user.id, + project_ids: as_user.authorized_projects.select(:id)) + else + found_notes.where('issues.confidential IS NULL OR issues.confidential IS FALSE') + end end def grouped_awards |