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

84 lines
1.3 KiB
Ruby
Raw Normal View History

2016-09-24 03:00:46 +00:00
# frozen_string_literal: true
2016-02-28 05:28:28 +00:00
class MapPolicy < ApplicationPolicy
class Scope < Scope
def resolve
visible = %w(public commons)
2016-09-24 04:27:34 +00:00
return scope.where(permission: visible) unless user
scope.where(permission: visible)
.or(scope.where(id: user.shared_maps.map(&:id)))
.or(scope.where(user_id: user.id))
2016-02-28 05:28:28 +00:00
end
end
def index?
true
2016-02-28 05:28:28 +00:00
end
def show?
2016-09-24 04:27:34 +00:00
record.permission.in?('commons', 'public') ||
record.collaborators.include?(user) ||
record.user == user
2016-02-28 05:28:28 +00:00
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-09-24 04:27:34 +00:00
return false unless user.present?
record.permission == 'commons' ||
record.collaborators.include?(user) ||
record.user == user
2016-02-28 05:28:28 +00:00
end
def destroy?
record.user == user || admin_override
2016-02-28 05:28:28 +00:00
end
def access?
2016-09-24 04:27:34 +00:00
# note that this is to edit who can access the map
user.present? && record.user == user
end
def activemaps?
user.blank? # redirect to root url if authenticated for some reason
end
2016-02-28 05:28:28 +00:00
def contains?
show?
end
def events?
show?
2016-02-28 05:28:28 +00:00
end
def export?
show?
end
def featuredmaps?
true
end
def mymaps?
user.present?
2016-02-28 05:28:28 +00:00
end
def star?
unstar?
end
def unstar?
user.present?
end
2016-02-28 05:28:28 +00:00
def screenshot?
update?
end
def usermaps?
true
2016-02-28 05:28:28 +00:00
end
end