Why does user permissions plugin not transform the response?

Same problem here. We faced this problem while we handled restricted field outputs inside populated API responses. The populated collection types structure in user permissions plugin is different, too.

Isn’t it rather advisable to change the native structure of the Strapi API and change the plugin response structure instead?
Or is it to be expected that the Strapi API adapts to the plugin API? After all, the recommended plugin currently has 4k weekly downloads. I think this shows that a unification of the APIs is desired here!

We decided at least to transform the response object inside extensions/user-permissions/strapi-server.js
Here an example how the code can look like for “find”:

module.exports = (plugin) => {
  plugin.controllers.user.find = async (ctx) => {
    data = await strapi.plugins["users-permissions"].services.user.fetchAll(
      ctx.query
    );

    return yourTransformFunction(data); // transform object here
  };

  return plugin;
};
1 Like