2019-06-07 08:59:07 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) Copyright Ascensio System Limited 2010-2018
|
|
|
|
*
|
|
|
|
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
|
|
|
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
|
|
|
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
|
|
|
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
|
|
|
*
|
|
|
|
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
|
|
|
*
|
|
|
|
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
|
|
|
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
|
|
|
*
|
|
|
|
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
|
|
|
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
|
|
|
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
|
|
|
* in every copy of the program you distribute.
|
|
|
|
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2021-01-26 09:29:50 +00:00
|
|
|
using System.Collections.Concurrent;
|
2019-06-07 08:59:07 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-02-17 08:58:14 +00:00
|
|
|
|
|
|
|
using ASC.Common;
|
2019-06-07 08:59:07 +00:00
|
|
|
using ASC.Common.Logging;
|
2019-09-09 12:56:33 +00:00
|
|
|
using ASC.Core;
|
2019-06-07 08:59:07 +00:00
|
|
|
using ASC.Web.Core.WebZones;
|
2019-07-12 13:23:39 +00:00
|
|
|
|
2019-06-10 16:15:34 +00:00
|
|
|
using Autofac;
|
2020-02-17 08:58:14 +00:00
|
|
|
|
2019-09-23 12:20:08 +00:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2019-10-17 15:55:35 +00:00
|
|
|
using Microsoft.Extensions.Options;
|
2019-06-07 08:59:07 +00:00
|
|
|
|
|
|
|
namespace ASC.Web.Core
|
|
|
|
{
|
|
|
|
[Flags]
|
|
|
|
public enum ItemAvailableState
|
|
|
|
{
|
|
|
|
Normal = 1,
|
|
|
|
Disabled = 2,
|
|
|
|
All = Normal | Disabled
|
|
|
|
}
|
|
|
|
|
2020-10-19 15:53:15 +00:00
|
|
|
[Singletone]
|
2019-06-07 08:59:07 +00:00
|
|
|
public class WebItemManager
|
|
|
|
{
|
2019-10-17 15:55:35 +00:00
|
|
|
private readonly ILog log;
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2021-01-26 09:29:50 +00:00
|
|
|
private ConcurrentDictionary<Guid, IWebItem> items;
|
|
|
|
private ConcurrentDictionary<Guid, IWebItem> Items
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (lazyItems.IsValueCreated)
|
|
|
|
{
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
return items = lazyItems.Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private readonly Lazy<ConcurrentDictionary<Guid, IWebItem>> lazyItems;
|
2019-09-23 12:20:08 +00:00
|
|
|
private readonly List<string> disableItem;
|
2019-06-07 08:59:07 +00:00
|
|
|
|
|
|
|
public static Guid CommunityProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{EA942538-E68E-4907-9394-035336EE0BA8}"); }
|
|
|
|
}
|
2019-08-15 12:04:42 +00:00
|
|
|
|
2019-06-07 08:59:07 +00:00
|
|
|
public static Guid ProjectsProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{1e044602-43b5-4d79-82f3-fd6208a11960}"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Guid CRMProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{6743007C-6F95-4d20-8C88-A8601CE5E76D}"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Guid DocumentsProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{E67BE73D-F9AE-4ce1-8FEC-1880CB518CB4}"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Guid PeopleProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{F4D98AFD-D336-4332-8778-3C6945C81EA0}"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Guid MailProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{2A923037-8B2D-487b-9A22-5AC0918ACF3F}"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Guid CalendarProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{32D24CB5-7ECE-4606-9C94-19216BA42086}"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Guid BirthdaysProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{37620AE5-C40B-45ce-855A-39DD7D76A1FA}"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Guid TalkProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{BF88953E-3C43-4850-A3FB-B1E43AD53A3E}"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Guid VoipModuleID
|
|
|
|
{
|
|
|
|
get { return new Guid("{46CFA73A-F320-46CF-8D5B-CD82E1D67F26}"); }
|
|
|
|
}
|
|
|
|
|
2021-01-26 09:29:50 +00:00
|
|
|
private ILifetimeScope Container { get; }
|
2020-08-12 09:58:08 +00:00
|
|
|
private IConfiguration Configuration { get; }
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2021-01-26 09:29:50 +00:00
|
|
|
|
2019-06-07 08:59:07 +00:00
|
|
|
public IWebItem this[Guid id]
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2021-01-26 09:29:50 +00:00
|
|
|
Items.TryGetValue(id, out var i);
|
2019-06-07 08:59:07 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 16:27:08 +00:00
|
|
|
public WebItemManager(ILifetimeScope container, IConfiguration configuration, IOptionsMonitor<ILog> options)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-06-10 16:15:34 +00:00
|
|
|
Container = container;
|
2019-09-23 12:20:08 +00:00
|
|
|
Configuration = configuration;
|
2019-10-17 15:55:35 +00:00
|
|
|
log = options.Get("ASC.Web");
|
2019-09-23 12:20:08 +00:00
|
|
|
disableItem = (Configuration["web:disabled-items"] ?? "").Split(",").ToList();
|
2021-01-26 09:29:50 +00:00
|
|
|
lazyItems = new Lazy<ConcurrentDictionary<Guid, IWebItem>>(LoadItems, System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 09:29:50 +00:00
|
|
|
private ConcurrentDictionary<Guid, IWebItem> LoadItems()
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2021-01-26 09:29:50 +00:00
|
|
|
var result = new ConcurrentDictionary<Guid, IWebItem>();
|
|
|
|
|
|
|
|
if (Container == null) return result;
|
2020-04-29 14:11:31 +00:00
|
|
|
|
2019-06-10 16:15:34 +00:00
|
|
|
foreach (var webitem in Container.Resolve<IEnumerable<IWebItem>>())
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-06-10 16:15:34 +00:00
|
|
|
var file = webitem.ID.ToString();
|
2019-06-07 08:59:07 +00:00
|
|
|
try
|
|
|
|
{
|
2019-06-10 12:17:45 +00:00
|
|
|
if (DisabledWebItem(file)) continue;
|
|
|
|
|
2021-01-26 09:29:50 +00:00
|
|
|
RegistryItem(result, webitem);
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
catch (Exception exc)
|
|
|
|
{
|
|
|
|
log.Error(string.Format("Couldn't load web item {0}", file), exc);
|
|
|
|
}
|
|
|
|
}
|
2021-01-26 09:29:50 +00:00
|
|
|
|
|
|
|
return result;
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 09:29:50 +00:00
|
|
|
private void RegistryItem(ConcurrentDictionary<Guid, IWebItem> result, IWebItem webitem)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2021-01-26 09:29:50 +00:00
|
|
|
if (webitem != null && !result.TryGetValue(webitem.ID, out _))
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2021-01-26 09:29:50 +00:00
|
|
|
if (webitem is IAddon addon)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2021-01-26 09:29:50 +00:00
|
|
|
addon.Init();
|
|
|
|
}
|
|
|
|
if (webitem is IProduct product)
|
|
|
|
{
|
|
|
|
product.Init();
|
|
|
|
}
|
2019-08-15 12:04:42 +00:00
|
|
|
|
2021-01-26 09:29:50 +00:00
|
|
|
if (webitem is IModule module)
|
|
|
|
{
|
|
|
|
if (module.Context != null && module.Context.SearchHandler != null)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2021-01-26 09:29:50 +00:00
|
|
|
//TODO
|
|
|
|
//SearchHandlerManager.Registry(module.Context.SearchHandler);
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-26 09:29:50 +00:00
|
|
|
|
|
|
|
result.TryAdd(webitem.ID, webitem);
|
|
|
|
log.DebugFormat("Web item {0} loaded", webitem.Name);
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-11 10:42:52 +00:00
|
|
|
public Guid GetParentItemID(Guid itemID)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-11 10:42:52 +00:00
|
|
|
return this[itemID] is IModule m ? m.ProjectId : Guid.Empty;
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-11 10:42:52 +00:00
|
|
|
public int GetSortOrder(IWebItem item)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-11 10:42:52 +00:00
|
|
|
return item != null && item.Context != null ? item.Context.DefaultSortOrder : 0;
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2019-09-11 10:42:52 +00:00
|
|
|
public List<IWebItem> GetItemsAll()
|
|
|
|
{
|
2021-01-26 09:29:50 +00:00
|
|
|
var list = Items.Values.ToList();
|
2019-06-07 08:59:07 +00:00
|
|
|
list.Sort((x, y) => GetSortOrder(x).CompareTo(GetSortOrder(y)));
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2019-09-11 10:42:52 +00:00
|
|
|
public List<T> GetItemsAll<T>() where T : IWebItem
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-11 10:42:52 +00:00
|
|
|
return GetItemsAll().OfType<T>().ToList();
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-11 10:42:52 +00:00
|
|
|
private bool DisabledWebItem(string name)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-11 10:42:52 +00:00
|
|
|
return disableItem.Contains(name);
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
2019-09-11 10:42:52 +00:00
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2020-10-19 15:53:15 +00:00
|
|
|
[Scope]
|
2019-09-11 10:42:52 +00:00
|
|
|
public class WebItemManagerSecurity
|
|
|
|
{
|
2020-08-12 09:58:08 +00:00
|
|
|
private WebItemSecurity WebItemSecurity { get; }
|
|
|
|
private AuthContext AuthContext { get; }
|
|
|
|
private WebItemManager WebItemManager { get; }
|
2019-09-11 10:42:52 +00:00
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public WebItemManagerSecurity(WebItemSecurity webItemSecurity, AuthContext authContext, WebItemManager webItemManager)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-11 10:42:52 +00:00
|
|
|
WebItemSecurity = webItemSecurity;
|
|
|
|
AuthContext = authContext;
|
|
|
|
WebItemManager = webItemManager;
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 14:51:39 +00:00
|
|
|
public List<IWebItem> GetItems(WebZoneType webZone)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-16 14:51:39 +00:00
|
|
|
return GetItems(webZone, ItemAvailableState.Normal);
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 14:51:39 +00:00
|
|
|
public List<IWebItem> GetItems(WebZoneType webZone, ItemAvailableState avaliableState)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-11 10:42:52 +00:00
|
|
|
var copy = WebItemManager.GetItemsAll().ToList();
|
|
|
|
var list = copy.Where(item =>
|
|
|
|
{
|
2019-09-16 14:51:39 +00:00
|
|
|
if ((avaliableState & ItemAvailableState.Disabled) != ItemAvailableState.Disabled && item.IsDisabled(WebItemSecurity, AuthContext))
|
2019-09-11 10:42:52 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var attribute = (WebZoneAttribute)Attribute.GetCustomAttribute(item.GetType(), typeof(WebZoneAttribute), true);
|
|
|
|
return attribute != null && (attribute.Type & webZone) != 0;
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
list.Sort((x, y) => WebItemManager.GetSortOrder(x).CompareTo(WebItemManager.GetSortOrder(y)));
|
2019-06-07 08:59:07 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2019-09-16 14:51:39 +00:00
|
|
|
public List<IWebItem> GetSubItems(Guid parentItemID)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-16 14:51:39 +00:00
|
|
|
return GetSubItems(parentItemID, ItemAvailableState.Normal);
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 14:51:39 +00:00
|
|
|
public List<IWebItem> GetSubItems(Guid parentItemID, ItemAvailableState avaliableState)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-16 14:51:39 +00:00
|
|
|
return GetItems(WebZoneType.All, avaliableState).OfType<IModule>()
|
2019-09-11 10:42:52 +00:00
|
|
|
.Where(p => p.ProjectId == parentItemID)
|
|
|
|
.Cast<IWebItem>()
|
|
|
|
.ToList();
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
2019-06-10 12:17:45 +00:00
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|