TBing 有的有的,给你提供一个思路,未经实践,仅供参考。
2.20.19 LTS完善主题模板判断用户角色,可以通过sec:authorize
来控制显示,参考halo-dev/halo7322。
使用AnnotationSetting
(参考:元数据表单定义)来给tag添加一个只给某个角色或者某个用户查看的元数据,然后在主题模板中获取元数据。
---
apiVersion: v1alpha1
kind: AnnotationSetting
metadata:
generateName: annotation-setting-
spec:
targetRef:
group: content.halo.run
kind: Tag
formSchema:
- $formkit: "text"
name: "authorize"
label: "授权用户"
value: "super-role"
<a th:with="requiredRole=${#annotations.getOrDefault(tag, 'authorize', 'super-role')}"
th:attr="'sec:authorize'='hasRole(\'' + ${requiredRole} + '\')'"
href="/console"
target="_blank"
data-i18n="user.console"
aria-label="access the management console">
</a>
但是具有很大的局限性,只能添加一个角色,即要么只能一个角色能看,要么就只有一个角色不能看,原因如下:
