2019-06-11 15:20:04 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) Copyright Ascensio System Limited 2010-2018
|
|
|
|
*
|
|
|
|
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
|
|
|
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
|
|
|
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
|
|
|
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
|
|
|
*
|
|
|
|
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
|
|
|
*
|
|
|
|
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
|
|
|
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
|
|
|
*
|
|
|
|
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
|
|
|
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
|
|
|
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
|
|
|
* in every copy of the program you distribute.
|
|
|
|
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Runtime.Serialization;
|
2019-06-13 09:04:46 +00:00
|
|
|
using ASC.Api.Core;
|
2019-06-11 15:20:04 +00:00
|
|
|
using ASC.Core;
|
|
|
|
using ASC.Core.Users;
|
|
|
|
using ASC.Web.Core.Users;
|
|
|
|
|
|
|
|
namespace ASC.Web.Api.Models
|
|
|
|
{
|
|
|
|
[DataContract(Name = "person", Namespace = "")]
|
|
|
|
public class EmployeeWraperFull : EmployeeWraper
|
|
|
|
{
|
|
|
|
[DataMember(Order = 10)]
|
|
|
|
public string FirstName { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 10)]
|
|
|
|
public string LastName { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 2)]
|
|
|
|
public string UserName { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 10)]
|
|
|
|
public string Email { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 12, EmitDefaultValue = false)]
|
|
|
|
protected List<Contact> Contacts { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 10, EmitDefaultValue = false)]
|
2019-06-13 09:25:53 +00:00
|
|
|
public ApiDateTime Birthday { get; set; }
|
2019-06-11 15:20:04 +00:00
|
|
|
|
|
|
|
[DataMember(Order = 10, EmitDefaultValue = false)]
|
|
|
|
public string Sex { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 10)]
|
|
|
|
public EmployeeStatus Status { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 10)]
|
|
|
|
public EmployeeActivationStatus ActivationStatus { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 10)]
|
2019-06-13 09:25:53 +00:00
|
|
|
public ApiDateTime Terminated { get; set; }
|
2019-06-11 15:20:04 +00:00
|
|
|
|
|
|
|
[DataMember(Order = 10, EmitDefaultValue = false)]
|
|
|
|
public string Department { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 10, EmitDefaultValue = false)]
|
2019-06-13 09:25:53 +00:00
|
|
|
public ApiDateTime WorkFrom { get; set; }
|
2019-06-11 15:20:04 +00:00
|
|
|
|
|
|
|
[DataMember(Order = 20, EmitDefaultValue = false)]
|
|
|
|
public List<GroupWrapperSummary> Groups { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 10, EmitDefaultValue = false)]
|
|
|
|
public string Location { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 10, EmitDefaultValue = false)]
|
|
|
|
public string Notes { get; set; }
|
|
|
|
|
2019-07-24 11:27:28 +00:00
|
|
|
[DataMember(Order = 20)]
|
|
|
|
public string AvatarMax { get; set; }
|
|
|
|
|
2019-09-13 11:41:15 +00:00
|
|
|
[DataMember(Order = 20)]
|
|
|
|
public string AvatarDefault { get; set; }
|
|
|
|
|
2019-06-11 15:20:04 +00:00
|
|
|
[DataMember(Order = 20)]
|
|
|
|
public string AvatarMedium { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 20)]
|
|
|
|
public string Avatar { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 20)]
|
|
|
|
public bool IsAdmin { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 20)]
|
|
|
|
public bool IsLDAP { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 20, EmitDefaultValue = false)]
|
|
|
|
public List<string> ListAdminModules { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 20)]
|
|
|
|
public bool IsOwner { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 2)]
|
|
|
|
public bool IsVisitor { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 20, EmitDefaultValue = false)]
|
|
|
|
public string CultureName { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember(Order = 11, EmitDefaultValue = false)]
|
2019-06-13 09:25:53 +00:00
|
|
|
protected string MobilePhone { get; set; }
|
2019-06-11 15:20:04 +00:00
|
|
|
|
|
|
|
[DataMember(Order = 11, EmitDefaultValue = false)]
|
|
|
|
protected MobilePhoneActivationStatus MobilePhoneActivationStatus { get; set; }
|
|
|
|
|
|
|
|
[DataMember(Order = 20)]
|
|
|
|
public bool IsSSO { get; set; }
|
|
|
|
|
|
|
|
public EmployeeWraperFull()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-13 09:25:53 +00:00
|
|
|
public EmployeeWraperFull(UserInfo userInfo, ApiContext context)
|
|
|
|
: base(userInfo, context)
|
2019-06-11 15:20:04 +00:00
|
|
|
{
|
|
|
|
UserName = userInfo.UserName;
|
|
|
|
FirstName = userInfo.FirstName;
|
|
|
|
LastName = userInfo.LastName;
|
2019-06-13 09:25:53 +00:00
|
|
|
Birthday = (ApiDateTime)userInfo.BirthDate;
|
2019-06-11 15:20:04 +00:00
|
|
|
|
|
|
|
if (userInfo.Sex.HasValue)
|
|
|
|
Sex = userInfo.Sex.Value ? "male" : "female";
|
|
|
|
|
|
|
|
Status = userInfo.Status;
|
|
|
|
ActivationStatus = userInfo.ActivationStatus & ~EmployeeActivationStatus.AutoGenerated;
|
2019-06-13 09:25:53 +00:00
|
|
|
Terminated = (ApiDateTime)userInfo.TerminatedDate;
|
2019-06-11 15:20:04 +00:00
|
|
|
|
2019-06-13 09:25:53 +00:00
|
|
|
WorkFrom = (ApiDateTime)userInfo.WorkFromDate;
|
2019-06-11 15:20:04 +00:00
|
|
|
Email = userInfo.Email;
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(userInfo.Location))
|
|
|
|
{
|
|
|
|
Location = userInfo.Location;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(userInfo.Notes))
|
|
|
|
{
|
|
|
|
Notes = userInfo.Notes;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(userInfo.MobilePhone))
|
|
|
|
{
|
|
|
|
MobilePhone = userInfo.MobilePhone;
|
|
|
|
}
|
|
|
|
|
|
|
|
MobilePhoneActivationStatus = userInfo.MobilePhoneActivationStatus;
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(userInfo.CultureName))
|
|
|
|
{
|
|
|
|
CultureName = userInfo.CultureName;
|
|
|
|
}
|
|
|
|
|
|
|
|
FillConacts(userInfo);
|
|
|
|
|
2019-06-13 09:25:53 +00:00
|
|
|
if (context.Check("groups") || context.Check("department"))
|
2019-06-13 09:04:46 +00:00
|
|
|
{
|
2019-08-08 09:26:58 +00:00
|
|
|
var groups = CoreContext.UserManager.GetUserGroups(context.Tenant, userInfo.ID)
|
|
|
|
.Select(x => new GroupWrapperSummary(x, context))
|
|
|
|
.ToList();
|
2019-06-11 15:20:04 +00:00
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
if (groups.Count > 0)
|
2019-06-11 15:20:04 +00:00
|
|
|
{
|
|
|
|
Groups = groups;
|
|
|
|
Department = string.Join(", ", Groups.Select(d => d.Name.HtmlEncode()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Department = "";
|
|
|
|
}
|
2019-06-13 09:04:46 +00:00
|
|
|
}
|
2019-06-11 15:20:04 +00:00
|
|
|
|
2019-07-24 12:34:23 +00:00
|
|
|
var userInfoLM = userInfo.LastModified.GetHashCode();
|
|
|
|
|
2019-09-13 11:41:15 +00:00
|
|
|
if (context.Check("avatarDefault"))
|
|
|
|
{
|
|
|
|
AvatarDefault = Convert.ToBase64String(CoreContext.UserManager.GetUserPhoto(context.Tenant.TenantId, userInfo.ID));
|
|
|
|
}
|
|
|
|
|
2019-07-24 11:27:28 +00:00
|
|
|
if (context.Check("avatarMax"))
|
|
|
|
{
|
2019-08-15 12:04:42 +00:00
|
|
|
AvatarMax = UserPhotoManager.GetMaxPhotoURL(context.Tenant.TenantId, userInfo.ID, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
|
2019-07-24 11:27:28 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 09:25:53 +00:00
|
|
|
if (context.Check("avatarMedium"))
|
2019-06-13 09:04:46 +00:00
|
|
|
{
|
2019-08-08 09:26:58 +00:00
|
|
|
AvatarMedium = UserPhotoManager.GetMediumPhotoURL(context.Tenant.TenantId, userInfo.ID, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
|
2019-06-13 09:04:46 +00:00
|
|
|
}
|
2019-06-11 15:20:04 +00:00
|
|
|
|
2019-06-13 09:25:53 +00:00
|
|
|
if (context.Check("avatar"))
|
2019-06-13 09:04:46 +00:00
|
|
|
{
|
2019-08-08 09:26:58 +00:00
|
|
|
Avatar = UserPhotoManager.GetBigPhotoURL(context.Tenant.TenantId, userInfo.ID, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
|
2019-06-13 09:04:46 +00:00
|
|
|
}
|
2019-06-11 15:20:04 +00:00
|
|
|
|
2019-06-13 09:25:53 +00:00
|
|
|
if (context.Check("listAdminModules"))
|
2019-06-13 09:04:46 +00:00
|
|
|
{
|
2019-08-08 09:26:58 +00:00
|
|
|
var listAdminModules = userInfo.GetListAdminModules(context.Tenant);
|
2019-06-11 15:20:04 +00:00
|
|
|
|
|
|
|
if (listAdminModules.Any())
|
|
|
|
ListAdminModules = listAdminModules;
|
2019-06-13 09:04:46 +00:00
|
|
|
}
|
2019-06-11 15:20:04 +00:00
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
IsVisitor = userInfo.IsVisitor(context.Tenant);
|
|
|
|
IsAdmin = userInfo.IsAdmin(context.Tenant);
|
|
|
|
IsOwner = userInfo.IsOwner(context.Tenant);
|
2019-06-11 15:20:04 +00:00
|
|
|
IsLDAP = userInfo.IsLDAP();
|
|
|
|
IsSSO = userInfo.IsSSO();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void FillConacts(UserInfo userInfo)
|
|
|
|
{
|
2019-09-02 15:09:45 +00:00
|
|
|
if (userInfo.Contacts == null) return;
|
|
|
|
|
2019-06-11 15:20:04 +00:00
|
|
|
var contacts = new List<Contact>();
|
2019-09-02 15:09:45 +00:00
|
|
|
|
2019-06-11 15:20:04 +00:00
|
|
|
for (var i = 0; i < userInfo.Contacts.Count; i += 2)
|
|
|
|
{
|
|
|
|
if (i + 1 < userInfo.Contacts.Count)
|
|
|
|
{
|
|
|
|
contacts.Add(new Contact(userInfo.Contacts[i], userInfo.Contacts[i + 1]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contacts.Any())
|
|
|
|
{
|
|
|
|
Contacts = contacts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
public static EmployeeWraperFull GetFull(Guid userId, ApiContext context)
|
2019-06-11 15:20:04 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2019-08-09 12:28:19 +00:00
|
|
|
return GetFull(CoreContext.UserManager.GetUsers(context.Tenant.TenantId, userId), context);
|
2019-06-11 15:20:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
2019-08-08 09:26:58 +00:00
|
|
|
return GetFull(ASC.Core.Users.Constants.LostUser, context);
|
2019-06-11 15:20:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-08 09:26:58 +00:00
|
|
|
public static EmployeeWraperFull GetFull(UserInfo userInfo, ApiContext context)
|
2019-06-11 15:20:04 +00:00
|
|
|
{
|
2019-08-08 09:26:58 +00:00
|
|
|
return new EmployeeWraperFull(userInfo, context);
|
2019-06-11 15:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public new static EmployeeWraperFull GetSample()
|
|
|
|
{
|
|
|
|
return new EmployeeWraperFull
|
2019-06-13 09:25:53 +00:00
|
|
|
{
|
|
|
|
Avatar = "url to big avatar",
|
|
|
|
AvatarSmall = "url to small avatar",
|
2019-07-24 11:27:28 +00:00
|
|
|
AvatarMax = "url to max avatar",
|
2019-06-13 09:25:53 +00:00
|
|
|
Contacts = new List<Contact> { Contact.GetSample() },
|
|
|
|
Email = "my@gmail.com",
|
|
|
|
FirstName = "Mike",
|
|
|
|
Id = Guid.Empty,
|
|
|
|
IsAdmin = false,
|
|
|
|
ListAdminModules = new List<string> { "projects", "crm" },
|
|
|
|
UserName = "Mike.Zanyatski",
|
|
|
|
LastName = "Zanyatski",
|
|
|
|
Title = "Manager",
|
|
|
|
Groups = new List<GroupWrapperSummary> { GroupWrapperSummary.GetSample() },
|
|
|
|
AvatarMedium = "url to medium avatar",
|
|
|
|
Birthday = ApiDateTime.GetSample(),
|
|
|
|
Department = "Marketing",
|
|
|
|
Location = "Palo Alto",
|
|
|
|
Notes = "Notes to worker",
|
|
|
|
Sex = "male",
|
|
|
|
Status = EmployeeStatus.Active,
|
|
|
|
WorkFrom = ApiDateTime.GetSample(),
|
|
|
|
Terminated = ApiDateTime.GetSample(),
|
|
|
|
CultureName = "en-EN",
|
|
|
|
IsLDAP = false,
|
|
|
|
IsSSO = false
|
|
|
|
};
|
2019-06-11 15:20:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|