topic policy
This commit is contained in:
parent
66f1d2ec0b
commit
52facb9c1d
1 changed files with 40 additions and 0 deletions
40
app/policies/topic_policy.rb
Normal file
40
app/policies/topic_policy.rb
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
class TopicPolicy < ApplicationPolicy
|
||||||
|
class Scope < Scope
|
||||||
|
def resolve
|
||||||
|
scope.where('permission IN ("public", "commons") OR user_id = ?', user.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def create?
|
||||||
|
user.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def show?
|
||||||
|
record.permission == 'commons' || record.permission == 'public' || record.user == user
|
||||||
|
end
|
||||||
|
|
||||||
|
def update?
|
||||||
|
# user.present? && (record.permission == 'commons' || record.user == user)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy?
|
||||||
|
record.user == user || user.admin
|
||||||
|
end
|
||||||
|
|
||||||
|
def autocomplete_topic?
|
||||||
|
user.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def network?
|
||||||
|
show?
|
||||||
|
end
|
||||||
|
|
||||||
|
def relative_numbers?
|
||||||
|
show?
|
||||||
|
end
|
||||||
|
|
||||||
|
def relatives?
|
||||||
|
show?
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue