angular.module('orderCloud')
    .controller('SecurityCtrl', SecurityController)
;

function SecurityController($exceptionHandler, $stateParams, toastr, Assignments, AvailableProfiles, OrderCloudSDK) {
    var vm = this;
    vm.assignments = Assignments;
    vm.profiles = AvailableProfiles;
    vm.buyerid = $stateParams.buyerid;
    vm.usergroupid = $stateParams.usergroupid;
    vm.adminusergroupid = $stateParams.adminusergroupid;

    vm.updateAssignment = function(scope) {
        if (scope.profile.selected) {
            var assignment = {
                securityProfileID: scope.profile.ID,
                buyerID: $stateParams.buyerid,
                userGroupID: $stateParams.usergroupid || $stateParams.adminusergroupid
            };
            OrderCloudSDK.SecurityProfiles.SaveAssignment(assignment)
                .then(function() {
                    toastr.success(scope.profile.Name + ' was enabled.');
                })
                .catch(function(ex) {
                    scope.profile.selected = false;
                    $exceptionHandler(ex);
                });
        } else {
            var options = {
                buyerID: $stateParams.buyerid,
                userGroupID: $stateParams.usergroupid || $stateParams.adminusergroupid
            };
            OrderCloudSDK.SecurityProfiles.DeleteAssignment(scope.profile.ID, options)
                .then(function() {
                    toastr.success(scope.profile.Name + ' was disabled.');
                })
                .catch(function(ex) {
                    scope.profile.selected = true;
                    $exceptionHandler(ex);
                });
        }
    };
}

angular.module('orderCloud')
    .controller('SecurityCtrl', SecurityController)
;

function SecurityController($exceptionHandler, $stateParams, toastr, Assignments, AvailableProfiles, OrderCloudSDK) {
    var vm = this;
    vm.assignments = Assignments;
    vm.profiles = AvailableProfiles;
    vm.buyerid = $stateParams.buyerid;
    vm.usergroupid = $stateParams.usergroupid;
    vm.adminusergroupid = $stateParams.adminusergroupid;

    vm.updateAssignment = function(scope) {
        if (scope.profile.selected) {
            var assignment = {
                securityProfileID: scope.profile.ID,
                buyerID: $stateParams.buyerid,
                userGroupID: $stateParams.usergroupid || $stateParams.sellerusergroupid
            };
            OrderCloudSDK.SecurityProfiles.SaveAssignment(assignment)
                .then(function() {
                    toastr.success(scope.profile.Name + ' was enabled.');
                })
                .catch(function(ex) {
                    scope.profile.selected = false;
                    $exceptionHandler(ex);
                });
        } else {
            var options = {
                buyerID: $stateParams.buyerid,
                userGroupID: $stateParams.usergroupid || $stateParams.sellerusergroupid
            };
            OrderCloudSDK.SecurityProfiles.DeleteAssignment(scope.profile.ID, options)
                .then(function() {
                    toastr.success(scope.profile.Name + ' was disabled.');
                })
                .catch(function(ex) {
                    scope.profile.selected = true;
                    $exceptionHandler(ex);
                });
        }
    };
}

Fix seller user group level security
Fix seller user group level security

After refactoring Admin* components to Seller* components we forgot to update the seller
user group security controller to use "sellerusergroupid" $stateParam instead of the old
"adminusergroupid".
