// Copyright Epic Games, Inc. All Rights Reserved. using EpicGames.Core; using EpicGames.Horde.Jobs; using EpicGames.Horde.Jobs.Bisect; using EpicGames.Horde.Jobs.Templates; using EpicGames.Horde.Streams; using EpicGames.Horde.Users; using MongoDB.Bson; namespace HordeServer.Users { /// /// Known user ids /// public static class KnownUsers { /// /// The system user. Used for automated processes. /// public static UserId System { get; } = UserId.Parse("6170b423b94a2c7c2d6b6f87"); } /// /// Document which collates information about a user, and their personal settings /// public interface IUser { /// /// The user id /// public UserId Id { get; } /// /// Full name of the user /// public string Name { get; } /// /// The user's login id /// public string Login { get; } /// /// The user's email /// public string? Email { get; } } /// /// Claims for a particular user /// public interface IUserClaims { /// /// The user id /// public UserId UserId { get; } /// /// Claims for this user (on last login) /// public IReadOnlyList Claims { get; } } /// /// /// public interface IUserJobTemplateSettings { /// /// The stream the job was run in /// public StreamId StreamId { get; } /// /// The template id of the job /// public TemplateId TemplateId { get; } /// /// The hash of the template definition /// public string TemplateHash { get; } /// /// The arguments defined when creating the job /// public IReadOnlyList Arguments { get; } /// /// The last time the job template was used /// public DateTime UpdateTimeUtc { get; } } /// /// Settings for updating job template user preference /// public class UpdateUserJobTemplateOptions { /// /// The stream the job was run in /// public StreamId StreamId { get; set; } /// /// The template id of the job /// public TemplateId TemplateId { get; set; } /// /// The hash of the template definition /// public string TemplateHash { get; set; } = String.Empty; /// /// The arguments defined when creating the job /// public IReadOnlyList Arguments { get; set; } = new List(); } /// /// User settings document /// public interface IUserSettings { /// /// The user id /// public UserId UserId { get; } /// /// Whether to enable experimental features /// public bool EnableExperimentalFeatures { get; } /// /// Whether to always tag CL descriptions for preflights /// public bool AlwaysTagPreflightCL { get; } /// /// Opaque settings dictionary for the dashboard /// public BsonValue DashboardSettings { get; } /// /// List of pinned jobs /// public IReadOnlyList PinnedJobIds { get; } /// /// List of pinned bisection tasks /// public IReadOnlyList PinnedBisectTaskIds { get; } /// /// List of job template preferences /// public IReadOnlyList? JobTemplateSettings { get; } } /// /// Extension methods /// public static class UserExtensions { /// /// Creates an API response object /// public static GetUserResponse ToApiResponse(this IUser user, IAvatar? avatar, IUserClaims? claims, IUserSettings? settings) { GetUserResponse response = new GetUserResponse(user.Id, user.Name); response.Email = user.Email; response.Image24 = avatar?.Image24; response.Image32 = avatar?.Image32; response.Image48 = avatar?.Image48; response.Image72 = avatar?.Image72; response.Claims = claims?.Claims.Select(x => new GetUserClaimResponse(x.Type, x.Value)).ToList(); if (settings != null) { response.EnableExperimentalFeatures = settings.EnableExperimentalFeatures; response.AlwaysTagPreflightCL = settings.AlwaysTagPreflightCL; response.DashboardSettings = BsonTypeMapper.MapToDotNetValue(settings.DashboardSettings); response.PinnedJobIds = settings.PinnedJobIds.ConvertAll(x => x.ToString()); response.PinnedBisectTaskIds = settings.PinnedBisectTaskIds.ConvertAll(x => x.ToString()); if (settings.JobTemplateSettings != null && settings.JobTemplateSettings.Count > 0) { response.JobTemplateSettings = new List(); for (int i = 0; i < settings.JobTemplateSettings.Count; i++) { response.JobTemplateSettings.Add(settings.JobTemplateSettings[i].ToApiResponse()); } } } return response; } /// /// Creates an API thin user response /// public static GetThinUserInfoResponse ToThinApiResponse(this IUser user) { return new GetThinUserInfoResponse(user.Id, user.Name, user.Email, user.Login); } /// /// Creates an API settings response /// public static GetJobTemplateSettingsResponse ToApiResponse(this IUserJobTemplateSettings settings) { return new GetJobTemplateSettingsResponse(settings.StreamId.ToString(), settings.TemplateId.ToString(), settings.TemplateHash.ToString(), settings.Arguments.ToList(), settings.UpdateTimeUtc); } } }