Skip to content

Commit

Permalink
Merge branch 'develop' into feature/redesign-tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Kulak committed Jan 25, 2022
2 parents eb6573b + 445f030 commit 67a749c
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 64 deletions.
3 changes: 2 additions & 1 deletion common/ASC.FederatedLogin/Helpers/RequestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;

namespace ASC.FederatedLogin.Helpers
Expand Down Expand Up @@ -59,7 +60,7 @@ public static string PerformRequest(string uri, string contentType = "", string
request.Content = new ByteArrayContent(bytes, 0, bytes.Length);
if (!string.IsNullOrEmpty(contentType))
{
request.Headers.Add("Content-Type", contentType);
request.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
}
}

Expand Down
102 changes: 53 additions & 49 deletions products/ASC.Calendar/Server/BusinessObjects/DataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Web;

Expand Down Expand Up @@ -205,9 +206,9 @@ public List<Calendar> LoadCalendarsForUser(Guid userId, out int newCalendarsCoun

public List<Calendar> LoadiCalStreamsForUser(Guid userId)
{
var calIds = CalendarDb.CalendarCalendars.Where(p =>
p.Tenant == TenantManager.GetCurrentTenant().TenantId &&
p.OwnerId == userId.ToString() &&
var calIds = CalendarDb.CalendarCalendars.Where(p =>
p.Tenant == TenantManager.GetCurrentTenant().TenantId &&
p.OwnerId == userId.ToString() &&
p.IcalUrl != null)
.Select(s => s.Id).ToArray();
var calendars = GetCalendarsByIds(calIds.ToArray());
Expand Down Expand Up @@ -256,31 +257,31 @@ select new

return data.FirstOrDefault().calUsrTimeZone == null ? TimeZoneConverter.GetTimeZone(data.FirstOrDefault().calTimeZone) : TimeZoneConverter.GetTimeZone(data.FirstOrDefault().calUsrTimeZone);

}

public List<object[]> GetCalendarIdByCaldavGuid(string caldavGuid)
{
}

public List<object[]> GetCalendarIdByCaldavGuid(string caldavGuid)
{
var data = CalendarDb.CalendarCalendars
.Where(p => p.CaldavGuid == caldavGuid)
.Select(s => new object[]{
.Select(s => new object[]{
s.Id,
s.OwnerId,
s.Tenant
}).ToList();

return data;
}
public Event GetEventIdByUid(string uid, int calendarId)
{
}).ToList();

return data;
}
public Event GetEventIdByUid(string uid, int calendarId)
{
var eventId = CalendarDb.CalendarEvents
.Where(p =>
.Where(p =>
uid.Contains(p.Uid) &&
p.CalendarId == calendarId
)
.Select(s => s.Id).FirstOrDefault();

return eventId == 0 ? null : GetEventById(eventId);
}
.Select(s => s.Id).FirstOrDefault();

return eventId == 0 ? null : GetEventById(eventId);
}

public Event GetEventIdOnlyByUid(string uid)
{
Expand Down Expand Up @@ -482,8 +483,8 @@ public string GetCalDavGuid(string id)
{
var dataCaldavGuid = CalendarDb.CalendarCalendars.Where(p => p.Id.ToString() == id).Select(s => s.CaldavGuid).FirstOrDefault();

return dataCaldavGuid;
return dataCaldavGuid;

}
public Calendar UpdateCalendar(int calendarId, string name, string description, List<SharingOptions.PublicItem> publicItems, List<UserViewSettings> viewSettings)
{
Expand Down Expand Up @@ -750,8 +751,8 @@ public Guid RemoveCalendar(int calendarId)
{
var dataCaldavGuid = CalendarDb.CalendarCalendars.Where(p => p.Id == calendarId).Select(s => s.CaldavGuid).ToArray();

if (dataCaldavGuid[0] != null)
caldavGuid = Guid.Parse(dataCaldavGuid[0].ToString());
if (dataCaldavGuid[0] != null)
caldavGuid = Guid.Parse(dataCaldavGuid[0].ToString());
}
catch (Exception ex)
{
Expand Down Expand Up @@ -794,7 +795,7 @@ public Guid RemoveCalendar(int calendarId)

public void RemoveCaldavCalendar(string currentUserName, string email, string calDavGuid, Uri myUri, bool isShared = false)
{
var calDavServerUrl = myUri.Scheme + "://" + myUri.Host + "/caldav";
var calDavServerUrl = myUri.Scheme + "://" + myUri.Host + "/caldav";
var requestUrl = calDavServerUrl + "/" + HttpUtility.UrlEncode(currentUserName) + "/" + (isShared ? calDavGuid + "-shared" : calDavGuid);

try
Expand All @@ -805,8 +806,11 @@ public void RemoveCaldavCalendar(string currentUserName, string email, string ca

var authorization = isShared ? GetSystemAuthorization() : GetUserAuthorization(email);

request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(authorization)));
request.Headers.Add("Content-Type", "text/xml; charset=utf-8");
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(authorization)));
request.Content.Headers.ContentType = new MediaTypeHeaderValue("text/xml")
{
CharSet = Encoding.UTF8.WebName
};

using var httpClient = new HttpClient();
httpClient.Send(request);
Expand All @@ -818,8 +822,8 @@ public void RemoveCaldavCalendar(string currentUserName, string email, string ca
}
public void RemoveExternalCalendarData(string calendarId)
{
using var tx = CalendarDb.Database.BeginTransaction();
using var tx = CalendarDb.Database.BeginTransaction();

var ccu = CalendarDb.CalendarCalendarUser.Where(r => r.ExtCalendarId == calendarId).SingleOrDefault();

if (ccu != null)
Expand Down Expand Up @@ -1021,20 +1025,20 @@ internal List<Event> LoadSharedEvents(Guid userId, int tenantId, DateTime utcSta
var groups = UserManager.GetUserGroups(userId).Select(g => g.ID).ToList();
groups.AddRange(UserManager.GetUserGroups(userId, Constants.SysGroupCategoryId).Select(g => g.ID));

var evIds = from events in CalendarDb.CalendarEvents
join eventItem in CalendarDb.CalendarEventItem on events.Id equals eventItem.EventId
where
events.Tenant == tenantId &&
(
eventItem.ItemId == userId || (groups.Contains(eventItem.ItemId) && eventItem.IsGroup == 1) &&
events.Tenant == tenantId &&
((events.StartDate >= utcStartDate && events.StartDate <= utcEndDate && events.Rrule == "") || events.Rrule != "") &&
events.OwnerId != userId &&
!(from calEventUser in CalendarDb.CalendarEventUser
where calEventUser.EventId == events.Id && calEventUser.UserId == userId && calEventUser.IsUnsubscribe == 1
select calEventUser.EventId).Any()
)
select events.Id;
var evIds = from events in CalendarDb.CalendarEvents
join eventItem in CalendarDb.CalendarEventItem on events.Id equals eventItem.EventId
where
events.Tenant == tenantId &&
(
eventItem.ItemId == userId || (groups.Contains(eventItem.ItemId) && eventItem.IsGroup == 1) &&
events.Tenant == tenantId &&
((events.StartDate >= utcStartDate && events.StartDate <= utcEndDate && events.Rrule == "") || events.Rrule != "") &&
events.OwnerId != userId &&
!(from calEventUser in CalendarDb.CalendarEventUser
where calEventUser.EventId == events.Id && calEventUser.UserId == userId && calEventUser.IsUnsubscribe == 1
select calEventUser.EventId).Any()
)
select events.Id;
return GetEventsByIds(evIds.ToArray(), userId, tenantId);
}

Expand All @@ -1058,8 +1062,8 @@ public List<Event> LoadEvents(int calendarId, Guid userId, int tenantId, DateTim
)
)
)
.Select(s => s.Id).ToList();

.Select(s => s.Id).ToList();

return GetEventsByIds(evIds.ToArray(), userId, tenantId);
}

Expand Down Expand Up @@ -1264,7 +1268,7 @@ public void UnsubscribeFromEvent(int eventID, Guid userId)
{
CalendarDb.CalendarEventItem.Remove(cei);
}
else if(!userNoSubscibe)
else if (!userNoSubscibe)
{
var newEventUser = new CalendarEventUser
{
Expand Down Expand Up @@ -1453,8 +1457,8 @@ DateTime createDate
}

CalendarDb.SaveChanges();
tx.Commit();
tx.Commit();

return GetEventById(eventId);
}

Expand Down Expand Up @@ -1606,8 +1610,8 @@ public void RemoveEventHistory(int eventId)

CalendarDb.SaveChanges();
tx.Commit();
}
}

