public static List <DocServiceParams.RecentDocument> GetRecentEditedDocument(bool forEdit, int count, string crumbsSeporator, IFileDao fileDao) { var recent = new List <DocServiceParams.RecentDocument>(); var activity = UserActivityManager.GetUserActivities(TenantProvider.CurrentTenantID, SecurityContext.CurrentAccount.ID, ProductEntryPoint.ID, null, UserActivityConstants.AllActionType, new[] { "OpenEditorFile" }, 0, 100); foreach (var entryId in activity.Select(userActivity => userActivity.ContentID.Substring("file_".Length))) { if (recent.Exists(r => r.ID.Equals(entryId))) { continue; } var fileAct = fileDao.GetFile(entryId); if (fileAct.RootFolderType == FolderType.TRASH) { continue; } if (!FileUtility.UsingHtml5(fileAct.Title)) { continue; } if (!Global.GetFilesSecurity().CanRead(fileAct)) { continue; } string uri; if (forEdit && Global.GetFilesSecurity().CanEdit(fileAct)) { uri = CommonLinkUtility.GetFileWebEditorUrl(fileAct.ID); } else { uri = CommonLinkUtility.GetFileWebViewerUrl(fileAct.ID); } var fileBreadCrumbs = Global.GetBreadCrumbs(fileAct.FolderID); recent.Add(new DocServiceParams.RecentDocument { ID = entryId, Title = fileAct.Title, Uri = CommonLinkUtility.GetFullAbsolutePath(uri), FolderPath = string.Join(crumbsSeporator, fileBreadCrumbs.Select(folder => folder.Title).ToArray()) }); if (recent.Count == count) { break; } } return(recent); }
public static File GetServiceParams(bool forEdit, object fileId, int version, bool itsNew, string shareLink, out DocServiceParams docServiceParams, bool forHtml5) { File file; const string crumbsSeporator = " > "; var breadCrumbs = new List <Folder>(); var recent = new ItemList <DocServiceParams.RecentDocument>(); var acesParams = new ItemList <DocServiceParams.Aces>(); var folderUrl = ""; var lastVersion = true; var checkLink = false; var canEdit = true; string fileExt; var documentType = string.Empty; using (var fileDao = Global.DaoFactory.GetFileDao()) { if (forEdit) { checkLink = CheckShareLink(shareLink, false, fileDao, out file); if (!checkLink && file == null) { file = fileDao.GetFile(fileId); } } else { if (version < 1) { var editLink = CheckShareLink(shareLink, fileDao, out file); checkLink = editLink <= FileShare.Read; if (checkLink) { canEdit = canEdit && editLink <= FileShare.ReadWrite; } else if (file == null) { file = fileDao.GetFile(fileId); } } else { file = fileDao.GetFile(fileId, version); if (file != null) { lastVersion = file.Version == fileDao.GetFile(fileId).Version; } } } if (file == null) { throw new Exception(FilesCommonResource.ErrorMassage_FileNotFound); } if (forHtml5 && !FileUtility.UsingHtml5(file.Title, forEdit)) { docServiceParams = new DocServiceParams(); return(file); } if (file.RootFolderType == FolderType.TRASH) { throw new Exception(FilesCommonResource.ErrorMassage_ViewTrashItem); } if (!checkLink) { canEdit &= Global.GetFilesSecurity().CanEdit(file); if (forEdit && !canEdit) { throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_EditFile); } if (!forEdit && !Global.GetFilesSecurity().CanRead(file)) { throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_ReadFile); } } fileExt = FileUtility.GetFileExtension(file.Title); canEdit = canEdit && (file.FileStatus & FileStatus.IsEditing) != FileStatus.IsEditing; if (forEdit && !canEdit) { throw new Exception(FilesCommonResource.ErrorMassage_UpdateEditingFile); } canEdit = canEdit && FileUtility.ExtsWebEdited.Contains(fileExt, Comparer); if (forEdit && !canEdit) { throw new Exception(FilesCommonResource.ErrorMassage_NotSupportedFormat); } if (!forEdit && !FileUtility.ExtsWebPreviewed.Contains(fileExt, Comparer)) { throw new Exception(FilesCommonResource.ErrorMassage_NotSupportedFormat); } if (forHtml5) { breadCrumbs = Global.GetBreadCrumbs(file.FolderID); recent = new ItemList <DocServiceParams.RecentDocument>(GetRecentEditedDocument(forEdit, 10, crumbsSeporator, fileDao)); if (FileUtility.DocumentExts.Contains(fileExt, Comparer)) { documentType = "text"; } else if (FileUtility.SpreadsheetExts.Contains(fileExt, Comparer)) { documentType = "spreadsheet"; } else if (FileUtility.PresentationExts.Contains(fileExt, Comparer)) { documentType = "presentation"; } } } var buttons = string.Empty; if (fileExt != ".pdf" && !FileUtility.PresentationExts.Contains(fileExt, Comparer)) { buttons += "download;"; } if (lastVersion && canEdit) { buttons += "save;edit;"; } if (SecurityContext.IsAuthenticated) { if (!checkLink && Global.EnableShare) { if (file.RootFolderType == FolderType.COMMON && Global.IsAdministrator) { buttons += "share;"; } else { if (file.RootFolderType == FolderType.USER && Equals(file.RootFolderId, Global.FolderMy)) { buttons += "share;"; } } } if (forHtml5) { buttons += "create;"; using (var folderDao = Global.DaoFactory.GetFolderDao()) { var parent = folderDao.GetFolder(file.FolderID); if (file.RootFolderType == FolderType.USER && file.RootFolderCreator != SecurityContext.CurrentAccount.ID && !Global.GetFilesSecurity().CanRead(parent)) { folderUrl = PathProvider.GetFolderUrl(Global.FolderShare, false, null); } else { folderUrl = PathProvider.GetFolderUrl(parent); } } try { var docService = ServiceLocator.Current.GetInstance <IFileStorageService>(); var aces = docService.GetSharedInfo(file.UniqID); foreach (var aceWrapper in aces) { string permission; switch (aceWrapper.Share) { case FileShare.Read: permission = FilesCommonResource.AceStatusEnum_Read; break; case FileShare.ReadWrite: permission = FilesCommonResource.AceStatusEnum_ReadWrite; break; default: continue; } var user = aceWrapper.SubjectName; if (aceWrapper.SubjectId.Equals(FileConstant.ShareLinkId)) { continue; //var domain = "?"; //switch (aceWrapper.Share) //{ // case FileShare.Read: // user = domain + CommonLinkUtility.GetFileWebViewerUrl(file.ID) + user; // break; // case FileShare.ReadWrite: // user = domain + CommonLinkUtility.GetFileWebEditorUrl(file.ID) + user; // break; // default: // continue; //} } acesParams.Add(new DocServiceParams.Aces { User = user, Permissions = permission }); } } catch (Exception) { } } } var versionForKey = file.Version; //CreateNewDoc if (forEdit) { versionForKey++; if (file.Version == 1 && file.ConvertedType != null && itsNew) { versionForKey = 1; } } var docKey = GetDocKey(file.ID, versionForKey, file.ModifiedOn); var docVKey = GetValidateKey(docKey, true); docServiceParams = new DocServiceParams { File = file, FileUri = GetFileUri(file), OutputType = string.IsNullOrEmpty(file.ProviderName) ? string.Empty : FileUtility.GetFileExtension(file.Title).Trim('.'), FileType = (file.ConvertedType ?? FileUtility.GetFileExtension(file.Title)).Trim('.'), FilePath = string.Join(crumbsSeporator, breadCrumbs.Select(folder => folder.Title).ToArray()), FolderUrl = folderUrl, Recent = recent, SharingSettings = acesParams, Buttons = buttons, DocumentType = documentType, Mode = forEdit ? "edit" : "view", Key = docKey, Vkey = docVKey, Lang = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).GetCulture().Name }; return(file); }