ensure topics and synapses have their permission match the map they're deferring to
This commit is contained in:
parent
a5f793fe54
commit
3c67f68d3b
3 changed files with 13 additions and 8 deletions
|
@ -32,6 +32,8 @@ class Map < ApplicationRecord
|
||||||
# Validate the attached image is image/jpg, image/png, etc
|
# Validate the attached image is image/jpg, image/png, etc
|
||||||
validates_attachment_content_type :screenshot, content_type: /\Aimage\/.*\Z/
|
validates_attachment_content_type :screenshot, content_type: /\Aimage\/.*\Z/
|
||||||
|
|
||||||
|
after_save :update_deferring_topics_and_synapses, if: :permission_changed?
|
||||||
|
|
||||||
def mappings
|
def mappings
|
||||||
topicmappings.or(synapsemappings)
|
topicmappings.or(synapsemappings)
|
||||||
end
|
end
|
||||||
|
@ -131,4 +133,9 @@ class Map < ApplicationRecord
|
||||||
end
|
end
|
||||||
removed.compact
|
removed.compact
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_deferring_topics_and_synapses
|
||||||
|
Topic.where(defer_to_map_id: id).update_all(permission: permission)
|
||||||
|
Synapse.where(defer_to_map_id: id).update_all(permission: permission)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,11 +2,10 @@
|
||||||
class SynapsePolicy < ApplicationPolicy
|
class SynapsePolicy < ApplicationPolicy
|
||||||
class Scope < Scope
|
class Scope < Scope
|
||||||
def resolve
|
def resolve
|
||||||
visible = %w(public commons)
|
return scope.where(permission: %w(public commons)) unless user
|
||||||
return scope.where(permission: visible) unless user
|
|
||||||
|
|
||||||
scope.where(permission: visible)
|
scope.where(permission: %w(public commons))
|
||||||
.or(scope.where.not(defer_to_map_id: nil).where(defer_to_map_id: user.all_accessible_maps.map(&:id)))
|
.or(scope.where(defer_to_map_id: user.all_accessible_maps.map(&:id)))
|
||||||
.or(scope.where(user_id: user.id))
|
.or(scope.where(user_id: user.id))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,11 +2,10 @@
|
||||||
class TopicPolicy < ApplicationPolicy
|
class TopicPolicy < ApplicationPolicy
|
||||||
class Scope < Scope
|
class Scope < Scope
|
||||||
def resolve
|
def resolve
|
||||||
visible = %w(public commons)
|
return scope.where(permission: %w(public commons)) unless user
|
||||||
return scope.where(permission: visible) unless user
|
|
||||||
|
|
||||||
scope.where(permission: visible)
|
scope.where(permission: %w(public commons))
|
||||||
.or(scope.where.not(defer_to_map_id: nil).where(defer_to_map_id: user.all_accessible_maps.map(&:id)))
|
.or(scope.where(defer_to_map_id: user.all_accessible_maps.map(&:id)))
|
||||||
.or(scope.where(user_id: user.id))
|
.or(scope.where(user_id: user.id))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue