Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mangei opened this issue Sep 24, 2015 · 0 comments
Open

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

mangei opened this issue Sep 24, 2015 · 0 comments

Comments

@mangei
Copy link

mangei commented Sep 24, 2015

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'
        };
    }]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant