2016-02-28 05:28:28 +00:00
|
|
|
class MapPolicy < ApplicationPolicy
|
|
|
|
class Scope < Scope
|
|
|
|
def resolve
|
2016-03-12 15:41:32 +00:00
|
|
|
visible = ['public', 'commons']
|
|
|
|
permission = 'maps.permission IN (?)'
|
2016-03-12 15:27:05 +00:00
|
|
|
if user
|
2016-03-12 15:41:32 +00:00
|
|
|
scope.where(permission + ' OR maps.user_id = ?', visible, 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-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
|
|
|
|
|
2016-03-26 07:21:55 +00:00
|
|
|
def export?
|
|
|
|
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-02-28 09:24:00 +00:00
|
|
|
user.present? && (record.permission == 'commons' || 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
|