Skip to content

Commit 1ad6004

Browse files
committed
Fix secure paste visibility: always visible to admins and paste author.
1 parent 113690b commit 1ad6004

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

app/controllers/pastes_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def find_paste_and_project
100100
else
101101
@pastes = Paste
102102
end
103-
@pastes = @pastes.insecure
103+
@pastes = @pastes.visible_to(User.current)
104104

105105
if params[:id].present?
106106
if Paste.secure_id?(params[:id])

app/models/paste.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class Paste < ActiveRecord::Base
3131
}
3232

3333
named_scope :secure, :conditions => "access_token IS NOT NULL"
34-
named_scope :insecure, :conditions => "access_token IS NULL"
34+
named_scope :visible_to, lambda { |user|
35+
{ :conditions => (user.admin? ? nil : ["access_token IS NULL OR author_id = ?", user.id]) }
36+
}
3537

3638
named_scope :expired, :conditions => "expires_at <= current_timestamp"
3739
default_scope :conditions => "expires_at IS NULL OR expires_at > current_timestamp"

0 commit comments

Comments
 (0)