authorized_applications_controller.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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_last_used_at_by_app, only: :index, unless: -> { request.format == :json }
  9. skip_before_action :require_functional!
  10. include Localized
  11. def destroy
  12. Web::PushSubscription.unsubscribe_for(params[:id], current_resource_owner)
  13. super
  14. end
  15. private
  16. def set_body_classes
  17. @body_classes = 'admin'
  18. end
  19. def store_current_location
  20. store_location_for(:user, request.url)
  21. end
  22. def require_not_suspended!
  23. forbidden if current_account.suspended?
  24. end
  25. def set_last_used_at_by_app
  26. @last_used_at_by_app = Doorkeeper::AccessToken
  27. .select('DISTINCT ON (application_id) application_id, last_used_at')
  28. .where(resource_owner_id: current_resource_owner.id)
  29. .where.not(last_used_at: nil)
  30. .order(application_id: :desc, last_used_at: :desc)
  31. .pluck(:application_id, :last_used_at)
  32. .to_h
  33. end
  34. end