current_user_aware.rb 583 B

123456789101112131415
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Gql::Context::CurrentUserAware < GraphQL::Query::Context # rubocop:disable GraphQL/ObjectDescription
  3. # Use this method to fetch the current user when it must be present - it throws an exception otherwise,
  4. # making sure unauthenticated requests are handled properly.
  5. def current_user
  6. self[:current_user] || raise(Exceptions::NotAuthorized, __('Authentication required'))
  7. end
  8. # If the current_user may be absent, use this method.
  9. def current_user?
  10. self[:current_user]
  11. end
  12. end