Skip to content

Commit

Permalink
Merge branch 'release/v4.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
sachatrauwaen committed Sep 21, 2020
2 parents 01f6100 + c7a08aa commit a3dadd8
Show file tree
Hide file tree
Showing 46 changed files with 529 additions and 142 deletions.
6 changes: 6 additions & 0 deletions OpenContent/App_LocalResources/SharedResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,10 @@
<data name="lUseTemplate.Text" xml:space="preserve">
<value>I want</value>
</data>
<data name="liOtherPortal.Text" xml:space="preserve">
<value>Other Portal</value>
</data>
<data name="lPortals.Text" xml:space="preserve">
<value>Portal</value>
</data>
</root>
12 changes: 12 additions & 0 deletions OpenContent/Components/Common/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
using System;
using System.Diagnostics;
using System.Web;

namespace Satrabel.OpenContent.Components
{
public static class Utils
{
/// <summary>
/// Use to safely call Debugger.Break()
/// </summary>
/// <remarks>
/// Never call Debugger.Break() without checking if Debugger is attached. We have observed weird errors when doing so.
/// </remarks>
public static void DebuggerBreak()
{
if (Debugger.IsAttached) Debugger.Break();
}

#region Url utils

public static string RemoveQueryParams(this string url)
Expand Down
10 changes: 10 additions & 0 deletions OpenContent/Components/Datasource/DnnUsersDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public override IDataItems GetAll(DataSourceContext context, Select selectQuery)
pageSize = selectQuery.PageSize;
var ruleDisplayName = selectQuery.Query.FilterRules.FirstOrDefault(f => f.Field == "DisplayName");
var ruleRoles = selectQuery.Query.FilterRules.FirstOrDefault(f => f.Field == "Roles");
var ruleApproved = selectQuery.Query.FilterRules.FirstOrDefault(f => f.Field == "Approved");

if (ruleDisplayName != null)
{
string displayName = ruleDisplayName.Value.AsString + "%";
Expand All @@ -151,13 +153,20 @@ public override IDataItems GetAll(DataSourceContext context, Select selectQuery)
var roleNames = ruleRoles.MultiValue.Select(r => r.AsString).ToList();
users = users.Where(u => u.Roles.Intersect(roleNames).Any());
}
if (ruleApproved!= null)
{
var val = bool.Parse(ruleApproved.Value.AsString);
users = users.Where(u => u.Membership.Approved == val);
}
}
else
{
users = UserController.GetUsers(context.PortalId, pageIndex, pageSize, ref total, true, false).Cast<UserInfo>();
}
int excluded = users.Count() - users.Count(u => u.IsInRole("Administrators"));
users = users.Where(u => !u.IsInRole("Administrators"));


//users = users.Skip(pageIndex * pageSize).Take(pageSize);
var dataList = new List<IDataItem>();
foreach (var user in users)
Expand Down Expand Up @@ -372,6 +381,7 @@ public IEnumerable<IIndexableItem> GetIndexableData(DataSourceContext context)

private static void ReIndexIfNeeded(int moduleid, int tabid, int portalId)
{
if (PortalSettings.Current == null) return; // we can not reindex even if we wanted, because we are not in a regular http context (maybe console? scheduler? ashx?)
var currentUserCount = UserController.GetUserCountByPortal(portalId);
var userCountAtLastIndex = DnnUtils.GetPortalSetting("UserCountAtLastIndex", 0);
if (currentUserCount != userCountAtLastIndex)
Expand Down
1 change: 0 additions & 1 deletion OpenContent/Components/Datasource/IDataIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ namespace Satrabel.OpenContent.Components.Datasource
public interface IDataIndex
{
IEnumerable<IIndexableItem> GetIndexableData(DataSourceContext context);
// void Reindex(DataSourceContext context);
}
}
12 changes: 6 additions & 6 deletions OpenContent/Components/Datasource/OpenContentDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ public virtual IDataItems GetAll(DataSourceContext context, Select selectQuery)
private static SelectQueryDefinition BuildQuery(DataSourceContext context, Select selectQuery)
{
SelectQueryDefinition def = new SelectQueryDefinition();
def.Build(selectQuery);
def.Build(selectQuery, context.CurrentCultureCode);
if (LogContext.IsLogActive)
{
var logKey = "Lucene query";
LogContext.Log(context.ActiveModuleId, logKey, "Filter", def.Filter.ToString());
LogContext.Log(context.ActiveModuleId, logKey, "Query", def.Query.ToString());
LogContext.Log(context.ActiveModuleId, logKey, "Sort", def.Sort.ToString());
LogContext.Log(context.ActiveModuleId, logKey, "Filter", def.Filter?.ToString());
LogContext.Log(context.ActiveModuleId, logKey, "Query", def.Query?.ToString());
LogContext.Log(context.ActiveModuleId, logKey, "Sort", def.Sort?.ToString());
LogContext.Log(context.ActiveModuleId, logKey, "PageIndex", def.PageIndex);
LogContext.Log(context.ActiveModuleId, logKey, "PageSize", def.PageSize);
}
Expand Down Expand Up @@ -359,7 +359,7 @@ public virtual JToken Action(DataSourceContext context, string action, IDataItem
{
ModuleId = GetModuleId(context),
Collection = "Submissions",
Title = item.Data["Title"] == null ? "Form" : item.Data["Title"].ToString(),
Title = item?.Data["Title"] == null ? "Form" : item.Data["Title"].ToString(),
Json = data["form"].ToString(),
CreatedByUserId = context.UserId,
CreatedOnDate = DateTime.Now,
Expand All @@ -374,7 +374,7 @@ public virtual JToken Action(DataSourceContext context, string action, IDataItem
// LuceneController.Instance.Add(content, indexConfig);
// LuceneController.Instance.Commit();
//}
return FormUtils.FormSubmit(data as JObject, item.Data.DeepClone() as JObject);
return FormUtils.FormSubmit(data as JObject, item?.Data?.DeepClone() as JObject);
}
return null;
}
Expand Down
11 changes: 10 additions & 1 deletion OpenContent/Components/Datasource/search/StringRuleValue.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Satrabel.OpenContent.Components.Datasource.Search
using System;

namespace Satrabel.OpenContent.Components.Datasource.Search
{
public class StringRuleValue : RuleValue
{
Expand All @@ -8,5 +10,12 @@ public StringRuleValue(string value)
_value = value;
}
public override string AsString => _value;

public override float AsFloat => float.Parse(_value);
public override int AsInteger => int.Parse(_value);
public override bool AsBoolean => bool.Parse(_value);
public override long AsLong => long.Parse(_value);

public override DateTime AsDateTime => DateTime.Parse(_value, null, System.Globalization.DateTimeStyles.RoundtripKind);
}
}
2 changes: 1 addition & 1 deletion OpenContent/Components/Dnn/DnnLanguageUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Satrabel.OpenContent.Components
public static class DnnLanguageUtils
{
/// <summary>
/// Gets the current culture code.
/// Gets the current culture code. Format en-US.
/// This code is based on long expierence of how hard it is to get the correct value.
/// </summary>
public static string GetCurrentCultureCode()
Expand Down
4 changes: 2 additions & 2 deletions OpenContent/Components/Dnn/DnnUrlUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ internal static string NavigateUrl(int tabId, PortalSettings portalSettings, str
return Globals.NavigateURL(tabId, isSuperTab, portalSettings, "", currentCultureCode);
}

internal static string NavigateUrl(int detailTabId, PortalSettings portalSettings, string pagename, params string[] additionalParameters)
internal static string NavigateUrl(int detailTabId, string currentCultureCode, PortalSettings portalSettings, string pagename, params string[] additionalParameters)
{
var isSuperTab = Globals.IsHostTab(detailTabId);
var url = Globals.NavigateURL(detailTabId, isSuperTab, portalSettings, "", DnnLanguageUtils.GetCurrentCultureCode(), pagename, additionalParameters);
var url = Globals.NavigateURL(detailTabId, isSuperTab, portalSettings, "", currentCultureCode, pagename, additionalParameters);
return url;
}

Expand Down
6 changes: 3 additions & 3 deletions OpenContent/Components/Dnn/DnnUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ public static bool IsPublishedTab(this TabInfo tab)

public static OpenContentSettings OpenContentSettings(this ModuleInfo module)
{
return new OpenContentSettings(ComponentSettingsInfo.Create(module.ModuleSettings));
return new OpenContentSettings(ComponentSettingsInfo.Create(module.ModuleSettings, module.TabModuleSettings));
}
public static OpenContentSettings OpenContentSettings(this ModuleInstanceContext module)
{
return new OpenContentSettings(ComponentSettingsInfo.Create(module.Settings));
return new OpenContentSettings(ComponentSettingsInfo.Create(module.Settings, null));
}
public static OpenContentSettings OpenContentSettings(this PortalModuleBase module)
{
return new OpenContentSettings(ComponentSettingsInfo.Create(module.Settings));
return new OpenContentSettings(ComponentSettingsInfo.Create(module.Settings, null));
}

internal static void RegisterScript(Page page, string sourceFolder, string jsfilename, int jsOrder, string provider = "DnnBodyProvider")
Expand Down
2 changes: 1 addition & 1 deletion OpenContent/Components/FeatureController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class FeatureController : ModuleSearchBase, IPortable, IUpgradeable, IMod
public string ExportModule(int moduleId)
{
string xml = "";
OpenContentController ctrl = new OpenContentController();
OpenContentController ctrl = new OpenContentController(PortalSettings.Current.PortalId);
var items = ctrl.GetContents(moduleId);
xml += "<opencontent>";
foreach (var item in items)
Expand Down
2 changes: 0 additions & 2 deletions OpenContent/Components/FileUploadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ private void UploadWholeFile(HttpContextBase context, ICollection<FilesStatus> s
}
}



public static string CleanUpFileName(string filename)
{
var newName = HttpUtility.UrlDecode(filename);
Expand Down
28 changes: 24 additions & 4 deletions OpenContent/Components/Form/FormUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static string SendMail(string mailFrom, string mailTo, string replyTo, st
DotNetNuke.Services.Mail.MailPriority priority = DotNetNuke.Services.Mail.MailPriority.Normal;
MailFormat bodyFormat = MailFormat.Html;
Encoding bodyEncoding = Encoding.UTF8;

string smtpServer = Host.SMTPServer;
string smtpAuthentication = Host.SMTPAuthentication;
string smtpUsername = Host.SMTPUsername;
Expand Down Expand Up @@ -301,7 +301,26 @@ public static JObject FormSubmit(JObject form, SettingsDTO settings, JObject ite
string body = formData;
if (!string.IsNullOrEmpty(notification.EmailBody))
{
body = hbs.Execute(notification.EmailBody, data);
try
{
body = hbs.Execute(notification.EmailBody, data);
}
catch (Exception ex)
{
throw new Exception("Email Body : " + ex.Message, ex);
}
}
string subject = notification.EmailSubject;
if (!string.IsNullOrEmpty(notification.EmailSubject))
{
try
{
subject = hbs.Execute(notification.EmailSubject, data);
}
catch (Exception ex)
{
throw new Exception("Email Subject : " + ex.Message, ex);
}
}
var attachements = new List<Attachment>();
if (form["Files"] is JArray)
Expand All @@ -312,15 +331,15 @@ public static JObject FormSubmit(JObject form, SettingsDTO settings, JObject ite
attachements.Add(new Attachment(FileManager.Instance.GetFileContent(file), fileItem["name"].ToString()));
}
}
string send = FormUtils.SendMail(from.ToString(), to.ToString(), reply?.ToString() ?? "", notification.CcEmails, notification.BccEmails, notification.EmailSubject, body, attachements);
string send = FormUtils.SendMail(from.ToString(), to.ToString(), reply?.ToString() ?? "", notification.CcEmails, notification.BccEmails, subject, body, attachements);
if (!string.IsNullOrEmpty(send))
{
errors.Add("From:" + from.ToString() + " - To:" + to.ToString() + " - " + send);
}
}
catch (Exception exc)
{
errors.Add("Notification " + (settings.Notifications.IndexOf(notification) + 1) + " : " + exc.Message);
errors.Add("Error in Email Notification " + (settings.Notifications.IndexOf(notification) + 1) + " : " + exc.Message);
App.Services.Logger.Error(exc);
}
}
Expand All @@ -343,6 +362,7 @@ public static JObject FormSubmit(JObject form, SettingsDTO settings, JObject ite
}
var res = new JObject();
res["message"] = message;
res["errors"] = new JArray(errors);
return res;
}
return null;
Expand Down
12 changes: 6 additions & 6 deletions OpenContent/Components/Handlebars/HandlebarsEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void Compile(string source)
catch (Exception ex)
{
App.Services.Logger.Error($"Failed to render Handlebar template source:[{source}]", ex);
throw new TemplateException("Failed to render Handlebar template " + source, ex, null, source);
throw new TemplateException("Failed to render Handlebar template " + ex.Message, ex, null, source);
}
}

Expand All @@ -72,7 +72,7 @@ public string Execute(Dictionary<string, object> model)
catch (Exception ex)
{
App.Services.Logger.Error(string.Format("Failed to execute Handlebar template with model:[{1}]", "", model), ex);
throw new TemplateException("Failed to render Handlebar template ", ex, model, "");
throw new TemplateException("Failed to render Handlebar template : "+ex.Message, ex, model, "");
}
}

