Implemented auto-mapper for mapping and converted over the user mappings. Got the gravatar directive working now too. Removed all umbracoUseMediumTrust settings.
This commit is contained in:
@@ -75,6 +75,8 @@ namespace Umbraco.Core
|
||||
//initialize the DatabaseContext
|
||||
dbContext.Initialize();
|
||||
|
||||
InitializeModelMappers();
|
||||
|
||||
//now we need to call the initialize methods
|
||||
ApplicationEventsResolver.Current.ApplicationEventHandlers
|
||||
.ForEach(x => x.OnApplicationInitialized(UmbracoApplication, ApplicationContext));
|
||||
@@ -95,6 +97,14 @@ namespace Umbraco.Core
|
||||
ApplicationContext = ApplicationContext.Current = new ApplicationContext(dbContext, serviceContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method allows for configuration of model mappers
|
||||
/// </summary>
|
||||
protected virtual void InitializeModelMappers()
|
||||
{
|
||||
//TODO: There will most likely be AutoMapper configs to put in here, we know they exist in web for now so we'll leave this here for future use
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Special method to initialize the ProfilerResolver
|
||||
/// </summary>
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
<add key="umbracoDefaultUILanguage" value="en"/>
|
||||
<add key="umbracoProfileUrl" value="profiler"/>
|
||||
<add key="umbracoUseSSL" value="false"/>
|
||||
<add key="umbracoUseMediumTrust" value="false"/>
|
||||
</appSettings>
|
||||
|
||||
<connectionStrings>
|
||||
|
||||
@@ -7,7 +7,16 @@ function avatarDirective() {
|
||||
return {
|
||||
restrict: "E", // restrict to an element
|
||||
replace: true, // replace the html element with the template
|
||||
templateUrl: 'views/directives/umb-avatar.html'
|
||||
templateUrl: 'views/directives/umb-avatar.html',
|
||||
scope: {
|
||||
name: '@',
|
||||
email: '@',
|
||||
hash: '@',
|
||||
},
|
||||
link: function(scope, element, attr, ctrl) {
|
||||
//set the gravatar url
|
||||
scope.gravatar = "http://www.gravatar.com/avatar/" + scope.hash + "?s=40";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<a href="#" title="{{name}}">
|
||||
<img ng-src="{{email}}" />
|
||||
<img ng-src="{{gravatar}}" />
|
||||
</a>
|
||||
@@ -3,7 +3,7 @@
|
||||
<ul class="sections">
|
||||
|
||||
<li class="avatar">
|
||||
<umb-avatar name="{{user.name}}" email="{{user.email}}"></umb-avatar>
|
||||
<umb-avatar name="{{user.name}}" email="{{user.email}}" hash="{{user.emailHash}}"></umb-avatar>
|
||||
</li>
|
||||
|
||||
<li ng-repeat="section in sections">
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<ul class="sections">
|
||||
|
||||
<li class="avatar">
|
||||
<umb-avatar name="{{user.name}}" email="{{user.email}}"></umb-avatar>
|
||||
<umb-avatar name="{{user.name}}" email="{{user.email}}" hash="{{user.emailHash}}"></umb-avatar>
|
||||
</li>
|
||||
|
||||
<li ng-repeat="section in sections">
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
|
||||
<system.web>
|
||||
<compilation debug="true" xdt:Transform="SetAttributes(debug)" />
|
||||
<!-- We no longer support medium trust so just remove it -->
|
||||
<trust xdt:Transform="Remove" />
|
||||
<trust level="Medium" originUrl=".*" xdt:Transform="Insert" />
|
||||
</system.web>
|
||||
|
||||
<runtime>
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
<add key="umbracoDefaultUILanguage" value="en" />
|
||||
<add key="umbracoProfileUrl" value="profiler" />
|
||||
<add key="umbracoUseSSL" value="false" />
|
||||
<add key="umbracoUseMediumTrust" value="false" />
|
||||
|
||||
<!-- Set this to true to enable storing the xml cache locally to the IIS server even if the app files are stored centrally on a SAN/NAS Alex Norcliffe 2010 02 for 4.1 -->
|
||||
<add key="umbracoContentXMLUseLocalTemp" value="false"/>
|
||||
@@ -283,4 +282,4 @@
|
||||
</pages>
|
||||
</system.web.webPages.razor>
|
||||
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
||||
@@ -13,5 +13,11 @@ namespace Umbraco.Web.Models.ContentEditing
|
||||
[DataMember(Name = "locale", IsRequired = true)]
|
||||
[Required]
|
||||
public string Language { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The MD5 lowercase hash of the email which can be used by gravatar
|
||||
/// </summary>
|
||||
[DataMember(Name = "emailHash")]
|
||||
public string EmailHash { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using AutoMapper;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
@@ -7,36 +8,39 @@ namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
internal class UserModelMapper
|
||||
{
|
||||
public UserDetail ToUserDetail(IUser user)
|
||||
/// <summary>
|
||||
/// Configures the automapper mappings
|
||||
/// </summary>
|
||||
internal static void Configure()
|
||||
{
|
||||
var detail = new UserDetail
|
||||
{
|
||||
Name = user.Name,
|
||||
Email = user.Email,
|
||||
Language = user.Language
|
||||
};
|
||||
var result = user.Id.TryConvertTo<int>();
|
||||
Mapper.CreateMap<IUser, UserDetail>()
|
||||
.ForMember(detail => detail.UserId, opt => opt.MapFrom(user => GetIntId(user.Id)))
|
||||
.ForMember(
|
||||
detail => detail.EmailHash,
|
||||
opt => opt.MapFrom(user => user.Email.ToLowerInvariant().Trim().ToMd5()));
|
||||
Mapper.CreateMap<IProfile, UserBasic>()
|
||||
.ForMember(detail => detail.UserId, opt => opt.MapFrom(profile => GetIntId(profile.Id)));
|
||||
}
|
||||
|
||||
private static int GetIntId(object id)
|
||||
{
|
||||
var result = id.TryConvertTo<int>();
|
||||
if (result.Success == false)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot convert the profile to a " + typeof(UserDetail).Name + " object since the id is not an integer");
|
||||
throw new InvalidOperationException(
|
||||
"Cannot convert the profile to a " + typeof(UserDetail).Name + " object since the id is not an integer");
|
||||
}
|
||||
detail.UserId = result.Result;
|
||||
return detail;
|
||||
return result.Result;
|
||||
}
|
||||
|
||||
public UserDetail ToUserDetail(IUser user)
|
||||
{
|
||||
return Mapper.Map<UserDetail>(user);
|
||||
}
|
||||
|
||||
public UserBasic ToUserBasic(IProfile profile)
|
||||
{
|
||||
var user = new UserBasic
|
||||
{
|
||||
Name = profile.Name
|
||||
};
|
||||
var result = profile.Id.TryConvertTo<int>();
|
||||
if (result.Success == false)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot convert the profile to a " + typeof(UserBasic).Name + " object since the id is not an integer");
|
||||
}
|
||||
user.UserId = result.Result;
|
||||
return user;
|
||||
return Mapper.Map<UserDetail>(profile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,9 @@
|
||||
<Project>{07fbc26b-2927-4a22-8d96-d644c667fecc}</Project>
|
||||
<Name>UmbracoExamine</Name>
|
||||
</ProjectReference>
|
||||
<Reference Include="AutoMapper">
|
||||
<HintPath>..\packages\AutoMapper.2.2.1\lib\net40\AutoMapper.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ClientDependency.Core, Version=1.7.0.2, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\ClientDependency.1.7.0.2\lib\ClientDependency.Core.dll</HintPath>
|
||||
@@ -309,7 +312,6 @@
|
||||
<Compile Include="Models\Mapping\ContentTypeModelMapper.cs" />
|
||||
<Compile Include="Models\Mapping\MediaModelMapper.cs" />
|
||||
<Compile Include="Models\Mapping\UserModelMapper.cs" />
|
||||
<Compile Include="Mvc\BackOfficeArea.cs" />
|
||||
<Compile Include="Trees\LegacyTreeApiController.cs" />
|
||||
<Compile Include="Trees\ISearchableTree.cs" />
|
||||
<Compile Include="Trees\LegacyTreeDataAdapter.cs" />
|
||||
|
||||
@@ -20,6 +20,7 @@ using Umbraco.Web.Editors;
|
||||
using Umbraco.Web.Media;
|
||||
using Umbraco.Web.Media.ThumbnailProviders;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Models.Mapping;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
@@ -111,6 +112,15 @@ namespace Umbraco.Web
|
||||
ProfilerResolver.Current.SetProfiler(new WebProfiler());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure the model mappers
|
||||
/// </summary>
|
||||
protected override void InitializeModelMappers()
|
||||
{
|
||||
base.InitializeModelMappers();
|
||||
UserModelMapper.Configure();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds custom types to the ApplicationEventsResolver
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="AutoMapper" version="2.2.1" targetFramework="net45" />
|
||||
<package id="ClientDependency" version="1.7.0.2" targetFramework="net40" />
|
||||
<package id="CodeSharp.Package.AspNetWebPage" version="1.0" targetFramework="net40" />
|
||||
<package id="Examine" version="0.1.51.2941" targetFramework="net40" />
|
||||
|
||||
@@ -101,31 +101,6 @@ namespace umbraco
|
||||
get { return Umbraco.Core.SystemUtilities.GetCurrentTrustLevel(); }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Forces umbraco to be medium trust compatible
|
||||
/// </summary>
|
||||
/// <value>If true, umbraco will be medium-trust compatible, no matter what Permission level the server is on.</value>
|
||||
[Obsolete("This property is no longer used and will be removed in future versions")]
|
||||
public static bool UseMediumTrust
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
var trustLevel = SystemUtilities.GetCurrentTrustLevel();
|
||||
if (trustLevel == AspNetHostingPermissionLevel.High || trustLevel == AspNetHostingPermissionLevel.Unrestricted)
|
||||
return false;
|
||||
else
|
||||
return bool.Parse(ConfigurationManager.AppSettings["umbracoUseMediumTrust"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a setting into the configuration file.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user