2022-03-15 18:00:53 +00:00
|
|
|
// (c) Copyright Ascensio System SIA 2010-2022
|
|
|
|
//
|
|
|
|
// This program is a free software product.
|
|
|
|
// You can redistribute it and/or modify it under the terms
|
|
|
|
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
|
|
|
|
// Foundation. In accordance with Section 7(a) of the GNU AGPL 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 details, see
|
|
|
|
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
|
|
//
|
|
|
|
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
|
|
|
|
//
|
|
|
|
// The interactive user interfaces in modified source and object code versions of the Program must
|
|
|
|
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
|
|
|
|
//
|
|
|
|
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
|
|
|
|
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
|
|
|
|
// trademark law for use of our trademarks.
|
|
|
|
//
|
|
|
|
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
|
|
|
|
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
|
|
|
|
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
namespace ASC.Web.Core;
|
|
|
|
|
|
|
|
[Flags]
|
|
|
|
public enum ItemAvailableState
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
Normal = 1,
|
|
|
|
Disabled = 2,
|
|
|
|
All = Normal | Disabled
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
[Singletone]
|
|
|
|
public class WebItemManager
|
|
|
|
{
|
2022-04-26 17:53:48 +00:00
|
|
|
private readonly ILogger _log;
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 16:57:02 +00:00
|
|
|
private ConcurrentDictionary<Guid, IWebItem> _items;
|
2022-03-17 15:13:38 +00:00
|
|
|
private ConcurrentDictionary<Guid, IWebItem> Items
|
|
|
|
{
|
|
|
|
get
|
2021-01-26 09:29:50 +00:00
|
|
|
{
|
2022-03-17 16:57:02 +00:00
|
|
|
if (_lazyItems.IsValueCreated)
|
2021-01-26 09:29:50 +00:00
|
|
|
{
|
2022-03-17 16:57:02 +00:00
|
|
|
return _items;
|
2021-01-26 09:29:50 +00:00
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 16:57:02 +00:00
|
|
|
return _items = _lazyItems.Value;
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2022-03-17 16:57:02 +00:00
|
|
|
private readonly Lazy<ConcurrentDictionary<Guid, IWebItem>> _lazyItems;
|
|
|
|
private readonly List<string> _disableItem;
|
2019-08-15 12:04:42 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public static Guid CommunityProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{EA942538-E68E-4907-9394-035336EE0BA8}"); }
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public static Guid ProjectsProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{1e044602-43b5-4d79-82f3-fd6208a11960}"); }
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public static Guid CRMProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{6743007C-6F95-4d20-8C88-A8601CE5E76D}"); }
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public static Guid DocumentsProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{E67BE73D-F9AE-4ce1-8FEC-1880CB518CB4}"); }
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public static Guid PeopleProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{F4D98AFD-D336-4332-8778-3C6945C81EA0}"); }
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public static Guid MailProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{2A923037-8B2D-487b-9A22-5AC0918ACF3F}"); }
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public static Guid CalendarProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{32D24CB5-7ECE-4606-9C94-19216BA42086}"); }
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public static Guid BirthdaysProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{37620AE5-C40B-45ce-855A-39DD7D76A1FA}"); }
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public static Guid TalkProductID
|
|
|
|
{
|
|
|
|
get { return new Guid("{BF88953E-3C43-4850-A3FB-B1E43AD53A3E}"); }
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public static Guid VoipModuleID
|
|
|
|
{
|
|
|
|
get { return new Guid("{46CFA73A-F320-46CF-8D5B-CD82E1D67F26}"); }
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-04-15 09:08:06 +00:00
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
private readonly IConfiguration _configuration;
|
2021-01-26 09:29:50 +00:00
|
|
|
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public IWebItem this[Guid id]
|
|
|
|
{
|
|
|
|
get
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
Items.TryGetValue(id, out var i);
|
|
|
|
return i;
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-04-26 17:53:48 +00:00
|
|
|
public WebItemManager(IServiceProvider serviceProvider, IConfiguration configuration, ILoggerProvider options)
|
2022-03-17 15:13:38 +00:00
|
|
|
{
|
2022-04-15 09:08:06 +00:00
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
_configuration = configuration;
|
2022-04-26 17:53:48 +00:00
|
|
|
_log = options.CreateLogger("ASC.Web");
|
2022-04-15 09:08:06 +00:00
|
|
|
_disableItem = (_configuration["web:disabled-items"] ?? "").Split(",").ToList();
|
|
|
|
_lazyItems = new Lazy<ConcurrentDictionary<Guid, IWebItem>>(LoadItems, LazyThreadSafetyMode.ExecutionAndPublication);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2021-01-26 09:29:50 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
private ConcurrentDictionary<Guid, IWebItem> LoadItems()
|
|
|
|
{
|
|
|
|
var result = new ConcurrentDictionary<Guid, IWebItem>();
|
2019-06-10 12:17:45 +00:00
|
|
|
|
2022-04-15 09:08:06 +00:00
|
|
|
foreach (var webitem in _serviceProvider.GetService<IEnumerable<IWebItem>>())
|
2022-03-17 15:13:38 +00:00
|
|
|
{
|
|
|
|
var file = webitem.ID.ToString();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (DisabledWebItem(file))
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
continue;
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
2021-01-26 09:29:50 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
RegistryItem(result, webitem);
|
|
|
|
}
|
|
|
|
catch (Exception exc)
|
|
|
|
{
|
2022-05-13 14:48:49 +00:00
|
|
|
_log.ErrorCouldntLoadWebItem(file, exc);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RegistryItem(ConcurrentDictionary<Guid, IWebItem> result, IWebItem webitem)
|
|
|
|
{
|
|
|
|
if (webitem != null && !result.TryGetValue(webitem.ID, out _))
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
if (webitem is IAddon addon)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
addon.Init();
|
|
|
|
}
|
|
|
|
if (webitem is IProduct product)
|
|
|
|
{
|
|
|
|
product.Init();
|
|
|
|
}
|
2019-08-15 12:04:42 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (webitem is IModule module)
|
|
|
|
{
|
|
|
|
if (module.Context != null && module.Context.SearchHandler != null)
|
2021-01-26 09:29:50 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
//TODO
|
|
|
|
//SearchHandlerManager.Registry(module.Context.SearchHandler);
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
result.TryAdd(webitem.ID, webitem);
|
2022-05-13 14:48:49 +00:00
|
|
|
_log.DebugWebItemLoaded(webitem.Name);
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public Guid GetParentItemID(Guid itemID)
|
|
|
|
{
|
|
|
|
return this[itemID] is IModule m ? m.ProjectId : Guid.Empty;
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public int GetSortOrder(IWebItem item)
|
|
|
|
{
|
|
|
|
return item != null && item.Context != null ? item.Context.DefaultSortOrder : 0;
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public List<IWebItem> GetItemsAll()
|
|
|
|
{
|
|
|
|
var list = Items.Values.ToList();
|
|
|
|
list.Sort((x, y) => GetSortOrder(x).CompareTo(GetSortOrder(y)));
|
|
|
|
return list;
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public List<T> GetItemsAll<T>() where T : IWebItem
|
|
|
|
{
|
|
|
|
return GetItemsAll().OfType<T>().ToList();
|
2019-09-11 10:42:52 +00:00
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
private bool DisabledWebItem(string name)
|
2019-09-11 10:42:52 +00:00
|
|
|
{
|
2022-03-17 16:57:02 +00:00
|
|
|
return _disableItem.Contains(name);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-11 10:42:52 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
[Scope]
|
|
|
|
public class WebItemManagerSecurity
|
|
|
|
{
|
2022-04-15 09:08:06 +00:00
|
|
|
private readonly WebItemSecurity _webItemSecurity;
|
|
|
|
private readonly AuthContext _authContext;
|
|
|
|
private readonly WebItemManager _webItemManager;
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public WebItemManagerSecurity(WebItemSecurity webItemSecurity, AuthContext authContext, WebItemManager webItemManager)
|
|
|
|
{
|
2022-04-15 09:08:06 +00:00
|
|
|
_webItemSecurity = webItemSecurity;
|
|
|
|
_authContext = authContext;
|
|
|
|
_webItemManager = webItemManager;
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public List<IWebItem> GetItems(WebZoneType webZone)
|
|
|
|
{
|
|
|
|
return GetItems(webZone, ItemAvailableState.Normal);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<IWebItem> GetItems(WebZoneType webZone, ItemAvailableState avaliableState)
|
|
|
|
{
|
2022-04-15 09:08:06 +00:00
|
|
|
var copy = _webItemManager.GetItemsAll().ToList();
|
2022-03-17 15:13:38 +00:00
|
|
|
var list = copy.Where(item =>
|
|
|
|
{
|
2022-04-15 09:08:06 +00:00
|
|
|
if ((avaliableState & ItemAvailableState.Disabled) != ItemAvailableState.Disabled && item.IsDisabled(_webItemSecurity, _authContext))
|
2019-09-11 10:42:52 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var attribute = (WebZoneAttribute)Attribute.GetCustomAttribute(item.GetType(), typeof(WebZoneAttribute), true);
|
|
|
|
return attribute != null && (attribute.Type & webZone) != 0;
|
|
|
|
}).ToList();
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-04-15 09:08:06 +00:00
|
|
|
list.Sort((x, y) => _webItemManager.GetSortOrder(x).CompareTo(_webItemManager.GetSortOrder(y)));
|
2022-03-17 15:13:38 +00:00
|
|
|
return list;
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public List<IWebItem> GetSubItems(Guid parentItemID)
|
|
|
|
{
|
|
|
|
return GetSubItems(parentItemID, ItemAvailableState.Normal);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<IWebItem> GetSubItems(Guid parentItemID, ItemAvailableState avaliableState)
|
|
|
|
{
|
|
|
|
return GetItems(WebZoneType.All, avaliableState)
|
|
|
|
.OfType<IModule>()
|
|
|
|
.Where(p => p.ProjectId == parentItemID)
|
|
|
|
.Cast<IWebItem>()
|
|
|
|
.ToList();
|
2019-06-10 12:17:45 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|