Add administrateur#feature_enabled? method
This commit is contained in:
parent
d1b3530da0
commit
322f93afbe
3 changed files with 18 additions and 1 deletions
|
@ -2,7 +2,7 @@ module TypeDeChampHelper
|
||||||
def tdc_options(current_administrateur)
|
def tdc_options(current_administrateur)
|
||||||
tdcs = TypeDeChamp.type_de_champs_list_fr
|
tdcs = TypeDeChamp.type_de_champs_list_fr
|
||||||
|
|
||||||
if !current_administrateur.id.in?(Features.champ_pj_allowed_for_admin_ids)
|
if !current_administrateur.feature_enabled?(:champ_pj_allowed)
|
||||||
tdcs.reject! { |tdc| tdc.last == "piece_justificative" }
|
tdcs.reject! { |tdc| tdc.last == "piece_justificative" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,11 @@ class Administrateur < ApplicationRecord
|
||||||
administrateur
|
administrateur
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def feature_enabled?(feature)
|
||||||
|
ids = Features.send(:"#{feature}_for_admin_ids")
|
||||||
|
ids.present? ? id.in?(ids) : false
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def generate_api_token
|
def generate_api_token
|
||||||
|
|
|
@ -66,4 +66,16 @@ describe Administrateur, type: :model do
|
||||||
it { expect(Administrateur.reset_password('123', '12345678').errors).not_to be_empty }
|
it { expect(Administrateur.reset_password('123', '12345678').errors).not_to be_empty }
|
||||||
it { expect(Administrateur.reset_password(reset_password_token, '').errors).not_to be_empty }
|
it { expect(Administrateur.reset_password(reset_password_token, '').errors).not_to be_empty }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#feature_enabled?' do
|
||||||
|
let(:administrateur) { create(:administrateur) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(Features).to receive(:champ_pj_allowed_for_admin_ids)
|
||||||
|
.and_return([administrateur.id])
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(administrateur.feature_enabled?(:yolo)).to be_falsey }
|
||||||
|
it { expect(administrateur.feature_enabled?(:champ_pj_allowed)).to be_truthy }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue