Class: UserApiKeyScope

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/user_api_key_scope.rb

Constant Summary collapse

SCOPES =
{
  read: [RouteMatcher.new(methods: :get)],
  write: [RouteMatcher.new(methods: %i[get post patch put delete])],
  message_bus: [RouteMatcher.new(methods: :post, actions: "message_bus")],
  push: [],
  one_time_password: [],
  notifications: [
    RouteMatcher.new(methods: :post, actions: "message_bus"),
    RouteMatcher.new(methods: :get, actions: "notifications#index"),
    RouteMatcher.new(methods: :put, actions: "notifications#mark_read"),
  ],
  session_info: [
    RouteMatcher.new(methods: :get, actions: "session#current"),
    RouteMatcher.new(methods: :get, actions: "users#topic_tracking_state"),
  ],
  bookmarks_calendar: [
    RouteMatcher.new(
      methods: :get,
      actions: "users#bookmarks",
      formats: :ics,
      params: %i[username],
    ),
  ],
  user_status: [
    RouteMatcher.new(methods: :get, actions: "user_status#get"),
    RouteMatcher.new(methods: :put, actions: "user_status#set"),
    RouteMatcher.new(methods: :delete, actions: "user_status#clear"),
  ],
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_scopesObject



34
35
36
37
38
39
40
# File 'app/models/user_api_key_scope.rb', line 34

def self.all_scopes
  scopes = SCOPES
  DiscoursePluginRegistry.user_api_key_scope_mappings.each do |mapping|
    scopes = scopes.merge!(mapping)
  end
  scopes
end

Instance Method Details

#permits?(env) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/user_api_key_scope.rb', line 42

def permits?(env)
  matchers.any? { |m| m.with_allowed_param_values(allowed_parameters).match?(env: env) }
end