People: added simple wrapper for getbyid method

fixed invite link
This commit is contained in:
pavelbannov 2022-02-09 14:05:21 +03:00
parent f1eef443ff
commit d27a33f08f
3 changed files with 53 additions and 18 deletions

View File

@ -173,6 +173,22 @@ namespace ASC.Web.Api.Models
return lambda;
}
public EmployeeWraperFull GetSimple(UserInfo userInfo)
{
var result = new EmployeeWraperFull
{
FirstName = userInfo.FirstName,
LastName = userInfo.LastName,
};
FillGroups(result, userInfo);
var userInfoLM = userInfo.LastModified.GetHashCode();
result.AvatarMax = UserPhotoManager.GetMaxPhotoURL(userInfo.ID, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
return result;
}
public EmployeeWraperFull GetFull(UserInfo userInfo)
{
var result = new EmployeeWraperFull
@ -223,23 +239,7 @@ namespace ASC.Web.Api.Models
}
FillConacts(result, userInfo);
if (Context.Check("groups") || Context.Check("department"))
{
var groups = UserManager.GetUserGroups(userInfo.ID)
.Select(x => new GroupWrapperSummary(x, UserManager))
.ToList();
if (groups.Count > 0)
{
result.Groups = groups;
result.Department = string.Join(", ", result.Groups.Select(d => d.Name.HtmlEncode()));
}
else
{
result.Department = "";
}
}
FillGroups(result, userInfo);
var userInfoLM = userInfo.LastModified.GetHashCode();
@ -269,6 +269,28 @@ namespace ASC.Web.Api.Models
return result;
}
private void FillGroups(EmployeeWraperFull result, UserInfo userInfo)
{
if (!Context.Check("groups") && !Context.Check("department"))
{
return;
}
var groups = UserManager.GetUserGroups(userInfo.ID)
.Select(x => new GroupWrapperSummary(x, UserManager))
.ToList();
if (groups.Count > 0)
{
result.Groups = groups;
result.Department = string.Join(", ", result.Groups.Select(d => d.Name.HtmlEncode()));
}
else
{
result.Department = "";
}
}
private void FillConacts(EmployeeWraperFull employeeWraperFull, UserInfo userInfo)
{
if (userInfo.ContactsList == null) return;

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Net.Http;
using System.Net.Mail;
using System.Security;
using System.Security.Claims;
using System.ServiceModel.Security;
using System.Threading;
using System.Web;
@ -235,10 +236,17 @@ namespace ASC.Employee.Core.Controllers
return EmployeeWraperFullHelper.GetFull(user);
}
[Authorize(AuthenticationSchemes = "confirm", Roles = "LinkInvite,Everyone")]
[Read("{username}", order: int.MaxValue)]
public EmployeeWraperFull GetById(string username)
{
if (CoreBaseSettings.Personal) throw new MethodAccessException("Method not available");
var isInvite = ApiContext.HttpContextAccessor.HttpContext.User.Claims
.Any(role => role.Type == ClaimTypes.Role && Enum.TryParse<ConfirmType>(role.Value, out var confirmType) && confirmType == ConfirmType.LinkInvite);
ApiContext.AuthByClaim();
var user = UserManager.GetUserByUserName(username);
if (user.ID == Constants.LostUser.ID)
{
@ -257,6 +265,11 @@ namespace ASC.Employee.Core.Controllers
throw new ItemNotFoundException("User not found");
}
if (isInvite)
{
return EmployeeWraperFullHelper.GetSimple(user);
}
return EmployeeWraperFullHelper.GetFull(user);
}

View File

@ -123,7 +123,7 @@ namespace ASC.Web.Api.Controllers
throw new SecurityException("Method not available");
}
return CommonLinkUtility.GetConfirmationUrl(string.Empty, ConfirmType.LinkInvite, (int)employeeType)
return CommonLinkUtility.GetConfirmationUrl(string.Empty, ConfirmType.LinkInvite, (int)employeeType, SecurityContext.CurrentAccount.ID)
+ $"&emplType={employeeType:d}";
}