mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Reuse #superadmin? in Delayed Job Web route
This moves #superadmin? to the user decorator so it can be reused outside FeatureFlags.
This commit is contained in:
@@ -11,25 +11,17 @@ class FeatureFlags
|
||||
#
|
||||
# @return [Boolean]
|
||||
def product_import_enabled?
|
||||
superadmin?
|
||||
user.superadmin?
|
||||
end
|
||||
|
||||
# Checks whether the "Enterprise Fee Summary" is enabled for the specified user
|
||||
#
|
||||
# @return [Boolean]
|
||||
def enterprise_fee_summary_enabled?
|
||||
superadmin?
|
||||
user.superadmin?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :user
|
||||
|
||||
# Checks whether the specified user is a superadmin, with full control of the
|
||||
# instance
|
||||
#
|
||||
# @return [Boolean]
|
||||
def superadmin?
|
||||
user.has_spree_role?('admin')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -74,6 +74,14 @@ Spree.user_class.class_eval do
|
||||
credit_cards.where(is_default: true).first
|
||||
end
|
||||
|
||||
# Checks whether the specified user is a superadmin, with full control of the
|
||||
# instance
|
||||
#
|
||||
# @return [Boolean]
|
||||
def superadmin?
|
||||
has_spree_role?('admin')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def limit_owned_enterprises
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Openfoodnetwork::Application.routes.draw do
|
||||
namespace :admin do
|
||||
|
||||
authenticated :spree_user, -> user { user.has_spree_role?('admin') } do
|
||||
authenticated :spree_user, -> user { user.superadmin? } do
|
||||
mount DelayedJobWeb, at: '/delayed_job'
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ describe FeatureFlags do
|
||||
describe '#product_import_enabled?' do
|
||||
context 'when the user is superadmin' do
|
||||
before do
|
||||
allow(user).to receive(:has_spree_role?).with('admin') { true }
|
||||
allow(user).to receive(:superadmin?) { true }
|
||||
end
|
||||
|
||||
it 'returns true' do
|
||||
@@ -17,7 +17,7 @@ describe FeatureFlags do
|
||||
|
||||
context 'when the user is not superadmin' do
|
||||
before do
|
||||
allow(user).to receive(:has_spree_role?).with('admin') { false }
|
||||
allow(user).to receive(:superadmin?) { false }
|
||||
end
|
||||
|
||||
it 'returns false' do
|
||||
|
||||
@@ -162,4 +162,22 @@ describe Spree.user_class do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#superadmin?' do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
context 'when the user has an admin spree role' do
|
||||
before { user.spree_roles << Spree::Role.create(name: 'admin') }
|
||||
|
||||
it 'returns true' do
|
||||
expect(user.superadmin?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the user does not have an admin spree role' do
|
||||
it 'returns false' do
|
||||
expect(user.superadmin?).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user