mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-17 22:57:16 +08:00
`.annotaterb.yml` has carried `classified_sort: true` since the project
switched from `annotate` to `annotaterb` (commit 0eab7daea4, July 2025),
but annotaterb's default behaviour is to compare the existing schema
block against what it would generate and skip the rewrite when the
column list matches — even when the *ordering* of those columns differs.
The result is that models which haven't had a schema change since the
config landed never get reordered, and `classified_sort` drift
accumulates indefinitely.
`--force` makes annotaterb always rewrite, so a single `bin/rake
annotate:clean` run brings every model into the canonical format and
keeps them there. Every schema block is now grouped primary-key →
regular columns → timestamps → foreign keys (alphabetical within each
group). Pure annotation comment change — no code modifications.
Also cleans up the rake task to avoid string interpolation for `system`
calls.
68 lines
2 KiB
Ruby
68 lines
2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class UserApiKeyScope < ActiveRecord::Base
|
|
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: :get, actions: "notifications#totals"),
|
|
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"),
|
|
],
|
|
}
|
|
|
|
def self.all_scopes
|
|
scopes = SCOPES
|
|
DiscoursePluginRegistry.user_api_key_scope_mappings.each do |mapping|
|
|
scopes = scopes.merge!(mapping)
|
|
end
|
|
scopes
|
|
end
|
|
|
|
def permits?(env)
|
|
matchers.any? { |m| m.with_allowed_param_values(allowed_parameters).match?(env: env) }
|
|
end
|
|
|
|
private
|
|
|
|
def matchers
|
|
@matchers ||= Array(self.class.all_scopes[name.to_sym])
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: user_api_key_scopes
|
|
#
|
|
# id :bigint not null, primary key
|
|
# allowed_parameters :jsonb
|
|
# name :string not null
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# user_api_key_id :integer not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_user_api_key_scopes_on_user_api_key_id (user_api_key_id)
|
|
#
|