require 'fiona7/editing_env_check' module Fiona7 class AccessPermissionCheck def initialize(obj, env, rc_user, reactor_user) self.obj = obj self.env = env self.rc_user = rc_user self.reactor_user = reactor_user end def read_permitted? if edited_contents_visible? read_permission_check else live_permission_check end end protected attr_accessor :obj, :env, :rc_user, :reactor_user def edited_contents_visible? Fiona7::EditingEnvCheck.new(self.env).rtc_selected? end # this is very quick! def live_permission_check self.obj.permitted_for_user?(self.rc_user) end # this is very slow! def read_permission_check if !self.reactor_user false else self.reactor_user.superuser? || (self.obj.permissions.root & self.reactor_user.groups).any? || (self.obj.permissions.read & self.reactor_user.groups).any? end end end end