Beispiel #1
0
        public IEnumerable <EncryptionAddress> GetAddressesWithAccess(string fileId)
        {
            var accountsString = EncryptionAddressHelper.GetAddresses(fileId);

            var accounts = accountsString.Select(JsonConvert.DeserializeObject <EncryptionAddress>);

            return(accounts);
        }
Beispiel #2
0
 public EncryptionController(
     PermissionContext permissionContext,
     AuthContext authContext,
     EncryptionLoginProvider encryptionLoginProvider,
     IOptionsMonitor <ILog> monitor,
     EncryptionAddressHelper encryptionAddressHelper,
     EncryptedDataDao encryptedDataDao)
 {
     PermissionContext       = permissionContext;
     AuthContext             = authContext;
     EncryptionLoginProvider = encryptionLoginProvider;
     EncryptionAddressHelper = encryptionAddressHelper;
     EncryptedDataDao        = encryptedDataDao;
     Log = monitor.Get("ASC.Api.Documents");
 }
 public DocumentServiceTrackerHelper(
     SecurityContext securityContext,
     UserManager userManager,
     TenantManager tenantManager,
     FilesLinkUtility filesLinkUtility,
     EmailValidationKeyProvider emailValidationKeyProvider,
     BaseCommonLinkUtility baseCommonLinkUtility,
     SocketManager socketManager,
     GlobalStore globalStore,
     DisplayUserSettingsHelper displayUserSettingsHelper,
     IDaoFactory daoFactory,
     IOptionsMonitor <ILog> options,
     DocumentServiceHelper documentServiceHelper,
     EntryManager entryManager,
     FileShareLink fileShareLink,
     FilesMessageService filesMessageService,
     EncryptionAddressHelper encryptionAddressHelper,
     DocumentServiceConnector documentServiceConnector,
     NotifyClient notifyClient,
     MailMergeTaskRunner mailMergeTaskRunner)
 {
     SecurityContext            = securityContext;
     UserManager                = userManager;
     TenantManager              = tenantManager;
     FilesLinkUtility           = filesLinkUtility;
     EmailValidationKeyProvider = emailValidationKeyProvider;
     BaseCommonLinkUtility      = baseCommonLinkUtility;
     SocketManager              = socketManager;
     GlobalStore                = globalStore;
     DisplayUserSettingsHelper  = displayUserSettingsHelper;
     DaoFactory               = daoFactory;
     DocumentServiceHelper    = documentServiceHelper;
     EntryManager             = entryManager;
     FileShareLink            = fileShareLink;
     FilesMessageService      = filesMessageService;
     EncryptionAddressHelper  = encryptionAddressHelper;
     DocumentServiceConnector = documentServiceConnector;
     NotifyClient             = notifyClient;
     MailMergeTaskRunner      = mailMergeTaskRunner;
     Logger = options.CurrentValue;
 }
        private TrackResponse ProcessSave <T>(T fileId, TrackerData fileData)
        {
            var comments = new List <string>();

            if (fileData.Status == TrackerStatus.Corrupted ||
                fileData.Status == TrackerStatus.CorruptedForceSave)
            {
                comments.Add(FilesCommonResource.ErrorMassage_SaveCorrupted);
            }

            var forcesave = fileData.Status == TrackerStatus.ForceSave || fileData.Status == TrackerStatus.CorruptedForceSave;

            if (fileData.Users == null || fileData.Users.Count == 0 || !Guid.TryParse(fileData.Users[0], out var userId))
            {
                userId = FileTracker.GetEditingBy(fileId).FirstOrDefault();
            }

            var app = ThirdPartySelector.GetAppByFileId(fileId.ToString());

            if (app == null)
            {
                File <T> fileStable;
                fileStable = DaoFactory.GetFileDao <T>().GetFileStable(fileId);

                var docKey = DocumentServiceHelper.GetDocKey(fileStable);
                if (!fileData.Key.Equals(docKey))
                {
                    Logger.ErrorFormat("DocService saving file {0} ({1}) with key {2}", fileId, docKey, fileData.Key);

                    StoringFileAfterError(fileId, userId.ToString(), DocumentServiceConnector.ReplaceDocumentAdress(fileData.Url));
                    return(new TrackResponse {
                        Message = "Expected key " + docKey
                    });
                }
            }

            UserInfo user = null;

            try
            {
                SecurityContext.AuthenticateMe(userId);

                user = UserManager.GetUsers(userId);
                var culture = string.IsNullOrEmpty(user.CultureName) ? TenantManager.GetCurrentTenant().GetCulture() : CultureInfo.GetCultureInfo(user.CultureName);
                Thread.CurrentThread.CurrentCulture   = culture;
                Thread.CurrentThread.CurrentUICulture = culture;
            }
            catch (Exception ex)
            {
                Logger.Info("DocService save error: anonymous author - " + userId, ex);
                if (!userId.Equals(ASC.Core.Configuration.Constants.Guest.ID))
                {
                    comments.Add(FilesCommonResource.ErrorMassage_SaveAnonymous);
                }
            }

            File <T> file        = null;
            var      saveMessage = "Not saved";

            if (string.IsNullOrEmpty(fileData.Url))
            {
                try
                {
                    comments.Add(FilesCommonResource.ErrorMassage_SaveUrlLost);

                    file = EntryManager.CompleteVersionFile(fileId, 0, false, false);

                    DaoFactory.GetFileDao <T>().UpdateComment(file.ID, file.Version, string.Join("; ", comments));

                    file = null;
                    Logger.ErrorFormat("DocService save error. Empty url. File id: '{0}'. UserId: {1}. DocKey '{2}'", fileId, userId, fileData.Key);
                }
                catch (Exception ex)
                {
                    Logger.Error(string.Format("DocService save error. Version update. File id: '{0}'. UserId: {1}. DocKey '{2}'", fileId, userId, fileData.Key), ex);
                }
            }
            else
            {
                if (fileData.Encrypted)
                {
                    comments.Add(FilesCommonResource.CommentEditEncrypt);
                }

                var forcesaveType = ForcesaveType.None;
                if (forcesave)
                {
                    switch (fileData.ForceSaveType)
                    {
                    case TrackerData.ForceSaveInitiator.Command:
                        forcesaveType = ForcesaveType.Command;
                        break;

                    case TrackerData.ForceSaveInitiator.Timer:
                        forcesaveType = ForcesaveType.Timer;
                        break;

                    case TrackerData.ForceSaveInitiator.User:
                        forcesaveType = ForcesaveType.User;
                        break;
                    }
                    comments.Add(fileData.ForceSaveType == TrackerData.ForceSaveInitiator.User
                                     ? FilesCommonResource.CommentForcesave
                                     : FilesCommonResource.CommentAutosave);
                }

                try
                {
                    file        = EntryManager.SaveEditing(fileId, null, DocumentServiceConnector.ReplaceDocumentAdress(fileData.Url), null, string.Empty, string.Join("; ", comments), false, fileData.Encrypted, forcesaveType);
                    saveMessage = fileData.Status == TrackerStatus.MustSave || fileData.Status == TrackerStatus.ForceSave ? null : "Status " + fileData.Status;
                }
                catch (Exception ex)
                {
                    Logger.Error(string.Format("DocService save error. File id: '{0}'. UserId: {1}. DocKey '{2}'. DownloadUri: {3}", fileId, userId, fileData.Key, fileData.Url), ex);
                    saveMessage = ex.Message;

                    StoringFileAfterError(fileId, userId.ToString(), DocumentServiceConnector.ReplaceDocumentAdress(fileData.Url));
                }
            }

            if (!forcesave)
            {
                FileTracker.Remove(fileId);
            }

            if (file != null)
            {
                if (user != null)
                {
                    FilesMessageService.Send(file, MessageInitiator.DocsService, MessageAction.UserFileUpdated, user.DisplayUserName(false, DisplayUserSettingsHelper), file.Title);
                }

                if (!forcesave)
                {
                    SaveHistory(file, (fileData.History ?? "").ToString(), DocumentServiceConnector.ReplaceDocumentAdress(fileData.ChangesUrl));
                }
            }

            SocketManager.FilesChangeEditors(fileId, !forcesave);

            var result = new TrackResponse {
                Message = saveMessage
            };

            if (string.IsNullOrEmpty(saveMessage) && file != null && file.Encrypted)
            {
                result.Addresses = EncryptionAddressHelper.GetAddresses(file.ID.ToString()).ToArray();
            }
            return(result);
        }