Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added creation options so we can create team site with the graph api for application and delegated permissions #1220

Conversation

danielpastoor
Copy link
Contributor

Feature for using the graph api to create a team site with group for both delegeted and app permissions.

What I did was I'm currently using the delegeted way to create a team site with group with language but I got a feature request from my organisation to also support ResourceBehaviorOptions.

But we can't set ResourceBehaviorOptions when using the delegated way. So I was looking at the api calls from sharepoint and found that they post the following data with creating a team site with group:

call: _api/GroupSiteManager/CreateGroupEx
{
    "displayName": "test test test test test v50",
    "alias": "testtesttesttesttestv500",
    "isPublic": false,
    "optionalParams": {
        "Description": "test test test test test v50",
        "Owners": {
            "results": [
                "danielpastoor@...."
            ]
        },
        "CreationOptions": {
            "results": [
                "AllowFileSharingForGuestUsers",
                "SPSiteLanguage:1043",
                "HubSiteId:00000000-0000-0000-0000-000000000000"
            ]
        },
        "Classification": ""
    },
}

Then I was curious what the meaning of the "CreationOptions" was.
Were I found out that it was also stored in the group when I get group with the graph api:

call: https://graph.microsoft.com/v1.0/groups/261c3090-2627-4949-b957-06627800bc6e
{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups/$entity",
    "id": "261c3090-2627-4949-b957-06627800bc6e",
    "deletedDateTime": null,
    "classification": null,
    "createdDateTime": "2023-07-05T07:53:51Z",
    "creationOptions": [
        "ProvisionGroupHomepage",
        "HubSiteId:00000000-0000-0000-0000-000000000000",
        "SPSiteLanguage:1043",
        "AllowFileSharingForGuestUsers"
    ],
    "description": "test test test test test v50",
    "displayName": "test test test test test v50",
    "expirationDateTime": null,
    "groupTypes": [
        "Unified"
    ],
    "isAssignableToRole": null,
    "mail": "testtesttesttesttestv500@....",
    "mailEnabled": true,
    "mailNickname": "testtesttesttesttestv500",
    "membershipRule": null,
    "membershipRuleProcessingState": null,
    "onPremisesDomainName": null,
    "onPremisesLastSyncDateTime": null,
    "onPremisesNetBiosName": null,
    "onPremisesSamAccountName": null,
    "onPremisesSecurityIdentifier": null,
    "onPremisesSyncEnabled": null,
    "preferredDataLocation": null,
    "preferredLanguage": null,
    "proxyAddresses": [
        "SMTP:testtesttesttesttestv500@...."
    ],
    "renewedDateTime": "2023-07-05T07:53:51Z",
    "resourceBehaviorOptions": [],
    "resourceProvisioningOptions": [],
    "securityEnabled": false,
    "securityIdentifier": "S-1-12-1-639381648-1229530663-1644582841-1857814648",
    "theme": null,
    "visibility": "Private",
    "serviceProvisioningErrors": [],
    "onPremisesProvisioningErrors": []
}

And if you look at the call response it contains the CreationOptions.
So then I did a request with the graph explorer to test this with delegated permissions if I can create a group with CreationOptions

call: Post: https://graph.microsoft.com/v1.0/groups
{
    "description": "testtesttesttesttestv556",
    "displayName": "testtesttesttesttestv556",
    "groupTypes": [
        "Unified"
    ],
    "mailEnabled": true,
    "mailNickname": "testtesttesttesttestv556",
    "securityEnabled": false,
    "creationOptions": [
        "ProvisionGroupHomepage",
        "HubSiteId:00000000-0000-0000-0000-000000000000",
        "SPSiteLanguage:1029",
        "AllowFileSharingForGuestUsers"
    ],
    "resourceBehaviorOptions": [
        "HideGroupInOutlook",
        "CalendarMemberReadOnly",
        "WelcomeEmailDisabled ",
        "AllowOnlyMembersToPost"
    ]
}

And it succeedded. And when I checked the sharepoint site language it was Czech.

Why I chose Czech. This is because it is a language I do not know and I would recognize the changed sharepoint url.
So I saw that the shared documents url now Sdilene%20dokumenty was.

Then I changed the code in the pnp.core.admin project to check if it works with App permissions and it did.

So that is the reason why I removed the sharepoint api call part and changed it all to the Graph api.

@danielpastoor
Copy link
Contributor Author

I'm currently changing the documentation for the pnp.core project and this will be included in my next commit.

Also I will test all options that are supported now

@codecov-commenter
Copy link

codecov-commenter commented Jul 5, 2023

Codecov Report

Patch coverage has no change and project coverage change: +2.15 🎉

Comparison is base (63545f3) 82.42% compared to head (5c9552e) 84.57%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1220      +/-   ##
==========================================
+ Coverage   82.42%   84.57%   +2.15%     
==========================================
  Files         416      624     +208     
  Lines       28590    43420   +14830     
==========================================
+ Hits        23565    36723   +13158     
- Misses       5025     6697    +1672     

see 357 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@danielpastoor
Copy link
Contributor Author

So this pull request also include support for the creation of a team site with the following options:

Delegated:

  • AllowOnlyMembersToPost
  • CalendarMemberReadOnly
  • ConnectorsDisabled
  • HideGroupInOutlook
  • SubscribeMembersToCalendarEventsDisabled
  • SubscribeNewGroupMembers
  • WelcomeEmailDisabled
  • Members

App Only:
-Language

  • SiteDesignId
  • HubSiteId
  • SensitivityLabelId
  • SiteAlias

…ing a Team Site With group because it is supported now
@danielpastoor
Copy link
Contributor Author

@jansenbe Do you maybe have time to check my pull-request?

@jansenbe
Copy link
Contributor

@danielpastoor : I've planned this for next week. Thx for your contribution 👍

@jansenbe jansenbe self-assigned this Jul 18, 2023
@jansenbe jansenbe added the area:admin 📜 Admin library related label Jul 18, 2023
@jansenbe
Copy link
Contributor

@danielpastoor : nice work, really useful! Thanks for sharing 🔝💪👍🚀

@jansenbe jansenbe merged commit 9d6acda into pnp:dev Jul 18, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:admin 📜 Admin library related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants