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

68 lines
1.2 KiB
Ruby
Raw Normal View History

2016-02-28 05:28:28 +00:00
class MapPolicy < ApplicationPolicy
class Scope < Scope
def resolve
visible = %w(public commons)
2016-03-12 15:41:32 +00:00
permission = 'maps.permission IN (?)'
2016-03-12 15:27:05 +00:00
if user
shared_maps = user.shared_maps.map(&:id)
scope.where(permission + ' OR maps.id IN (?) OR maps.user_id = ?', visible, shared_maps, user.id)
2016-03-12 15:27:05 +00:00
else
2016-03-12 15:41:32 +00:00
scope.where(permission, visible)
2016-03-12 15:27:05 +00:00
end
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?
record.permission == 'commons' || record.permission == 'public' || record.collaborators.include?(user) || record.user == user
2016-02-28 05:28:28 +00:00
end
def export?
show?
end
def events?
show?
end
2016-02-28 05:28:28 +00:00
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?
user.present? && (record.permission == 'commons' || record.collaborators.include?(user) || record.user == user)
end
def access?
# note that this is to edit access
user.present? && record.user == user
2016-02-28 05:28:28 +00:00
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