pnp / PnP-Sites-Core

Microsoft 365 Dev PnP Core component (.NET) targeted for increasing developer productivity with CSOM based solutions.
Other
415 stars 642 forks source link

Associated groups from template should not be created #2127

Open heinrich-ulbricht opened 5 years ago

heinrich-ulbricht commented 5 years ago

Category

Environment

3.7.1903.0ö

Expected or Desired Behavior

When provisioning from a template I don't expect the associated groups of the template (Owner, Members, Visitors) to be provisioned. If anything I expect the members to be mapped to the (already existing, differently named) associated groups of the new site.

Observed Behavior

The associated groups from the template are being created thus you have every group two times, but with different site names. One is something like "Site template owners" and one is "Site newsite owners".

Steps to Reproduce

  1. export site as template using -All handler
  2. import from template into a new site using -All handler
  3. look at newsite/_layouts/15/groups.aspx
  4. see all Owner, Member and Visitor groups two times
SchauDK commented 5 years ago

I totally agree. This is something that has changed recently!!!! In the exported template the associated groups should be replaced with tokens. If no membership groups exist on the target site, default membership groups should be created.

jensotto commented 5 years ago

I don't agree with this assessment. I see no reason why associated groups specified in the template should not be created and assigned as associated groups if that's what is specified in the template. The purpose of the template is to define how a site should be provisioned, and for that to happen the groups need to be created and assigned as associated groups. If a diferent behaviour is required then the template needs to be modified for example by using tokens or removing the associated groups attributes. One imporvement that could be done is to check if the associated group titles could be translated to a token matching the default group names when extracting the template.

heinrich-ulbricht commented 5 years ago

@jensotto I like your idea for improvement, using tokens seems reasonable. And as soon as you implement this you will get into the situation where the groups already exist in the destination site. And if so my suggestion is to skip creating them anew and just use the ones already in place. Also I'm not quite sure if this ticket can be closed yet, but I have to look deeper into the accepted fix to come to a conclusion. Tokens really would be nice.

jensotto commented 5 years ago

@heinrich-ulbricht I don't see how the groups would be re-created. Am I missing something?

heinrich-ulbricht commented 5 years ago

@jensotto I'm having this in mind:

Situation adressed by the ticket:

The template Site My Template contains those associated groups:

Using PnP Templating cmdlets I save this site as template, the group names are part of the template.

Now I create a new destination site "Team Site" which after creation contains the following associated groups:

⚠️ Now I apply the template "My Template" to the site "Team Site". The resulting groups are:

I find this highly unintuitive. My expectation of the resulting groups in "Team Site" would still be:

No need for the groups from "My Template". (Or at least make this a command line switch to choose the desired behavior.)

Your proposal of using tokens:

Now if I understand you correctly with tokens this behavior would change. Those groups:

Will be represented like this in the exported template (not sure about the token name though):

When applying this to the site "Team Site" the token {sitetitle} would be replaced by "Team Site". So the groups are:

Now there I see the collision from a technical standpoint. Those groups already exist in "Team Site". The engine would have to handle this.

Interesting side observation that could complicate the matter. Right after creating a site the groups seem to have generic names for a minute or so, like this:

After waiting a bit the names are changed to the final name with site title.

Does this all make sense?

jensotto commented 5 years ago

Yes, that is how I understood this. Technically the groups are not re-created or duplicated. The groups are defined in the template and should therefore be provisioned. But I do see the issue it creates when applying the template without any modifications to a different site. I think a lot of the confusion would be addressed if we can implement a token in the associated groups. Maybe a switch to turn on or off extraction of associated groups could be added too.

heinrich-ulbricht commented 5 years ago

Another opportunity to cite @erwinvanhunen (which I will continue to do until eternity ;)):

the majority of people using PnP PowerShell are not coders, and do not necessarily have an understanding of the APIs and object models behind the scenes.

So let's accept this challenge to find the time to make this more intuitive 😃

heinrich-ulbricht commented 5 years ago

After looking more into this issue and the ongoing discussions I realized that my problem was not really that the new groups were created - @jensotto is right here, the engine behaves as expected. The problem was that the associated group titles were exported to the template in the first place which then lead to new groups being created (unexpectedly).