public async Task UnlinkUser(UnlinkUserInput input) { var currentUserAccount = await _userLinkManager.GetUserAccountAsync(AbpSession.ToUserIdentifier()); if (!currentUserAccount.UserLinkId.HasValue) { throw new ApplicationException(L("You are not linked to any account")); } if (!await _userLinkManager.AreUsersLinked(AbpSession.ToUserIdentifier(), input.ToUserIdentifier())) { return; } await _userLinkManager.Unlink(input.ToUserIdentifier()); }
public async Task Should_Link_User_To_Different_Tenant_User() { //Arrange LoginAsHostAdmin(); var testTenantId = await CreateTestTenantAndTestUser(); //Act LoginAsDefaultTenantAdmin(); await _userLinkAppService.LinkToUser(new LinkToUserInput { TenancyName = "Test", UsernameOrEmailAddress = "test", Password = "******" }); //Assert var defaultTenantAdmin = await UsingDbContextAsync(context => context.Users.FirstOrDefaultAsync(u => u.TenantId == AbpSession.TenantId && u.Id == AbpSession.UserId)); var defaultTenantAccount = await _userLinkManager.GetUserAccountAsync(defaultTenantAdmin.ToUserIdentifier()); var testUser = await UsingDbContextAsync(testTenantId, context => context.Users.FirstOrDefaultAsync(u => u.UserName == "test")); var testUserAccount = await _userLinkManager.GetUserAccountAsync(testUser.ToUserIdentifier()); defaultTenantAccount.UserLinkId.ShouldBe(testUserAccount.UserLinkId); defaultTenantAccount.UserLinkId.ShouldBe(defaultTenantAccount.Id); }
public async Task <PagedResultDto <LinkedUserDto> > GetLinkedUsers(GetLinkedUsersInput input) { var currentUserAccount = await _userLinkManager.GetUserAccountAsync(AbpSession.ToUserIdentifier()); if (currentUserAccount == null) { return(new PagedResultDto <LinkedUserDto>(0, new List <LinkedUserDto>())); } var query = CreateLinkedUsersQuery(currentUserAccount, input.Sorting); query = query.Skip(input.SkipCount) .Take(input.MaxResultCount); var totalCount = await query.CountAsync(); var linkedUsers = await query.ToListAsync(); return(new PagedResultDto <LinkedUserDto>( totalCount, linkedUsers )); }
public async Task <PagedResultOutput <LinkedUserDto> > GetLinkedUsers(GetLinkedUsersInput input) { var currentUserAccount = await _userLinkManager.GetUserAccountAsync(AbpSession.ToUserIdentifier()); if (currentUserAccount == null) { return(new PagedResultOutput <LinkedUserDto>(0, new List <LinkedUserDto>())); } using (UnitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant)) { var query = CreateLinkedUsersQuery(currentUserAccount, input.Sorting) .Skip(input.SkipCount) .Take(input.MaxResultCount); var totalCount = await query.CountAsync(); var linkedUsers = await query.ToListAsync(); return(new PagedResultOutput <LinkedUserDto>( totalCount, linkedUsers )); } }
public async Task Should_Link_User_To_Different_Tenant_User() { //Arrange LoginAsHostAdmin(); var testTenantId = await CreateTestTenantAndTestUser(); //Act LoginAsDefaultTenantAdmin(); //Assert var defaultTenantAdmin = await UsingDbContextAsync(context => context.Users.FirstOrDefaultAsync(u => u.TenantId == AbpSession.TenantId && u.Id == AbpSession.UserId)); var defaultTenantAccount = await _userLinkManager.GetUserAccountAsync(defaultTenantAdmin.ToUserIdentifier()); var testUser = await UsingDbContextAsync(testTenantId, context => context.Users.FirstOrDefaultAsync(u => u.UserName == "test")); var testUserAccount = await _userLinkManager.GetUserAccountAsync(testUser.ToUserIdentifier()); defaultTenantAccount.UserLinkId.ShouldBe(testUserAccount.UserLinkId); defaultTenantAccount.UserLinkId.ShouldBe(defaultTenantAccount.Id); }