From 40bd9ed95a30996c6785b33688eda02a6ef24d60 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 23 Sep 2016 16:41:15 +0800 Subject: [PATCH] refactor maps controller a bit --- app/models/map.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/models/map.rb b/app/models/map.rb index 9c30479f..7de744a2 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -108,4 +108,23 @@ class Map < ApplicationRecord self.screenshot = data save end + + # user param helps determine what records are visible + def contains(user) + allmappers = contributors + allcollaborators = editors + alltopics = Pundit.policy_scope(user, topics).to_a + allsynapses = Pundit.policy_scope(user, synapses).to_a + allmappings = Pundit.policy_scope(user, mappings).to_a + + json = {} + json['map'] = self + json['topics'] = alltopics + json['synapses'] = allsynapses + json['mappings'] = allmappings + json['mappers'] = allmappers + json['collaborators'] = allcollaborators + json['messages'] = messages.sort_by(&:created_at) + json['stars'] = stars + end end