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

feat: 自定义菜单添加访问权限控制 #480

Merged
merged 1 commit into from
Nov 7, 2023

Conversation

RelaxedDong
Copy link
Contributor

背景:

admin可添加自定义页面,或者是其它系统进行内嵌,菜单栏目前没有权限控制,有安全性、越权等相关问题。

解决:

使用Django内部的权限系统,调用user.get_all_permissions(),渲染自定义菜单栏时,判断对应的菜单栏是否在用户权限列表中。

SIMPLEUI_CONFIG的menus`,主菜单,或者是多级菜单支持配置permission字段,作为权限控制

案例:

如果用户拥有:account.view_accountmodel权限,那么菜单1-1-1无权访问

SIMPLEUI_CONFIG = {
    'system_keep': True,
    'dynamic': True,  # 设置是否开启动态菜单, 默认为False. 如果开启, 则会在每次用户登陆时动态展示菜单内容
    'menus': [{
        'name': '主菜单',
        'icon': 'fa fa-desktop',
        'permission': 'account.view_accountmodel',
        'models': [
            {
                'name': '菜单1',
                'icon': 'fa fa-file',
                'models': [{
                    'name': '菜单1-1',
                    'icon': 'far fa-surprise',
                    'models': [
                        {
                            'permission': 'account.view_accountmodel2',
                            'name': '菜单1-1-1',
                            'url': 'https://www.iqiyi.com/dianshiju/',
                        },
                        {
                            'name': '菜单1-1-1',
                            'icon': 'far fa-surprise',
                            'url': 'https://zhidao.baidu.com/',
                            'models': [
                                {
                                    'name': '菜单1-1-1-1',
                                    'permission': 'account.view_accountmodel',
                                    'url': 'https://www.iqiyi.com/dianshiju/',
                                }]
                        }
                    ]
                }
                ]
            }
        ]
    }]
}

效果:

image

@RelaxedDong RelaxedDong changed the base branch from master to dev October 22, 2023 13:23
@newpanjing newpanjing merged commit 1f63aac into newpanjing:dev Nov 7, 2023
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

Successfully merging this pull request may close these issues.

2 participants