[root@adminset ~]# cat ./adminset/templates/main-sidebar.html
<script>
$(document).ready(function(){
$('.loading').fadeOut();
$.get('/accounts/permission/user_permission/',function(data){
if (data) {
var obj = data.split(",");
for (var i=0;i<obj.length;i++){
document.getElementById(obj[i]).style.display = "block";
}
}
});
});
</script>
<aside class="main-sidebar">
<!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar">
<div style="height: 60px">
</div>
<!-- Sidebar user panel (optional) -->
<!-- /.search form -->
<!-- Sidebar Menu -->
<ul class="sidebar-menu" id="sidebar-menu">
{# <li class="header">HEADER</li>#}
<!-- Optionally, you can add icons to the links -->
{# <li><a href="{% url 'index' %}"><i class="fa fa-dashboard"></i> <span>首页面板</span></a></li>#}
{% if request.user.is_superuser %}
--------request.user.is_superuser----------
015208
True
--------request.user.is_superuser----------
<h1>{{request.user.is_superuser}}</h1>
<li id="navi"><a href="{% url 'navi' %}"><i class="fa fa-link"></i> <span>站点导航</span></a></li>
<li id="cmdb"><a href="{% url 'cmdb' %}"><i class="fa fa-database"></i> <span>资产管理</span></a></li>
<!--<li id="appconf"><a href="{% url 'appconf' %}"><i class="fa fa-outdent"></i> <span>应用管理</span></a></li>
<li id="setup"><a href="{% url 'job_list' %}"><i class="fa fa-cogs"></i> <span>任务编排</span></a></li>
<li id="delivery"><a href="{% url 'delivery' %}"><i class="fa fa-retweet"></i> <span>持续交付</span></a></li>
<li id="monitor"><a href="{% url 'monitor' %}"><i class="fa fa-television"></i> <span>监控平台</span></a></li>-->
<li id="accounts"><a href="{% url 'user_list' %}"><i class="fa fa-users"></i> <span>用户管理</span></a></li>
<li id="config"><a href="{% url 'config' %}"><i class="fa fa fa-cog"></i> <span>系统配置</span></a></li>
{% else %}
<li id="navi" style="display: none"><a href="{% url 'navi' %}"><i class="fa fa-link"></i> <span>站点导航</span></a></li>
<li id="cmdb" style="display: none"><a href="{% url 'cmdb' %}"><i class="fa fa-database"></i> <span>资产管理</span></a></li>
<li id="appconf" style="display: none"><a href="{% url 'appconf' %}"><i class="fa fa-outdent"></i> <span>应用管理</span></a></li>
<li id="setup" style="display: none"><a href="{% url 'job_list' %}"><i class="fa fa-cogs"></i> <span>任务编排</span></a></li>
<li id="delivery" style="display: none"><a href="{% url 'delivery' %}"><i class="fa fa-retweet"></i> <span>持续交付</span></a></li>
<li id="monitor" style="display: none"><a href="{% url 'monitor' %}"><i class="fa fa-television"></i> <span>监控平台</span></a></li>
<li id="accounts" style="display: none"><a href="{% url 'user_list' %}"><i class="fa fa-users"></i> <span>用户管理</span></a></li>
<li id="config" style="display: none"><a href="{% url 'config' %}"><i class="fa fa fa-cog"></i> <span>系统配置</span></a></li>
{% endif %}
</ul>
<!-- /.sidebar-menu -->
</section>
<!-- /.sidebar -->
</aside>
权限认证模块,
此模块会先判断用户是否是管理员(is_superuser为True),如果是管理员,则具有所有权限,
如果不是管理员则获取request.user和request.path两个参数,判断两个参数是否匹配,匹配则有权限,反之则没有。