mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge duplicate Spree::User#superadmin? into existing Spree::admin?
This commit is contained in:
@@ -53,11 +53,11 @@ module Spree
|
||||
spree_roles.where(name: role_in_question.to_s).any?
|
||||
end
|
||||
|
||||
# Checks whether the specified user is a superadmin, with full control of the instance
|
||||
def admin?
|
||||
has_spree_role?('admin')
|
||||
end
|
||||
|
||||
|
||||
# handle_asynchronously will define send_reset_password_instructions_with_delay.
|
||||
# If handle_asynchronously is called twice, we get an infinite job loop.
|
||||
handle_asynchronously :send_reset_password_instructions unless method_defined? :send_reset_password_instructions_with_delay
|
||||
@@ -120,14 +120,6 @@ module Spree
|
||||
end
|
||||
end
|
||||
|
||||
# Checks whether the specified user is a superadmin, with full control of the
|
||||
# instance
|
||||
#
|
||||
# @return [Boolean]
|
||||
def superadmin?
|
||||
has_spree_role?('admin')
|
||||
end
|
||||
|
||||
def generate_spree_api_key!
|
||||
self.spree_api_key = SecureRandom.hex(24)
|
||||
save!
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Openfoodnetwork::Application.routes.draw do
|
||||
namespace :admin do
|
||||
|
||||
authenticated :spree_user, -> user { user.superadmin? } do
|
||||
authenticated :spree_user, -> user { user.admin? } do
|
||||
mount DelayedJobWeb, at: '/delayed_job'
|
||||
end
|
||||
|
||||
|
||||
@@ -167,31 +167,16 @@ describe Spree.user_class do
|
||||
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
|
||||
describe '#admin?' do
|
||||
it 'returns true when the user has an admin spree role' do
|
||||
expect(create(:admin_user).admin?).to be_truthy
|
||||
end
|
||||
|
||||
context 'when the user does not have an admin spree role' do
|
||||
it 'returns false' do
|
||||
expect(user.superadmin?).to eq(false)
|
||||
end
|
||||
it 'returns false when the user does not have an admin spree role' do
|
||||
expect(create(:user).admin?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
before(:all) { Spree::Role.create name: 'admin' }
|
||||
|
||||
it '#admin?' do
|
||||
expect(create(:admin_user).admin?).to be_truthy
|
||||
expect(create(:user).admin?).to be_falsey
|
||||
end
|
||||
|
||||
context '#destroy' do
|
||||
it 'can not delete if it has completed orders' do
|
||||
order = build(:order, completed_at: Time.zone.now)
|
||||
|
||||
Reference in New Issue
Block a user