mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
For OC, fetch all enterprises we have access to, including those via E2E relationships
This commit is contained in:
@@ -330,7 +330,7 @@ angular.module('order_cycle', ['ngResource'])
|
||||
}])
|
||||
|
||||
.factory('Enterprise', ['$resource', ($resource) ->
|
||||
Enterprise = $resource('/admin/enterprises/:enterprise_id.json', {}, {'index': {method: 'GET', isArray: true}})
|
||||
Enterprise = $resource('/admin/enterprises/for_order_cycle/:enterprise_id.json', {}, {'index': {method: 'GET', isArray: true}})
|
||||
|
||||
{
|
||||
Enterprise: Enterprise
|
||||
|
||||
@@ -6,6 +6,11 @@ module Admin
|
||||
create.after :grant_management
|
||||
|
||||
helper 'spree/products'
|
||||
include OrderCyclesHelper
|
||||
|
||||
def for_order_cycle
|
||||
@collection = order_cycle_permitted_enterprises
|
||||
end
|
||||
|
||||
|
||||
def bulk_update
|
||||
@@ -53,7 +58,7 @@ module Admin
|
||||
end
|
||||
|
||||
def collection_actions
|
||||
[:index, :bulk_update]
|
||||
[:index, :for_order_cycle, :bulk_update]
|
||||
end
|
||||
|
||||
def load_methods_and_fees
|
||||
|
||||
@@ -76,6 +76,7 @@ class AbilityDecorator
|
||||
can [:admin, :index, :read, :edit, :update, :bulk_update, :clone], OrderCycle do |order_cycle|
|
||||
user.enterprises.include? order_cycle.coordinator
|
||||
end
|
||||
can [:for_order_cycle], Enterprise
|
||||
|
||||
can [:index, :create], EnterpriseFee
|
||||
can [:admin, :read, :edit, :bulk_update, :destroy], EnterpriseFee do |enterprise_fee|
|
||||
|
||||
@@ -33,12 +33,15 @@ Openfoodnetwork::Application.routes.draw do
|
||||
|
||||
namespace :admin do
|
||||
resources :order_cycles do
|
||||
post :bulk_update, :on => :collection, :as => :bulk_update
|
||||
post :bulk_update, on: :collection, as: :bulk_update
|
||||
get :clone, on: :member
|
||||
end
|
||||
|
||||
resources :enterprises do
|
||||
post :bulk_update, :on => :collection, :as => :bulk_update
|
||||
collection do
|
||||
get :for_order_cycle
|
||||
post :bulk_update, as: :bulk_update
|
||||
end
|
||||
|
||||
resources :producer_properties do
|
||||
post :update_positions, on: :collection
|
||||
|
||||
@@ -451,12 +451,10 @@ feature %q{
|
||||
create(:enterprise_relationship, parent: distributor_permitted, child: distributor_managed,
|
||||
permissions_list: [:add_to_order_cycle])
|
||||
end
|
||||
let!(:product_managed) { create(:product, supplier: supplier_managed) }
|
||||
let!(:product_permitted) { create(:product, supplier: supplier_permitted) }
|
||||
|
||||
before do
|
||||
product = create(:product, supplier: supplier_managed)
|
||||
product.distributors << distributor_managed
|
||||
product.save!
|
||||
|
||||
@new_user = create_enterprise_user
|
||||
@new_user.enterprise_roles.build(enterprise: supplier_managed).save
|
||||
@new_user.enterprise_roles.build(enterprise: distributor_managed).save
|
||||
@@ -492,6 +490,9 @@ feature %q{
|
||||
select 'Permitted supplier', from: 'new_supplier_id'
|
||||
click_button 'Add supplier'
|
||||
|
||||
select_incoming_variant supplier_managed, 0, product_managed.master
|
||||
select_incoming_variant supplier_permitted, 1, product_permitted.master
|
||||
|
||||
select 'Managed distributor', from: 'order_cycle_coordinator_id'
|
||||
click_button 'Add coordinator fee'
|
||||
select 'Managed distributor fee', from: 'order_cycle_coordinator_fee_0_id'
|
||||
@@ -574,4 +575,11 @@ feature %q{
|
||||
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def select_incoming_variant(supplier, exchange_no, variant)
|
||||
page.find("table.exchanges tr.supplier-#{supplier.id} td.products input").click
|
||||
check "order_cycle_incoming_exchange_#{exchange_no}_variants_#{variant.id}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -327,7 +327,7 @@ describe 'OrderCycle services', ->
|
||||
inject ($injector, _$httpBackend_)->
|
||||
Enterprise = $injector.get('Enterprise')
|
||||
$httpBackend = _$httpBackend_
|
||||
$httpBackend.whenGET('/admin/enterprises.json').respond [
|
||||
$httpBackend.whenGET('/admin/enterprises/for_order_cycle.json').respond [
|
||||
{id: 1, name: 'One', supplied_products: [1, 2]}
|
||||
{id: 2, name: 'Two', supplied_products: [3, 4]}
|
||||
{id: 3, name: 'Three', supplied_products: [5, 6]}
|
||||
|
||||
@@ -264,7 +264,7 @@ module Spree
|
||||
end
|
||||
|
||||
it 'should have the ability administrate and create enterpises' do
|
||||
should have_ability([:admin, :index, :create], for: Enterprise)
|
||||
should have_ability([:admin, :index, :for_order_cycle, :create], for: Enterprise)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user