Skip to content

Commit

Permalink
Merge pull request #16 from OpenMAVN/15-update-permission-level
Browse files Browse the repository at this point in the history
15 update permission level
  • Loading branch information
vitaliidasaev committed Apr 28, 2020
2 parents 0112196 + d83a5c2 commit b6d4deb
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum AdminManagementError
None = 0,
LoginNotFound,
PasswordMismatch,
AdminEmailIsNotVerified,
RegisteredWithAnotherPassword,
AlreadyRegistered,
InvalidEmailOrPasswordFormat,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MAVN.Service.AdminManagement.Client.Models.Enums
namespace MAVN.Service.AdminManagement.Client.Models.Enums
{
/// <summary>
/// Level of permission. Edit includes View.
Expand All @@ -12,6 +12,10 @@ public enum AdminPermissionLevel
/// <summary>
/// Editing rights.
/// </summary>
Edit
Edit,
/// <summary>
/// Partner rights.
/// </summary>
PartnerEdit
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace MAVN.Service.AdminManagement.Domain.Enums
namespace MAVN.Service.AdminManagement.Domain.Enums
{
public enum PermissionLevel
{
View,
Edit
Edit,
PartnerEdit
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
namespace MAVN.Service.AdminManagement.Domain.Enums
namespace MAVN.Service.AdminManagement.Domain.Enums
{
public enum ServicesError
{
None = 0,

LoginNotFound,

AdminEmailIsNotVerified,

PasswordMismatch,

RegisteredWithAnotherPassword,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net;
using System.Threading.Tasks;
using Common;
Expand Down Expand Up @@ -41,6 +41,11 @@ public async Task<AuthResultModel> AuthAsync(string login, string password)

if (admin.Error == AdminUserErrorCodes.None)
{
if (!admin.Profile.IsEmailVerified)
{
return new AuthResultModel { Error = ServicesError.AdminEmailIsNotVerified };
}

if (admin.Profile.IsActive == false)
{
return new AuthResultModel {Error = ServicesError.AdminNotActive};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net;
using System.Threading.Tasks;
using Lykke.Common.Api.Contract.Responses;
Expand Down Expand Up @@ -28,14 +28,7 @@ public async Task UserTriesToLogIn_WithMissingLogin_LoginNotFoundErrorReturned()
var adminUsersService = new Mock<IAdminUserService>();

var response = new AdminCredentialsValidationResponse { Error = CredentialsError.LoginNotFound };
var adminUsersServiceResponse = new AdminUserResult
{
Error = AdminUserErrorCodes.None,
Profile = new AdminUser
{
IsActive = true
}
};
var adminUsersServiceResponse = GetAdminUserResult();

credentialsClient
.Setup(x => x.Admins.ValidateAsync(It.IsAny<CredentialsValidationRequest>()))
Expand Down Expand Up @@ -70,14 +63,7 @@ public async Task UserTriesToLogIn_WithWrongPassword_PasswordMismatchErrorReturn
var adminUsersService = new Mock<IAdminUserService>();

var response = new AdminCredentialsValidationResponse { Error = CredentialsError.PasswordMismatch };
var adminUsersServiceResponse = new AdminUserResult
{
Error = AdminUserErrorCodes.None,
Profile = new AdminUser
{
IsActive = true
}
};
var adminUsersServiceResponse = GetAdminUserResult();

credentialsClient
.Setup(x => x.Admins.ValidateAsync(It.IsAny<CredentialsValidationRequest>()))
Expand Down Expand Up @@ -112,14 +98,7 @@ public async Task UserTriesToLogIn_WithInvalidFormatEmail_InvalidEmailOrPassword
var adminUsersService = new Mock<IAdminUserService>();

var exception = new ClientApiException(HttpStatusCode.BadRequest, new ErrorResponse());
var adminUsersServiceResponse = new AdminUserResult
{
Error = AdminUserErrorCodes.None,
Profile = new AdminUser
{
IsActive = true
}
};
var adminUsersServiceResponse = GetAdminUserResult();

credentialsClient
.Setup(x => x.Admins.ValidateAsync(It.IsAny<CredentialsValidationRequest>()))
Expand Down Expand Up @@ -154,14 +133,7 @@ public async Task UserTriesToLogIn_UnexpectedErrorInValidation_InvalidOperationI
var adminUsersService = new Mock<IAdminUserService>();

var response = new AdminCredentialsValidationResponse { Error = CredentialsError.LoginAlreadyExists };
var adminUsersServiceResponse = new AdminUserResult
{
Error = AdminUserErrorCodes.None,
Profile = new AdminUser
{
IsActive = true
}
};
var adminUsersServiceResponse = GetAdminUserResult();

credentialsClient
.Setup(x => x.Admins.ValidateAsync(It.IsAny<CredentialsValidationRequest>()))
Expand Down Expand Up @@ -192,14 +164,7 @@ public async Task UserTriesToLogIn_WithValidCredentials_SuccessfullyAuthenticate
var adminUsersService = new Mock<IAdminUserService>();

var credentialsResponse = new AdminCredentialsValidationResponse { AdminId = "1" };
var adminUsersServiceResponse = new AdminUserResult
{
Error = AdminUserErrorCodes.None,
Profile = new AdminUser
{
IsActive = true
}
};
var adminUsersServiceResponse = GetAdminUserResult();

credentialsClient
.Setup(x => x.Admins.ValidateAsync(It.IsAny<CredentialsValidationRequest>()))
Expand Down Expand Up @@ -231,5 +196,18 @@ public async Task UserTriesToLogIn_WithValidCredentials_SuccessfullyAuthenticate
Assert.Equal(sessionResponse.SessionToken, result.Token);
Assert.Equal(ServicesError.None, result.Error);
}

private AdminUserResult GetAdminUserResult()
{
return new AdminUserResult
{
Error = AdminUserErrorCodes.None,
Profile = new AdminUser
{
IsEmailVerified = true,
IsActive = true
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand All @@ -13,7 +13,8 @@ public class PermissionsListTest
private readonly HashSet<string> _expectedPermissionLevels = new HashSet<string>
{
nameof(PermissionLevel.View),
nameof(PermissionLevel.Edit)
nameof(PermissionLevel.Edit),
nameof(PermissionLevel.PartnerEdit)
};

/// <summary>
Expand Down Expand Up @@ -44,4 +45,4 @@ public void PermissionLevels_WasNotModifiedAccidentally()
}
}
}
}
}

0 comments on commit b6d4deb

Please sign in to comment.