3

We have multiple sites defined in Craft and we want content editors to only have visibility of things that are relevant to the one site they've been assigned to.

I've set this up using a User Group for each site that has permissions to edit only that site. But there are three major goals I am unable to achieve at the same time:

GOAL 1: it must be as easy as possible to add more sites in future when needed.

To achieve GOAL 1, all sites use the same Globals, Sections and Entry Types. This works well but contradicts with GOAL 2.

GOAL 2: content editors should not be able to see folders and files belonging to other sites.

I can't achieve GOAL 2 at the moment because all sites using the same Globals, Sections and Entry Types means they all use the same Asset Fields and therefore all content editors need access to the same Volumes.

Asset Locations are defined using {site.handle} in the path, so file locations are siloed by site just fine. But content editors can see folders and files belonging to other sites on the Assets screen.

The only way I can see of achieving GOAL 2 is to have a separate Volume for each site... but I think that would go against GOAL 1 because then every site would need to use different Asset Fields and consequently we'd need a complicated set up within Entry Types and Globals of duplicated Asset Fields that are hidden conditionally by User Group.

Does anyone know of a way to achieve GOAL 2 without majorly contradicting GOAL 1?

GOAL 3: content editors should be able to invite colleagues to their site. But they should not have visibility of user groups or content editors belonging to other sites.

I can't see a way of achieving this. It looks like everyone who has access to the Users screen can see all users and user groups. Does anyone know a way around this?

1 Answer 1

3

Neither assets nor users support multi-site. Their content does (i.e. custom fields for assets and/or users can be "translatable"), but all assets and users will always propagate to all the sites in the install, and there's no feasible way to prevent that.

The only way I can see of achieving GOAL 2 is to have a separate Volume for each site

Correct, the only way to effectively "hide" assets from specific users or user groups, is to create a separate volume (and not give those users or groups access to it).

You don't necessarily have to create different/multiple asset fields, though – just give your asset fields access to all the volumes in their "Sources" setting, and make sure the "Show unpermitted volumes" setting is unchecked.

A clean-ish way to do it could be to create one user group per site, with the appropriate permissions configured (i.e. "User Group Site A" is able to view "Volume Site A", etc). Users can belong to multiple groups, which means that a single user could be put into one or multiple groups giving them the appropriate per-site permissions.

Adding a new site with a setup like that should still be relatively simple – add the site, add the new volume, and then create the new user group giving access to that site and volume.

content editors should be able to invite colleagues to their site. But they should not have visibility of user groups or content editors belonging to other sites.

I'm not seeing a way to achieve this without resorting to some kind of "hack".

Potentially, you could create a custom Yii module, that taps into the craft\elements\User::EVENT_REGISTER_SOURCES event, checks the user group for the currently logged-in user, and unsets the sources for the other user groups, that this user shouldn't have access to.

Another, and possible simpler option could be to use the CPCSS and Control Panel Body Classes plugins in order to hide the unwanted user group sources from the CP.

Neither of these options should be considered "safe". I.e. if a user in site A has access to the Users section and is a bit savvy, they will probably find a way to view the data that they're not supposed to see.

IMO, in the end both of these problems are signals that your use-case might be a bad fit for Craft CMS's multi-site feature. When it comes to assets and users, the system is not designed to work the way you need it to, and trying to work around that might not be the best idea (especially long-term, or if it's crucial that assets or users data does not "leak" between sites).

Personally, I'd either live with the limitations, or if that's a non-starter, consider if these sites would work better as standalone Craft installs (potentially using the same codebase/repo, to reduce maintenance/upkeep).

3
  • 1
    The last paragraph was my thought exactly. Build once, deploy many. One code-base with separate installs for every site. Environment variables for everything that's different between the sites (primary domain etc).
    – MoritzLost
    Commented Apr 8 at 10:35
  • 1
    Brilliant answer - glad to be set right about asset fields. I'd got it in my head they can only use one Volume at a time because the one I quickly looked at had "Restrict assets to a single location" checked 🤦‍♂️ Commented Apr 8 at 22:35
  • 1
    I take the point about the use-case being a bad fit for Craft. But using different Volumes as you suggested leaves just the one limitation which we can live with - it's far easier for us to centrally manage Users than have a separate Craft install per site. And maybe User management permissions will become more granular some time in the future. Commented Apr 8 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.