2019-09-03 15:13:25 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2020-06-16 11:55:46 +00:00
|
|
|
|
using System.Net;
|
2020-01-22 07:53:16 +00:00
|
|
|
|
using System.Security;
|
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;
|
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; }
|
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; }
|
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-06-23 11:14:13 +00:00
|
|
|
|
IConfiguration configuration
|
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-10-28 13:21:24 +00:00
|
|
|
|
TenantExtra = tenantExtra;
|
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")]
|
2020-10-09 10:05:48 +00:00
|
|
|
|
public object GetShortenLink(string link)
|
2019-09-03 15:13:25 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2019-12-20 11:17:01 +00:00
|
|
|
|
return UrlShortener.Instance.GetShortenLink(link);
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2019-10-17 15:55:35 +00:00
|
|
|
|
Log.Error("getshortenlink", ex);
|
2019-09-03 15:13:25 +00:00
|
|
|
|
return link;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 13:21:24 +00:00
|
|
|
|
[Read("tenantextra")]
|
|
|
|
|
public object GetTenantExtra()
|
|
|
|
|
{
|
|
|
|
|
return new
|
|
|
|
|
{
|
|
|
|
|
opensource = TenantExtra.Opensource,
|
|
|
|
|
enterprise = TenantExtra.Enterprise,
|
|
|
|
|
tariff = TenantExtra.GetCurrentTariff(),
|
|
|
|
|
quota = TenantExtra.GetTenantQuota(),
|
|
|
|
|
notPaid = TenantExtra.IsNotPaid(),
|
|
|
|
|
licenseAccept = SettingsManager.LoadForCurrentUser<TariffSettings>().LicenseAcceptSetting
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 15:13:25 +00:00
|
|
|
|
|
|
|
|
|
[Read("usedspace")]
|
|
|
|
|
public double GetUsedSpace()
|
|
|
|
|
{
|
|
|
|
|
return Math.Round(
|
2019-09-17 08:07:46 +00:00
|
|
|
|
TenantManager.FindTenantQuotaRows(new TenantQuotaRowQuery(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()
|
|
|
|
|
{
|
2019-09-12 11:34:58 +00:00
|
|
|
|
return UserManager.GetUserNames(EmployeeStatus.Active).Count();
|
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
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
using var wc = new WebClient();
|
|
|
|
|
var bytes = wc.DownloadData(string.Format(Configuration["bookmarking:thumbnail-url"], url));
|
|
|
|
|
var type = wc.ResponseHeaders["Content-Type"] ?? "image/png";
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
var settings = SettingsManager.LoadForCurrentUser<OpensourcePresentSettings>();
|
|
|
|
|
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")]
|
2020-11-10 10:41:32 +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")]
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|