metamaps--metamaps/app/policies/topic_policy.rb
Connor Turland a133702be2 Some topics and synapses were hidden from users erroneously (#944)
* ensure topics and synapses have their permission match the map they're deferring to

* update permission of topics and synapses as map perm changes, when defer_to_map

* try enabling count threshold on rubocop

* remove unused mk_permission functions

* change *_count methods to use delegate to save lines in map.rb model

* rubocop topic.rb
2016-12-06 16:46:46 -05:00

62 lines
1.1 KiB
Ruby

# frozen_string_literal: true
class TopicPolicy < ApplicationPolicy
class Scope < Scope
def resolve
return scope.where(permission: %w(public commons)) unless user
scope.where(permission: %w(public commons))
.or(scope.where(defer_to_map_id: user.all_accessible_maps.map(&:id)))
.or(scope.where(user_id: user.id))
end
end
def index?
true
end
def create?
user.present?
end
def show?
if record.defer_to_map.present?
map_policy.show?
else
record.permission.in?(['commons', 'public']) || record.user == user
end
end
def update?
return false unless user.present?
if record.defer_to_map.present?
map_policy.update?
else
record.permission == 'commons' || record.user == user
end
end
def destroy?
record.user == user || admin_override
end
def autocomplete_topic?
user.present?
end
def network?
show?
end
def relative_numbers?
show?
end
def relatives?
show?
end
# Helpers
def map_policy
@map_policy ||= Pundit.policy(user, record.defer_to_map)
end
end