IRestRequest IRequestBuilder.PostCreateDownloadShare(ApiCreateDownloadShareRequest downloadShareParams) { RestRequest request = new RestRequest(ApiConfig.ApiPostCreateDownloadShare, Method.POST); SetGeneralRestValues(request, true, downloadShareParams); return(request); }
internal static ApiCreateDownloadShareRequest ToUnencryptedApiCreateDownloadShareRequest(CreateDownloadShareRequest request) { ApiExpiration apiExpiration = null; if (request.Expiration.HasValue) { apiExpiration = new ApiExpiration { ExpireAt = request.Expiration, EnableExpiration = request.Expiration.Value.Ticks != 0 }; } ApiCreateDownloadShareRequest apiCreateDownloadShareRequest = new ApiCreateDownloadShareRequest { NodeId = request.NodeId, Name = request.Name, Notes = request.Notes, Expiration = apiExpiration, ShowCreatorName = request.ShowCreatorName, ShowCreatorUserName = request.ShowCreatorUserName, NotifyCreator = request.NotifyCreator, MaxAllowedDownloads = request.MaxAllowedDownloads, Password = request.AccessPassword }; if (request.EmailRecipients != null) { // Check if the list is not empty is still in the previous validator done apiCreateDownloadShareRequest.SendMail = true; apiCreateDownloadShareRequest.MailRecipients = GenerateRecipientString(request.EmailRecipients); apiCreateDownloadShareRequest.MailBody = request.EmailBody; apiCreateDownloadShareRequest.MailSubject = request.EmailSubject; } else { apiCreateDownloadShareRequest.SendMail = false; } if (request.SmsRecipients != null) { // Check if the list is not empty is still in the previous validator done apiCreateDownloadShareRequest.SendSms = true; apiCreateDownloadShareRequest.SmsRecipients = GenerateRecipientString(request.SmsRecipients); } else { apiCreateDownloadShareRequest.SendSms = false; } return(apiCreateDownloadShareRequest); }
public void ToUnencryptedApiCreateDownloadShareRequest(string smsRecipients, string emailRecipients) { // ARRANGE ApiCreateDownloadShareRequest expected = FactoryShare.ApiCreateDownloadShareRequest; List <string> smsRecList = null; if (smsRecipients != null) { smsRecList = new List <string>(); smsRecList.AddRange(smsRecipients.Split(',')); expected.SmsRecipients = smsRecipients; expected.SendSms = true; } List <string> emailRecList = null; if (emailRecipients != null) { emailRecList = new List <string>(); emailRecList.AddRange(emailRecipients.Split(',')); expected.MailBody = "Some body"; expected.MailSubject = "You received a DRACOON share!"; expected.MailRecipients = emailRecipients; expected.SendMail = true; } CreateDownloadShareRequest param = new CreateDownloadShareRequest(expected.NodeId) { Name = expected.Name, Notes = expected.Notes, Expiration = expected.Expiration.ExpireAt, ShowCreatorName = expected.ShowCreatorName, ShowCreatorUserName = expected.ShowCreatorUserName, NotifyCreator = expected.NotifyCreator, MaxAllowedDownloads = expected.MaxAllowedDownloads, AccessPassword = expected.Password, EmailRecipients = emailRecList, EmailBody = expected.MailBody, EmailSubject = expected.MailSubject, SmsRecipients = smsRecList }; // ACT ApiCreateDownloadShareRequest actual = ShareMapper.ToUnencryptedApiCreateDownloadShareRequest(param); // ASSERT Assert.Equal(expected, actual, new ApiCreateDownloadShareRequestComparer()); }
public DownloadShare CreateDownloadShare(CreateDownloadShareRequest request) { _client.Executor.CheckApiServerVersion(); #region Parameter Validation request.MustNotNull(nameof(request)); Node targetNode = _client.NodesImpl.GetNode(request.NodeId); // Node id is still checked in previous called getNode() // To save much effort throw this restriction instantly and not let the rest api throw this error if (targetNode.IsEncrypted.GetValueOrDefault(false) && targetNode.Type != NodeType.File) { throw new DracoonApiException(DracoonApiCode.VALIDATION_DL_SHARE_CANNOT_CREATE_ON_ENCRYPTED_ROOM_FOLDER); } request.Name.MustNotNullOrEmptyOrWhitespace(nameof(request.Name), true); request.MaxAllowedDownloads.NullableMustPositive(nameof(request.MaxAllowedDownloads)); if (targetNode.IsEncrypted.GetValueOrDefault(false) && string.IsNullOrWhiteSpace(request.EncryptionPassword) && !string.IsNullOrWhiteSpace(request.AccessPassword)) { throw new ArgumentException("Download share of a encrypted node must have a encryption password and no access password."); } if (!targetNode.IsEncrypted.GetValueOrDefault(false) && string.IsNullOrWhiteSpace(request.AccessPassword) && !string.IsNullOrWhiteSpace(request.EncryptionPassword)) { throw new ArgumentException("Download share of a not encrypted node must have a access password and no encryption password."); } if (targetNode.IsEncrypted.GetValueOrDefault(false) && string.IsNullOrWhiteSpace(request.EncryptionPassword)) { throw new ArgumentException("Download share of a encrypted node must have a encryption password."); } if (!targetNode.IsEncrypted.GetValueOrDefault(false)) { request.AccessPassword?.MustNotNullOrEmptyOrWhitespace(nameof(request.AccessPassword)); } if (request.EmailRecipients != null) { request.EmailRecipients.EnumerableMustNotNullOrEmpty(nameof(request.EmailRecipients)); request.EmailRecipients.ForEach(current => current.MustNotNullOrEmptyOrWhitespace(nameof(request.EmailRecipients) + " element")); request.EmailBody.MustNotNullOrEmptyOrWhitespace(nameof(request.EmailBody)); request.EmailSubject.MustNotNullOrEmptyOrWhitespace(nameof(request.EmailSubject)); } if (request.SmsRecipients != null) { request.SmsRecipients.EnumerableMustNotNullOrEmpty(nameof(request.SmsRecipients)); request.SmsRecipients.ForEach(current => current.MustNotNullOrEmptyOrWhitespace(nameof(request.SmsRecipients) + " element")); if (string.IsNullOrEmpty(request.AccessPassword)) { throw new ArgumentException("If a SMS should be sent, a access password must be set."); } } #endregion ApiCreateDownloadShareRequest apiRequest = ShareMapper.ToUnencryptedApiCreateDownloadShareRequest(request); if (targetNode.IsEncrypted.GetValueOrDefault(false)) { UserKeyPair creatorKeyPair = _client.AccountImpl.GetAndCheckUserKeyPair(); EncryptedFileKey creatorEncryptedFileKey = _client.NodesImpl.GetEncryptedFileKey(request.NodeId); PlainFileKey plainFileKey = _client.NodesImpl.DecryptFileKey(creatorEncryptedFileKey, creatorKeyPair.UserPrivateKey, request.NodeId); UserKeyPair newGeneratedKeyPair = _client.AccountImpl.GenerateNewUserKeyPair(request.EncryptionPassword); EncryptedFileKey newEncryptedFileKey = _client.NodesImpl.EncryptFileKey(plainFileKey, newGeneratedKeyPair.UserPublicKey, request.NodeId); apiRequest.KeyPair = UserMapper.ToApiUserKeyPair(newGeneratedKeyPair); apiRequest.FileKey = FileMapper.ToApiFileKey(newEncryptedFileKey); } IRestRequest restRequest = _client.Builder.PostCreateDownloadShare(apiRequest); ApiDownloadShare resultShare = _client.Executor.DoSyncApiCall <ApiDownloadShare>(restRequest, DracoonRequestExecutor.RequestType.PostCreateDownloadShare); return(ShareMapper.FromApiDownloadShare(resultShare)); }