DocSpace-client/products/ASC.Calendar/Server/Models/PublicItemWrapper.cs

196 lines
7.6 KiB
C#
Raw Normal View History

2020-02-13 09:18:13 +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;
using System.Runtime.Serialization;
using ASC.Core;
using ASC.Core.Users;
using ASC.Common.Security.Authentication;
using ASC.Common.Security.Authorizing;
2020-02-25 13:36:20 +00:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using ASC.Common.Utils;
using ASC.Web.Core.Users;
2020-02-27 14:15:25 +00:00
using ASC.Common;
2020-03-19 12:09:03 +00:00
using ASC.Calendar.iCalParser;
using ASC.Calendar.BusinessObjects;
2021-06-30 13:36:45 +00:00
using System.Text.Json.Serialization;
2020-02-13 09:18:13 +00:00
namespace ASC.Calendar.Models
2020-02-21 12:33:51 +00:00
{
[DataContract(Name = "publicItem")]
2021-04-13 08:40:31 +00:00
[Scope]
2020-02-13 09:18:13 +00:00
public class PublicItemWrapper : ASC.Web.Core.Calendars.SharingOptions.PublicItem
2020-02-21 12:33:51 +00:00
{
[DataMember(Name = "id", Order = 10)]
public string ItemId { get; set; }
[DataMember(Name = "name", Order = 20)]
public string ItemName { get; set; }
[DataMember(Name = "isGroup", Order = 30)]
public new bool IsGroup { get; set; }
[DataMember(Name = "canEdit", Order = 40)]
public bool CanEdit { get; set; }
2021-06-30 13:36:45 +00:00
[JsonPropertyName("selectedAction")]
2020-02-21 12:33:51 +00:00
public AccessOption SharingOption { get; set; }
public static PublicItemWrapper GetSample()
{
return new PublicItemWrapper
{
SharingOption = AccessOption.GetSample(),
CanEdit = true,
IsGroup = true,
ItemName = "Everyone",
ItemId = "2fdfe577-3c26-4736-9df9-b5a683bb8520"
};
}
}
2021-05-17 18:35:23 +00:00
[Scope]
2020-02-21 12:33:51 +00:00
public class PublicItemWrapperHelper
2020-02-13 09:18:13 +00:00
{
private Guid _owner;
private string _calendarId;
private string _eventId;
private bool _isCalendar;
2020-02-25 13:36:20 +00:00
public UserManager UserManager { get; }
private AuthManager Authentication { get; }
public AuthContext AuthContext { get; }
private TenantManager TenantManager { get; }
private TimeZoneConverter TimeZoneConverter { get; }
private PermissionContext PermissionContext { get; }
public DisplayUserSettingsHelper DisplayUserSettingsHelper { get; }
2020-03-19 12:09:03 +00:00
public DataProvider DataProvider { get; }
2020-02-25 13:36:20 +00:00
public PublicItemWrapperHelper(
UserManager userManager,
AuthManager authentication,
AuthContext authContext,
TenantManager tenantManager,
TimeZoneConverter timeZoneConverter,
PermissionContext permissionContext,
2020-03-19 12:09:03 +00:00
DisplayUserSettingsHelper displayUserSettingsHelper,
DataProvider dataProvider)
2020-02-25 13:36:20 +00:00
{
UserManager = userManager;
Authentication = authentication;
TenantManager = tenantManager;
AuthContext = authContext;
TimeZoneConverter = timeZoneConverter;
PermissionContext = permissionContext;
DisplayUserSettingsHelper = displayUserSettingsHelper;
2020-03-19 12:09:03 +00:00
DataProvider = dataProvider;
2020-02-21 12:33:51 +00:00
}
2020-02-13 09:18:13 +00:00
2020-02-21 12:33:51 +00:00
public PublicItemWrapper Get(ASC.Web.Core.Calendars.SharingOptions.PublicItem publicItem, string calendartId, Guid owner)
2020-02-13 09:18:13 +00:00
{
2020-02-21 12:33:51 +00:00
var result = new PublicItemWrapper();
result.Id = publicItem.Id;
result.IsGroup = publicItem.IsGroup;
2020-02-13 09:18:13 +00:00
_owner = owner;
_calendarId = calendartId;
_isCalendar = true;
2020-02-21 12:33:51 +00:00
Init(publicItem, ref result);
return result;
}
public PublicItemWrapper Get(ASC.Web.Core.Calendars.SharingOptions.PublicItem publicItem, string calendarId, string eventId, Guid owner)
2020-02-13 09:18:13 +00:00
{
2020-02-21 12:33:51 +00:00
var result = new PublicItemWrapper();
result.Id = publicItem.Id;
result.IsGroup = publicItem.IsGroup;
2020-02-13 09:18:13 +00:00
_owner = owner;
_calendarId = calendarId;
_eventId = eventId;
_isCalendar = false;
2020-02-21 12:33:51 +00:00
Init(publicItem, ref result);
return result;
2020-02-13 09:18:13 +00:00
}
2020-02-21 12:33:51 +00:00
protected void Init(ASC.Web.Core.Calendars.SharingOptions.PublicItem publicItem, ref PublicItemWrapper result)
2020-02-13 09:18:13 +00:00
{
2020-02-21 12:33:51 +00:00
result.ItemId = publicItem.Id.ToString();
2020-02-25 13:36:20 +00:00
//---ItemName
if (result.IsGroup)
result.ItemName = UserManager.GetGroupInfo(publicItem.Id).Name;
else
result.ItemName = UserManager.GetUsers(publicItem.Id).DisplayUserName(DisplayUserSettingsHelper);
2020-02-21 12:33:51 +00:00
2020-02-25 13:36:20 +00:00
//---CanEdit
result.CanEdit = !publicItem.Id.Equals(_owner);
2020-02-13 09:18:13 +00:00
2020-02-25 13:36:20 +00:00
//---SharingOption
if (publicItem.Id.Equals(_owner))
2020-02-13 09:18:13 +00:00
{
2020-02-25 13:36:20 +00:00
result.SharingOption = AccessOption.OwnerOption;
2020-02-13 09:18:13 +00:00
}
2020-02-25 13:36:20 +00:00
else
2020-02-13 09:18:13 +00:00
{
2020-02-25 13:36:20 +00:00
var subject = publicItem.IsGroup ? (ISubject)UserManager.GetGroupInfo(publicItem.Id) : (ISubject)Authentication.GetAccountByID(TenantManager.GetCurrentTenant().TenantId, publicItem.Id);
int calId;
if (_isCalendar && int.TryParse(_calendarId, out calId))
2020-02-21 12:33:51 +00:00
{
2020-03-19 12:09:03 +00:00
var icalendar = new iCalendar(AuthContext, TimeZoneConverter, TenantManager);
var obj = new BusinessObjects.Calendar(AuthContext, TimeZoneConverter, icalendar, DataProvider) { Id = _calendarId };
2020-02-25 13:36:20 +00:00
if (PermissionContext.PermissionResolver.Check(subject, obj, null, CalendarAccessRights.FullAccessAction))
result.SharingOption = AccessOption.FullAccessOption;
else
result.SharingOption = AccessOption.ReadOption;
2020-02-21 12:33:51 +00:00
}
2020-02-25 13:36:20 +00:00
else if (!_isCalendar)
2020-02-13 09:18:13 +00:00
{
2020-03-19 12:09:03 +00:00
var icalendar = new iCalendar(AuthContext, TimeZoneConverter, TenantManager);
var obj = new BusinessObjects.Event(AuthContext, TimeZoneConverter, icalendar, DataProvider) { Id = _eventId, CalendarId = _calendarId };
2020-02-25 13:36:20 +00:00
if (PermissionContext.PermissionResolver.Check(subject, obj, null, CalendarAccessRights.FullAccessAction))
result.SharingOption = AccessOption.FullAccessOption;
2020-02-21 12:33:51 +00:00
else
2020-02-25 13:36:20 +00:00
result.SharingOption = AccessOption.ReadOption;
2020-02-13 09:18:13 +00:00
}
2020-02-25 13:36:20 +00:00
else
{
result.SharingOption = AccessOption.ReadOption;
}
2020-02-21 12:33:51 +00:00
}
2020-02-25 13:36:20 +00:00
}
}
}