2018-09-24 13:50:42 +10:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2018-09-20 17:22:39 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Composing;
|
|
|
|
|
|
using Umbraco.Core.Models.ContentEditing;
|
2018-09-24 13:50:42 +10:00
|
|
|
|
using Umbraco.Core.Logging;
|
2018-12-06 10:02:23 +01:00
|
|
|
|
using Umbraco.Core.Manifest;
|
2018-10-14 15:56:22 +01:00
|
|
|
|
using Umbraco.Core.Models.Membership;
|
2018-09-20 17:22:39 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.ContentApps
|
|
|
|
|
|
{
|
2018-12-06 10:02:23 +01:00
|
|
|
|
public class ContentAppDefinitionCollection : BuilderCollectionBase<IContentAppFactory>
|
2018-09-20 17:22:39 +02:00
|
|
|
|
{
|
2018-09-24 09:34:25 +02:00
|
|
|
|
private readonly ILogger _logger;
|
2018-12-06 10:02:23 +01:00
|
|
|
|
private readonly IContentAppFactory _factory;
|
2018-09-24 13:50:42 +10:00
|
|
|
|
|
2018-12-06 10:02:23 +01:00
|
|
|
|
public ContentAppDefinitionCollection(IEnumerable<IContentAppFactory> items, ILogger logger)
|
2018-09-20 17:22:39 +02:00
|
|
|
|
: base(items)
|
2018-09-24 13:50:42 +10:00
|
|
|
|
{
|
2018-09-24 09:34:25 +02:00
|
|
|
|
_logger = logger;
|
2018-09-24 13:50:42 +10:00
|
|
|
|
}
|
2018-09-20 17:22:39 +02:00
|
|
|
|
|
2018-10-16 15:05:17 +02:00
|
|
|
|
private IEnumerable<IReadOnlyUserGroup> GetCurrentUserGroups()
|
|
|
|
|
|
{
|
|
|
|
|
|
var umbracoContext = Composing.Current.UmbracoContext;
|
|
|
|
|
|
var currentUser = umbracoContext?.Security?.CurrentUser;
|
|
|
|
|
|
return currentUser == null
|
|
|
|
|
|
? Enumerable.Empty<IReadOnlyUserGroup>()
|
|
|
|
|
|
: currentUser.Groups;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-14 15:56:22 +01:00
|
|
|
|
public IEnumerable<ContentApp> GetContentAppsFor(object o, IEnumerable<IReadOnlyUserGroup> userGroups=null)
|
2018-09-20 17:22:39 +02:00
|
|
|
|
{
|
2018-10-16 15:05:17 +02:00
|
|
|
|
var roles = GetCurrentUserGroups();
|
2018-12-06 10:02:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var apps = Enumerable.Empty<ContentApp>();// this.Select(x => x.GetContentAppFor(o, roles)).WhereNotNull().OrderBy(x => x.Weight).ToList();
|
|
|
|
|
|
|
2018-09-24 09:34:25 +02:00
|
|
|
|
|
|
|
|
|
|
var aliases = new HashSet<string>();
|
2018-09-24 13:50:42 +10:00
|
|
|
|
List<string> dups = null;
|
2018-09-24 09:34:25 +02:00
|
|
|
|
|
|
|
|
|
|
foreach (var app in apps)
|
2018-09-24 13:50:42 +10:00
|
|
|
|
{
|
2018-09-24 09:34:25 +02:00
|
|
|
|
if (aliases.Contains(app.Alias))
|
|
|
|
|
|
(dups ?? (dups = new List<string>())).Add(app.Alias);
|
2018-09-24 13:50:42 +10:00
|
|
|
|
else
|
2018-09-24 09:34:25 +02:00
|
|
|
|
aliases.Add(app.Alias);
|
2018-09-24 13:50:42 +10:00
|
|
|
|
}
|
2018-09-24 09:34:25 +02:00
|
|
|
|
|
2018-09-24 13:50:42 +10:00
|
|
|
|
if (dups != null)
|
|
|
|
|
|
{
|
2018-09-24 09:34:25 +02:00
|
|
|
|
// dying is not user-friendly, so let's write to log instead, and wish people read logs...
|
|
|
|
|
|
|
|
|
|
|
|
//throw new InvalidOperationException($"Duplicate content app aliases found: {string.Join(",", dups)}");
|
2018-11-06 10:25:35 +00:00
|
|
|
|
_logger.Warn<ContentAppDefinitionCollection>("Duplicate content app aliases found: {DuplicateAliases}", string.Join(",", dups));
|
2018-09-24 13:50:42 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-24 09:34:25 +02:00
|
|
|
|
return apps;
|
2018-09-20 17:22:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|