Skip to content

Commit

Permalink
add support for hidden api keys, used in hosting scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Nov 20, 2014
1 parent a9cda0f commit 6b10c4d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/api_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Admin::ApiController < Admin::AdminController

def index
render_serialized(ApiKey.all.to_a, ApiKeySerializer)
render_serialized(ApiKey.where(hidden: false).to_a, ApiKeySerializer)
end

def regenerate_key
Expand Down
2 changes: 1 addition & 1 deletion app/models/api_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def regenerate!(updated_by)
end

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?
api_key = ApiKey.create(key: SecureRandom.hex(32), created_by: Discourse.system_user)
end
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20141120043401_add_hidden_to_api_keys.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6b10c4d

Please sign in to comment.