Ok, I solved this now with some Panel CSS and JS. Here’s how I did it:
In my blueprints, I added a help text to some section that shows the role of the currently logged in user:
mysection:
type: pages
help: "{{ kirby.user.role.name }}"
Then I created a panel CSS that makes this help footer invisible (but still readable to JS) and that hides the third entry in the status change panel. Also, it adds a style that makes this entry visible again if my panel pages main body has a data-role
attribute of admin
or reviewer
:
.k-collection-footer, .k-collection-help, .k-collection-help p {
visibility: hidden;
height: 0;
margin: 0;
}
.k-field-name-status li:nth-child(3) {
display: none;
}
body[data-role = "admin"] .k-field-name-status li:nth-child(3),
body[data-role = "reviewer"] .k-field-name-status li:nth-child(3) {
display: block;
}
Lastly I added some Panel JS that detects the hidden footer and its content and assigns that content as a data attribute to the panel page’s body tag. As soon as the body tag gets a data-role
attribute of admin
or reviewer
, the “Published” option becomes available again in the status change panel, otherwise it doesn’t:
const userRoleInterval = setInterval(() => {
const userP = document.querySelector('.k-section-name-draftprojects footer p');
if(userP) {
if(userP.textContent === "admin" || userP.textContent === "reviewer") {
document.body.setAttribute("data-role", userP.textContent);
}
clearInterval(userRoleInterval);
}
}, 10);
Note: This needs to use the setInterval()
method as Vue will take a moment to make the panel page available. If anyone knows how to detect the Vue lifecycle hooks from the outside via Vanilla JS, please let me know. Also, this setup works only if there is a single help text on the page. Otherwise you would maybe need to prefix the help text with a specific prefix that JS could detect.
I think I will open a feature request for a dedicated changeStatusToListed
permission, as my solution is more hacky then I would like to (and is of course not secure, but for my specific project it’s sufficient).