Prevent users from changing their Full Names

I did take a look; hiding the field with the API can be done, but I can’t find any data I can rely on to know if that user is approved or not (in the preference page context) :thinking:

This is what I have for now.
I’m unsure if I should feel bad; maybe a little hacky here. :smile:

js
<script type="text/discourse-plugin" version="0.8">

const { setting } = require("discourse/lib/computed");

api.modifyClass("controller:preferences/account", {
  pluginId: "hide-name-in-preferences",

  get canEditName() {
    const enables_name = setting("enable_names");

    if (enables_name && this.isCurrentUser && !this.model.staff) {
      if (this.model.name) {
        // Hide only the input field (name is displayed)
        this.model.can_edit_name = false;
      } else {
        // Hide the whole section
        return false;
      }
    }

    return enables_name;
  },
});
    
</script>
1 Like