Skip to content

Commit

Permalink
#10 Исправил регистрацию на LDAP пользователя
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryGhost committed Jun 20, 2020
1 parent b7d3cea commit 0d7f3dd
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 152 deletions.
13 changes: 8 additions & 5 deletions Idone/Idone.DAL/Base/Extensions/DbSetExtension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace Idone.DAL.Base.Extensions
{
using System.Linq;

using Idone.DAL.Dictionaries;
using Idone.DAL.DTO;

using LanguageExt;

Expand Down Expand Up @@ -29,21 +32,21 @@ public static void Clear<T>(this DbSet<T> dbSet)
/// </summary>
/// <typeparam name="T"> Тип сущности. </typeparam>
/// <param name="dbSet"> Репозиторий. </param>
/// <param name="keyValues"> Параметры поиска. </param>
/// <param name="keyValue"> Параметр поиска. </param>
/// <returns> Возвращает монаду Maybe. </returns>
public static Option<T> Find<T>(this DbSet<T> dbSet, params object[] keyValues)
public static Option<T> Find<T>(this DbSet<T> dbSet, IIdentity keyValue)
where T : class
{
var searchResult = dbSet.Find(keyValues);
var searchResult = dbSet.Find(keyValue.Id);
return searchResult != null
? Some(searchResult)
: None;
}

public static Either<Error, T> FindEither<T>(this DbSet<T> dbSet, params object[] keyValues)
public static Either<Error, T> FindEither<T>(this DbSet<T> dbSet, IIdentity keyValue)
where T : class
{
return dbSet.Find<T>(keyValues).ToEither(Error.NotFoundRecord);
return dbSet.Find<T>(keyValue).ToEither(Error.NotFoundRecord);
}
}
}
6 changes: 3 additions & 3 deletions Idone/Idone.DAL/DTO/DtoLinkRolePermissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DtoLinkRolePermissions : Record<DtoLinkRolePermissions>
/// </summary>
/// <param name="roleId"> Идентификатор роли. </param>
/// <param name="permissionIds"> Идентификаторы прав.</param>
public DtoLinkRolePermissions(int roleId, IEnumerable<int> permissionIds)
public DtoLinkRolePermissions(IIdentity roleId, IEnumerable<IIdentity> permissionIds)
{
RoleId = roleId;
PermissionIds = permissionIds;
Expand All @@ -23,11 +23,11 @@ public DtoLinkRolePermissions(int roleId, IEnumerable<int> permissionIds)
/// <summary>
/// Идентификаторы прав.
/// </summary>
public IEnumerable<int> PermissionIds { get; }
public IEnumerable<IIdentity> PermissionIds { get; }

/// <summary>
/// Идентификатор роли.
/// </summary>
public int RoleId { get; }
public IIdentity RoleId { get; }
}
}
2 changes: 1 addition & 1 deletion Idone/Idone.Security/Services/AdService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Idone.Security.Services
/// <summary>
/// Сервис по работе с AD-пользователями.
/// </summary>
public partial class AdService
public class AdService
{
/// <summary>
/// Домен сервиса Active Directory.
Expand Down
29 changes: 13 additions & 16 deletions Idone/Idone.Security/Services/DictValueCase.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
namespace Idone.Security.Services
{
public partial class AdService
internal enum DictValueCase
{
internal enum DictValueCase
{
WrongKey = 0,
WrongKey = 0,

EmptyValue = 1
}
EmptyValue = 1
}

internal class DictValueCases
internal class DictValueCases
{
private DictValueCases(DictValueCase valueCase, string value)
{
private DictValueCases(DictValueCase valueCase, string value)
{
DictValueCase = (valueCase, value);
}
DictValueCase = (valueCase, value);
}

public (DictValueCase, string) DictValueCase { get; }
public (DictValueCase, string) DictValueCase { get; }

public static DictValueCases Create(DictValueCase valueCase, string value)
{
return new DictValueCases(valueCase, value);
}
public static DictValueCases Create(DictValueCase valueCase, string value)
{
return new DictValueCases(valueCase, value);
}
}
}
2 changes: 1 addition & 1 deletion Idone/Idone.Security/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public UserService(AppContext appContext)
public Either<Error, Success> DenyRolePermissions(DtoLinkRolePermissions link)
{
var dbQuery = _appContext.RolePermissions.AsQueryable();
var foundUser = dbQuery.FirstOrDefault(x => x.Id == link.RoleId) ?? Left<Error, RolePermission>(Error.NotFoundRecord);
var foundUser = dbQuery.FirstOrDefault(x => x.Id == link.RoleId.Id) ?? Left<Error, RolePermission>(Error.NotFoundRecord);

var result = foundUser.Bind(rolePermission =>
{
Expand Down
10 changes: 6 additions & 4 deletions Idone/Idone.Tests/Helpers/IdoneApiHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,18 @@ module IdoneApiHelper =
(entity2 : #IIdentity list)
: DtoLinkRolePermissions list =
(entity1, entity2)
||> List.map2 (fun e1 e2 ->
new DtoLinkRolePermissions(e1.Id, [e2.Id] |> List.toSeq))
||> List.map2 (fun e1 e2 ->
new DtoLinkRolePermissions(e1, Seq.ofList [e2 :> IIdentity]))

let toRoleDtos (roles : Role list) : DtoNewRole list =
roles |> List.map (fun role -> new DtoNewRole(role.Name))

let toEitherDefault x = toEither x Error.Exception

let takeFirst (rows : 'a seq) : Either<Error, 'a> =
rows |> Seq.cast<'a> |> Seq.head |> LanguageExt.Prelude.Right<Error, 'a>

let mbFirst = rows |> Seq.cast<'a> |> Seq.tryHead

toEither mbFirst Error.NotFoundRecord

let takeFirstRow (row : DtoGrid<'b>) : Either<Error, 'b> =
row.Rows |> takeFirst

0 comments on commit 0d7f3dd

Please sign in to comment.