public IEnumerable <EncryptionAddress> GetAddressesWithAccess(string fileId) { var accountsString = EncryptionAddress.GetAddresses(fileId); var accounts = accountsString.Select(JsonConvert.DeserializeObject <EncryptionAddress>); return(accounts); }
public object UpdateAddress(string address, string publicKey) { SecurityContext.DemandPermissions(new UserSecurityProvider(SecurityContext.CurrentAccount.ID), Core.Users.Constants.Action_EditUser); if (string.IsNullOrEmpty(address)) { throw new ArgumentNullException("address"); } if (string.IsNullOrEmpty(publicKey)) { throw new ArgumentNullException("publicKey"); } var currentAddressString = EncryptionLoginProvider.GetAddress(); if (!string.IsNullOrEmpty(currentAddressString)) { var currentAddress = JsonConvert.DeserializeObject <EncryptionAddress>(currentAddressString); if (currentAddress != null && !string.IsNullOrEmpty(currentAddress.PublicKey) && currentAddress.PublicKey.Equals(publicKey)) { return(new { isset = true }); } LogManager.GetLogger("ASC.Api.Documents").InfoFormat("User {0} updates address", SecurityContext.CurrentAccount.ID); } var account = new EncryptionAddress { Address = address, PublicKey = publicKey }; var accountString = JsonConvert.SerializeObject(account); EncryptionLoginProvider.UpdateAddress(accountString); return(new { isset = !string.IsNullOrEmpty(EncryptionLoginProvider.GetAddress()) }); }
private static TrackResponse ProcessSave(string fileId, TrackerData fileData) { Guid userId; 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 userId)) { userId = FileTracker.GetEditingBy(fileId).FirstOrDefault(); } var app = ThirdPartySelector.GetAppByFileId(fileId); if (app == null) { File fileStable; using (var fileDao = Global.DaoFactory.GetFileDao()) { fileStable = fileDao.GetFileStable(fileId); } var docKey = DocumentServiceHelper.GetDocKey(fileStable); if (!fileData.Key.Equals(docKey)) { Global.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 = CoreContext.UserManager.GetUsers(userId); var culture = string.IsNullOrEmpty(user.CultureName) ? CoreContext.TenantManager.GetCurrentTenant().GetCulture() : CultureInfo.GetCultureInfo(user.CultureName); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; } catch (Exception ex) { Global.Logger.Info("DocService save error: anonymous author - " + userId, ex); if (!userId.Equals(ASC.Core.Configuration.Constants.Guest.ID)) { comments.Add(FilesCommonResource.ErrorMassage_SaveAnonymous); } } File file = null; var saveMessage = "Not saved"; if (string.IsNullOrEmpty(fileData.Url)) { try { comments.Add(FilesCommonResource.ErrorMassage_SaveUrlLost); file = EntryManager.CompleteVersionFile(fileId, 0, false, false); using (var fileDao = Global.DaoFactory.GetFileDao()) { fileDao.UpdateComment(file.ID, file.Version, string.Join("; ", comments)); } file = null; Global.Logger.ErrorFormat("DocService save error. Empty url. File id: '{0}'. UserId: {1}. DocKey '{2}'", fileId, userId, fileData.Key); } catch (Exception ex) { Global.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) { Global.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), file.Title); } if (!forcesave) { SaveHistory(file, (fileData.History ?? "").ToString(), DocumentServiceConnector.ReplaceDocumentAdress(fileData.ChangesUrl)); } } Global.SocketManager.FilesChangeEditors(fileId, !forcesave); var result = new TrackResponse { Message = saveMessage }; if (string.IsNullOrEmpty(saveMessage) && file != null && file.Encrypted) { result.Addresses = EncryptionAddress.GetAddresses(file.ID.ToString()).ToArray(); } return(result); }