diff --git a/src/Database/Database.csproj b/src/Database/Database.csproj index 490cb576a7c6e5fa3f243c6f75bd477a9f01c8fe..01e3f96900b9612eb1a8ff73bec44928920d9f74 100644 --- a/src/Database/Database.csproj +++ b/src/Database/Database.csproj @@ -84,6 +84,7 @@ <Compile Include="ReturnObjects\ActivatedFeatureObject.cs" /> <Compile Include="Models\LogModel.cs" /> <Compile Include="ReturnObjects\DisciplineObject.cs" /> + <Compile Include="ReturnObjects\ExternalAuthenticatorsObject.cs" /> <Compile Include="ReturnObjects\FeatureObject.cs" /> <Compile Include="ReturnObjects\GitlabResourceTypeObject.cs" /> <Compile Include="ReturnObjects\IReturnObject.cs" /> diff --git a/src/Database/Models/UserModel.cs b/src/Database/Models/UserModel.cs index c77f15041693a5c895412ea1827aabea5d20d36a..7976069f7466a10264ee32e848b208e8ddc1e239 100644 --- a/src/Database/Models/UserModel.cs +++ b/src/Database/Models/UserModel.cs @@ -41,6 +41,15 @@ namespace Coscine.Database.Models disciplines = user.UserDisciplinesUserIdIds.Select((discipline) => new DisciplineObject(discipline.Discipline.Id, discipline.Discipline.Url, discipline.Discipline.DisplayNameDe, discipline.Discipline.DisplayNameEn)); } + var externalAuthenticatorModel = new ExternalAuthenticatorModel(); + var externalAuthenticators = externalAuthenticatorModel.GetAllWhere( + (externalAuthenticator) => + (from relation in externalAuthenticator.ExternalIdsResourceTypeIdIds + where relation.UserId == user.Id select relation).Any()) + .Select((externalAuthenticator) => + new ExternalAuthenticatorsObject( + externalAuthenticator.Id, externalAuthenticator.DisplayName)); + if (user.Title == null && user.TitleId.HasValue) { TitleModel titleModel = new TitleModel(); @@ -65,7 +74,8 @@ namespace Coscine.Database.Models user.Organization, user.Institute, disciplines, - false); + false, + externalAuthenticators); } public int UpdateByObject(User user, UserObject userObject) diff --git a/src/Database/ReturnObjects/ExternalAuthenticatorsObject.cs b/src/Database/ReturnObjects/ExternalAuthenticatorsObject.cs new file mode 100644 index 0000000000000000000000000000000000000000..85fdab685116364ebb4dc8abbcca583f471ac2d1 --- /dev/null +++ b/src/Database/ReturnObjects/ExternalAuthenticatorsObject.cs @@ -0,0 +1,18 @@ +using System; + +namespace Coscine.Database.ReturnObjects +{ + [Serializable] + public class ExternalAuthenticatorsObject : IReturnObject + { + public Guid Id { get; set; } + + public string DisplayName { get; set; } + + public ExternalAuthenticatorsObject(Guid id, string displayName) + { + Id = id; + DisplayName = displayName; + } + } +} \ No newline at end of file diff --git a/src/Database/ReturnObjects/UserObject.cs b/src/Database/ReturnObjects/UserObject.cs index f6340e6c902d68d2879ca69f9f44be5772891b65..959285634286b12f6297d863921085473b5e0a1a 100644 --- a/src/Database/ReturnObjects/UserObject.cs +++ b/src/Database/ReturnObjects/UserObject.cs @@ -30,7 +30,9 @@ namespace Coscine.Database.ReturnObjects public bool IsRegistered { get; set; } - public UserObject(Guid id, string displayName, string givenname, string surname, string emailAddress, bool hasProjectRole = false, TitleObject title = null, LanguageObject language = null, string organization = "", string institute = "", IEnumerable<DisciplineObject> disciplines = null, bool isRegistered = false) + public IEnumerable<ExternalAuthenticatorsObject> ExternalAuthenticators { get; set; } + + public UserObject(Guid id, string displayName, string givenname, string surname, string emailAddress, bool hasProjectRole = false, TitleObject title = null, LanguageObject language = null, string organization = "", string institute = "", IEnumerable<DisciplineObject> disciplines = null, bool isRegistered = false, IEnumerable<ExternalAuthenticatorsObject> externalAuthenticators = null) { Id = id; DisplayName = displayName; @@ -46,6 +48,8 @@ namespace Coscine.Database.ReturnObjects HasProjectRole = hasProjectRole; IsRegistered = isRegistered; + + ExternalAuthenticators = externalAuthenticators; } } }