Skip to content

Commit 4972d6f

Browse files
committed
implements security policy for document types
1 parent 0bc116b commit 4972d6f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
# app/policies/document_type_policy.rb
4+
class DocumentTypePolicy < ApplicationPolicy
5+
def index?
6+
true
7+
end
8+
9+
def show?
10+
index?
11+
end
12+
13+
def create?
14+
!user.nil?
15+
end
16+
17+
def new?
18+
create?
19+
end
20+
21+
def edit?
22+
(!user.nil? && owner?) || !user.nil? && privileged?
23+
end
24+
25+
def update?
26+
edit?
27+
end
28+
29+
def review?
30+
!user.nil? && privileged?
31+
end
32+
33+
def destroy?
34+
false
35+
end
36+
37+
private
38+
39+
def privileged?
40+
user.curator? || user.admin?
41+
end
42+
43+
def owner?
44+
record.user.nil? ? (user.curator? || user.admin?) : (user == record.user)
45+
end
46+
end

0 commit comments

Comments
 (0)