public bool CanSetAccess <T>(FileEntry <T> entry) { return (entry != null && (entry.RootFolderType == FolderType.COMMON && Global.IsAdministrator || entry.RootFolderType == FolderType.USER && (Equals(entry.RootFolderId, GlobalFolderHelper.GetFolderMy <T>()) || FileSecurity.CanEdit(entry)) && !UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager))); }
public File <T> SaveDocument <T>(string envelopeId, string documentId, string documentName, T folderId) { if (string.IsNullOrEmpty(envelopeId)) { throw new ArgumentNullException("envelopeId"); } if (string.IsNullOrEmpty(documentId)) { throw new ArgumentNullException("documentId"); } var token = DocuSignToken.GetToken(); var account = GetDocuSignAccount(token); var configuration = GetConfiguration(account, token); var fileDao = DaoFactory.GetFileDao <T>(); var folderDao = DaoFactory.GetFolderDao <T>(); if (string.IsNullOrEmpty(documentName)) { documentName = "new.pdf"; } Folder <T> folder; if (folderId == null || (folder = folderDao.GetFolder(folderId)) == null || folder.RootFolderType == FolderType.TRASH || !FileSecurity.CanCreate(folder)) { if (GlobalFolderHelper.FolderMy != 0) { folderId = GlobalFolderHelper.GetFolderMy <T>(); } else { throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create); } } var file = ServiceProvider.GetService <File <T> >(); file.FolderID = folderId; file.Comment = FilesCommonResource.CommentCreateByDocuSign; file.Title = FileUtility.ReplaceFileExtension(documentName, ".pdf"); var envelopesApi = new EnvelopesApi(configuration); Log.Info("DocuSign webhook get stream: " + documentId); using (var stream = envelopesApi.GetDocument(account.AccountId, envelopeId, documentId)) { file.ContentLength = stream.Length; file = fileDao.SaveFile(file, stream); } FilesMessageService.Send(file, MessageInitiator.ThirdPartyProvider, MessageAction.DocumentSignComplete, "DocuSign", file.Title); FileMarker.MarkAsNew(file); return(file); }
public File <T> SaveConvertedFile <T>(File <T> file, string convertedFileUrl) { var fileSecurity = FileSecurity; var fileDao = DaoFactory.GetFileDao <T>(); var folderDao = DaoFactory.GetFolderDao <T>(); File <T> newFile = null; var newFileTitle = FileUtility.ReplaceFileExtension(file.Title, FileUtility.GetInternalExtension(file.Title)); if (!FilesSettingsHelper.StoreOriginalFiles && fileSecurity.CanEdit(file)) { newFile = (File <T>)file.Clone(); newFile.Version++; } else { var folderId = GlobalFolderHelper.GetFolderMy <T>(); var parent = folderDao.GetFolder(file.FolderID); if (parent != null && fileSecurity.CanCreate(parent)) { folderId = parent.ID; } if (Equals(folderId, 0)) { throw new SecurityException(FilesCommonResource.ErrorMassage_FolderNotFound); } if (FilesSettingsHelper.UpdateIfExist && (parent != null && !folderId.Equals(parent.ID) || !file.ProviderEntry)) { newFile = fileDao.GetFile(folderId, newFileTitle); if (newFile != null && fileSecurity.CanEdit(newFile) && !EntryManager.FileLockedForMe(newFile.ID) && !FileTracker.IsEditing(newFile.ID)) { newFile.Version++; } else { newFile = null; } } if (newFile == null) { newFile = ServiceProvider.GetService <File <T> >(); newFile.FolderID = folderId; } } newFile.Title = newFileTitle; newFile.ConvertedType = null; newFile.Comment = string.Format(FilesCommonResource.CommentConvert, file.Title); var req = (HttpWebRequest)WebRequest.Create(convertedFileUrl); if (WorkContext.IsMono && ServicePointManager.ServerCertificateValidationCallback == null) { ServicePointManager.ServerCertificateValidationCallback += (s, c, n, p) => true; //HACK: http://ubuntuforums.org/showthread.php?t=1841740 } try { using (var convertedFileStream = new ResponseStream(req.GetResponse())) { newFile.ContentLength = convertedFileStream.Length; newFile = fileDao.SaveFile(newFile, convertedFileStream); } } catch (WebException e) { using var response = e.Response; var httpResponse = (HttpWebResponse)response; var errorString = string.Format("WebException: {0}", httpResponse.StatusCode); if (httpResponse.StatusCode != HttpStatusCode.NotFound) { using var responseStream = response.GetResponseStream(); if (responseStream != null) { using var readStream = new StreamReader(responseStream); var text = readStream.ReadToEnd(); errorString += string.Format(" Error message: {0}", text); } } throw new Exception(errorString); } FilesMessageService.Send(newFile, MessageInitiator.DocsService, MessageAction.FileConverted, newFile.Title); FileMarker.MarkAsNew(newFile); var tagDao = DaoFactory.GetTagDao <T>(); var tags = tagDao.GetTags(file.ID, FileEntryType.File, TagType.System).ToList(); if (tags.Any()) { tags.ForEach(r => r.EntryId = newFile.ID); tagDao.SaveTags(tags); } return(newFile); }