2016-02-28 05:28:28 +00:00
|
|
|
class MapPolicy < ApplicationPolicy
|
|
|
|
class Scope < Scope
|
|
|
|
def resolve
|
2016-07-26 00:14:23 +00:00
|
|
|
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
|
2016-04-24 15:50:35 +00:00
|
|
|
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?
|
2016-04-24 15:50:35 +00:00
|
|
|
record.permission == 'commons' || record.permission == 'public' || record.collaborators.include?(user) || record.user == user
|
2016-02-28 05:28:28 +00:00
|
|
|
end
|
|
|
|
|
2016-03-26 07:21:55 +00:00
|
|
|
def export?
|
|
|
|
show?
|
|
|
|
end
|
|
|
|
|
2016-04-14 18:35:28 +00:00
|
|
|
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?
|
2016-04-24 15:50:35 +00:00
|
|
|
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
|