File tree Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -94,13 +94,8 @@ def destroy
94
94
private
95
95
96
96
def find_paste_and_project
97
- if params [ :project_id ] . present?
98
- @project = Project . find ( params [ :project_id ] )
99
- @pastes = @project . pastes
100
- else
101
- @pastes = Paste
102
- end
103
- @pastes = @pastes . visible ( User . current )
97
+ @project = Project . find ( params [ :project_id ] ) if params [ :project_id ] . present?
98
+ @pastes = Paste . visible ( User . current , :project => @project )
104
99
105
100
if params [ :id ] . present?
106
101
if Paste . secure_id? ( params [ :id ] )
Original file line number Diff line number Diff line change @@ -35,15 +35,21 @@ class Paste < ActiveRecord::Base
35
35
scope :expired , where ( "expires_at <= current_timestamp" )
36
36
scope :unexpired , where ( "expires_at IS NULL OR expires_at > current_timestamp" )
37
37
38
+ #
39
+ # * Restrict to project, if given.
38
40
#
39
41
# * Admin users should be able to see all pastes (even secure ones.)
40
42
#
41
43
# * An ordinary user can see a secure paste only if he has authored it.
42
44
#
43
45
# * Never show expired pastes even to an admin.
44
46
#
45
- scope :visible , lambda { |user , options = { } |
46
- where ( user . admin? ? nil : [ "access_token IS NULL OR author_id = ?" , user . id ] ) . unexpired
47
+ scope :visible , lambda { |user , *args |
48
+ options = args . first || { }
49
+ s = self
50
+ s = s . where ( :project_id => options [ :project ] ) if options [ :project ]
51
+ s = s . where ( [ "access_token IS NULL OR author_id = ?" , user . id ] ) unless user . admin?
52
+ s . unexpired
47
53
}
48
54
49
55
acts_as_searchable :columns => [ "#{ table_name } .title" , "#{ table_name } .text" ] ,
You can’t perform that action at this time.
0 commit comments