app/models/plan.rb
##
# determines if the plan is readable by the specified user
#
# user_id - The Integer id for a user
#
# Returns Boolean
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
determines if the plan is readable by the specified user
user_id - The Integer id for a user


determines if the plan is readable by the specified user user_id - The Integer id for a user
def readable_by?(user_id)
    return true if commentable_by?(user_id)
    current_user = User.find(user_id)
    return false unless current_user.present?
    if current_user.can_super_admin? && Rails.configuration.x.plans.super_admins_read_all
      true
    elsif current_user.can_org_admin? && Rails.configuration.x.plans.org_admins_read_all
      owner_and_coowners.map(&:org_id).include?(current_user.org_id)
    else
      false
    end
  end
def readable_by? ( user_id ) return true if commentable_by? ( user_id ) current_user = User . find ( user_id ) return false unless current_user . present? if current_user . can_super_admin? && Rails . configuration . x . plans . super_admins_read_all true elsif current_user . can_org_admin? && Rails . configuration . x . plans . org_admins_read_all owner_and_coowners . map ( & :org_id ) . include? ( current_user . org_id ) else false end end
determines if the plan is readable by the specified user
user_id - The Integer id for a user
determines if the plan is readable by the specified user user_id - The Integer id for a user
# If the user is a super admin and the config allows for supers to view plans # If the user is an org admin and the config allows for org admins to view plans
user_id