Hi everyone,
Long-time reader and browser, first-time poster!Ā Ā š
I'm one of the Canvas Account Admins at our institution, and I've been tasked with giving a member of our institution a subaccount admin role with very narrow parametersāeasy enough through permissions. However, we've discovered we have some LTIs installed (with placement in the Account Navigation) that, if this user visits those pages, they can edit things we don't want them to be able to.
After consulting with our CSM, unfortunately our only option is to use custom JavaScript to hide those LTI links within that specific subaccount. On one hand, this is fine because the admins on our team who would normally access those LTIs at the subaccount level are still able to at the root account, and elsewhere in other accounts if neededāhiding them from all admin users only in this specific subaccount shouldn't be an issue. On the other hand, I've seen custom CSS and JS used at other institutions to highly detrimental effect, so it's something I'm extremely wary about and cautious of.
That said, while I'm admittedly no coder or developer, I've enlisted the help of ChatGPT and have been testing in beta, and have found some JS that, so far, seems to work well:
Ā
// Defer until all page elements load
window.onload = function () {
// Select and hide the child elements of the div with the ID "left-side"
var leftSideElement = document.getElementById('left-side');
if (leftSideElement) {
var ltiSelectors = '.context_external_tool_332, ' +
'.context_external_tool_333, ' +
'.context_external_tool_573, ' +
'.context_external_tool_154';
var ltiElements = leftSideElement.querySelectorAll(ltiSelectors);
ltiElements.forEach(function (ltiElement) {
ltiElement.style.display = 'none';
});
}
};Ā
This actually works really well! However, the problem I'm running into is that one of the LTIsāCredentialsāalso uses the same class defined in the JS above (context_external_tool_154) in both the Account Navigation Menu and in individual Course Navigation Menus. That means, within this specific subaccount, if I want to hide the admin-level Credentials LTI (where the user could edit things), it also hides the course-level Credentials link in the course navigation menu.Ā This canāt work, because we want faculty in this subaccount to have the option to use Credentials if they choose to.
Normally, my next step would be, "ok, let's figure out how to target the Account Navigation Menu and exclude the Course Navigation Menu." Problem is...Canvas doesn't seem to differentiate them at all in terms of HTML on the page. Here's the HTML structure of the Account Navigation Menu:
Ā
<div id="main" class="ic-Layout-columns">
<div class="ic-Layout-watermark"></div>
<div id="left-side"
class="ic-app-course-menu ic-sticky-on list-view"
style="display: block"
>
<div id="sticky-container" class="ic-sticky-frame">
<nav role="navigation" aria-label="Admin Navigation Menu"><ul id="section-tabs">...Nav Links Here...</ul></nav>
</div>
</div>Ā
And here's the HTML structure of the Course Navigation Menu:
<div id="main" class="ic-Layout-columns">
<div class="ic-Layout-watermark"></div>
<div id="left-side"
class="ic-app-course-menu ic-sticky-on list-view"
style="display: block"
>
<div id="sticky-container" class="ic-sticky-frame">
<span id="section-tabs-header-subtitle" class="ellipsis">2023 Fall Semester</span>
<nav role="navigation" aria-label="Courses Navigation Menu"><ul id="section-tabs">...Nav Links Here...</ul></nav>
</div>
</div>The only difference I'm seeing is in the "aria-label" attribute, but in all my testing, there's no way (at least, none that I've found to work so far) to target the