2019-05-27 09:46:04 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-09-16 09:24:06 +00:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Imaging;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
using System.IO;
|
2019-05-27 09:46:04 +00:00
|
|
|
|
using System.Linq;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Mail;
|
2019-06-17 11:57:07 +00:00
|
|
|
|
using System.Security;
|
2019-07-19 08:38:31 +00:00
|
|
|
|
|
2019-06-14 08:15:28 +00:00
|
|
|
|
using ASC.Api.Core;
|
2019-06-13 15:01:29 +00:00
|
|
|
|
using ASC.Common.Web;
|
2019-05-27 09:46:04 +00:00
|
|
|
|
using ASC.Core;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
using ASC.Core.Tenants;
|
2019-05-27 09:46:04 +00:00
|
|
|
|
using ASC.Core.Users;
|
2019-06-21 10:42:16 +00:00
|
|
|
|
using ASC.Data.Reassigns;
|
2019-06-17 11:57:07 +00:00
|
|
|
|
using ASC.FederatedLogin;
|
|
|
|
|
using ASC.FederatedLogin.Profile;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
using ASC.MessagingSystem;
|
2019-07-05 13:58:04 +00:00
|
|
|
|
using ASC.People;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
using ASC.People.Models;
|
2019-08-13 13:05:36 +00:00
|
|
|
|
using ASC.People.Resources;
|
2019-05-22 09:28:34 +00:00
|
|
|
|
using ASC.Web.Api.Models;
|
2019-05-27 12:49:48 +00:00
|
|
|
|
using ASC.Web.Api.Routing;
|
2019-06-14 08:15:28 +00:00
|
|
|
|
using ASC.Web.Core;
|
2019-06-17 11:57:07 +00:00
|
|
|
|
using ASC.Web.Core.PublicResources;
|
2019-06-14 08:15:28 +00:00
|
|
|
|
using ASC.Web.Core.Users;
|
2019-07-17 08:55:08 +00:00
|
|
|
|
using ASC.Web.Studio.Core;
|
2019-06-17 11:57:07 +00:00
|
|
|
|
using ASC.Web.Studio.Core.Notify;
|
|
|
|
|
using ASC.Web.Studio.UserControls.Statistics;
|
|
|
|
|
using ASC.Web.Studio.Utility;
|
2019-07-19 08:38:31 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2019-07-02 15:30:31 +00:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
using Microsoft.AspNetCore.Http.Extensions;
|
2019-05-17 08:32:23 +00:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2019-07-19 08:38:31 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
using SecurityContext = ASC.Core.SecurityContext;
|
2019-05-17 08:32:23 +00:00
|
|
|
|
|
|
|
|
|
namespace ASC.Employee.Core.Controllers
|
|
|
|
|
{
|
2019-05-27 12:49:48 +00:00
|
|
|
|
[DefaultRoute]
|
2019-05-17 08:32:23 +00:00
|
|
|
|
[ApiController]
|
|
|
|
|
public class PeopleController : ControllerBase
|
|
|
|
|
{
|
2019-06-13 15:01:29 +00:00
|
|
|
|
public Common.Logging.LogManager LogManager { get; }
|
2019-08-09 12:28:19 +00:00
|
|
|
|
public Tenant Tenant { get { return ApiContext.Tenant; } }
|
2019-07-29 10:51:14 +00:00
|
|
|
|
public ApiContext ApiContext { get; }
|
2019-06-17 13:53:10 +00:00
|
|
|
|
public MessageService MessageService { get; }
|
2019-06-21 12:42:27 +00:00
|
|
|
|
public QueueWorkerReassign QueueWorkerReassign { get; }
|
|
|
|
|
public QueueWorkerRemove QueueWorkerRemove { get; }
|
2019-08-01 08:47:15 +00:00
|
|
|
|
public StudioNotifyService StudioNotifyService { get; }
|
|
|
|
|
public UserManagerWrapper UserManagerWrapper { get; }
|
|
|
|
|
|
|
|
|
|
public PeopleController(Common.Logging.LogManager logManager,
|
|
|
|
|
MessageService messageService,
|
|
|
|
|
QueueWorkerReassign queueWorkerReassign,
|
|
|
|
|
QueueWorkerRemove queueWorkerRemove,
|
|
|
|
|
StudioNotifyService studioNotifyService,
|
|
|
|
|
UserManagerWrapper userManagerWrapper,
|
|
|
|
|
ApiContext apiContext)
|
2019-06-13 15:01:29 +00:00
|
|
|
|
{
|
|
|
|
|
LogManager = logManager;
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService = messageService;
|
2019-06-21 12:42:27 +00:00
|
|
|
|
QueueWorkerReassign = queueWorkerReassign;
|
|
|
|
|
QueueWorkerRemove = queueWorkerRemove;
|
2019-08-01 08:47:15 +00:00
|
|
|
|
StudioNotifyService = studioNotifyService;
|
|
|
|
|
UserManagerWrapper = userManagerWrapper;
|
2019-07-29 10:51:14 +00:00
|
|
|
|
ApiContext = apiContext;
|
2019-06-13 15:01:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 13:58:04 +00:00
|
|
|
|
[Read("info")]
|
|
|
|
|
public Module GetModule()
|
|
|
|
|
{
|
|
|
|
|
var product = new PeopleProduct();
|
|
|
|
|
product.Init();
|
|
|
|
|
return new Module(product, true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Read]
|
2019-05-27 09:46:04 +00:00
|
|
|
|
public IEnumerable<EmployeeWraper> GetAll()
|
|
|
|
|
{
|
|
|
|
|
return GetByStatus(EmployeeStatus.Active);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-14 08:15:28 +00:00
|
|
|
|
[Read("status/{status}")]
|
2019-05-27 09:46:04 +00:00
|
|
|
|
public IEnumerable<EmployeeWraper> GetByStatus(EmployeeStatus status)
|
|
|
|
|
{
|
|
|
|
|
if (CoreContext.Configuration.Personal) throw new Exception("Method not available");
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var query = CoreContext.UserManager.GetUsers(Tenant, status).AsEnumerable();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
if ("group".Equals(ApiContext.FilterBy, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(ApiContext.FilterValue))
|
|
|
|
|
{
|
|
|
|
|
var groupId = new Guid(ApiContext.FilterValue);
|
|
|
|
|
//Filter by group
|
2019-08-09 12:28:19 +00:00
|
|
|
|
query = query.Where(x => CoreContext.UserManager.IsUserInGroup(Tenant, x.ID, groupId));
|
2019-06-14 16:14:24 +00:00
|
|
|
|
ApiContext.SetDataFiltered();
|
|
|
|
|
}
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return query.Select(x => new EmployeeWraperFull(x, ApiContext));
|
2019-05-27 09:46:04 +00:00
|
|
|
|
}
|
2019-05-27 12:49:48 +00:00
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Read("@self")]
|
2019-05-27 12:49:48 +00:00
|
|
|
|
public EmployeeWraper Self()
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
return new EmployeeWraperFull(CoreContext.UserManager.GetUsers(Tenant.TenantId, SecurityContext.CurrentAccount.ID), ApiContext);
|
2019-05-27 12:49:48 +00:00
|
|
|
|
}
|
2019-06-13 15:01:29 +00:00
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Read("email")]
|
2019-06-14 08:15:28 +00:00
|
|
|
|
public EmployeeWraperFull GetByEmail([FromQuery]string email)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (CoreContext.Configuration.Personal && !CoreContext.UserManager.GetUsers(Tenant.TenantId, SecurityContext.CurrentAccount.ID).IsOwner(Tenant))
|
2019-06-14 08:15:28 +00:00
|
|
|
|
throw new MethodAccessException("Method not available");
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var user = CoreContext.UserManager.GetUserByEmail(Tenant.TenantId, email);
|
2019-06-14 08:15:28 +00:00
|
|
|
|
if (user.ID == Constants.LostUser.ID)
|
|
|
|
|
{
|
|
|
|
|
throw new ItemNotFoundException("User not found");
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return new EmployeeWraperFull(user, ApiContext);
|
2019-06-14 08:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Read("{username}", order: int.MaxValue)]
|
2019-06-13 15:01:29 +00:00
|
|
|
|
public EmployeeWraperFull GetById(string username)
|
|
|
|
|
{
|
|
|
|
|
if (CoreContext.Configuration.Personal) throw new MethodAccessException("Method not available");
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var user = CoreContext.UserManager.GetUserByUserName(Tenant.TenantId, username);
|
2019-06-13 15:01:29 +00:00
|
|
|
|
if (user.ID == Constants.LostUser.ID)
|
|
|
|
|
{
|
2019-06-14 08:15:28 +00:00
|
|
|
|
if (Guid.TryParse(username, out var userId))
|
2019-06-13 15:01:29 +00:00
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
user = CoreContext.UserManager.GetUsers(Tenant.TenantId, userId);
|
2019-06-13 15:01:29 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-06-14 08:15:28 +00:00
|
|
|
|
LogManager.Get("ASC.Api").Error(string.Format("Account {0} сould not get user by name {1}", SecurityContext.CurrentAccount.ID, username));
|
2019-06-13 15:01:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (user.ID == Constants.LostUser.ID)
|
|
|
|
|
{
|
|
|
|
|
throw new ItemNotFoundException("User not found");
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return new EmployeeWraperFull(user, ApiContext);
|
2019-06-13 15:01:29 +00:00
|
|
|
|
}
|
2019-06-14 08:15:28 +00:00
|
|
|
|
|
|
|
|
|
[Read("@search/{query}")]
|
|
|
|
|
public IEnumerable<EmployeeWraperFull> GetSearch(string query)
|
|
|
|
|
{
|
|
|
|
|
if (CoreContext.Configuration.Personal) throw new MethodAccessException("Method not available");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var groupId = Guid.Empty;
|
|
|
|
|
if ("group".Equals(ApiContext.FilterBy, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(ApiContext.FilterValue))
|
|
|
|
|
{
|
|
|
|
|
groupId = new Guid(ApiContext.FilterValue);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
return CoreContext.UserManager.Search(Tenant, query, EmployeeStatus.Active, groupId).Select(x => new EmployeeWraperFull(x, ApiContext));
|
2019-06-14 08:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception error)
|
|
|
|
|
{
|
|
|
|
|
LogManager.Get("ASC.Api").Error(error);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Read("search")]
|
2019-06-14 08:15:28 +00:00
|
|
|
|
public IEnumerable<EmployeeWraperFull> GetPeopleSearch([FromQuery]string query)
|
|
|
|
|
{
|
|
|
|
|
return GetSearch(query);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Read("status/{status}/search")]
|
2019-06-14 08:15:28 +00:00
|
|
|
|
public IEnumerable<EmployeeWraperFull> GetAdvanced(EmployeeStatus status, [FromQuery]string query)
|
|
|
|
|
{
|
|
|
|
|
if (CoreContext.Configuration.Personal) throw new MethodAccessException("Method not available");
|
|
|
|
|
try
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var list = CoreContext.UserManager.GetUsers(Tenant, status).AsEnumerable();
|
2019-06-14 08:15:28 +00:00
|
|
|
|
|
|
|
|
|
if ("group".Equals(ApiContext.FilterBy, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(ApiContext.FilterValue))
|
|
|
|
|
{
|
|
|
|
|
var groupId = new Guid(ApiContext.FilterValue);
|
|
|
|
|
//Filter by group
|
2019-08-09 12:28:19 +00:00
|
|
|
|
list = list.Where(x => CoreContext.UserManager.IsUserInGroup(Tenant, x.ID, groupId));
|
2019-06-14 08:15:28 +00:00
|
|
|
|
ApiContext.SetDataFiltered();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list = list.Where(x => x.FirstName != null && x.FirstName.IndexOf(query, StringComparison.OrdinalIgnoreCase) > -1 || (x.LastName != null && x.LastName.IndexOf(query, StringComparison.OrdinalIgnoreCase) != -1) ||
|
|
|
|
|
(x.UserName != null && x.UserName.IndexOf(query, StringComparison.OrdinalIgnoreCase) != -1) || (x.Email != null && x.Email.IndexOf(query, StringComparison.OrdinalIgnoreCase) != -1) || (x.Contacts != null && x.Contacts.Any(y => y.IndexOf(query, StringComparison.OrdinalIgnoreCase) != -1)));
|
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return list.Select(x => new EmployeeWraperFull(x, ApiContext));
|
2019-06-14 08:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception error)
|
|
|
|
|
{
|
|
|
|
|
LogManager.Get("ASC.Api").Error(error);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// Adds a new portal user from import with the first and last name, email address
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <short>
|
|
|
|
|
///// Add new import user
|
|
|
|
|
///// </short>
|
|
|
|
|
///// <param name="userList">The list of users to add</param>
|
|
|
|
|
///// <param name="importUsersAsCollaborators" optional="true">Add users as guests (bool type: false|true)</param>
|
|
|
|
|
///// <returns>Newly created users</returns>
|
|
|
|
|
//[Create("import/save")]
|
|
|
|
|
//public void SaveUsers(string userList, bool importUsersAsCollaborators)
|
|
|
|
|
//{
|
|
|
|
|
// lock (progressQueue.SynchRoot)
|
|
|
|
|
// {
|
|
|
|
|
// var task = progressQueue.GetItems().OfType<ImportUsersTask>().FirstOrDefault(t => (int)t.Id == TenantProvider.CurrentTenantID);
|
|
|
|
|
// if (task != null && task.IsCompleted)
|
|
|
|
|
// {
|
|
|
|
|
// progressQueue.Remove(task);
|
|
|
|
|
// task = null;
|
|
|
|
|
// }
|
|
|
|
|
// if (task == null)
|
|
|
|
|
// {
|
|
|
|
|
// progressQueue.Add(new ImportUsersTask(userList, importUsersAsCollaborators, GetHttpHeaders(HttpContext.Current.Request))
|
|
|
|
|
// {
|
|
|
|
|
// Id = TenantProvider.CurrentTenantID,
|
|
|
|
|
// UserId = SecurityContext.CurrentAccount.ID,
|
|
|
|
|
// Percentage = 0
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//[Read("import/status")]
|
|
|
|
|
//public object GetStatus()
|
|
|
|
|
//{
|
|
|
|
|
// lock (progressQueue.SynchRoot)
|
|
|
|
|
// {
|
|
|
|
|
// var task = progressQueue.GetItems().OfType<ImportUsersTask>().FirstOrDefault(t => (int)t.Id == TenantProvider.CurrentTenantID);
|
|
|
|
|
// if (task == null) return null;
|
|
|
|
|
|
|
|
|
|
// return new
|
|
|
|
|
// {
|
|
|
|
|
// Completed = task.IsCompleted,
|
|
|
|
|
// Percents = (int)task.Percentage,
|
|
|
|
|
// UserCounter = task.GetUserCounter,
|
|
|
|
|
// Status = (int)task.Status,
|
|
|
|
|
// Error = (string)task.Error,
|
|
|
|
|
// task.Data
|
|
|
|
|
// };
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Read("filter")]
|
2019-06-14 08:15:28 +00:00
|
|
|
|
public IEnumerable<EmployeeWraperFull> GetFullByFilter(EmployeeStatus? employeeStatus, Guid? groupId, EmployeeActivationStatus? activationStatus, EmployeeType? employeeType, bool? isAdministrator)
|
|
|
|
|
{
|
|
|
|
|
var users = GetByFilter(employeeStatus, groupId, activationStatus, employeeType, isAdministrator);
|
2019-08-30 12:40:57 +00:00
|
|
|
|
return users.Select(u => new EmployeeWraperFull(u, ApiContext));
|
2019-06-14 08:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Read("simple/filter")]
|
2019-06-14 08:15:28 +00:00
|
|
|
|
public IEnumerable<EmployeeWraper> GetSimpleByFilter(EmployeeStatus? employeeStatus, Guid? groupId, EmployeeActivationStatus? activationStatus, EmployeeType? employeeType, bool? isAdministrator)
|
|
|
|
|
{
|
|
|
|
|
var users = GetByFilter(employeeStatus, groupId, activationStatus, employeeType, isAdministrator);
|
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return users.Select(u => new EmployeeWraper(u, ApiContext));
|
2019-06-14 08:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<UserInfo> GetByFilter(EmployeeStatus? employeeStatus, Guid? groupId, EmployeeActivationStatus? activationStatus, EmployeeType? employeeType, bool? isAdministrator)
|
|
|
|
|
{
|
|
|
|
|
if (CoreContext.Configuration.Personal) throw new MethodAccessException("Method not available");
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var isAdmin = CoreContext.UserManager.GetUsers(Tenant.TenantId, SecurityContext.CurrentAccount.ID).IsAdmin(Tenant) ||
|
|
|
|
|
WebItemSecurity.IsProductAdministrator(Tenant, WebItemManager.PeopleProductID, SecurityContext.CurrentAccount.ID);
|
2019-06-14 08:15:28 +00:00
|
|
|
|
|
2019-08-08 14:42:29 +00:00
|
|
|
|
var includeGroups = new List<List<Guid>>();
|
2019-08-05 13:45:33 +00:00
|
|
|
|
if (groupId.HasValue)
|
2019-06-14 08:15:28 +00:00
|
|
|
|
{
|
2019-08-08 14:42:29 +00:00
|
|
|
|
includeGroups.Add(new List<Guid> { groupId.Value });
|
2019-06-14 08:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:45:33 +00:00
|
|
|
|
var excludeGroups = new List<Guid>();
|
2019-06-14 08:15:28 +00:00
|
|
|
|
|
|
|
|
|
if (employeeType != null)
|
|
|
|
|
{
|
|
|
|
|
switch (employeeType)
|
|
|
|
|
{
|
|
|
|
|
case EmployeeType.User:
|
2019-08-05 13:45:33 +00:00
|
|
|
|
excludeGroups.Add(Constants.GroupVisitor.ID);
|
2019-06-14 08:15:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case EmployeeType.Visitor:
|
2019-08-08 14:42:29 +00:00
|
|
|
|
includeGroups.Add(new List<Guid> { Constants.GroupVisitor.ID });
|
2019-06-14 08:15:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isAdministrator.HasValue && isAdministrator.Value)
|
|
|
|
|
{
|
2019-08-08 14:42:29 +00:00
|
|
|
|
var adminGroups = new List<Guid>
|
|
|
|
|
{
|
|
|
|
|
Constants.GroupAdmin.ID
|
|
|
|
|
};
|
2019-06-14 08:15:28 +00:00
|
|
|
|
|
2019-08-05 13:45:33 +00:00
|
|
|
|
var products = WebItemManager.Instance.GetItemsAll().Where(i => i is IProduct || i.ID == WebItemManager.MailProductID);
|
2019-08-15 12:04:42 +00:00
|
|
|
|
adminGroups.AddRange(products.Select(r => r.ID));
|
2019-06-14 08:15:28 +00:00
|
|
|
|
|
2019-08-08 14:42:29 +00:00
|
|
|
|
includeGroups.Add(adminGroups);
|
2019-06-14 08:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-15 15:54:56 +00:00
|
|
|
|
var users = CoreContext.UserManager.GetUsers(Tenant.TenantId, isAdmin, employeeStatus, includeGroups, excludeGroups, activationStatus, ApiContext.FilterValue, ApiContext.SortBy, !ApiContext.SortDescending, ApiContext.Count, ApiContext.StartIndex, out var total);
|
2019-06-14 08:15:28 +00:00
|
|
|
|
|
2019-09-03 09:31:15 +00:00
|
|
|
|
ApiContext.SetTotalCount(total)
|
|
|
|
|
.SetCount(users.Count);
|
2019-06-14 08:15:28 +00:00
|
|
|
|
|
|
|
|
|
return users;
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Create]
|
2019-09-23 15:36:22 +00:00
|
|
|
|
[Authorize(AuthenticationSchemes = "confirm", Roles = "LinkInvite,Administrators")]
|
2019-06-14 16:14:24 +00:00
|
|
|
|
public EmployeeWraperFull AddMember(MemberModel memberModel)
|
|
|
|
|
{
|
2019-09-16 09:21:10 +00:00
|
|
|
|
ApiContext.AuthByClaim();
|
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, Constants.Action_AddRemoveUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(memberModel.Password))
|
|
|
|
|
memberModel.Password = UserManagerWrapper.GeneratePassword();
|
|
|
|
|
|
|
|
|
|
memberModel.Password = memberModel.Password.Trim();
|
|
|
|
|
|
|
|
|
|
var user = new UserInfo();
|
|
|
|
|
|
|
|
|
|
//Validate email
|
|
|
|
|
var address = new MailAddress(memberModel.Email);
|
|
|
|
|
user.Email = address.Address;
|
|
|
|
|
//Set common fields
|
|
|
|
|
user.FirstName = memberModel.Firstname;
|
|
|
|
|
user.LastName = memberModel.Lastname;
|
|
|
|
|
user.Title = memberModel.Title;
|
|
|
|
|
user.Location = memberModel.Location;
|
|
|
|
|
user.Notes = memberModel.Comment;
|
|
|
|
|
user.Sex = "male".Equals(memberModel.Sex, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
? true
|
|
|
|
|
: ("female".Equals(memberModel.Sex, StringComparison.OrdinalIgnoreCase) ? (bool?)false : null);
|
|
|
|
|
|
2019-09-20 11:07:57 +00:00
|
|
|
|
user.BirthDate = memberModel.Birthday != null && memberModel.Birthday != DateTime.MinValue ? TenantUtil.DateTimeFromUtc(Convert.ToDateTime(memberModel.Birthday)) : (DateTime?)null;
|
|
|
|
|
user.WorkFromDate = memberModel.Worksfrom != null && memberModel.Worksfrom != DateTime.MinValue ? TenantUtil.DateTimeFromUtc(Convert.ToDateTime(memberModel.Worksfrom)) : DateTime.UtcNow.Date;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
|
|
UpdateContacts(memberModel.Contacts, user);
|
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
user = UserManagerWrapper.AddUser(Tenant, user, memberModel.Password, false, true, memberModel.IsVisitor);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
|
|
var messageAction = memberModel.IsVisitor ? MessageAction.GuestCreated : MessageAction.UserCreated;
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(messageAction, MessageTarget.Create(user.ID), user.DisplayUserName(false));
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
|
|
UpdateDepartments(memberModel.Department, user);
|
|
|
|
|
|
|
|
|
|
if (memberModel.Files != UserPhotoManager.GetDefaultPhotoAbsoluteWebPath())
|
|
|
|
|
{
|
|
|
|
|
UpdatePhotoUrl(memberModel.Files, user);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return new EmployeeWraperFull(user, ApiContext);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Create("active")]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public EmployeeWraperFull AddMemberAsActivated(MemberModel memberModel)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, Constants.Action_AddRemoveUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
var user = new UserInfo();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (string.IsNullOrEmpty(memberModel.Password))
|
|
|
|
|
memberModel.Password = UserManagerWrapper.GeneratePassword();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
//Validate email
|
|
|
|
|
var address = new MailAddress(memberModel.Email);
|
|
|
|
|
user.Email = address.Address;
|
|
|
|
|
//Set common fields
|
|
|
|
|
user.FirstName = memberModel.Firstname;
|
|
|
|
|
user.LastName = memberModel.Lastname;
|
|
|
|
|
user.Title = memberModel.Title;
|
|
|
|
|
user.Location = memberModel.Location;
|
|
|
|
|
user.Notes = memberModel.Comment;
|
|
|
|
|
user.Sex = "male".Equals(memberModel.Sex, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
? true
|
|
|
|
|
: ("female".Equals(memberModel.Sex, StringComparison.OrdinalIgnoreCase) ? (bool?)false : null);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
user.BirthDate = memberModel.Birthday != null ? TenantUtil.DateTimeFromUtc(Convert.ToDateTime(memberModel.Birthday)) : (DateTime?)null;
|
|
|
|
|
user.WorkFromDate = memberModel.Worksfrom != null ? TenantUtil.DateTimeFromUtc(Convert.ToDateTime(memberModel.Worksfrom)) : DateTime.UtcNow.Date;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
UpdateContacts(memberModel.Contacts, user);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
user = UserManagerWrapper.AddUser(Tenant, user, memberModel.Password, false, false, memberModel.IsVisitor);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
user.ActivationStatus = EmployeeActivationStatus.Activated;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
UpdateDepartments(memberModel.Department, user);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (memberModel.Files != UserPhotoManager.GetDefaultPhotoAbsoluteWebPath())
|
2019-06-14 16:14:24 +00:00
|
|
|
|
{
|
2019-06-17 11:57:07 +00:00
|
|
|
|
UpdatePhotoUrl(memberModel.Files, user);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return new EmployeeWraperFull(user, ApiContext);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-29 10:50:18 +00:00
|
|
|
|
[Update("{userid}/culture")]
|
|
|
|
|
public EmployeeWraperFull UpdateMemberCulture(string userid, UpdateMemberModel memberModel)
|
|
|
|
|
{
|
|
|
|
|
var user = GetUserInfo(userid);
|
|
|
|
|
|
|
|
|
|
if (CoreContext.UserManager.IsSystemUser(user.ID))
|
|
|
|
|
throw new SecurityException();
|
|
|
|
|
|
|
|
|
|
SecurityContext.DemandPermissions(Tenant, new UserSecurityProvider(user.ID), Constants.Action_EditUser);
|
|
|
|
|
|
|
|
|
|
var curLng = user.CultureName;
|
|
|
|
|
|
|
|
|
|
if (SetupInfo.EnabledCultures.Find(c => string.Equals(c.Name, memberModel.CultureName, StringComparison.InvariantCultureIgnoreCase)) != null)
|
|
|
|
|
{
|
|
|
|
|
if (curLng != memberModel.CultureName)
|
|
|
|
|
{
|
|
|
|
|
user.CultureName = memberModel.CultureName;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
CoreContext.UserManager.SaveUserInfo(Tenant, user);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
user.CultureName = curLng;
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MessageService.Send(MessageAction.UserUpdatedLanguage, MessageTarget.Create(user.ID), user.DisplayUserName(false));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new EmployeeWraperFull(user, ApiContext);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
[Update("{userid}")]
|
2019-07-26 11:37:50 +00:00
|
|
|
|
public EmployeeWraperFull UpdateMember(string userid, UpdateMemberModel memberModel)
|
2019-06-14 16:14:24 +00:00
|
|
|
|
{
|
2019-07-26 11:37:50 +00:00
|
|
|
|
var user = GetUserInfo(userid);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (CoreContext.UserManager.IsSystemUser(user.ID))
|
|
|
|
|
throw new SecurityException();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, new UserSecurityProvider(user.ID), Constants.Action_EditUser);
|
2019-07-26 11:37:50 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
var self = SecurityContext.CurrentAccount.ID.Equals(user.ID);
|
|
|
|
|
var resetDate = new DateTime(1900, 01, 01);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
//Update it
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
var isLdap = user.IsLDAP();
|
|
|
|
|
var isSso = user.IsSSO();
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var isAdmin = WebItemSecurity.IsProductAdministrator(Tenant, WebItemManager.PeopleProductID, SecurityContext.CurrentAccount.ID);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (!isLdap && !isSso)
|
|
|
|
|
{
|
|
|
|
|
//Set common fields
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
user.FirstName = memberModel.Firstname ?? user.FirstName;
|
|
|
|
|
user.LastName = memberModel.Lastname ?? user.LastName;
|
|
|
|
|
user.Location = memberModel.Location ?? user.Location;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (isAdmin)
|
|
|
|
|
{
|
|
|
|
|
user.Title = memberModel.Title ?? user.Title;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (!UserFormatter.IsValidUserName(user.FirstName, user.LastName))
|
|
|
|
|
throw new Exception(Resource.ErrorIncorrectUserName);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
user.Notes = memberModel.Comment ?? user.Notes;
|
|
|
|
|
user.Sex = ("male".Equals(memberModel.Sex, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
? true
|
|
|
|
|
: ("female".Equals(memberModel.Sex, StringComparison.OrdinalIgnoreCase) ? (bool?)false : null)) ?? user.Sex;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
user.BirthDate = memberModel.Birthday != null ? TenantUtil.DateTimeFromUtc(Convert.ToDateTime(memberModel.Birthday)) : user.BirthDate;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (user.BirthDate == resetDate)
|
|
|
|
|
{
|
|
|
|
|
user.BirthDate = null;
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
user.WorkFromDate = memberModel.Worksfrom != null ? TenantUtil.DateTimeFromUtc(Convert.ToDateTime(memberModel.Worksfrom)) : user.WorkFromDate;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (user.WorkFromDate == resetDate)
|
|
|
|
|
{
|
|
|
|
|
user.WorkFromDate = null;
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
//Update contacts
|
|
|
|
|
UpdateContacts(memberModel.Contacts, user);
|
|
|
|
|
UpdateDepartments(memberModel.Department, user);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (memberModel.Files != UserPhotoManager.GetPhotoAbsoluteWebPath(Tenant, user.ID))
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
|
|
|
|
UpdatePhotoUrl(memberModel.Files, user);
|
|
|
|
|
}
|
|
|
|
|
if (memberModel.Disable.HasValue)
|
|
|
|
|
{
|
|
|
|
|
user.Status = memberModel.Disable.Value ? EmployeeStatus.Terminated : EmployeeStatus.Active;
|
|
|
|
|
user.TerminatedDate = memberModel.Disable.Value ? DateTime.UtcNow : (DateTime?)null;
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (self && !isAdmin)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
StudioNotifyService.SendMsgToAdminAboutProfileUpdated(Tenant.TenantId);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
// change user type
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var canBeGuestFlag = !user.IsOwner(Tenant) && !user.IsAdmin(Tenant) && !user.GetListAdminModules(Tenant).Any() && !user.IsMe();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (memberModel.IsVisitor && !user.IsVisitor(Tenant) && canBeGuestFlag)
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.AddUserIntoGroup(Tenant, user.ID, Constants.GroupVisitor.ID);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
WebItemSecurity.ClearCache();
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (!self && !memberModel.IsVisitor && user.IsVisitor(Tenant))
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
|
|
|
|
var usersQuota = TenantExtra.GetTenantQuota().ActiveUsers;
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (TenantStatisticsProvider.GetUsersCount(Tenant) < usersQuota)
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.RemoveUserFromGroup(Tenant, user.ID, Constants.GroupVisitor.ID);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
WebItemSecurity.ClearCache();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new TenantQuotaException(string.Format("Exceeds the maximum active users ({0})", usersQuota));
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.SaveUserInfo(Tenant, user, memberModel.IsVisitor);
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.UserUpdated, MessageTarget.Create(user.ID), user.DisplayUserName(false));
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (memberModel.Disable.HasValue && memberModel.Disable.Value)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
HttpContext.ResetUserCookie(Tenant.TenantId, user.ID);
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.CookieSettingsUpdated);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return new EmployeeWraperFull(user, ApiContext);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
[Delete("{userid}")]
|
|
|
|
|
public EmployeeWraperFull DeleteMember(string userid)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, Constants.Action_AddRemoveUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
var user = GetUserInfo(userid);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (CoreContext.UserManager.IsSystemUser(user.ID) || user.IsLDAP())
|
|
|
|
|
throw new SecurityException();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (user.Status != EmployeeStatus.Terminated)
|
|
|
|
|
throw new Exception("The user is not suspended");
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-21 10:42:16 +00:00
|
|
|
|
CheckReassignProccess(new[] { user.ID });
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
var userName = user.DisplayUserName(false);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
UserPhotoManager.RemovePhoto(Tenant, user.ID);
|
|
|
|
|
CoreContext.UserManager.DeleteUser(Tenant, user.ID);
|
2019-08-12 10:53:12 +00:00
|
|
|
|
QueueWorkerRemove.Start(Tenant.TenantId, user, SecurityContext.CurrentAccount.ID, false);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.UserDeleted, MessageTarget.Create(user.ID), userName);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return new EmployeeWraperFull(user, ApiContext);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-10-04 04:58:38 +00:00
|
|
|
|
[Delete("@self")]
|
|
|
|
|
[Authorize(AuthenticationSchemes = "confirm", Roles = "ProfileRemove")]
|
|
|
|
|
public EmployeeWraperFull DeleteProfile()
|
|
|
|
|
{
|
|
|
|
|
ApiContext.AuthByClaim();
|
|
|
|
|
|
|
|
|
|
if (CoreContext.UserManager.IsSystemUser(SecurityContext.CurrentAccount.ID))
|
|
|
|
|
throw new SecurityException();
|
|
|
|
|
|
|
|
|
|
var user = GetUserInfo(SecurityContext.CurrentAccount.ID.ToString());
|
|
|
|
|
|
|
|
|
|
if (!CoreContext.UserManager.UserExists(user))
|
|
|
|
|
throw new Exception(Resource.ErrorUserNotFound);
|
|
|
|
|
|
|
|
|
|
if(user.IsLDAP())
|
|
|
|
|
throw new SecurityException();
|
|
|
|
|
|
|
|
|
|
_ = SecurityContext.AuthenticateMe(ASC.Core.Configuration.Constants.CoreSystem);
|
|
|
|
|
|
|
|
|
|
user.Status = EmployeeStatus.Terminated;
|
|
|
|
|
|
|
|
|
|
CoreContext.UserManager.SaveUserInfo(Tenant, user);
|
|
|
|
|
|
|
|
|
|
var userName = user.DisplayUserName(false);
|
|
|
|
|
MessageService.Send(MessageAction.UsersUpdatedStatus, MessageTarget.Create(user.ID), userName);
|
|
|
|
|
|
|
|
|
|
HttpContext.ResetUserCookie(Tenant.TenantId, user.ID);
|
|
|
|
|
MessageService.Send(MessageAction.CookieSettingsUpdated);
|
|
|
|
|
|
|
|
|
|
if (CoreContext.Configuration.Personal)
|
|
|
|
|
{
|
|
|
|
|
UserPhotoManager.RemovePhoto(Tenant, user.ID);
|
|
|
|
|
CoreContext.UserManager.DeleteUser(Tenant, user.ID);
|
|
|
|
|
MessageService.Send(MessageAction.UserDeleted, MessageTarget.Create(user.ID), userName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//StudioNotifyService.Instance.SendMsgProfileHasDeletedItself(user);
|
|
|
|
|
//StudioNotifyService.SendMsgProfileDeletion(Tenant.TenantId, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new EmployeeWraperFull(user, ApiContext);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Update("{userid}/contacts")]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public EmployeeWraperFull UpdateMemberContacts(string userid, UpdateMemberModel memberModel)
|
|
|
|
|
{
|
|
|
|
|
var user = GetUserInfo(userid);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (CoreContext.UserManager.IsSystemUser(user.ID))
|
|
|
|
|
throw new SecurityException();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
UpdateContacts(memberModel.Contacts, user);
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.SaveUserInfo(Tenant, user);
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return new EmployeeWraperFull(user, ApiContext);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Create("{userid}/contacts")]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public EmployeeWraperFull SetMemberContacts(string userid, UpdateMemberModel memberModel)
|
|
|
|
|
{
|
|
|
|
|
var user = GetUserInfo(userid);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (CoreContext.UserManager.IsSystemUser(user.ID))
|
|
|
|
|
throw new SecurityException();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
UpdateContacts(memberModel.Contacts, user);
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.SaveUserInfo(Tenant, user);
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return new EmployeeWraperFull(user, ApiContext);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Delete("{userid}/contacts")]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public EmployeeWraperFull DeleteMemberContacts(string userid, UpdateMemberModel memberModel)
|
|
|
|
|
{
|
|
|
|
|
var user = GetUserInfo(userid);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (CoreContext.UserManager.IsSystemUser(user.ID))
|
|
|
|
|
throw new SecurityException();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
DeleteContacts(memberModel.Contacts, user);
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.SaveUserInfo(Tenant, user);
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return new EmployeeWraperFull(user, ApiContext);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Read("{userid}/photo")]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public ThumbnailsDataWrapper GetMemberPhoto(string userid)
|
|
|
|
|
{
|
|
|
|
|
var user = GetUserInfo(userid);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (CoreContext.UserManager.IsSystemUser(user.ID))
|
|
|
|
|
throw new SecurityException();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
return new ThumbnailsDataWrapper(Tenant, user.ID);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-09-24 12:27:13 +00:00
|
|
|
|
|
2019-09-13 11:41:15 +00:00
|
|
|
|
public FormFile Base64ToImage(string base64String, string fileName)
|
|
|
|
|
{
|
|
|
|
|
byte[] imageBytes = Convert.FromBase64String(base64String);
|
|
|
|
|
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
|
|
|
|
|
|
|
|
|
|
ms.Write(imageBytes, 0, imageBytes.Length);
|
|
|
|
|
return new FormFile(ms, 0, ms.Length, fileName, fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Create("{userid}/photo/cropped")]
|
|
|
|
|
public FileUploadResult UploadCroppedMemberPhoto(string userid, UploadCroppedPhotoModel model)
|
|
|
|
|
{
|
|
|
|
|
var result = new FileUploadResult();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Guid userId;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
userId = new Guid(userid);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
userId = SecurityContext.CurrentAccount.ID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SecurityContext.DemandPermissions(Tenant, new UserSecurityProvider(userId), Constants.Action_EditUser);
|
|
|
|
|
|
2019-09-24 12:27:13 +00:00
|
|
|
|
var userPhoto = Base64ToImage(model.base64CroppedImage, "userPhoto_" + userId.ToString());
|
2019-09-13 11:41:15 +00:00
|
|
|
|
var defaultUserPhoto = Base64ToImage(model.base64DefaultImage, "defaultPhoto" + userId.ToString());
|
|
|
|
|
|
|
|
|
|
if (userPhoto.Length > SetupInfo.MaxImageUploadSize)
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = FileSizeComment.FileImageSizeExceptionString;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data = new byte[userPhoto.Length];
|
|
|
|
|
using var inputStream = userPhoto.OpenReadStream();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-09-13 11:41:15 +00:00
|
|
|
|
var br = new BinaryReader(inputStream);
|
|
|
|
|
br.Read(data, 0, (int)userPhoto.Length);
|
|
|
|
|
br.Close();
|
|
|
|
|
|
|
|
|
|
var defaultData = new byte[defaultUserPhoto.Length];
|
|
|
|
|
using var defaultInputStream = defaultUserPhoto.OpenReadStream();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-09-13 11:41:15 +00:00
|
|
|
|
var defaultBr = new BinaryReader(defaultInputStream);
|
|
|
|
|
defaultBr.Read(defaultData, 0, (int)defaultUserPhoto.Length);
|
|
|
|
|
defaultBr.Close();
|
|
|
|
|
|
2019-09-16 09:24:06 +00:00
|
|
|
|
CheckImgFormat(data);
|
2019-09-13 11:41:15 +00:00
|
|
|
|
|
|
|
|
|
if (model.Autosave)
|
|
|
|
|
{
|
|
|
|
|
if (data.Length > SetupInfo.MaxImageUploadSize)
|
|
|
|
|
throw new ImageSizeLimitException();
|
|
|
|
|
|
|
|
|
|
var mainPhoto = UserPhotoManager.SaveOrUpdateCroppedPhoto(Tenant, userId, data, defaultData);
|
|
|
|
|
|
|
|
|
|
result.Data =
|
|
|
|
|
new
|
|
|
|
|
{
|
|
|
|
|
main = mainPhoto,
|
|
|
|
|
retina = UserPhotoManager.GetRetinaPhotoURL(Tenant.TenantId, userId),
|
|
|
|
|
max = UserPhotoManager.GetMaxPhotoURL(Tenant.TenantId, userId),
|
|
|
|
|
big = UserPhotoManager.GetBigPhotoURL(Tenant.TenantId, userId),
|
|
|
|
|
medium = UserPhotoManager.GetMediumPhotoURL(Tenant.TenantId, userId),
|
|
|
|
|
small = UserPhotoManager.GetSmallPhotoURL(Tenant.TenantId, userId),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.Data = UserPhotoManager.SaveTempPhoto(Tenant.TenantId, data, SetupInfo.MaxImageUploadSize, UserPhotoManager.OriginalFotoSize.Width, UserPhotoManager.OriginalFotoSize.Height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.Success = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (UnknownImageFormatException)
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = PeopleResource.ErrorUnknownFileImageType;
|
|
|
|
|
}
|
|
|
|
|
catch (ImageWeightLimitException)
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = PeopleResource.ErrorImageWeightLimit;
|
|
|
|
|
}
|
|
|
|
|
catch (ImageSizeLimitException)
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = PeopleResource.ErrorImageSizetLimit;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = ex.Message.HtmlEncode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2019-07-17 08:55:08 +00:00
|
|
|
|
[Create("{userid}/photo")]
|
2019-09-24 14:07:24 +00:00
|
|
|
|
public FileUploadResult UploadMemberPhoto(string userid, IFormCollection model)
|
2019-07-17 08:55:08 +00:00
|
|
|
|
{
|
|
|
|
|
var result = new FileUploadResult();
|
2019-09-24 14:07:24 +00:00
|
|
|
|
bool autosave = Boolean.Parse(model["Autosave"]);
|
|
|
|
|
|
2019-07-17 08:55:08 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (model.Files.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
Guid userId;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
userId = new Guid(userid);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
userId = SecurityContext.CurrentAccount.ID;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, new UserSecurityProvider(userId), Constants.Action_EditUser);
|
2019-07-17 08:55:08 +00:00
|
|
|
|
|
|
|
|
|
var userPhoto = model.Files[0];
|
|
|
|
|
|
|
|
|
|
if (userPhoto.Length > SetupInfo.MaxImageUploadSize)
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = FileSizeComment.FileImageSizeExceptionString;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data = new byte[userPhoto.Length];
|
|
|
|
|
using var inputStream = userPhoto.OpenReadStream();
|
|
|
|
|
|
|
|
|
|
var br = new BinaryReader(inputStream);
|
|
|
|
|
br.Read(data, 0, (int)userPhoto.Length);
|
|
|
|
|
br.Close();
|
|
|
|
|
|
2019-09-16 09:24:06 +00:00
|
|
|
|
CheckImgFormat(data);
|
2019-07-17 08:55:08 +00:00
|
|
|
|
|
2019-09-24 14:07:24 +00:00
|
|
|
|
if (autosave)
|
2019-07-17 08:55:08 +00:00
|
|
|
|
{
|
|
|
|
|
if (data.Length > SetupInfo.MaxImageUploadSize)
|
|
|
|
|
throw new ImageSizeLimitException();
|
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var mainPhoto = UserPhotoManager.SaveOrUpdatePhoto(Tenant, userId, data);
|
2019-07-17 08:55:08 +00:00
|
|
|
|
|
|
|
|
|
result.Data =
|
|
|
|
|
new
|
|
|
|
|
{
|
|
|
|
|
main = mainPhoto,
|
2019-08-09 12:28:19 +00:00
|
|
|
|
retina = UserPhotoManager.GetRetinaPhotoURL(Tenant.TenantId, userId),
|
|
|
|
|
max = UserPhotoManager.GetMaxPhotoURL(Tenant.TenantId, userId),
|
|
|
|
|
big = UserPhotoManager.GetBigPhotoURL(Tenant.TenantId, userId),
|
|
|
|
|
medium = UserPhotoManager.GetMediumPhotoURL(Tenant.TenantId, userId),
|
|
|
|
|
small = UserPhotoManager.GetSmallPhotoURL(Tenant.TenantId, userId),
|
2019-07-17 08:55:08 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-08-27 14:57:06 +00:00
|
|
|
|
result.Data = UserPhotoManager.SaveTempPhoto(Tenant.TenantId, data, SetupInfo.MaxImageUploadSize, UserPhotoManager.OriginalFotoSize.Width, UserPhotoManager.OriginalFotoSize.Height);
|
2019-07-17 08:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.Success = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = PeopleResource.ErrorEmptyUploadFileSelected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (UnknownImageFormatException)
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = PeopleResource.ErrorUnknownFileImageType;
|
|
|
|
|
}
|
|
|
|
|
catch (ImageWeightLimitException)
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = PeopleResource.ErrorImageWeightLimit;
|
|
|
|
|
}
|
|
|
|
|
catch (ImageSizeLimitException)
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = PeopleResource.ErrorImageSizetLimit;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = ex.Message.HtmlEncode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Update("{userid}/photo")]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public ThumbnailsDataWrapper UpdateMemberPhoto(string userid, UpdateMemberModel model)
|
|
|
|
|
{
|
|
|
|
|
var user = GetUserInfo(userid);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (CoreContext.UserManager.IsSystemUser(user.ID))
|
|
|
|
|
throw new SecurityException();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (model.Files != UserPhotoManager.GetPhotoAbsoluteWebPath(Tenant, user.ID))
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
|
|
|
|
UpdatePhotoUrl(model.Files, user);
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.SaveUserInfo(Tenant, user);
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.UserAddedAvatar, MessageTarget.Create(user.ID), user.DisplayUserName(false));
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
return new ThumbnailsDataWrapper(Tenant, user.ID);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Delete("{userid}/photo")]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public ThumbnailsDataWrapper DeleteMemberPhoto(string userid)
|
|
|
|
|
{
|
|
|
|
|
var user = GetUserInfo(userid);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (CoreContext.UserManager.IsSystemUser(user.ID))
|
|
|
|
|
throw new SecurityException();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, new UserSecurityProvider(user.ID), Constants.Action_EditUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
UserPhotoManager.RemovePhoto(Tenant, user.ID);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.SaveUserInfo(Tenant, user);
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.UserDeletedAvatar, MessageTarget.Create(user.ID), user.DisplayUserName(false));
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
return new ThumbnailsDataWrapper(Tenant, user.ID);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Create("{userid}/photo/thumbnails")]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public ThumbnailsDataWrapper CreateMemberPhotoThumbnails(string userid, ThumbnailsModel thumbnailsModel)
|
|
|
|
|
{
|
|
|
|
|
var user = GetUserInfo(userid);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (CoreContext.UserManager.IsSystemUser(user.ID))
|
|
|
|
|
throw new SecurityException();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, new UserSecurityProvider(user.ID), Constants.Action_EditUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(thumbnailsModel.TmpFile))
|
|
|
|
|
{
|
|
|
|
|
var fileName = Path.GetFileName(thumbnailsModel.TmpFile);
|
2019-08-27 14:57:06 +00:00
|
|
|
|
var data = UserPhotoManager.GetTempPhotoData(Tenant.TenantId, fileName);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
var settings = new UserPhotoThumbnailSettings(thumbnailsModel.X, thumbnailsModel.Y, thumbnailsModel.Width, thumbnailsModel.Height);
|
|
|
|
|
settings.SaveForUser(user.ID);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
UserPhotoManager.SaveOrUpdatePhoto(Tenant, user.ID, data);
|
2019-08-27 14:57:06 +00:00
|
|
|
|
UserPhotoManager.RemoveTempPhoto(Tenant.TenantId, fileName);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
UserPhotoThumbnailManager.SaveThumbnails(Tenant.TenantId, thumbnailsModel.X, thumbnailsModel.Y, thumbnailsModel.Width, thumbnailsModel.Height, user.ID);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.SaveUserInfo(Tenant, user);
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.UserUpdatedAvatarThumbnails, MessageTarget.Create(user.ID), user.DisplayUserName(false));
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
return new ThumbnailsDataWrapper(Tenant, user.ID);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
[AllowAnonymous]
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Create("password", false)]
|
2019-08-12 10:53:12 +00:00
|
|
|
|
public string SendUserPassword(MemberModel memberModel)
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
2019-08-12 10:53:12 +00:00
|
|
|
|
var userInfo = UserManagerWrapper.SendUserPassword(Tenant.TenantId, memberModel.Email, MessageService, HttpContext);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
return string.Format(Resource.MessageYourPasswordSuccessfullySendedToEmail, userInfo.Email);
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Update("{userid}/password")]
|
2019-09-27 09:20:10 +00:00
|
|
|
|
[Authorize(AuthenticationSchemes = "confirm", Roles = "PasswordChange,EmailChange,Activation,Administrators")]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public EmployeeWraperFull ChangeUserPassword(Guid userid, MemberModel memberModel)
|
|
|
|
|
{
|
2019-09-23 15:36:22 +00:00
|
|
|
|
ApiContext.AuthByClaim();
|
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, new UserSecurityProvider(userid), Constants.Action_EditUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var user = CoreContext.UserManager.GetUsers(Tenant.TenantId, userid);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-30 12:40:57 +00:00
|
|
|
|
if (!CoreContext.UserManager.UserExists(user)) return null;
|
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (CoreContext.UserManager.IsSystemUser(user.ID))
|
|
|
|
|
throw new SecurityException();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(memberModel.Email))
|
|
|
|
|
{
|
|
|
|
|
var address = new MailAddress(memberModel.Email);
|
|
|
|
|
if (!string.Equals(address.Address, user.Email, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
user.Email = address.Address.ToLowerInvariant();
|
|
|
|
|
user.ActivationStatus = EmployeeActivationStatus.Activated;
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.SaveUserInfo(Tenant, user);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(memberModel.Password))
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.SetUserPassword(Tenant.TenantId, userid, memberModel.Password);
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.UserUpdatedPassword);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
HttpContext.ResetUserCookie(Tenant.TenantId, userid);
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.CookieSettingsUpdated);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return new EmployeeWraperFull(GetUserInfo(userid.ToString()), ApiContext);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-09-13 14:30:24 +00:00
|
|
|
|
|
|
|
|
|
[Create("email", false)]
|
|
|
|
|
public string SendEmailChangeInstructions(UpdateMemberModel model)
|
|
|
|
|
{
|
|
|
|
|
Guid.TryParse(model.UserId, out Guid userid);
|
|
|
|
|
|
|
|
|
|
if (userid == Guid.Empty) throw new ArgumentNullException("userid");
|
|
|
|
|
|
|
|
|
|
var email = (model.Email ?? "").Trim();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(email)) throw new Exception(Resource.ErrorEmailEmpty);
|
|
|
|
|
|
|
|
|
|
if (!email.TestEmailRegex()) throw new Exception(Resource.ErrorNotCorrectEmail);
|
|
|
|
|
|
|
|
|
|
var viewer = CoreContext.UserManager.GetUsers(Tenant.TenantId, SecurityContext.CurrentAccount.ID);
|
|
|
|
|
var user = CoreContext.UserManager.GetUsers(Tenant.TenantId, userid);
|
|
|
|
|
|
|
|
|
|
if (user == null)
|
|
|
|
|
throw new Exception(Resource.ErrorUserNotFound);
|
|
|
|
|
|
|
|
|
|
if (viewer == null || (user.IsOwner(Tenant) && viewer.ID != user.ID))
|
|
|
|
|
throw new Exception(Resource.ErrorAccessDenied);
|
|
|
|
|
|
|
|
|
|
var existentUser = CoreContext.UserManager.GetUserByEmail(Tenant.TenantId, email);
|
|
|
|
|
|
|
|
|
|
if (existentUser.ID != Constants.LostUser.ID)
|
|
|
|
|
throw new Exception(CustomNamingPeople.Substitute<Resource>("ErrorEmailAlreadyExists"));
|
|
|
|
|
|
|
|
|
|
if (!viewer.IsAdmin(Tenant))
|
|
|
|
|
{
|
|
|
|
|
StudioNotifyService.SendEmailChangeInstructions(Tenant.TenantId, user, email);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (email == user.Email)
|
|
|
|
|
throw new Exception(Resource.ErrorEmailsAreTheSame);
|
|
|
|
|
|
|
|
|
|
user.Email = email;
|
|
|
|
|
user.ActivationStatus = EmployeeActivationStatus.NotActivated;
|
|
|
|
|
CoreContext.UserManager.SaveUserInfo(Tenant, user);
|
|
|
|
|
StudioNotifyService.SendEmailActivationInstructions(Tenant.TenantId, user, email);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MessageService.Send(MessageAction.UserSentEmailChangeInstructions, user.DisplayUserName(false));
|
|
|
|
|
|
|
|
|
|
return string.Format(Resource.MessageEmailChangeInstuctionsSentOnEmail, email);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
private UserInfo GetUserInfo(string userNameOrId)
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
|
|
|
|
UserInfo user;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var userId = new Guid(userNameOrId);
|
2019-08-09 12:28:19 +00:00
|
|
|
|
user = CoreContext.UserManager.GetUsers(Tenant.TenantId, userId);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
|
|
|
|
catch (FormatException)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
user = CoreContext.UserManager.GetUserByUserName(Tenant.TenantId, userNameOrId);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
|
|
|
|
if (user == null || user.ID == Constants.LostUser.ID)
|
|
|
|
|
throw new ItemNotFoundException("user not found");
|
|
|
|
|
return user;
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
[Update("activationstatus/{activationstatus}")]
|
2019-09-27 09:20:10 +00:00
|
|
|
|
[Authorize(AuthenticationSchemes = "confirm", Roles = "Activation,Administrators")]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public IEnumerable<EmployeeWraperFull> UpdateEmployeeActivationStatus(EmployeeActivationStatus activationstatus, UpdateMembersModel model)
|
|
|
|
|
{
|
2019-09-27 09:20:10 +00:00
|
|
|
|
ApiContext.AuthByClaim();
|
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
var retuls = new List<EmployeeWraperFull>();
|
|
|
|
|
foreach (var id in model.UserIds.Where(userId => !CoreContext.UserManager.IsSystemUser(userId)))
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, new UserSecurityProvider(id), Constants.Action_EditUser);
|
|
|
|
|
var u = CoreContext.UserManager.GetUsers(Tenant.TenantId, id);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (u.ID == Constants.LostUser.ID || u.IsLDAP()) continue;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
u.ActivationStatus = activationstatus;
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.SaveUserInfo(Tenant, u);
|
2019-08-08 09:26:58 +00:00
|
|
|
|
retuls.Add(new EmployeeWraperFull(u, ApiContext));
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
return retuls;
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
[Update("type/{type}")]
|
|
|
|
|
public IEnumerable<EmployeeWraperFull> UpdateUserType(EmployeeType type, UpdateMembersModel model)
|
|
|
|
|
{
|
|
|
|
|
var users = model.UserIds
|
|
|
|
|
.Where(userId => !CoreContext.UserManager.IsSystemUser(userId))
|
2019-08-09 12:28:19 +00:00
|
|
|
|
.Select(userId => CoreContext.UserManager.GetUsers(Tenant.TenantId, userId))
|
2019-06-17 11:57:07 +00:00
|
|
|
|
.ToList();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (user.IsOwner(Tenant) || user.IsAdmin(Tenant) || user.IsMe() || user.GetListAdminModules(Tenant).Any())
|
2019-06-17 11:57:07 +00:00
|
|
|
|
continue;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case EmployeeType.User:
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (user.IsVisitor(Tenant))
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (TenantStatisticsProvider.GetUsersCount(Tenant) < TenantExtra.GetTenantQuota().ActiveUsers)
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.RemoveUserFromGroup(Tenant, user.ID, Constants.GroupVisitor.ID);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
WebItemSecurity.ClearCache();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EmployeeType.Visitor:
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.AddUserIntoGroup(Tenant, user.ID, Constants.GroupVisitor.ID);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
WebItemSecurity.ClearCache();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.UsersUpdatedType, MessageTarget.Create(users.Select(x => x.ID)), users.Select(x => x.DisplayUserName(false)));
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return users.Select(user => new EmployeeWraperFull(user, ApiContext));
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
[Update("status/{status}")]
|
|
|
|
|
public IEnumerable<EmployeeWraperFull> UpdateUserStatus(EmployeeStatus status, UpdateMembersModel model)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, Constants.Action_EditUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var users = model.UserIds.Select(userId => CoreContext.UserManager.GetUsers(Tenant.TenantId, userId))
|
2019-06-17 11:57:07 +00:00
|
|
|
|
.Where(u => !CoreContext.UserManager.IsSystemUser(u.ID) && !u.IsLDAP())
|
|
|
|
|
.ToList();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (user.IsOwner(Tenant) || user.IsMe())
|
2019-06-17 11:57:07 +00:00
|
|
|
|
continue;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
switch (status)
|
|
|
|
|
{
|
|
|
|
|
case EmployeeStatus.Active:
|
|
|
|
|
if (user.Status == EmployeeStatus.Terminated)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (TenantStatisticsProvider.GetUsersCount(Tenant) < TenantExtra.GetTenantQuota().ActiveUsers || user.IsVisitor(Tenant))
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
|
|
|
|
user.Status = EmployeeStatus.Active;
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.SaveUserInfo(Tenant, user);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EmployeeStatus.Terminated:
|
|
|
|
|
user.Status = EmployeeStatus.Terminated;
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.SaveUserInfo(Tenant, user);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
HttpContext.ResetUserCookie(Tenant.TenantId, user.ID);
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.CookieSettingsUpdated);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.UsersUpdatedStatus, MessageTarget.Create(users.Select(x => x.ID)), users.Select(x => x.DisplayUserName(false)));
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return users.Select(user => new EmployeeWraperFull(user, ApiContext));
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Update("invite")]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public IEnumerable<EmployeeWraperFull> ResendUserInvites(UpdateMembersModel model)
|
|
|
|
|
{
|
|
|
|
|
var users = model.UserIds
|
|
|
|
|
.Where(userId => !CoreContext.UserManager.IsSystemUser(userId))
|
2019-08-09 12:28:19 +00:00
|
|
|
|
.Select(userId => CoreContext.UserManager.GetUsers(Tenant.TenantId, userId))
|
2019-06-17 11:57:07 +00:00
|
|
|
|
.ToList();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
|
|
|
|
if (user.IsActive) continue;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (user.ActivationStatus == EmployeeActivationStatus.Pending)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (user.IsVisitor(Tenant))
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
StudioNotifyService.GuestInfoActivation(Tenant.TenantId, user);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
StudioNotifyService.UserInfoActivation(Tenant.TenantId, user);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-03 12:23:58 +00:00
|
|
|
|
StudioNotifyService.SendEmailActivationInstructions(Tenant.TenantId, user, user.Email);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.UsersSentActivationInstructions, MessageTarget.Create(users.Select(x => x.ID)), users.Select(x => x.DisplayUserName(false)));
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return users.Select(user => new EmployeeWraperFull(user, ApiContext));
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-09-03 11:10:32 +00:00
|
|
|
|
[Update("delete", Order = -1)]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public IEnumerable<EmployeeWraperFull> RemoveUsers(UpdateMembersModel model)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, Constants.Action_AddRemoveUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-21 10:42:16 +00:00
|
|
|
|
CheckReassignProccess(model.UserIds);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var users = model.UserIds.Select(userId => CoreContext.UserManager.GetUsers(Tenant.TenantId, userId))
|
2019-06-17 11:57:07 +00:00
|
|
|
|
.Where(u => !CoreContext.UserManager.IsSystemUser(u.ID) && !u.IsLDAP())
|
|
|
|
|
.ToList();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
var userNames = users.Select(x => x.DisplayUserName(false)).ToList();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
|
|
|
|
if (user.Status != EmployeeStatus.Terminated) continue;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
UserPhotoManager.RemovePhoto(Tenant, user.ID);
|
2019-08-15 12:04:42 +00:00
|
|
|
|
CoreContext.UserManager.DeleteUser(Tenant, user.ID);
|
2019-08-12 10:53:12 +00:00
|
|
|
|
QueueWorkerRemove.Start(Tenant.TenantId, user, SecurityContext.CurrentAccount.ID, false);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.UsersDeleted, MessageTarget.Create(users.Select(x => x.ID)), userNames);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
return users.Select(user => new EmployeeWraperFull(user, ApiContext));
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Update("self/delete")]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public string SendInstructionsToDelete()
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var user = CoreContext.UserManager.GetUsers(Tenant.TenantId, SecurityContext.CurrentAccount.ID);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (user.IsLDAP())
|
|
|
|
|
throw new SecurityException();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-09-03 12:23:58 +00:00
|
|
|
|
StudioNotifyService.SendMsgProfileDeletion(Tenant.TenantId, user);
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.UserSentDeleteInstructions);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
return string.Format(Resource.SuccessfullySentNotificationDeleteUserInfoMessage, "<b>" + user.Email + "</b>");
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Update("thirdparty/linkaccount")]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public void LinkAccount(string serializedProfile)
|
|
|
|
|
{
|
|
|
|
|
var profile = new LoginProfile(serializedProfile);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (string.IsNullOrEmpty(profile.AuthorizationError))
|
|
|
|
|
{
|
|
|
|
|
GetLinker().AddLink(SecurityContext.CurrentAccount.ID.ToString(), profile);
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.UserLinkedSocialAccount, GetMeaningfulProviderName(profile.Provider));
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// ignore cancellation
|
|
|
|
|
if (profile.AuthorizationError != "Canceled at provider")
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(profile.AuthorizationError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Delete("thirdparty/unlinkaccount")]
|
2019-06-17 11:57:07 +00:00
|
|
|
|
public void UnlinkAccount(string provider)
|
|
|
|
|
{
|
|
|
|
|
GetLinker().RemoveProvider(SecurityContext.CurrentAccount.ID.ToString(), provider);
|
2019-06-17 13:53:10 +00:00
|
|
|
|
MessageService.Send(MessageAction.UserUnlinkedSocialAccount, GetMeaningfulProviderName(provider));
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
private static AccountLinker GetLinker()
|
|
|
|
|
{
|
|
|
|
|
return new AccountLinker("webstudio");
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
private static string GetMeaningfulProviderName(string providerName)
|
|
|
|
|
{
|
|
|
|
|
switch (providerName)
|
|
|
|
|
{
|
|
|
|
|
case "google":
|
|
|
|
|
case "openid":
|
|
|
|
|
return "Google";
|
|
|
|
|
case "facebook":
|
|
|
|
|
return "Facebook";
|
|
|
|
|
case "twitter":
|
|
|
|
|
return "Twitter";
|
|
|
|
|
case "linkedin":
|
|
|
|
|
return "LinkedIn";
|
|
|
|
|
default:
|
|
|
|
|
return "Unknown Provider";
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Read(@"reassign/progress")]
|
2019-06-21 10:42:16 +00:00
|
|
|
|
public ReassignProgressItem GetReassignProgress(Guid userId)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, Constants.Action_EditUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-12 10:53:12 +00:00
|
|
|
|
return QueueWorkerReassign.GetProgressItemStatus(Tenant.TenantId, userId);
|
2019-06-21 10:42:16 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Update(@"reassign/terminate")]
|
2019-06-21 10:42:16 +00:00
|
|
|
|
public void TerminateReassign(Guid userId)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, Constants.Action_EditUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-12 10:53:12 +00:00
|
|
|
|
QueueWorkerReassign.Terminate(Tenant.TenantId, userId);
|
2019-06-21 10:42:16 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Create(@"reassign/start")]
|
2019-06-21 10:42:16 +00:00
|
|
|
|
public ReassignProgressItem StartReassign(Guid fromUserId, Guid toUserId, bool deleteProfile)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, Constants.Action_EditUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var fromUser = CoreContext.UserManager.GetUsers(Tenant.TenantId, fromUserId);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-21 10:42:16 +00:00
|
|
|
|
if (fromUser == null || fromUser.ID == Constants.LostUser.ID)
|
|
|
|
|
throw new ArgumentException("User with id = " + fromUserId + " not found");
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (fromUser.IsOwner(Tenant) || fromUser.IsMe() || fromUser.Status != EmployeeStatus.Terminated)
|
2019-06-21 10:42:16 +00:00
|
|
|
|
throw new ArgumentException("Can not delete user with id = " + fromUserId);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var toUser = CoreContext.UserManager.GetUsers(Tenant.TenantId, toUserId);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-21 10:42:16 +00:00
|
|
|
|
if (toUser == null || toUser.ID == Constants.LostUser.ID)
|
|
|
|
|
throw new ArgumentException("User with id = " + toUserId + " not found");
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (toUser.IsVisitor(Tenant) || toUser.Status == EmployeeStatus.Terminated)
|
2019-06-21 10:42:16 +00:00
|
|
|
|
throw new ArgumentException("Can not reassign data to user with id = " + toUserId);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-12 10:53:12 +00:00
|
|
|
|
return QueueWorkerReassign.Start(Tenant.TenantId, fromUserId, toUserId, SecurityContext.CurrentAccount.ID, deleteProfile);
|
2019-06-21 10:42:16 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-21 10:42:16 +00:00
|
|
|
|
private void CheckReassignProccess(IEnumerable<Guid> userIds)
|
|
|
|
|
{
|
|
|
|
|
foreach (var userId in userIds)
|
|
|
|
|
{
|
2019-08-12 10:53:12 +00:00
|
|
|
|
var reassignStatus = QueueWorkerReassign.GetProgressItemStatus(Tenant.TenantId, userId);
|
2019-06-21 10:42:16 +00:00
|
|
|
|
if (reassignStatus == null || reassignStatus.IsCompleted)
|
|
|
|
|
continue;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var userName = CoreContext.UserManager.GetUsers(Tenant.TenantId, userId).DisplayUserName();
|
2019-06-21 10:42:16 +00:00
|
|
|
|
throw new Exception(string.Format(Resource.ReassignDataRemoveUserError, userName));
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
|
2019-06-21 10:42:16 +00:00
|
|
|
|
#region Remove user data
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Read(@"remove/progress")]
|
2019-06-21 10:42:16 +00:00
|
|
|
|
public RemoveProgressItem GetRemoveProgress(Guid userId)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, Constants.Action_EditUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-12 10:53:12 +00:00
|
|
|
|
return QueueWorkerRemove.GetProgressItemStatus(Tenant.TenantId, userId);
|
2019-06-21 10:42:16 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Update(@"remove/terminate")]
|
2019-06-21 10:42:16 +00:00
|
|
|
|
public void TerminateRemove(Guid userId)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, Constants.Action_EditUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-12 10:53:12 +00:00
|
|
|
|
QueueWorkerRemove.Terminate(Tenant.TenantId, userId);
|
2019-06-21 10:42:16 +00:00
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-25 10:46:10 +00:00
|
|
|
|
[Create(@"remove/start")]
|
2019-06-21 10:42:16 +00:00
|
|
|
|
public RemoveProgressItem StartRemove(Guid userId)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, Constants.Action_EditUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var user = CoreContext.UserManager.GetUsers(Tenant.TenantId, userId);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-06-21 10:42:16 +00:00
|
|
|
|
if (user == null || user.ID == Constants.LostUser.ID)
|
|
|
|
|
throw new ArgumentException("User with id = " + userId + " not found");
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (user.IsOwner(Tenant) || user.IsMe() || user.Status != EmployeeStatus.Terminated)
|
2019-06-21 10:42:16 +00:00
|
|
|
|
throw new ArgumentException("Can not delete user with id = " + userId);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
2019-08-12 10:53:12 +00:00
|
|
|
|
return QueueWorkerRemove.Start(Tenant.TenantId, user, SecurityContext.CurrentAccount.ID, true);
|
2019-06-21 10:42:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2019-06-17 11:57:07 +00:00
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
private void UpdateDepartments(IEnumerable<Guid> department, UserInfo user)
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
if (!SecurityContext.CheckPermissions(Tenant, Constants.Action_EditGroups)) return;
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (department == null) return;
|
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var groups = CoreContext.UserManager.GetUserGroups(Tenant, user.ID);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
var managerGroups = new List<Guid>();
|
|
|
|
|
foreach (var groupInfo in groups)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.RemoveUserFromGroup(Tenant, user.ID, groupInfo.ID);
|
|
|
|
|
var managerId = CoreContext.UserManager.GetDepartmentManager(Tenant.TenantId, groupInfo.ID);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (managerId == user.ID)
|
|
|
|
|
{
|
|
|
|
|
managerGroups.Add(groupInfo.ID);
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.SetDepartmentManager(Tenant.TenantId, groupInfo.ID, Guid.Empty);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach (var guid in department)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
var userDepartment = CoreContext.UserManager.GetGroupInfo(Tenant.TenantId, guid);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (userDepartment != Constants.LostGroupInfo)
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.AddUserIntoGroup(Tenant, user.ID, guid);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (managerGroups.Contains(guid))
|
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
CoreContext.UserManager.SetDepartmentManager(Tenant.TenantId, guid, user.ID);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
private void UpdateContacts(IEnumerable<Contact> contacts, UserInfo user)
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, new UserSecurityProvider(user.ID), Constants.Action_EditUser);
|
2019-09-02 15:09:45 +00:00
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (contacts == null) return;
|
|
|
|
|
|
2019-09-02 15:09:45 +00:00
|
|
|
|
if (user.Contacts == null)
|
|
|
|
|
{
|
|
|
|
|
user.Contacts = new List<string>();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
user.Contacts.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-10 08:53:47 +00:00
|
|
|
|
foreach (var contact in contacts.Where(c => !string.IsNullOrEmpty(c.Value)))
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
|
|
|
|
user.Contacts.Add(contact.Type);
|
|
|
|
|
user.Contacts.Add(contact.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
|
private void DeleteContacts(IEnumerable<Contact> contacts, UserInfo user)
|
2019-06-17 11:57:07 +00:00
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, new UserSecurityProvider(user.ID), Constants.Action_EditUser);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
if (contacts == null) return;
|
|
|
|
|
|
2019-09-02 15:09:45 +00:00
|
|
|
|
if (user.Contacts == null)
|
|
|
|
|
{
|
|
|
|
|
user.Contacts = new List<string>();
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-17 11:57:07 +00:00
|
|
|
|
foreach (var contact in contacts)
|
|
|
|
|
{
|
|
|
|
|
var index = user.Contacts.IndexOf(contact.Type);
|
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
|
|
|
|
//Remove existing
|
|
|
|
|
user.Contacts.RemoveRange(index, 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdatePhotoUrl(string files, UserInfo user)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(files))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-09 12:28:19 +00:00
|
|
|
|
SecurityContext.DemandPermissions(Tenant, new UserSecurityProvider(user.ID), Constants.Action_EditUser);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
|
|
|
|
|
if (!files.StartsWith("http://") && !files.StartsWith("https://"))
|
|
|
|
|
{
|
|
|
|
|
files = new Uri(ApiContext.HttpContext.Request.GetDisplayUrl()).GetLeftPart(UriPartial.Scheme | UriPartial.Authority) + "/" + files.TrimStart('/');
|
|
|
|
|
}
|
|
|
|
|
var request = WebRequest.Create(files);
|
|
|
|
|
using var response = (HttpWebResponse)request.GetResponse();
|
|
|
|
|
using var inputStream = response.GetResponseStream();
|
|
|
|
|
using var br = new BinaryReader(inputStream);
|
|
|
|
|
var imageByteArray = br.ReadBytes((int)response.ContentLength);
|
2019-08-09 12:28:19 +00:00
|
|
|
|
UserPhotoManager.SaveOrUpdatePhoto(Tenant, user.ID, imageByteArray);
|
2019-06-17 11:57:07 +00:00
|
|
|
|
}
|
2019-07-17 08:55:08 +00:00
|
|
|
|
|
2019-09-16 09:24:06 +00:00
|
|
|
|
private static void CheckImgFormat(byte[] data)
|
|
|
|
|
{
|
|
|
|
|
ImageFormat imgFormat;
|
2019-07-17 08:55:08 +00:00
|
|
|
|
|
2019-09-16 09:24:06 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using var stream = new MemoryStream(data);
|
|
|
|
|
using var img = new Bitmap(stream);
|
|
|
|
|
imgFormat = img.RawFormat;
|
|
|
|
|
}
|
|
|
|
|
catch (OutOfMemoryException)
|
|
|
|
|
{
|
|
|
|
|
throw new ImageSizeLimitException();
|
|
|
|
|
}
|
|
|
|
|
catch (ArgumentException error)
|
|
|
|
|
{
|
|
|
|
|
throw new UnknownImageFormatException(error);
|
|
|
|
|
}
|
2019-07-17 08:55:08 +00:00
|
|
|
|
|
2019-09-16 09:24:06 +00:00
|
|
|
|
if (!imgFormat.Equals(ImageFormat.Png) && !imgFormat.Equals(ImageFormat.Jpeg))
|
|
|
|
|
{
|
|
|
|
|
throw new UnknownImageFormatException();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-17 08:32:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|