mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
add support for hidden api keys, used in hosting scenarios
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
class Admin::ApiController < Admin::AdminController
|
class Admin::ApiController < Admin::AdminController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
render_serialized(ApiKey.all.to_a, ApiKeySerializer)
|
render_serialized(ApiKey.where(hidden: false).to_a, ApiKeySerializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def regenerate_key
|
def regenerate_key
|
||||||
|
@ -12,7 +12,7 @@ class ApiKey < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.create_master_key
|
def self.create_master_key
|
||||||
api_key = ApiKey.find_by(user_id: nil)
|
api_key = ApiKey.find_by(user_id: nil, hidden: false)
|
||||||
if api_key.blank?
|
if api_key.blank?
|
||||||
api_key = ApiKey.create(key: SecureRandom.hex(32), created_by: Discourse.system_user)
|
api_key = ApiKey.create(key: SecureRandom.hex(32), created_by: Discourse.system_user)
|
||||||
end
|
end
|
||||||
|
7
db/migrate/20141120043401_add_hidden_to_api_keys.rb
Normal file
7
db/migrate/20141120043401_add_hidden_to_api_keys.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class AddHiddenToApiKeys < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
change_table :api_keys do |t|
|
||||||
|
t.boolean :hidden, null: false, default: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user