map policy
This commit is contained in:
parent
cec6d3bfcd
commit
1e01ff8bc9
1 changed files with 48 additions and 0 deletions
48
app/policies/map_policy.rb
Normal file
48
app/policies/map_policy.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
class MapPolicy < ApplicationPolicy
|
||||
class Scope < Scope
|
||||
def resolve
|
||||
scope.where('permission IN ("public", "commons") OR user_id = ?', @user.id)
|
||||
end
|
||||
end
|
||||
|
||||
def activemaps?
|
||||
@user.blank? # redirect to root url if authenticated for some reason
|
||||
end
|
||||
|
||||
def featuredmaps?
|
||||
true
|
||||
end
|
||||
|
||||
def mymaps?
|
||||
@user.present?
|
||||
end
|
||||
|
||||
def usermaps?
|
||||
true
|
||||
end
|
||||
|
||||
def show?
|
||||
@record.permission == 'commons' || @record.permission == 'public' || @record.user == @user
|
||||
end
|
||||
|
||||
def contains?
|
||||
show?
|
||||
end
|
||||
|
||||
def create?
|
||||
@user.present?
|
||||
end
|
||||
|
||||
def update?
|
||||
@user.present? && (@record.permission == 'commons' || @record.user == @user)
|
||||
true
|
||||
end
|
||||
|
||||
def screenshot?
|
||||
update?
|
||||
end
|
||||
|
||||
def destroy?
|
||||
@record.user == @user || @user.admin
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue