lib/seek/permissions/policy_based_authorization.rb
def all_authorized_for action, user=User.current_user, projects=nil, filter_by_permissions=true
          projects=Array(projects) unless projects.nil?
          user_id = user.nil? ? 0 : user.id
          assets = []
          programatic_project_filter = !projects.nil? && (!Seek::Config.auth_lookup_enabled || (self==Assay || self==Study))
          if Seek::Config.auth_lookup_enabled
            if (lookup_table_consistent?(user_id))
              Rails.logger.info("Lookup table #{lookup_table_name} is complete for user_id = #{user_id}")
              assets = lookup_for_action_and_user action, user_id,projects
            else
              Rails.logger.info("Lookup table #{lookup_table_name} is incomplete for user_id = #{user_id} - doing things the slow way")
              assets = default_order.select { |df| df.send("authorized_for_#{action}?",user) }
              programatic_project_filter = !projects.nil?
            end
          else
            assets = default_order.select { |df| df.send("authorized_for_#{action}?",user) }
          end

          if filter_by_permissions
            assets = assets.select{|a| a.send("state_allows_#{action}?",user)}
          end

          if programatic_project_filter
            assets.select { |a| !(a.projects & projects).empty? }
          else
            assets
          end
        end
#returns all the authorised items for a given action and optionally a user and set of projects. If user is nil, the items authorised for an
#anonymous user are returned. If one or more projects are provided, then only the assets linked to those projects are included.
# if filter_by_permissions is true, then as well as the authorization the state based permissions will also be applied
returns all the authorised items for a given action and optionally a user and set of projects. If user is nil, the items authorised for an
anonymous user are returned. If one or more projects are provided, then only the assets linked to those projects are included.
if filter_by_permissions is true, then as well as the authorization the state based permissions will also be applied
returns all the authorised items for a given action and optionally a user and set of projects . If user is nil the items authorised for an anonymous user are returned . If one or more projects are provided then only the assets linked to those projects are included . if filter_by_permissions is true then as well as the authorization the state based permissions will also be applied
def all_authorized_for action, user=User.current_user, projects=nil, filter_by_permissions=true
          projects=Array(projects) unless projects.nil?
          user_id = user.nil? ? 0 : user.id
          assets = []
          programatic_project_filter = !projects.nil? && (!Seek::Config.auth_lookup_enabled || (self==Assay || self==Study))
          if Seek::Config.auth_lookup_enabled
            if (lookup_table_consistent?(user_id))
              Rails.logger.info("Lookup table #{lookup_table_name} is complete for user_id = #{user_id}")
              assets = lookup_for_action_and_user action, user_id,projects
            else
              Rails.logger.info("Lookup table #{lookup_table_name} is incomplete for user_id = #{user_id} - doing things the slow way")
              assets = default_order.select { |df| df.send("authorized_for_#{action}?",user) }
              programatic_project_filter = !projects.nil?
            end
          else
            assets = default_order.select { |df| df.send("authorized_for_#{action}?",user) }
          end
          if filter_by_permissions
            assets = assets.select{|a| a.send("state_allows_#{action}?",user)}
          end
          if programatic_project_filter
            assets.select { |a| !(a.projects & projects).empty? }
          else
            assets
          end
        end
def all_authorized_for action , user = User . current_user , projects = nil , filter_by_permissions = true projects = Array ( projects ) unless projects . nil? user_id = user . nil? ? 0 : user . id assets = [ ] programatic_project_filter = ! projects . nil? && ( ! Seek :: Config . auth_lookup_enabled || ( self == Assay || self == Study ) ) if Seek :: Config . auth_lookup_enabled if ( lookup_table_consistent? ( user_id ) ) Rails . logger . info ( "Lookup table #{lookup_table_name} is complete for user_id = #{user_id}" ) assets = lookup_for_action_and_user action , user_id , projects else Rails . logger . info ( "Lookup table #{lookup_table_name} is incomplete for user_id = #{user_id} - doing things the slow way" ) assets = default_order . select { | df | df . send ( "authorized_for_#{action}?" , user ) } programatic_project_filter = ! projects . nil? end else assets = default_order . select { | df | df . send ( "authorized_for_#{action}?" , user ) } end if filter_by_permissions assets = assets . select { | a | a . send ( "state_allows_#{action}?" , user ) } end if programatic_project_filter assets . select { | a | ! ( a . projects & projects ) . empty? } else assets end end
returns all the authorised items for a given action and optionally a user and set of projects.
returns all the authorised items for a given action and optionally a user and set of projects .
action
user
current_user
projects
filter_by_permissions