mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Admin can create enterprise relationships with permissions
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
angular.module("ofn.admin").controller "AdminEnterpriseRelationshipsCtrl", ($scope, EnterpriseRelationships, Enterprises) ->
|
||||
$scope.EnterpriseRelationships = EnterpriseRelationships
|
||||
$scope.Enterprises = Enterprises
|
||||
$scope.permissions = {}
|
||||
|
||||
$scope.create = ->
|
||||
$scope.EnterpriseRelationships.create($scope.parent_id, $scope.child_id)
|
||||
$scope.EnterpriseRelationships.create($scope.parent_id, $scope.child_id, $scope.permissions)
|
||||
|
||||
$scope.delete = (enterprise_relationship) ->
|
||||
if confirm("Are you sure?")
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
angular.module("ofn.admin").factory 'EnterpriseRelationships', ($http, enterprise_relationships) ->
|
||||
new class EnterpriseRelationships
|
||||
create_errors: ""
|
||||
all_permissions: [
|
||||
'add_products_to_order_cycle'
|
||||
'manage_products'
|
||||
]
|
||||
|
||||
constructor: ->
|
||||
@enterprise_relationships = enterprise_relationships
|
||||
|
||||
create: (parent_id, child_id) ->
|
||||
$http.post('/admin/enterprise_relationships', {enterprise_relationship: {parent_id: parent_id, child_id: child_id}}).success (data, status) =>
|
||||
create: (parent_id, child_id, permissions) ->
|
||||
permissions = (name for name, enabled of permissions when enabled)
|
||||
$http.post('/admin/enterprise_relationships', {enterprise_relationship: {parent_id: parent_id, child_id: child_id, permissions_list: permissions}}).success (data, status) =>
|
||||
@enterprise_relationships.unshift(data)
|
||||
@create_errors = ""
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
%tr
|
||||
%td
|
||||
%select{name: "enterprise_relationship_parent_id", "ng-model" => "parent_id", "ng-options" => "e.id as e.name for e in Enterprises.my_enterprises"}
|
||||
%td permits
|
||||
%td
|
||||
%div{"ng-repeat" => "permission in EnterpriseRelationships.all_permissions"}
|
||||
%label
|
||||
%input{type: "checkbox", "ng-model" => "permissions[permission]"}
|
||||
{{ EnterpriseRelationships.permission_presentation(permission) }}
|
||||
%td
|
||||
%select{name: "enterprise_relationship_child_id", "ng-model" => "child_id", "ng-options" => "e.id as e.name for e in Enterprises.all_enterprises"}
|
||||
%td.actions
|
||||
|
||||
@@ -38,11 +38,16 @@ feature %q{
|
||||
|
||||
visit admin_enterprise_relationships_path
|
||||
select 'One', from: 'enterprise_relationship_parent_id'
|
||||
check 'can add products to order cycle from'
|
||||
check 'can manage the products of'
|
||||
uncheck 'can manage the products of'
|
||||
select 'Two', from: 'enterprise_relationship_child_id'
|
||||
click_button 'Create'
|
||||
|
||||
page.should have_relationship e1, e2
|
||||
EnterpriseRelationship.where(parent_id: e1, child_id: e2).should be_present
|
||||
page.should have_relationship e1, e2, ['can add products to order cycle from']
|
||||
er = EnterpriseRelationship.where(parent_id: e1, child_id: e2).first
|
||||
er.should be_present
|
||||
er.permissions.map(&:name).should == ['add_products_to_order_cycle']
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user