{"record":{"id":"f489febe0c710fc6","repo":"instructure/canvas-lms","slug":"page-access-denied","errorCode":null,"errorMessage":"Page access denied","messagePattern":"Page access denied","errorType":"validation","errorClass":"ContentUnavailable","httpStatus":null,"severity":"error","filePath":"app/services/study_assist.rb","lineNumber":159,"sourceCode":"        if page_id.present?\n          resolve_page(page_id)\n        elsif file_id.present?\n          resolve_file(file_id)\n        else\n          raise ContentUnavailable, \"No pageID or fileID provided\"\n        end\n\n      if content.text.length > MAX_CONTENT_CHARS\n        raise ContentTooLarge, \"Content exceeds #{MAX_CONTENT_CHARS} character limit\"\n      end\n\n      content\n    end\n\n    def resolve_page(page_id)\n      page = @course.wiki_pages.not_deleted.find_by(url: page_id)\n      raise ContentUnavailable, \"Page not found\" if page.nil?\n      raise ContentUnavailable, \"Page access denied\" unless page.grants_right?(@user, :read)\n\n      shard_safe_key = shard_safe_cache_key_for(page)\n      text = Rails.cache.fetch(text_cache_key_for(:page, shard_safe_key), expires_in: TEXT_CACHE_TTL) do\n        html_to_text(page.body.to_s)\n      end\n\n      Content.new(kind: :page, id: page.id, cache_key_with_version: shard_safe_key, text:)\n    end\n\n    def resolve_file(file_id)\n      attachment = @course.attachments.find_by(id: file_id)\n      raise ContentUnavailable, \"File not found\" if attachment.nil? || attachment.deleted?\n      raise ContentUnavailable, \"File access denied\" unless attachment.grants_right?(@user, :read)\n      raise ContentUnavailable, \"File is locked\" if attachment.locked_for?(@user, check_policies: true)\n      raise UnsupportedContentType unless supported_attachment?(attachment)\n      raise ContentTooLarge, \"File exceeds #{MAX_FILE_BYTES} byte limit\" if attachment.size && attachment.size > MAX_FILE_BYTES\n\n      shard_safe_key = shard_safe_cache_key_for(attachment)","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/services/study_assist.rb#L141-L177","documentation":"StudyAssist::ContentUnavailable with 'Page access denied' is raised by resolve_page when the page exists but page.grants_right?(@user, :read) is false. The service enforces per-user read permissions before using page content in an LLM call.","triggerScenarios":"Calling #call with a valid page_id but a user who lacks :read on that wiki page (unpublished page, module-locked page, non-enrolled user, or user from a different course/account).","commonSituations":"Teacher-constructed service call reusing an admin's page but a student @user; unpublished pages students can't read; module requirement/lock rules denying read; token/user mismatch in API integration.","solutions":["Ensure the @user passed to StudyAssist has read access to the page (enrollment, published page)","Check page.grants_right?(user, :read) before invoking the service","Handle ContentUnavailable in the caller and surface a friendly message","Publish the page or adjust module locks if access should be granted"],"exampleFix":"// before\nStudyAssist.new(course: @course, user: @user, prompt:, page_id: page.url).call\n// after\nif page.grants_right?(@user, :read)\n  StudyAssist.new(course: @course, user: @user, prompt:, page_id: page.url).call\nelse\n  render json: { error: 'page unavailable' }, status: :forbidden\nend","handlingStrategy":"validation","validationCode":"page = course.wiki_pages.not_deleted.find_by(url: page_id)\nreturn nil unless page&.grants_right?(user, :read)","typeGuard":"null","tryCatchPattern":"begin\n  StudyAssist.new(course:, user:, prompt:, page_id:).call\nrescue StudyAssist::ContentUnavailable\n  render json: { error: 'page not available' }, status: :forbidden\nend","preventionTips":["Check grants_right?(user, :read) before invoking","Ensure the user has appropriate enrollment","Publish pages intended for student use"],"tags":["ruby","study-assist","permissions","access-control"],"backgroundTag":"permission-denied","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}