public static string GetEventUid(string uid, string id = null)
{
if (!string.IsNullOrEmpty(uid))
Expand Down
13 changes: 10 additions & 3 deletions products/ASC.Calendar/Server/Controllers/CalendarController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security;
using System.Text;
using System.Text.Json;
Expand Down Expand Up @@ -1030,7 +1031,10 @@ private string GetUserCaldavCalendar(string calUrl, string encoded)
var request = new HttpRequestMessage();
request.Method = HttpMethod.Get;
request.RequestUri = new Uri(calUrl);
request.Headers.Add("Content-Type", "text/xml; charset=utf-8");
request.Content.Headers.ContentType = new MediaTypeHeaderValue("text/xml")
{
CharSet = Encoding.UTF8.WebName
};
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(authorization)));

try
Expand Down Expand Up @@ -4188,8 +4192,11 @@ private void UpdateCalDavEvent(string change, Uri calDavUrl)
var _email = UserManager.GetUsers(ownerId).Email;
var authorization = sharedPostfixIndex != -1 ? DataProvider.GetSystemAuthorization() : DataProvider.GetUserAuthorization(_email);
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(authorization)));
request.Headers.Add("Content-Type", "text/calendar; charset=utf-8");

request.Content.Headers.ContentType = new MediaTypeHeaderValue("text/calendar")
{
CharSet = Encoding.UTF8.WebName
};

