概述
两种思路:
- 通过修改html代码,控制相关控件的显示,来实现权限控制;
- 通过修改velocity 文件来调整控件显示;
自定义HTML隐藏附件下载和页面导出按钮
在confluence上面的工具栏,点击【设置】-【General Configuration】-【Custom HTML】-"At end of the BODY"添加的代码如下:
<script type="text/javascript">
$(document).ready(function(){
$('body').bind("DOMNodeInserted",function(e){
if(AJS.params.spaceKey=="**") // **表示空间标识
{
if(AJS.params.canRemovePage==false) //当用户没有删除页面的权限时
{
$('.cp-control-panel-download').hide(); //隐藏可以预览的附件(word或pdf)下载按钮
$('.cp-button').hide(); //隐藏不能预览的附件(压缩文件或者其他不支持预览的)下载按钮
$(".filename").attr("disabled",true).css("pointer-events","none"); //把文件列表模式下的附件设置为灰色
$('head').append('<style> @media print{html, body{display:none} } </style> ');//禁用页面打印
$('body').attr('oncontextmenu','self.event.returnValue=false'); //禁用右键菜单
$('body').attr('onselectstart','return false'); //禁用选中文字
}
}
})
AJS.toInit(function(){
if(AJS.params.spaceKey=="**")
{
if(AJS.params.canRemovePage==false)
{
AJS.$('#action-export-word-link').hide(); //隐藏导出为word按钮
AJS.$('#action-export-pdf-link').hide(); //隐藏导出为pdf按钮
AJS.$('#view-attachments-link').hide(); //隐藏附件按钮
$('head').append('<style> @media print{html, body{display:none} } </style> ');//禁用页面打印
$('body').attr('oncontextmenu','self.event.returnValue=false'); //禁用右键菜单
$('body').attr('onselectstart','return false'); //禁用选中文字
}
}
});})
</script>
Hide the download button on the preview page
Space Tools–Look and feel–Layout–Content Layouts—Page Layout
<style type="text/css">
.cp-control-panel-download {
display:none !important;
}
.cp-waiting-message-download {
display:none !important;
}
a.download-all-link {
display: none !important;
}
a#download-all-link {
display: none !important;
}
</style>
Hide attachment button
Space Tools–Look and feel–Layout–Content Layouts—Main Layout
#if ($userAccessor.hasMembership('confluence-administrators', $helper.action.remoteUser.name))
#else
<script type="text/javascript">
AJS.toInit(function(){
AJS.$('#view-attachments-link').hide();
AJS.$('#view-in-hierarchy-link').hide();
AJS.$('#content-metadata-attachments').hide();
});
</script>
#end
#if ($userAccessor.hasMembership('confluence-administrators', $helper.action.remoteUser.name))
#else
<script type="text/javascript">
AJS.toInit(function(){
AJS.$('#space-tools-menu-trigger').hide();
});
</script>
#end
disable right mouse click
Space Tools–Look and feel–Layout–Content Layouts—Page Layout
<script type="application/javascript">
content_dom = document.getElementsByClassName("confluence-embedded-file");
for (var i = 0; i < content_dom.length; i++) {
content_dom[i].oncontextmenu = function () {
return false;
}
}
a_dom = document.querySelectorAll('a[data-linked-resource-type="attachment"]')
for (var i = 0; i < a_dom.length; i++) {
a_dom[i].oncontextmenu = function () {
return false;
}
}
</script>
print out a blank page
Space Tools–Look and feel–Layout–Content Layouts—Page Layout
<style type="text/css" media="print">
body { visibility: hidden; display: none }
</style>
Disable attachments for a whole Space
修改 listattachmentsforspace.vm
文件,参考Disable attachments for a whole Space
Disable attachments for a specific page
修改 attachments-table.vm
文件,参考Disable attachments for a specific page