Beispiel #1
0
        public static async Task <TeamChannel> AddChannelAsync(string accessToken, HttpClient httpClient, string groupId, string displayName, string description, bool isPrivate, string ownerUPN)
        {
            var channel = new TeamChannel()
            {
                Description = description,
                DisplayName = displayName,
            };

            if (isPrivate)
            {
                channel.MembershipType = "private";
            }
            if (isPrivate)
            {
                channel.Type = "#Microsoft.Teams.Core.channel";
                var user = await GraphHelper.GetAsync <User>(httpClient, $"v1.0/users/{ownerUPN}", accessToken);

                channel.Members = new List <TeamChannelMember>();
                channel.Members.Add(new TeamChannelMember()
                {
                    Roles = new List <string> {
                        "owner"
                    }, UserIdentifier = $"https://graph.microsoft.com/beta/users/('{user.Id}')"
                });
                return(await GraphHelper.PostAsync <TeamChannel>(httpClient, $"beta/teams/{groupId}/channels", channel, accessToken));
            }
            else
            {
                return(await GraphHelper.PostAsync <TeamChannel>(httpClient, $"v1.0/teams/{groupId}/channels", channel, accessToken));
            }
        }
Beispiel #2
0
        public static async Task <TeamChannel> AddChannelAsync(string accessToken, HttpClient httpClient, string groupId, string displayName, string description, bool isPrivate, string ownerUPN, bool isFavoriteByDefault)
        {
            var channel = new TeamChannel()
            {
                Description = description,
                DisplayName = displayName,
            };

            if (isPrivate)
            {
                channel.MembershipType = "private";
            }
            if (isPrivate)
            {
                channel.Type = "#Microsoft.Graph.channel";
                var user = await GraphHelper.GetAsync <User>(httpClient, $"v1.0/users/{ownerUPN}", accessToken);

                channel.Members = new List <TeamChannelMember>();
                channel.Members.Add(new TeamChannelMember()
                {
                    Roles = new List <string> {
                        "owner"
                    }, UserIdentifier = $"https://{PnPConnection.Current.GraphEndPoint}/v1.0/users('{user.Id}')"
                });
                return(await GraphHelper.PostAsync <TeamChannel>(httpClient, $"v1.0/teams/{groupId}/channels", channel, accessToken));
            }
            else
            {
                channel.IsFavoriteByDefault = isFavoriteByDefault;
                return(await GraphHelper.PostAsync <TeamChannel>(httpClient, $"v1.0/teams/{groupId}/channels", channel, accessToken));
            }
        }
        public async Task <TeamChannel> CreateOrGetChannelInfo(string channelId, string teamId)
        {
            var teamChannel = await _meetingDBService.GetChannelById(channelId);

            if (teamChannel == null)
            {
                var channel = await GraphClient.Teams[teamId].Channels[channelId].Request().GetAsync();
                var plan    = await _planTaskService.GetOrCreatePlanByChannel(teamId, channelId);

                var channelFolder = await _fileService.GetChannelFolder(teamId, channelId);

                var noteSection = await _notesService.GetChannelSection(teamId, channel.DisplayName);

                teamChannel = new TeamChannel
                {
                    Id               = channel.Id,
                    Name             = channel.DisplayName,
                    PlanId           = plan.Id,
                    OnenoteSectionId = noteSection.Id,
                    FolderId         = channelFolder.Id
                };
                await _meetingDBService.AddChannel(teamChannel);
            }
            return(teamChannel);
        }
Beispiel #4
0
        public static TeamChannel AddChannel(string accessToken, HttpClient httpClient, string groupId, string displayName, string description, bool isPrivate)
        {
            var channel = new TeamChannel()
            {
                Description = description,
                DisplayName = displayName,
            };

            if (isPrivate)
            {
                channel.MembershipType = "private";
            }
            return(GraphHelper.PostAsync <TeamChannel>(httpClient, $"beta/teams/{groupId}/channels", channel, accessToken).GetAwaiter().GetResult());
        }
Beispiel #5
0
        private static string UpdateTeamChannel(TeamChannel channel, string teamId, JToken existingChannel, string accessToken)
        {
            var channelId            = existingChannel["id"].ToString();
            var channelDisplayName   = existingChannel["displayName"].ToString();
            var identicalChannelName = channel.DisplayName == channelDisplayName;

            // Prepare the request body for the Channel update
            var channelToUpdate = new
            {
                description = channel.Description,
                // You can't update a channel if its displayName is exactly the same, so remove it temporarily.
                displayName = identicalChannelName ? null : channel.DisplayName,
            };

            // Updating isFavouriteByDefault is currently not supported on either endpoint. Using the beta endpoint results in an error.
            HttpHelper.MakePatchRequestForString($"{GraphHelper.MicrosoftGraphBaseURI}v1.0/teams/{teamId}/channels/{channelId}", channelToUpdate, HttpHelper.JsonContentType, accessToken);

            return(channelId);
        }
Beispiel #6
0
        private static string CreateTeamChannel(PnPMonitoredScope scope, TeamChannel channel, string teamId, string accessToken)
        {
            var channelToCreate = new
            {
                channel.Description,
                channel.DisplayName,
                channel.IsFavoriteByDefault
            };

            var channelId = GraphHelper.CreateOrUpdateGraphObject(scope,
                                                                  HttpMethodVerb.POST,
                                                                  $"{GraphHelper.MicrosoftGraphBaseURI}beta/teams/{teamId}/channels",
                                                                  channelToCreate,
                                                                  HttpHelper.JsonContentType,
                                                                  accessToken,
                                                                  "NameAlreadyExists",
                                                                  CoreResources.Provisioning_ObjectHandlers_Teams_Team_ChannelAlreadyExists,
                                                                  "displayName",
                                                                  channel.DisplayName,
                                                                  CoreResources.Provisioning_ObjectHandlers_Teams_Team_ProvisioningError,
                                                                  false);

            return(channelId);
        }
        public async Task <Meeting> InitializeMeeting(string title, string teamId, TeamChannel channel, DateTime date, string[] agendas)
        {
            var folder = await _fileService.CreateMeetingFolder(teamId, channel.FolderId, $"{title}-{date.ToString("yyyy-MM-dd")}");

            var bucket = await _planTaskService.CreateBucket(channel.PlanId, $"{title}-{date.ToString("yyyy-MM-dd")}");

            var meeting = new Meeting()
            {
                TeamId    = teamId,
                ChannelId = channel.Id,
                FolderId  = folder.Id,
                BucketId  = bucket.Id,
                StartTime = date,
                NoteTitle = $"{title} - {date.ToString("MM/dd/yyyy")}",
                Agendas   = agendas.Select(o => new Agenda()
                {
                    Title = o
                }).ToList()
            };

            await _meetingDBService.AddMeeting(meeting);

            return(meeting);
        }
Beispiel #8
0
 public static TeamChannel UpdateChannel(HttpClient httpClient, string accessToken, string groupId, string channelId, TeamChannel channel)
 {
     return(GraphHelper.PatchAsync(httpClient, accessToken, $"beta/teams/{groupId}/channels/{channelId}", channel).GetAwaiter().GetResult());
 }
Beispiel #9
0
 public static async Task <TeamChannel> UpdateChannelAsync(HttpClient httpClient, string accessToken, string groupId, string channelId, TeamChannel channel)
 {
     return(await GraphHelper.PatchAsync(httpClient, accessToken, $"beta/teams/{groupId}/channels/{channelId}", channel));
 }
Beispiel #10
0
        public void Initialize()
        {
            if (!TestCommon.AppOnlyTesting())
            {
                const string teamTemplateName = "Sample Engineering Team";
                _teamNames.Add(teamTemplateName);
                _jsonTemplate = "{ \"[email protected]\": \"https://graph.microsoft.com/beta/teamsTemplates(\'standard\')\", \"visibility\": \"Private\", \"displayName\": \"" + teamTemplateName + "\", \"description\": \"This is a sample engineering team, used to showcase the range of properties supported by this API\", \"channels\": [ { \"displayName\": \"Announcements 📢\", \"isFavoriteByDefault\": true, \"description\": \"This is a sample announcements channel that is favorited by default. Use this channel to make important team, product, and service announcements.\" }, { \"displayName\": \"Training 🏋️\", \"isFavoriteByDefault\": true, \"description\": \"This is a sample training channel, that is favorited by default, and contains an example of pinned website and YouTube tabs.\", \"tabs\": [ { \"[email protected]\": \"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps(\'com.microsoft.teamspace.tab.web\')\", \"name\": \"A Pinned Website\", \"configuration\": { \"contentUrl\": \"https://docs.microsoft.com/en-us/microsoftteams/microsoft-teams\" } }, { \"[email protected]\": \"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps(\'com.microsoft.teamspace.tab.youtube\')\", \"name\": \"A Pinned YouTube Video\", \"configuration\": { \"contentUrl\": \"https://tabs.teams.microsoft.com/Youtube/Home/YoutubeTab?videoId=X8krAMdGvCQ\", \"websiteUrl\": \"https://www.youtube.com/watch?v=X8krAMdGvCQ\" } } ] }, { \"displayName\": \"Planning 📅 \", \"description\": \"This is a sample of a channel that is not favorited by default, these channels will appear in the more channels overflow menu.\", \"isFavoriteByDefault\": false }, { \"displayName\": \"Issues and Feedback 🐞\", \"description\": \"This is a sample of a channel that is not favorited by default, these channels will appear in the more channels overflow menu.\" } ], \"memberSettings\": { \"allowCreateUpdateChannels\": true, \"allowDeleteChannels\": true, \"allowAddRemoveApps\": true, \"allowCreateUpdateRemoveTabs\": true, \"allowCreateUpdateRemoveConnectors\": true }, \"guestSettings\": { \"allowCreateUpdateChannels\": false, \"allowDeleteChannels\": false }, \"funSettings\": { \"allowGiphy\": true, \"giphyContentRating\": \"Moderate\", \"allowStickersAndMemes\": true, \"allowCustomMemes\": true }, \"messagingSettings\": { \"allowUserEditMessages\": true, \"allowUserDeleteMessages\": true, \"allowOwnerDeleteMessages\": true, \"allowTeamMentions\": true, \"allowChannelMentions\": true }, \"installedApps\": [ { \"[email protected]\": \"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps(\'com.microsoft.teamspace.tab.vsts\')\" }, { \"[email protected]\": \"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps(\'1542629c-01b3-4a6d-8f76-1938b779e48d\')\" } ] }";

                const string teamName = @"Unallowed &_,.;:/\""!@$%^*[]+=&'|<>{}-()?#¤`´~¨ Ääkköset";
                _teamNames.Add(teamName);
                var security = new TeamSecurity
                {
                    AllowToAddGuests = false,
                    Owners           = { new TeamSecurityUser {
                                             UserPrincipalName = ConfigurationManager.AppSettings["SPOUserName"]
                                         } }
                };
                var funSettings = new TeamFunSettings
                {
                    AllowCustomMemes      = true,
                    AllowGiphy            = true,
                    AllowStickersAndMemes = true,
                    GiphyContentRating    = TeamGiphyContentRating.Moderate
                };
                var guestSettings = new TeamGuestSettings
                {
                    AllowCreateUpdateChannels = false,
                    AllowDeleteChannels       = false
                };
                var memberSettings = new TeamMemberSettings
                {
                    AllowDeleteChannels               = false,
                    AllowAddRemoveApps                = true,
                    AllowCreateUpdateChannels         = true,
                    AllowCreateUpdateRemoveConnectors = false,
                    AllowCreateUpdateRemoveTabs       = true
                };
                var messagingSettings = new TeamMessagingSettings
                {
                    AllowChannelMentions     = true,
                    AllowOwnerDeleteMessages = true,
                    AllowTeamMentions        = false,
                    AllowUserDeleteMessages  = true,
                    AllowUserEditMessages    = true
                };
                var channel = new TeamChannel
                {
                    DisplayName         = "Another channel",
                    Description         = "Another channel description!",
                    IsFavoriteByDefault = true
                };
                var tab = new TeamTab
                {
                    DisplayName = "OneNote Tab",
                    TeamsAppId  = "0d820ecd-def2-4297-adad-78056cde7c78"/*,
                                                                         * Configuration = new TeamTabConfiguration
                                                                         * {
                                                                         * ContentUrl = "https://todo-improve-this-test-when-tab-resource-provisioning-has-been-implemented"
                                                                         * }*/
                };
                channel.Tabs.Add(tab);
                var message = new TeamChannelMessage
                {
                    Message = "Welcome to this awesome new channel!"
                };
                channel.Messages.Add(message);

                _team = new Team {
                    DisplayName = teamName, Description = "Testing creating mailNickname from a display name that has unallowed and accented characters", Visibility = TeamVisibility.Public, Security = security, FunSettings = funSettings, GuestSettings = guestSettings, MemberSettings = memberSettings, MessagingSettings = messagingSettings, Channels = { channel }
                };
            }
        }
