public OperationResultWithData <IEnumerable <ScoShortcutDto> > GetShortcuts() { try { if (!LmsCompany.GetSetting <bool>(LmsCompanySettingNames.EnableMyContent)) { return(OperationResultWithData <IEnumerable <ScoShortcutDto> > .Error("Operation is not enabled.")); } var param = Session.LtiSession.LtiParam; var ac = this.GetUserProvider(); var lmsUser = _lmsUserModel.GetOneByUserIdAndCompanyLms(param.lms_user_id, LmsCompany.Id).Value; var contentService = new ContentService(Logger, ac); IEnumerable <ScoShortcut> shortcuts = contentService.GetShortcuts(new ScoShortcutType[] { ScoShortcutType.content, ScoShortcutType.my_content }); var result = shortcuts.Select(x => new ScoShortcutDto { ScoId = x.ScoId, Type = x.Type, Name = Resources.ScoShortcutNames.ResourceManager.GetString(x.Type.Replace('-', '_')), // TRICK: AC trick to change my-content to my_content }); return(result.ToSuccessResult()); } catch (Exception ex) { string errorMessage = GetOutputErrorMessage("ContentApi-GetShortcuts", ex); return(OperationResultWithData <IEnumerable <ScoShortcutDto> > .Error(errorMessage)); } }
public OperationResult GetDownloadLink(string scoId) { try { var ac = this.GetUserProvider(); var contentService = new ContentService(Logger, ac); var helper = new ContentControllerHelper <ScoContentDto>(Logger, contentService, new ScoContentDtoMapper()); var param = Session.LtiSession.LtiParam; var lmsUser = _lmsUserModel.GetOneByUserIdAndCompanyLms(param.lms_user_id, LmsCompany.Id).Value; if (lmsUser == null) { throw new EdugameCloud.Lti.Core.WarningMessageException($"No user with id {param.lms_user_id} found in the database."); } string breezeToken = MeetingSetup.ACLogin(LmsCompany, param, lmsUser, ac).BreezeSession; return(helper.GetDownloadAsZipLink(scoId, breezeToken)); } catch (Exception ex) { string errorMessage = GetOutputErrorMessage("ContentApi-GetDownloadLink", ex); return(OperationResultWithData <IEnumerable <ScoContentDto> > .Error(errorMessage)); } }
private async Task CreateAnnouncement( LmsMeetingType meetingType, ILmsLicense lmsCompany, ILtiParam param, MeetingDTOInput meetingDto) { if (!lmsCompany.ShowAnnouncements.GetValueOrDefault() || string.IsNullOrEmpty(param.context_title)) { return; } var announcementTitle = string.Format( "A new {0} room was created for course {1}", meetingNames[meetingType], param.context_title); string announcementMessage = GetAnnouncementMessage(meetingType, meetingDto, param.referer); switch (lmsCompany.LmsProviderId) { case (int)LmsProviderEnum.Canvas: var lmsUser = LmsUserModel.GetOneByUserIdAndCompanyLms(param.lms_user_id, lmsCompany.Id).Value; var token = UsersSetup.IsTeacher(param, lmsCompany) && !string.IsNullOrEmpty(lmsUser.Token) ? lmsUser.Token : lmsCompany.AdminUser.Return(a => a.Token, string.Empty); await CanvasApi.CreateAnnouncement( lmsCompany.LmsDomain, token, param.course_id, announcementTitle, announcementMessage); break; case (int)LmsProviderEnum.Blackboard: BlackboardApi.CreateAnnouncement(param.course_id.ToString(), param.lms_user_id, lmsCompany.GetLMSSettings(Settings), announcementTitle, announcementMessage); break; case (int)LmsProviderEnum.AgilixBuzz: // string error; // this.dlapApi.CreateAnnouncement( // credentials, // param.course_id, // announcementTitle, // announcementMessage, // out error); break; } }
public async Task <(string url, string breezeSession)> JoinRecording(ILmsLicense lmsCompany, LtiParamDTO param, string recordingUrl, IAdobeConnectProxy provider, string mode = null) { LmsUserDTO lmsUserDto = null; var acRecordingScoResult = provider.GetScoByUrl(recordingUrl); if (!acRecordingScoResult.Success) { logger.Error(string.Format("[AdobeConnectProxy Error] {0}. Recording url:{1}", acRecordingScoResult.Status.GetErrorInfo(), recordingUrl)); throw new AdobeConnectException(acRecordingScoResult.Status); } var lmsUser = lmsUserModel.GetOneByUserIdAndCompanyLms(param.lms_user_id, lmsCompany.Id).Value; if (lmsUser == null) { throw new Core.WarningMessageException(string.Format("No user with id {0} found in the database.", param.lms_user_id)); } var courseMeetings = this.lmsCourseMeetingModel.GetByCompanyAndScoId(lmsCompany, acRecordingScoResult.ScoInfo.FolderId, 0); // for AC provisioning courseMeeting.scoId() is used, so here we can take only first record if Dynamic provisioning is enabled for at least one meeting // if sync is enabled then all meetings with the same scoId should have the same users roster and the same value of EnableDynamicProvisioning property var courseMeeting = courseMeetings.FirstOrDefault(x => x.EnableDynamicProvisioning); if (courseMeeting != null && (LmsMeetingType)courseMeeting.LmsMeetingType != LmsMeetingType.StudyGroup && lmsCompany.UseSynchronizedUsers) { var lmsUserDtoRes = await usersSetup.GetOrCreateUserWithAcRole(lmsCompany, provider, param, courseMeeting, param.lms_user_id); lmsUserDto = lmsUserDtoRes.Data; if (!lmsUserDtoRes.IsSuccess) { throw new Core.WarningMessageException( string.Format( "[Dynamic provisioning] Could not create user, id={0}. Message: {1}", param.lms_user_id, lmsUserDtoRes.Message)); } meetingSetup.ProcessDynamicProvisioning(provider, lmsCompany, courseMeeting, lmsUser, lmsUserDto); } var loginResult = meetingSetup.ACLogin(lmsCompany, param, lmsUser, provider); string breezeToken = loginResult.BreezeSession; meetingSetup.ProcessGuestAuditUsers(provider, lmsCompany, acRecordingScoResult.ScoInfo.FolderId, loginResult.User.PrincipalId, param, () => courseMeetings); var baseUrl = lmsCompany.AcServer + "/" + recordingUrl; var breezeSession = breezeToken ?? string.Empty; var url = string.Format( "{0}?{1}{2}{3}", baseUrl, mode != null ? string.Format("pbMode={0}", mode) : string.Empty, mode != null && !lmsCompany.LoginUsingCookie.GetValueOrDefault() ? "&" : string.Empty, !lmsCompany.LoginUsingCookie.GetValueOrDefault() && breezeToken != null ? "session=" + breezeToken : string.Empty); return(url, breezeSession); }
public override async Task <OperationResultWithData <List <LmsUserDTO> > > GetUsers(Dictionary <string, object> licenseSettings, string courseId, ILtiUserListParam param = null) { if (licenseSettings == null) { throw new ArgumentNullException(nameof(licenseSettings)); } if (string.IsNullOrEmpty((string)licenseSettings[LmsUserSettingNames.Token])) { Logger.WarnFormat("[GetD2LUsers]: Admin Token does not exist for LmsCompany key: {1}.", licenseSettings[LmsLicenseSettingNames.LicenseKey]); throw new WarningMessageException(Resources.Messages.NoLicenseAdmin); } string[] tokens = ((string)licenseSettings[LmsUserSettingNames.Token]).Split(' '); // get course users list var classlistEnrollments = d2lApiService.GetApiObjects <List <ClasslistUser> >( tokens[0], tokens[1], (string)licenseSettings[LmsLicenseSettingNames.LmsDomain], string.Format( d2lApiService.EnrollmentsClasslistUrlFormat, (string)this.settings.BrightspaceApiVersion, courseId), licenseSettings); // mapping to LmsUserDTO var result = new List <LmsUserDTO>(); if (classlistEnrollments != null) { // get enrollments - this information contains user roles var enrollmentsList = new List <OrgUnitUser>(); PagedResultSet <OrgUnitUser> enrollments = null; do { enrollments = d2lApiService.GetApiObjects <PagedResultSet <OrgUnitUser> >( tokens[0], tokens[1], (string)licenseSettings[LmsLicenseSettingNames.LmsDomain], string.Format( d2lApiService.EnrollmentsUrlFormat, (string)this.settings.BrightspaceApiVersion, courseId) + (enrollments != null ? "?bookmark=" + enrollments.PagingInfo.Bookmark : string.Empty), licenseSettings); if (enrollments == null || enrollments.Items == null) { var error = "Incorrect API call or returned data. Please contact site administrator"; Logger.Error("[D2L Enrollments]: Object returned from API has null value"); return(OperationResultWithData <List <LmsUserDTO> > .Error(error)); } enrollmentsList.AddRange(enrollments.Items); } while (enrollments.PagingInfo.HasMoreItems && !string.IsNullOrEmpty(enrollments.PagingInfo.Bookmark)); string currentLmsUserId = param?.lms_user_id; // current user is not enrolled to this course (user is admin) -> add him to user list if (AllowAdminAdditionToCourse && classlistEnrollments.All(x => x.Identifier != currentLmsUserId)) { var currentLmsUser = lmsUserModel.GetOneByUserIdAndCompanyLms(currentLmsUserId, (int)licenseSettings[LmsLicenseSettingNames.LicenseId]).Value; if ((currentLmsUser != null) && !string.IsNullOrEmpty(currentLmsUser.Token)) { string[] currentUserTokens = currentLmsUser.Token.Split(' '); var currentUserInfo = d2lApiService.GetApiObjects <WhoAmIUser>( currentUserTokens[0], currentUserTokens[1], (string)licenseSettings[LmsLicenseSettingNames.LmsDomain], string.Format(d2lApiService.WhoAmIUrlFormat, (string)this.settings.BrightspaceApiVersion), licenseSettings); if (currentUserInfo != null) { // var userInfo = d2lApiService.GetApiObjects <UserData>(tokens[0], tokens[1], (string)licenseSettings[LmsLicenseSettingNames.LmsDomain], string.Format(d2lApiService.GetUserUrlFormat, (string)this.settings.BrightspaceApiVersion, currentUserInfo.Identifier), licenseSettings); classlistEnrollments.Add( new ClasslistUser { Identifier = currentUserInfo.Identifier, Username = currentUserInfo.UniqueName, DisplayName = currentUserInfo.FirstName + " " + currentUserInfo.LastName, Email = userInfo.ExternalEmail, // TODO: is it OK?? }); } } } foreach (ClasslistUser enrollment in classlistEnrollments) { OrgUnitUser userInfo = enrollmentsList.FirstOrDefault(e => e.User.Identifier == enrollment.Identifier); var user = new LmsUserDTO { Id = enrollment.Identifier, Login = enrollment.Username, Name = enrollment.GetValidFullName(), Email = enrollment.Email ?? userInfo?.User.EmailAddress, LmsRole = userInfo != null ? userInfo.Role.Name : "Unknown", }; result.Add(user); } } return(result.ToSuccessResult()); }