metamaps--metamaps/app/policies/map_policy.rb

49 lines
782 B
Ruby
Raw Normal View History

2016-02-28 05:28:28 +00:00
class MapPolicy < ApplicationPolicy
class Scope < Scope
def resolve
2016-03-11 22:37:32 +00:00
scope.where('maps.permission IN (?) OR maps.user_id = ?', ["public", "commons"], user.id)
2016-02-28 05:28:28 +00:00
end
end
def activemaps?
2016-02-28 09:24:00 +00:00
user.blank? # redirect to root url if authenticated for some reason
2016-02-28 05:28:28 +00:00
end
def featuredmaps?
true
end
def mymaps?
2016-02-28 09:24:00 +00:00
user.present?
2016-02-28 05:28:28 +00:00
end
def usermaps?
true
end
def show?
2016-02-28 09:24:00 +00:00
record.permission == 'commons' || record.permission == 'public' || record.user == user
2016-02-28 05:28:28 +00:00
end
def contains?
show?
end
def create?
2016-02-28 09:24:00 +00:00
user.present?
2016-02-28 05:28:28 +00:00
end
def update?
2016-02-28 09:24:00 +00:00
user.present? && (record.permission == 'commons' || record.user == user)
2016-02-28 05:28:28 +00:00
true
end
def screenshot?
update?
end
def destroy?
2016-03-11 13:32:18 +00:00
record.user == user || admin_override
2016-02-28 05:28:28 +00:00
end
end