mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FEATURE: allow "developer" account flagging via developers table
This mechanism for flagging developer accounts will eventually replace DISCOURSE_DEVELOPER_EMAILS
This commit is contained in:
parent
c6dbaca0dc
commit
ab68e0c9db
4 changed files with 51 additions and 1 deletions
22
app/models/developer.rb
Normal file
22
app/models/developer.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
require_dependency 'distributed_cache'
|
||||||
|
|
||||||
|
class Developer < ActiveRecord::Base
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
after_save :rebuild_cache
|
||||||
|
after_destroy :rebuild_cache
|
||||||
|
|
||||||
|
@id_cache = DistributedCache.new('developer_ids')
|
||||||
|
|
||||||
|
def self.user_ids
|
||||||
|
@id_cache["ids"] ||= rebuild_cache
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.rebuild_cache
|
||||||
|
@id_cache["ids"] = Set.new(Developer.pluck(:user_id))
|
||||||
|
end
|
||||||
|
|
||||||
|
def rebuild_cache
|
||||||
|
Developer.rebuild_cache
|
||||||
|
end
|
||||||
|
end
|
7
db/migrate/20160727233044_create_developers_table.rb
Normal file
7
db/migrate/20160727233044_create_developers_table.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
class CreateDevelopersTable < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :developers do |t|
|
||||||
|
t.integer :user_id, null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -74,7 +74,8 @@ class Guardian
|
||||||
(
|
(
|
||||||
Rails.configuration.respond_to?(:developer_emails) &&
|
Rails.configuration.respond_to?(:developer_emails) &&
|
||||||
Rails.configuration.developer_emails.include?(@user.email)
|
Rails.configuration.developer_emails.include?(@user.email)
|
||||||
)
|
) ||
|
||||||
|
Developer.user_ids.include?(@user.id)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
20
spec/models/developer_spec.rb
Normal file
20
spec/models/developer_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe Developer do
|
||||||
|
it "can correctly flag developer accounts" do
|
||||||
|
user = Fabricate(:user)
|
||||||
|
guardian = Guardian.new(user)
|
||||||
|
|
||||||
|
expect(guardian.is_developer?).to eq(false)
|
||||||
|
|
||||||
|
Developer.create!(user_id: user.id)
|
||||||
|
|
||||||
|
# not an admin so not a developer yet
|
||||||
|
expect(guardian.is_developer?).to eq(false)
|
||||||
|
|
||||||
|
user.update_columns(admin: true)
|
||||||
|
|
||||||
|
expect(guardian.is_developer?).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue