authorized_applications_controller.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # frozen_string_literal: true
  2. class Oauth::AuthorizedApplicationsController < Doorkeeper::AuthorizedApplicationsController
  3. skip_before_action :authenticate_resource_owner!
  4. before_action :store_current_location
  5. before_action :authenticate_resource_owner!
  6. before_action :require_not_suspended!, only: :destroy
  7. before_action :set_body_classes
  8. before_action :set_cache_headers
  9. before_action :set_last_used_at_by_app, only: :index, unless: -> { request.format == :json }
  10. skip_before_action :require_functional!
  11. include Localized
  12. def destroy
  13. Web::PushSubscription.unsubscribe_for(params[:id], current_resource_owner)
  14. super
  15. end
  16. private
  17. def set_body_classes
  18. @body_classes = 'admin'
  19. end
  20. def store_current_location
  21. store_location_for(:user, request.url)
  22. end
  23. def require_not_suspended!
  24. forbidden if current_account.unavailable?
  25. end
  26. def set_cache_headers
  27. response.cache_control.replace(private: true, no_store: true)
  28. end
  29. def set_last_used_at_by_app
  30. @last_used_at_by_app = Doorkeeper::AccessToken
  31. .select('DISTINCT ON (application_id) application_id, last_used_at')
  32. .where(resource_owner_id: current_resource_owner.id)
  33. .where.not(last_used_at: nil)
  34. .order(application_id: :desc, last_used_at: :desc)
  35. .pluck(:application_id, :last_used_at)
  36. .to_h
  37. end
  38. end