简体   繁体   中英

How do I find out which tab/location a Plan falls under?

I'm trying to create a full clone of a Microsoft Team Site using Microsoft Graph by doing a basic clone of the team site and then using the API to copy and configure all of the content.

My first task is to get the Planner copied across. I've made it far enough to copy all available Plans, Buckets, and Tasks.

My problem is I can't figure out:

1) Which tab/location the plan belonged to in the old team

2) How to put the new plan into said tab/location in the new team

public async Task<IEnumerable<Channel>> GetChannels(string accessToken, string teamId) {

    string endpoint = $"{GraphRootUri}/teams/{teamId}/channels";
    HttpResponseMessage response =
        await ServiceHelper.SendRequest(HttpMethod.Get, endpoint, accessToken); //old functionality of stolen method - ignore these two lines

    string destinationTeamID = "Teamid";

    //find all plans
    endpoint = $"{GraphRootUri}/groups/{teamId}/planner/plans";
    HttpResponseMessage responsePlans = await ServiceHelper.SendRequest(HttpMethod.Get, endpoint, accessToken);
    var plansIn = await ParseList<Planner>(responsePlans);

    //the following two sections are just me seeing if I can find references to the plans
    endpoint = $"{GraphRootUri}/teams/{teamId}/channels";
    HttpResponseMessage responseChannels = await ServiceHelper.SendRequest(HttpMethod.Get, endpoint, accessToken);
    var inChannels = await responseChannels.Content.ReadAsStringAsync();

    endpoint = $"{GraphRootUri}/teams/{teamId}/channels/mychannellocation/tabs";
    HttpResponseMessage responseTabs = await ServiceHelper.SendRequest(HttpMethod.Get, endpoint, accessToken);
    var inTabs = await responseTabs.Content.ReadAsStringAsync();

    //the following code copies the plans, buckets and tasks
    foreach (Planner plan in plansIn) {

        //first we get everything from the previous team plan

        //grab tasks from the previous plan
        endpoint = $"{GraphRootUri}/planner/plans/{plan.id}/tasks";
        HttpResponseMessage responseTasks = await ServiceHelper.SendRequest(HttpMethod.Get, endpoint, accessToken);
        var inTasks = await ParseList<plannerTask>(responseTasks);

        //get all buckets
        endpoint = $"{GraphRootUri}/planner/plans/{plan.id}/buckets";
        HttpResponseMessage responseBuckets = await ServiceHelper.SendRequest(HttpMethod.Get, endpoint, accessToken);
        var inBuckets = await ParseList<plannerBucket>(responseBuckets);

        endpoint = $"{GraphRootUri}/planner/tasks";
        //HttpResponseMessage responseTasks = await ServiceHelper.SendRequest(HttpMethod.Get, endpoint, accessToken);
        //  .content .Deserialize<plannerPlan>(); ;

        //then we start to create everything in the new team
        //create the plan in the new team
        endpoint = $"{GraphRootUri}/planner/plans";
        var sendPlanResponse =
            await ServiceHelper.SendRequest(HttpMethod.Post, endpoint, accessToken, new plannerStub(plan, destinationTeamID));
        var newPlanString = await sendPlanResponse.Content.ReadAsStringAsync();
        //get the created plan
        var newPlan = JsonConvert.DeserializeObject<Planner>(newPlanString);

        //create buckets in the new team
        Dictionary<string, string> bucketIdMap = new Dictionary<string, string>();
        foreach (plannerBucket bucket in inBuckets) {
            endpoint = $"{GraphRootUri}/planner/buckets";
            var outBucket = new plannerBucketStub(bucket, newPlan.id);
            var sendBucketResponse =
                await ServiceHelper.SendRequest(HttpMethod.Post, endpoint, accessToken, new plannerStub(plan, destinationTeamID));
            //get the created Bucket
            var newBucket = JsonConvert.DeserializeObject<plannerBucket>(await sendPlanResponse.Content.ReadAsStringAsync());
            bucketIdMap[bucket.id] = newBucket.id; //so we can send the tasks to our new bucket

        }

        //create tasks in the new team
        foreach (plannerTask task in inTasks) {
            endpoint = $"{GraphRootUri}/planner/tasks";
            task.bucketId = bucketIdMap[task.bucketId];
            task.planId = newPlan.id;
            var sendBucketResponse = await ServiceHelper.SendRequest(HttpMethod.Post, endpoint, accessToken, task);

        }

        //put planner in appropriate tab - stuck at this point
        endpoint = $"{GraphRootUri}/teams/{newPlan.id}/channels/";

    }
}

The previous code is what I have so far, does anyone know how I can find out where the old planner lived and how to put the new planner in the same place on a new team?

The destination team right now is a clone of the first team.

My best guess is to use the 'contexts' of the planner, but I can't find any documentation on this. Does anyone know how to address this? edit. I've tried using the contexts to no effect, I am officially lost.

Incidentally, if anyone has found a code repository that does a full clone of Microsoft Teams sites that I've been too thick to find please let me know

To anyone that's given my question enough time to read this far, thank you so much for your help, any advice would be appreciated at this point.

In the Teams and Planner integration, links to Plans are maintained by Teams, so your best bet is to look there to see if you can find a Plan id somewhere. Unfortunately I'm not familiar with those APIs.

On Planner, there are two optional properties that help navigate back to Teams. First is the context on Plan, which contains "displayNameSegments" property. This should match the team/channel name structure. The second on is the contextDetails on PlanDetails, which contain a URL for the team. These properties are only available in beta. They are not guaranteed to be filled in and they can be inaccurate.

Finding a Tab Position

You can detect the position of a Channel Tab by parsing the results returned by /v1.0/teams/{group-id}/channels/{channel-id}/tabs . The resulting teamsTab array will contain the tabs in reverse order (first tab last):

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#teams('{{id}}')/channels('{id}')/tabs",
  "value": [
    {
      "id": "{id}",
      "displayName": "Tab #2",
      "webUrl": "{url}",
      "configuration": {
        "entityId": null,
        "contentUrl": null,
        "removeUrl": null,
        "websiteUrl": null,
        "wikiTabId": 1,
        "wikiDefaultTab": true,
        "hasContent": false
      }
    },
    {
      "id": "{id}",
      "displayName": "Tab #1",
      "webUrl": "{url}",
      "configuration": {
        "entityId": "{plan-id}",
        "contentUrl": "{url}",
        "removeUrl": "{url}",
        "websiteUrl": "{url}",
        "dateAdded": "2019-02-04T17:38:11.079Z"
      }
    }
  ]
}

Keep in mind that Conversations and Files are not actually tabs and their position is fixed. As such, neither will show up in the /tabs result. Your code should assume that your tab order actually starts at the 3rd tab position in the UI.

Setting a Tab position

In order to duplicate the order of the pinned tabs, you'll need to add the tabs in the order you want them. If you need to reorder existing tabs, you'll need to first remove them and recreate them in the order you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM