-
Notifications
You must be signed in to change notification settings - Fork 0
/
discussion_policy.rb
54 lines (43 loc) · 1.03 KB
/
discussion_policy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class DiscussionPolicy < ApplicationPolicy
delegate :writable?, to: :board_policy
def index?
true
end
def show?
board_policy.show?
end
def create?
if Array.wrap(record).compact.any? { |d| d.board.section == 'zooniverse' }
writable? && confirmed? && of_posting_age?
else
writable? && confirmed?
end
end
def update?
(owner? || moderator? || admin?) && writable?
end
alias_method :owner_update?, :update?
def destroy?
(moderator? || admin?) && writable?
end
def board_policy
BoardPolicy.new user, boards
end
def boards
Array.wrap(record).compact.collect &:board
end
class Scope < Scope
delegate :zooniverse_admin?, :permissions, to: :@board_scope
def initialize(user, scope)
@board_scope = BoardPolicy::Scope.new user, Board
super
end
def resolve
return scope.all if zooniverse_admin?
scope.joins(:board).where permissions.join(' or ')
end
def board_scope
BoardPolicy::Scope.new user, Board
end
end
end