Expand All @@ -87,7 +87,7 @@ public string Execute(string source, object model)
catch (Exception ex)
{
App.Services.Logger.Error($"Failed to render Handlebar template source:[{source}], model:[{model}]", ex);
throw new TemplateException("Failed to render Handlebar template ", ex, model, source);
throw new TemplateException("Failed to render Handlebar template : " + ex.Message, ex, model, source);
}
}
public string ExecuteWithoutFaillure(string source, Dictionary<string, object> model, string defaultValue)
Expand Down Expand Up @@ -613,15 +613,15 @@ private static void RegisterEmailHelper(HandlebarsDotNet.IHandlebars hbs)

private static void RegisterUrlHelper(HandlebarsDotNet.IHandlebars hbs)
{
hbs.RegisterHelper("url", (writer, context, parameters) =>
hbs.RegisterHelper("prefixurl", (writer, context, parameters) =>
{
try
{
string url = parameters[0].ToString();
string lowerUrl = url.ToLower();
if (!lowerUrl.StartsWith("http://") &&
!lowerUrl.StartsWith("https://") &&
!lowerUrl.StartsWith("phone:") &&
!lowerUrl.StartsWith("tel:") &&
!lowerUrl.StartsWith("mail:"))
{
if (IsEmailAdress(url))
Expand All @@ -630,7 +630,7 @@ private static void RegisterUrlHelper(HandlebarsDotNet.IHandlebars hbs)
}
else if (IsPhoneNumber(url))
{
url = "phone:" + url;
url = "tel:" + url;
}
else
{
Expand Down
Loading

0 comments on commit a3dadd8

Please sign in to comment.