Beispiel #11
0
 public async Task <int> AddChannel(TeamChannel teamChannel)
 {
     _showCaseDbContext.TeamChannels.Add(teamChannel);
     return(await _showCaseDbContext.SaveChangesAsync());
 }
        public async Task <Meeting> SetupMeetingEvent(string title, DateTime start, DateTime end, Meeting meeting, TeamChannel channel, IFormFile[] files, string[] attendees)
        {
            var attachments = new List <DriveItem>();

            var meetingAttendees = new List <MeetingAttendee>();
            var taskFiles        = new List <TaskFile>();

            if (files != null && files.Length > 0)
            {
                var users = new List <User>();

                foreach (var attendee in attendees)
                {
                    var graphUser = await _userService.GetUserByEmail(attendee);

                    users.Add(graphUser);

                    meetingAttendees.Add(new MeetingAttendee
                    {
                        Email     = attendee,
                        Name      = graphUser.UserPrincipalName,
                        MeetingId = meeting.Id
                    });
                }

                foreach (var file in files)
                {
                    using (var fileStram = file.OpenReadStream())
                    {
                        var uploadFile = await _fileService.UploadFile(meeting.TeamId, meeting.FolderId, file.FileName, fileStram);

                        attachments.Add(uploadFile);
                        await _planTaskService.CreatePreReadTaskForEachUser(channel.PlanId, meeting.BucketId, $"[Pre-reading] {file.FileName}", uploadFile, start, users.Select(i => i.Id).ToArray());

                        taskFiles.Add(new TaskFile
                        {
                            Location  = uploadFile.WebUrl,
                            Name      = uploadFile.Name,
                            MeetingId = meeting.Id
                        });
                    }
                }
            }

            var joinUrl = await _communicationService.CreateOnlineMeeting(title, start, (await _userService.Me()).Id);

            var model = new EmailTemplateViewModel()
            {
                Agendas     = meeting.Agendas.Select(a => a.Title),
                Attachments = attachments,
                JoinUrl     = joinUrl
            };

            var emailContent = await _viewRenderService.RenderToStringAsync("Templates/Invitation", model);

            var meetingEvent = await _calendarService.CreateEvent(title,
                                                                  DateTimeTimeZone.FromDateTime(start),
                                                                  DateTimeTimeZone.FromDateTime(end),
                                                                  emailContent,
                                                                  attendees.Select(mail =>
                                                                                   new Attendee
            {
                EmailAddress = new EmailAddress {
                    Address = mail
                },
                Type = AttendeeType.Required
            }),
                                                                  meeting,
                                                                  meeting.BucketId);

            meeting.EventId = meetingEvent.Id;
            await _meetingDBService.UpdateMeeting(meeting, meetingAttendees, taskFiles);

            return(meeting);
        }