Skip to content

Commit

Permalink
added users order by lastname|displayname
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeybannov committed Aug 15, 2024
1 parent 4a21d7d commit 35a24da
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
12 changes: 12 additions & 0 deletions common/ASC.Core.Common/Context/Impl/UserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ public IAsyncEnumerable<UserInfo> GetUsers(
sortType = UserSortType.FirstName;
}

if (sortType == UserSortType.DisplayName)
{
if (UserFormatter.GetUserDisplayDefaultOrder() == DisplayUserNameFormat.FirstLast)
{
sortType = UserSortType.FirstName;
}
else
{
sortType = UserSortType.LastName;
}
}

return userService.GetUsers(Tenant.Id, isDocSpaceAdmin, employeeStatus, includeGroups, excludeGroups, combinedGroups, activationStatus, accountLoginType, quotaFilter, text, withoutGroup, Tenant.OwnerId, sortType, sortOrderAsc, limit, offset);
}

Expand Down
2 changes: 2 additions & 0 deletions common/ASC.Core.Common/Core/SortType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public enum GroupSortType
public enum UserSortType
{
FirstName,
LastName,
DisplayName,
Type,
Email,
Department,
Expand Down
7 changes: 7 additions & 0 deletions common/ASC.Core.Common/Data/DbUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@ from @quota in quotaRow.DefaultIfEmpty()
case UserSortType.Email:
q = (sortOrderAsc ? q.OrderBy(u => u.Email) : q.OrderByDescending(u => u.Email));
break;
case UserSortType.LastName:
q = sortOrderAsc
? q.OrderBy(r => r.Status == EmployeeStatus.Active ? 0 : r.Status == EmployeeStatus.Pending ? 1 : 2)
.ThenBy(u => u.Status == EmployeeStatus.Pending ? u.Email : u.LastName)
: q.OrderBy(r => r.Status == EmployeeStatus.Active ? 0 : r.Status == EmployeeStatus.Pending ? 1 : 2)
.ThenByDescending(u => u.Status == EmployeeStatus.Pending ? u.Email : u.LastName);
break;
case UserSortType.FirstName:
default:
q = sortOrderAsc
Expand Down
2 changes: 1 addition & 1 deletion common/ASC.Core.Common/Users/UserFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private string GetUserDisplayFormat(DisplayUserNameFormat format)
return formats[format];
}

private static DisplayUserNameFormat GetUserDisplayDefaultOrder()
public static DisplayUserNameFormat GetUserDisplayDefaultOrder()
{
var culture = CultureInfo.CurrentCulture.Name;
if (!_displayFormats.TryGetValue(culture, out var formats))
Expand Down

0 comments on commit 35a24da

Please sign in to comment.