“New topic” button working incorrectly

The admins have added a CSS customization that looks like this:

body:not([class*="category-council-"]):not(.staff).closed-topic .reply, 
body:not([class*="category-council-"]):not(.staff).closed-topic #topic-footer-buttons .create, 
body:not([class*="category-council-"]):not(.staff).closed-topic .timeline-container .create, 
body:not([class*="category-council-"]):not(.staff).closed-topic #reply-control {
  display: none !important;
}

This appears to be ok at initial glance, but then I can see body.closed-topic is applied to the topic list… which really doesn’t make sense.

This class isn’t in Discourse by default, so tracking down another customization that adds that…

<script type="text/discourse-plugin" version="0.8">
const container = Discourse.__container__;
const controller = container.lookup("controller:topic");
const currentUser = api.getCurrentUser();

api.onPageChange(() => {

  if (!currentUser || currentUser.admin || currentUser.moderator || currentUser.trust_level != 4 ) {
    return;
  } else {
    let model = controller.get("model");
    
    document.querySelector("body").classList.add("closed-topic");
    
    if (model) {
      if (!model.closed) {
        document.querySelector("body").classList.remove("closed-topic");
      }
    }
  }

});
</script>

So here, if you’re logged in, not an admin, not a moderator, and are trust level 4… then it adds the closed-topic class to the page body.

This class is only removed if model.closed is false, which means… if it’s not a closed topic (or even if it’s not a topic at all) the closed-topic class will be applied.

This line:

document.querySelector("body").classList.add("closed-topic");

should probably be within if (model) because otherwise it’s applied even when there’s no model present (e.g., when you’re not within a topic)…

It seems the intention was to prevent trust level 4 users from replying to closed topics, but it’s applied too broadly.