Skip to content

Has "all", "any" operator for authorities #42

@mangei

Description

@mangei

we implemented such an operator into cat-main-menu.js , but because of the new way the visibility is evaluated, we have to add this operator somewhere again.

with the new visiblity service, we also can implement this for buttons and actions.

This is the old code of cat-main-menu.js

angular.module('cat.directives.menu')
    .directive('catMainMenu', ['$mainMenu', '$rootScope', '$location', function CatMainMenuDirective($mainMenu, $rootScope, $location) {
        return {
            restrict: 'E',
            scope: {},
            link: function CatMainMenuLink(scope) {
                scope.menus = $mainMenu.getMenus();
                scope.isVisible = function (entry) {
                    var visible = false;
                    if (entry.isMenu() || entry.isGroup()) {
                        _.forEach(entry.getEntries(), function (subEntry) {
                            visible = visible || scope.isVisible(subEntry);
                        });
                        if (entry.isMenu()) {
                            _.forEach(entry.getGroups(), function (groups) {
                                visible = visible || scope.isVisible(groups);
                            });
                        }
                    } else {
                        return scope.isAllowed(entry);
                    }
                    return visible;
                };
                scope.isAllowed = function (entry) {
                    var rights = entry.getOptions().rights;
                    var rightsOperator = entry.getOptions().rightsOperator || 'all';
                    if (!!rights) {
                        if (_.isArray(rights)) {
                            var allowed = true;
                            if ('all' === rightsOperator) {
                                for (var i = 0; i < rights.length; i++) {
                                    allowed = allowed && $rootScope.isAllowed(rights[i]);
                                }
                            } else if ('any' === rightsOperator) {
                                allowed = false;
                                for (var j = 0; j < rights.length; j++) {
                                    allowed = allowed || $rootScope.isAllowed(rights[j]);
                                }
                            }
                            return allowed;
                        }
                        return $rootScope.isAllowed(rights);
                    }
                    return true;
                };

                scope.isActive = function (path) {
                    return $location.path().substr(0, path.length) === path;
                };
            },
            templateUrl: 'template/cat-main-menu.tpl.html'
        };
    }]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions