Sha256: a2985600b83b73635e29ae2358aa395b42dc6c447660ee2fbcdb957c39c4f455
Contents?: true
Size: 1.8 KB
Versions: 5
Compression:
Stored size: 1.8 KB
Contents
require 'fiona7/forbidden_obj_classes' require 'fiona7/tasks/task' module Fiona7 module Tasks class Loader def initialize(user_name=nil, groups=nil, forbidden_classes=Fiona7::ForbiddenObjClasses.new.call) self.user_name = user_name self.groups = groups self.forbidden_classes = forbidden_classes end def call raw_tasks = self.tasks_query.joins( "INNER JOIN #{Fiona7::EditedObj.table_name} objs ON objs.obj_id = #{RailsConnector::Task.table_name}.obj_id" ).where( "objs.obj_class NOT IN (?)", self.forbidden_classes ).order("#{RailsConnector::Task.table_name}.time_stamp DESC") objs = nil Scrivito::Workspace.find('rtc').as_current do objs = Hash[ Scrivito::BasicObj.find(raw_tasks.map(&:obj_id)).map {|obj| [obj.id.to_i, obj] } ] end real_tasks = raw_tasks.map do |raw_task| if obj = objs[raw_task.obj_id] Fiona7::Tasks::Task.new( raw_task.task_id, obj, raw_task.full_task_type, raw_task.title, raw_task.user_login, raw_task.group_name, raw_task.time_stamp_date, raw_task.task_comment ) end end # NOTE: this will cause to hide tasks which do not have # a valid scrivito obj assigned real_tasks.compact end protected attr_accessor :user_name, :groups, :forbidden_classes def tasks_query if self.user_name.present? && self.groups.present? RailsConnector::Task.where( "user_login = ? OR group_name IN (?)", self.user_name, self.groups ) else RailsConnector::Task.where(user_login: self.user_name) end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems