2019-09-03 15:13:25 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2020-06-16 11:55:46 +00:00
|
|
|
|
using System.Net;
|
2021-10-12 10:14:33 +00:00
|
|
|
|
using System.Net.Http;
|
2020-01-22 07:53:16 +00:00
|
|
|
|
using System.Security;
|
2022-01-31 14:35:36 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2020-06-15 15:33:53 +00:00
|
|
|
|
|
2019-09-03 15:13:25 +00:00
|
|
|
|
using ASC.Api.Core;
|
2020-02-17 08:58:14 +00:00
|
|
|
|
using ASC.Common;
|
2019-09-03 15:13:25 +00:00
|
|
|
|
using ASC.Common.Logging;
|
|
|
|
|
using ASC.Core;
|
|
|
|
|
using ASC.Core.Billing;
|
2020-11-04 11:15:14 +00:00
|
|
|
|
using ASC.Core.Common.Notify.Push;
|
2020-09-18 14:45:59 +00:00
|
|
|
|
using ASC.Core.Common.Settings;
|
2019-09-03 15:13:25 +00:00
|
|
|
|
using ASC.Core.Tenants;
|
|
|
|
|
using ASC.Core.Users;
|
2020-11-01 11:58:43 +00:00
|
|
|
|
using ASC.Web.Api.Models;
|
2019-09-03 15:13:25 +00:00
|
|
|
|
using ASC.Web.Api.Routing;
|
2020-01-22 07:53:16 +00:00
|
|
|
|
using ASC.Web.Core;
|
2021-11-16 17:40:15 +00:00
|
|
|
|
using ASC.Web.Core.Files;
|
2020-11-04 11:15:14 +00:00
|
|
|
|
using ASC.Web.Core.Mobile;
|
2019-09-03 15:13:25 +00:00
|
|
|
|
using ASC.Web.Core.Utility;
|
2020-09-18 14:45:59 +00:00
|
|
|
|
using ASC.Web.Studio.Core;
|
2020-10-28 13:21:24 +00:00
|
|
|
|
using ASC.Web.Studio.UserControls.Management;
|
2019-09-03 15:13:25 +00:00
|
|
|
|
using ASC.Web.Studio.Utility;
|
2019-12-20 11:17:01 +00:00
|
|
|
|
|
2019-09-03 15:13:25 +00:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-06-23 11:14:13 +00:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2019-10-17 15:55:35 +00:00
|
|
|
|
using Microsoft.Extensions.Options;
|
2019-09-03 15:13:25 +00:00
|
|
|
|
|
2020-06-16 11:55:46 +00:00
|
|
|
|
using SecurityContext = ASC.Core.SecurityContext;
|
|
|
|
|
|
2019-09-03 15:13:25 +00:00
|
|
|
|
namespace ASC.Web.Api.Controllers
|
|
|
|
|
{
|
2020-10-19 15:53:15 +00:00
|
|
|
|
[Scope]
|
2019-09-03 15:13:25 +00:00
|
|
|
|
[DefaultRoute]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class PortalController : ControllerBase
|
|
|
|
|
{
|
2020-05-28 13:28:51 +00:00
|
|
|
|
|
2020-11-01 11:58:43 +00:00
|
|
|
|
private Tenant Tenant { get { return ApiContext.Tenant; } }
|
2019-09-03 15:13:25 +00:00
|
|
|
|
|
2020-08-12 09:58:08 +00:00
|
|
|
|
private ApiContext ApiContext { get; }
|
|
|
|
|
private UserManager UserManager { get; }
|
|
|
|
|
private TenantManager TenantManager { get; }
|
|
|
|
|
private PaymentManager PaymentManager { get; }
|
|
|
|
|
private CommonLinkUtility CommonLinkUtility { get; }
|
|
|
|
|
private UrlShortener UrlShortener { get; }
|
|
|
|
|
private AuthContext AuthContext { get; }
|
|
|
|
|
private WebItemSecurity WebItemSecurity { get; }
|
|
|
|
|
private SecurityContext SecurityContext { get; }
|
2020-09-18 14:45:59 +00:00
|
|
|
|
private SettingsManager SettingsManager { get; }
|
2020-11-01 11:58:43 +00:00
|
|
|
|
private IMobileAppInstallRegistrator MobileAppInstallRegistrator { get; }
|
2020-08-12 09:58:08 +00:00
|
|
|
|
private IConfiguration Configuration { get; set; }
|
2021-11-16 17:40:15 +00:00
|
|
|
|
private CoreBaseSettings CoreBaseSettings { get; }
|
|
|
|
|
private LicenseReader LicenseReader { get; }
|
|
|
|
|
private SetupInfo SetupInfo { get; }
|
|
|
|
|
private DocumentServiceLicense DocumentServiceLicense { get; }
|
2020-10-28 13:21:24 +00:00
|
|
|
|
private TenantExtra TenantExtra { get; set; }
|
2019-10-17 15:55:35 +00:00
|
|
|
|
public ILog Log { get; }
|
2022-01-13 11:19:39 +00:00
|
|
|
|
public IHttpClientFactory ClientFactory { get; }
|
2019-09-03 15:13:25 +00:00
|
|
|
|
|
|
|
|
|
|
2019-10-17 15:55:35 +00:00
|
|
|
|
public PortalController(
|
2019-11-06 15:03:09 +00:00
|
|
|
|
IOptionsMonitor<ILog> options,
|
2019-09-09 12:56:33 +00:00
|
|
|
|
ApiContext apiContext,
|
|
|
|
|
UserManager userManager,
|
2019-09-17 12:42:32 +00:00
|
|
|
|
TenantManager tenantManager,
|
2019-09-19 15:55:44 +00:00
|
|
|
|
PaymentManager paymentManager,
|
2019-09-24 10:32:12 +00:00
|
|
|
|
CommonLinkUtility commonLinkUtility,
|
2019-09-27 10:45:37 +00:00
|
|
|
|
UrlShortener urlShortener,
|
2020-01-22 07:53:16 +00:00
|
|
|
|
AuthContext authContext,
|
2020-06-16 11:55:46 +00:00
|
|
|
|
WebItemSecurity webItemSecurity,
|
2020-06-17 11:00:28 +00:00
|
|
|
|
SecurityContext securityContext,
|
2020-09-18 14:45:59 +00:00
|
|
|
|
SettingsManager settingsManager,
|
2020-11-04 11:15:14 +00:00
|
|
|
|
IMobileAppInstallRegistrator mobileAppInstallRegistrator,
|
2020-11-02 10:56:52 +00:00
|
|
|
|
TenantExtra tenantExtra,
|
2020-12-28 13:22:08 +00:00
|
|
|
|
IConfiguration configuration,
|
|
|
|
|
CoreBaseSettings coreBaseSettings,
|
|
|
|
|
LicenseReader licenseReader,
|
2021-11-16 17:40:15 +00:00
|
|
|
|
SetupInfo setupInfo,
|
2022-01-31 11:35:16 +00:00
|
|
|
|
DocumentServiceLicense documentServiceLicense,
|
2022-01-13 11:19:39 +00:00
|
|
|
|
IHttpClientFactory clientFactory
|
2019-09-09 12:56:33 +00:00
|
|
|
|
)
|
2019-09-03 15:13:25 +00:00
|
|
|
|
{
|
2019-11-06 15:03:09 +00:00
|
|
|
|
Log = options.CurrentValue;
|
2019-09-03 15:13:25 +00:00
|
|
|
|
ApiContext = apiContext;
|
2019-09-09 12:56:33 +00:00
|
|
|
|
UserManager = userManager;
|
2019-09-17 08:07:46 +00:00
|
|
|
|
TenantManager = tenantManager;
|
2019-09-18 14:18:44 +00:00
|
|
|
|
PaymentManager = paymentManager;
|
2019-09-19 15:55:44 +00:00
|
|
|
|
CommonLinkUtility = commonLinkUtility;
|
2019-09-24 10:32:12 +00:00
|
|
|
|
UrlShortener = urlShortener;
|
2020-01-22 07:53:16 +00:00
|
|
|
|
AuthContext = authContext;
|
|
|
|
|
WebItemSecurity = webItemSecurity;
|
2020-06-16 11:55:46 +00:00
|
|
|
|
SecurityContext = securityContext;
|
2020-09-18 14:45:59 +00:00
|
|
|
|
SettingsManager = settingsManager;
|
2020-11-04 11:15:14 +00:00
|
|
|
|
MobileAppInstallRegistrator = mobileAppInstallRegistrator;
|
2020-06-23 11:14:13 +00:00
|
|
|
|
Configuration = configuration;
|
2020-12-28 13:22:08 +00:00
|
|
|
|
CoreBaseSettings = coreBaseSettings;
|
|
|
|
|
LicenseReader = licenseReader;
|
|
|
|
|
SetupInfo = setupInfo;
|
2021-11-16 17:40:15 +00:00
|
|
|
|
DocumentServiceLicense = documentServiceLicense;
|
2020-10-28 13:21:24 +00:00
|
|
|
|
TenantExtra = tenantExtra;
|
2022-01-13 11:19:39 +00:00
|
|
|
|
ClientFactory = clientFactory;
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Read("")]
|
|
|
|
|
public Tenant Get()
|
|
|
|
|
{
|
|
|
|
|
return Tenant;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Read("users/{userID}")]
|
|
|
|
|
public UserInfo GetUser(Guid userID)
|
|
|
|
|
{
|
2019-09-12 11:34:58 +00:00
|
|
|
|
return UserManager.GetUsers(userID);
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Read("users/invite/{employeeType}")]
|
2020-10-09 10:05:48 +00:00
|
|
|
|
public object GeInviteLink(EmployeeType employeeType)
|
2019-09-03 15:13:25 +00:00
|
|
|
|
{
|
2020-02-03 10:48:06 +00:00
|
|
|
|
if (!WebItemSecurity.IsProductAdministrator(WebItemManager.PeopleProductID, AuthContext.CurrentAccount.ID))
|
2020-01-22 07:53:16 +00:00
|
|
|
|
{
|
|
|
|
|
throw new SecurityException("Method not available");
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-30 08:45:55 +00:00
|
|
|
|
return CommonLinkUtility.GetConfirmationUrl(string.Empty, ConfirmType.LinkInvite, (int)employeeType)
|
2019-09-03 15:13:25 +00:00
|
|
|
|
+ $"&emplType={employeeType:d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Update("getshortenlink")]
|
2022-01-31 14:35:36 +00:00
|
|
|
|
public async Task<object> GetShortenLinkAsync(ShortenLinkModel model)
|
2019-09-03 15:13:25 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-01-31 14:35:36 +00:00
|
|
|
|
return await UrlShortener.Instance.GetShortenLinkAsync(model.Link);
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2019-10-17 15:55:35 +00:00
|
|
|
|
Log.Error("getshortenlink", ex);
|
2021-03-21 15:29:35 +00:00
|
|
|
|
return model.Link;
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 13:21:24 +00:00
|
|
|
|
[Read("tenantextra")]
|
2022-01-31 14:35:36 +00:00
|
|
|
|
public async Task<object> GetTenantExtraAsync()
|
2020-10-28 13:21:24 +00:00
|
|
|
|
{
|
|
|
|
|
return new
|
|
|
|
|
{
|
2020-12-28 13:22:08 +00:00
|
|
|
|
customMode = CoreBaseSettings.CustomMode,
|
2020-10-28 13:21:24 +00:00
|
|
|
|
opensource = TenantExtra.Opensource,
|
|
|
|
|
enterprise = TenantExtra.Enterprise,
|
|
|
|
|
tariff = TenantExtra.GetCurrentTariff(),
|
|
|
|
|
quota = TenantExtra.GetTenantQuota(),
|
|
|
|
|
notPaid = TenantExtra.IsNotPaid(),
|
2020-12-28 13:22:08 +00:00
|
|
|
|
licenseAccept = SettingsManager.LoadForCurrentUser<TariffSettings>().LicenseAcceptSetting,
|
|
|
|
|
enableTariffPage = //TenantExtra.EnableTarrifSettings - think about hide-settings for opensource
|
|
|
|
|
(!CoreBaseSettings.Standalone || !string.IsNullOrEmpty(LicenseReader.LicensePath))
|
|
|
|
|
&& string.IsNullOrEmpty(SetupInfo.AmiMetaUrl)
|
2021-11-16 17:40:15 +00:00
|
|
|
|
&& !CoreBaseSettings.CustomMode,
|
2022-01-31 14:35:36 +00:00
|
|
|
|
DocServerUserQuota = await DocumentServiceLicense.GetLicenseQuotaAsync(),
|
|
|
|
|
DocServerLicense = await DocumentServiceLicense.GetLicenseAsync()
|
2020-10-28 13:21:24 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 15:13:25 +00:00
|
|
|
|
|
|
|
|
|
[Read("usedspace")]
|
|
|
|
|
public double GetUsedSpace()
|
|
|
|
|
{
|
|
|
|
|
return Math.Round(
|
2020-12-28 13:22:08 +00:00
|
|
|
|
TenantManager.FindTenantQuotaRows(Tenant.TenantId)
|
2019-09-03 15:13:25 +00:00
|
|
|
|
.Where(q => !string.IsNullOrEmpty(q.Tag) && new Guid(q.Tag) != Guid.Empty)
|
|
|
|
|
.Sum(q => q.Counter) / 1024f / 1024f / 1024f, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Read("userscount")]
|
|
|
|
|
public long GetUsersCount()
|
|
|
|
|
{
|
2022-01-31 11:35:16 +00:00
|
|
|
|
return CoreBaseSettings.Personal ? 1 : UserManager.GetUserNames(EmployeeStatus.Active).Length;
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Read("tariff")]
|
|
|
|
|
public Tariff GetTariff()
|
|
|
|
|
{
|
2019-09-18 14:18:44 +00:00
|
|
|
|
return PaymentManager.GetTariff(Tenant.TenantId);
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Read("quota")]
|
|
|
|
|
public TenantQuota GetQuota()
|
|
|
|
|
{
|
2019-09-17 08:07:46 +00:00
|
|
|
|
return TenantManager.GetTenantQuota(Tenant.TenantId);
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Read("quota/right")]
|
|
|
|
|
public TenantQuota GetRightQuota()
|
|
|
|
|
{
|
|
|
|
|
var usedSpace = GetUsedSpace();
|
|
|
|
|
var needUsersCount = GetUsersCount();
|
|
|
|
|
|
2019-09-17 08:07:46 +00:00
|
|
|
|
return TenantManager.GetTenantQuotas().OrderBy(r => r.Price)
|
2019-09-03 15:13:25 +00:00
|
|
|
|
.FirstOrDefault(quota =>
|
|
|
|
|
quota.ActiveUsers > needUsersCount
|
|
|
|
|
&& quota.MaxTotalSize > usedSpace
|
|
|
|
|
&& !quota.Year);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Read("path")]
|
2020-10-09 10:05:48 +00:00
|
|
|
|
public object GetFullAbsolutePath(string virtualPath)
|
2019-09-03 15:13:25 +00:00
|
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
|
return CommonLinkUtility.GetFullAbsolutePath(virtualPath);
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
2020-05-28 13:28:51 +00:00
|
|
|
|
|
2020-06-16 11:55:46 +00:00
|
|
|
|
[Read("thumb")]
|
|
|
|
|
public FileResult GetThumb(string url)
|
2020-06-25 12:17:22 +00:00
|
|
|
|
{
|
2022-01-21 13:27:09 +00:00
|
|
|
|
if (!SecurityContext.IsAuthenticated || Configuration["bookmarking:thumbnail-url"] == null)
|
2020-06-16 11:55:46 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2020-06-25 12:17:22 +00:00
|
|
|
|
|
2020-06-16 11:55:46 +00:00
|
|
|
|
url = url.Replace("&", "&");
|
2020-06-25 12:17:22 +00:00
|
|
|
|
url = WebUtility.UrlEncode(url);
|
|
|
|
|
|
2021-10-12 10:14:33 +00:00
|
|
|
|
var request = new HttpRequestMessage();
|
|
|
|
|
request.RequestUri = new Uri(string.Format(Configuration["bookmarking:thumbnail-url"], url));
|
|
|
|
|
|
2022-01-13 11:19:39 +00:00
|
|
|
|
var httpClient = ClientFactory.CreateClient();
|
2021-11-24 19:34:39 +00:00
|
|
|
|
using var response = httpClient.Send(request);
|
2021-10-12 10:14:33 +00:00
|
|
|
|
using var stream = response.Content.ReadAsStream();
|
|
|
|
|
var bytes = new byte[stream.Length];
|
|
|
|
|
stream.Read(bytes, 0, (int)stream.Length);
|
|
|
|
|
|
|
|
|
|
string type;
|
|
|
|
|
if (response.Headers.TryGetValues("Content-Type", out var values))
|
|
|
|
|
{
|
|
|
|
|
type = values.First();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
type = "image/png";
|
|
|
|
|
}
|
2020-06-25 12:17:22 +00:00
|
|
|
|
return File(bytes, type);
|
2020-06-16 11:55:46 +00:00
|
|
|
|
}
|
2020-09-18 14:45:59 +00:00
|
|
|
|
|
|
|
|
|
[Create("present/mark")]
|
|
|
|
|
public void MarkPresentAsReaded()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-12-28 13:22:08 +00:00
|
|
|
|
var settings = SettingsManager.LoadForCurrentUser<OpensourceGiftSettings>();
|
2020-09-18 14:45:59 +00:00
|
|
|
|
settings.Readed = true;
|
|
|
|
|
SettingsManager.SaveForCurrentUser(settings);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("MarkPresentAsReaded", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-04 11:15:14 +00:00
|
|
|
|
|
2020-11-01 11:58:43 +00:00
|
|
|
|
[Create("mobile/registration")]
|
2021-11-24 19:34:39 +00:00
|
|
|
|
public void RegisterMobileAppInstallFromBody([FromBody] MobileAppModel model)
|
2020-11-01 11:58:43 +00:00
|
|
|
|
{
|
|
|
|
|
var currentUser = UserManager.GetUsers(SecurityContext.CurrentAccount.ID);
|
|
|
|
|
MobileAppInstallRegistrator.RegisterInstall(currentUser.Email, model.Type);
|
2020-11-10 10:41:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Create("mobile/registration")]
|
|
|
|
|
[Consumes("application/x-www-form-urlencoded")]
|
2021-11-24 19:34:39 +00:00
|
|
|
|
public void RegisterMobileAppInstallFromForm([FromForm] MobileAppModel model)
|
2020-11-01 11:58:43 +00:00
|
|
|
|
{
|
|
|
|
|
var currentUser = UserManager.GetUsers(SecurityContext.CurrentAccount.ID);
|
|
|
|
|
MobileAppInstallRegistrator.RegisterInstall(currentUser.Email, model.Type);
|
2020-11-04 12:22:43 +00:00
|
|
|
|
}
|
2019-10-31 13:54:43 +00:00
|
|
|
|
|
2020-11-04 11:15:14 +00:00
|
|
|
|
[Create("mobile/registration")]
|
|
|
|
|
public void RegisterMobileAppInstall(MobileAppType type)
|
|
|
|
|
{
|
|
|
|
|
var currentUser = UserManager.GetUsers(SecurityContext.CurrentAccount.ID);
|
|
|
|
|
MobileAppInstallRegistrator.RegisterInstall(currentUser.Email, type);
|
|
|
|
|
}
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|