2016-09-24 11:00:46 +08:00
|
|
|
# frozen_string_literal: true
|
2016-02-28 13:28:28 +08:00
|
|
|
class MapPolicy < ApplicationPolicy
|
|
|
|
class Scope < Scope
|
|
|
|
def resolve
|
2016-07-26 08:14:23 +08:00
|
|
|
visible = %w(public commons)
|
2016-03-13 02:41:32 +11:00
|
|
|
permission = 'maps.permission IN (?)'
|
2016-03-13 02:27:05 +11:00
|
|
|
if user
|
2016-04-24 11:50:35 -04: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-13 02:27:05 +11:00
|
|
|
else
|
2016-03-13 02:41:32 +11:00
|
|
|
scope.where(permission, visible)
|
2016-03-13 02:27:05 +11:00
|
|
|
end
|
2016-02-28 13:28:28 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-22 01:22:40 +08:00
|
|
|
def index?
|
|
|
|
true
|
2016-02-28 13:28:28 +08:00
|
|
|
end
|
|
|
|
|
2016-09-22 01:22:40 +08:00
|
|
|
def show?
|
|
|
|
record.permission == 'commons' || record.permission == 'public' || record.collaborators.include?(user) || record.user == user
|
2016-02-28 13:28:28 +08:00
|
|
|
end
|
|
|
|
|
2016-09-22 01:22:40 +08:00
|
|
|
def create?
|
2016-02-28 17:24:00 +08:00
|
|
|
user.present?
|
2016-02-28 13:28:28 +08:00
|
|
|
end
|
|
|
|
|
2016-09-22 01:22:40 +08:00
|
|
|
def update?
|
|
|
|
user.present? && (record.permission == 'commons' || record.collaborators.include?(user) || record.user == user)
|
2016-02-28 13:28:28 +08:00
|
|
|
end
|
|
|
|
|
2016-09-22 01:22:40 +08:00
|
|
|
def destroy?
|
|
|
|
record.user == user || admin_override
|
2016-02-28 13:28:28 +08:00
|
|
|
end
|
|
|
|
|
2016-09-22 01:22:40 +08:00
|
|
|
def access?
|
|
|
|
# note that this is to edit access
|
|
|
|
user.present? && record.user == user
|
2016-03-26 15:21:55 +08:00
|
|
|
end
|
|
|
|
|
2016-09-22 01:22:40 +08:00
|
|
|
def activemaps?
|
|
|
|
user.blank? # redirect to root url if authenticated for some reason
|
2016-04-14 14:35:28 -04:00
|
|
|
end
|
|
|
|
|
2016-02-28 13:28:28 +08:00
|
|
|
def contains?
|
|
|
|
show?
|
|
|
|
end
|
|
|
|
|
2016-09-22 01:22:40 +08:00
|
|
|
def events?
|
|
|
|
show?
|
2016-02-28 13:28:28 +08:00
|
|
|
end
|
|
|
|
|
2016-09-22 01:22:40 +08:00
|
|
|
def export?
|
|
|
|
show?
|
2016-04-24 11:50:35 -04:00
|
|
|
end
|
|
|
|
|
2016-09-22 01:22:40 +08:00
|
|
|
def featuredmaps?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def mymaps?
|
|
|
|
user.present?
|
2016-02-28 13:28:28 +08:00
|
|
|
end
|
|
|
|
|
2016-08-31 16:58:49 -04:00
|
|
|
def star?
|
|
|
|
unstar?
|
|
|
|
end
|
|
|
|
|
|
|
|
def unstar?
|
|
|
|
user.present?
|
|
|
|
end
|
|
|
|
|
2016-02-28 13:28:28 +08:00
|
|
|
def screenshot?
|
|
|
|
update?
|
|
|
|
end
|
|
|
|
|
2016-09-22 01:22:40 +08:00
|
|
|
def usermaps?
|
|
|
|
true
|
2016-02-28 13:28:28 +08:00
|
|
|
end
|
|
|
|
end
|