Log.Info(String.Format("UpdateCalDavEvent eventURl: {0}", eventURl));

string ics = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using System.Threading.Tasks;

using ASC.Common;
using ASC.Core.Common.Configuration;
using ASC.FederatedLogin;
Expand Down Expand Up @@ -261,8 +262,11 @@ public ResumableUploadSession CreateResumableSession(Item onedriveFile, long con
var request = new HttpRequestMessage();
request.RequestUri = uploadUriBuilder.Uri;
request.Method = HttpMethod.Post;
request.Headers.Add("Authorization", "Bearer " + AccessToken);
request.Headers.Add("Content-Type", "application/json; charset=UTF-8");
request.Headers.Add("Authorization", "Bearer " + AccessToken);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json")
{
CharSet = Encoding.UTF8.WebName
};

var uploadSession = new ResumableUploadSession(onedriveFile.Id, folderId, contentLength);

Expand Down
3 changes: 2 additions & 1 deletion products/ASC.Files/Core/ThirdPartyApp/BoxApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -343,7 +344,7 @@ public void SaveFile(string fileId, string fileType, string downloadUrl, Stream

request.Method = HttpMethod.Post;
request.Headers.Add("Authorization", "Bearer " + token);
request.Headers.Add("Content-Type", "multipart/form-data; boundary=" + boundary);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("multipart/form-data; boundary=" + boundary);
Logger.Debug("BoxApp: save file totalSize - " + tmpStream.Length);

tmpStream.Seek(0, SeekOrigin.Begin);
Expand Down
5 changes: 3 additions & 2 deletions products/ASC.Files/Core/ThirdPartyApp/GoogleDriveApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -321,7 +322,7 @@ public void SaveFile(string fileId, string fileType, string downloadUrl, Stream
request.RequestUri = new Uri(GoogleLoginProvider.GoogleUrlFileUpload + "/{fileId}?uploadType=media".Replace("{fileId}", fileId));
request.Method = HttpMethod.Patch;
request.Headers.Add("Authorization", "Bearer " + token);
request.Headers.Add("Content-Type", MimeMapping.GetMimeMapping(currentType));
request.Content.Headers.ContentType = new MediaTypeHeaderValue(MimeMapping.GetMimeMapping(currentType));

if (stream != null)
{
Expand Down Expand Up @@ -769,7 +770,7 @@ private string CreateFile(Stream content, string fileName, string folderId, Toke

request.Method = HttpMethod.Post;
request.Headers.Add("Authorization", "Bearer " + token);
request.Headers.Add("Content-Type", "multipart/related; boundary=" + boundary);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("multipart/related; boundary=" + boundary);

Logger.Debug("GoogleDriveApp: create file totalSize - " + tmpStream.Length);

Expand Down
4 changes: 2 additions & 2 deletions products/ASC.Files/Core/Utils/MailMergeTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web;

using ASC.Common;
using ASC.Common.Web;
using ASC.Core;
using ASC.Core.Common;
using ASC.Web.Studio.Core;
Expand Down Expand Up @@ -137,7 +137,7 @@ private string AttachToMail(MailMergeTask mailMergeTask)
request.RequestUri = new Uri(BaseCommonLinkUtility.GetFullAbsolutePath(apiUrlAttach));
request.Method = HttpMethod.Post;
request.Headers.Add("Authorization", SecurityContext.AuthenticateMe(SecurityContext.CurrentAccount.ID));
request.Headers.Add("Content-Type", MimeMapping.GetMimeMapping(mailMergeTask.AttachTitle));
request.Content.Headers.ContentType = new MediaTypeHeaderValue(mailMergeTask.AttachTitle);
request.Content = new StreamContent(mailMergeTask.Attach);

// hack. http://ubuntuforums.org/showthread.php?t=1841740
Expand Down
5 changes: 3 additions & 2 deletions web/ASC.Web.Core/Sms/SmsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
using System.Web;

Expand Down Expand Up @@ -169,7 +170,7 @@ public virtual bool SendMessage(string number, string message)

var request = new HttpRequestMessage();
request.RequestUri = new Uri(url);
request.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");

using var httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromMilliseconds(15000);
Expand Down Expand Up @@ -263,7 +264,7 @@ public string GetBalance(Tenant tenant, bool eraseCache = false)

var request = new HttpRequestMessage();
request.RequestUri = new Uri(url);
request.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");

using var httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromMilliseconds(1000);
Expand Down

0 comments on commit 67a749c

Please sign in to comment.