1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-07 10:55:43 -05:00

organizations to account profile

This commit is contained in:
Kyle Spearrin
2017-03-02 21:51:03 -05:00
parent 0b87e2c57e
commit b18b6a44ef
4 changed files with 26 additions and 5 deletions

View File

@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Identity;
using Bit.Core.Domains; using Bit.Core.Domains;
using Bit.Core.Enums; using Bit.Core.Enums;
using System.Linq; using System.Linq;
using Bit.Core.Repositories;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {
@ -18,15 +19,18 @@ namespace Bit.Api.Controllers
{ {
private readonly IUserService _userService; private readonly IUserService _userService;
private readonly ICipherService _cipherService; private readonly ICipherService _cipherService;
private readonly IOrganizationRepository _organizationRepository;
private readonly UserManager<User> _userManager; private readonly UserManager<User> _userManager;
public AccountsController( public AccountsController(
IUserService userService, IUserService userService,
ICipherService cipherService, ICipherService cipherService,
IOrganizationRepository organizationRepository,
UserManager<User> userManager) UserManager<User> userManager)
{ {
_userService = userService; _userService = userService;
_cipherService = cipherService; _cipherService = cipherService;
_organizationRepository = organizationRepository;
_userManager = userManager; _userManager = userManager;
} }
@ -155,7 +159,8 @@ namespace Bit.Api.Controllers
public async Task<ProfileResponseModel> GetProfile() public async Task<ProfileResponseModel> GetProfile()
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
var response = new ProfileResponseModel(user); var organizations = await _organizationRepository.GetManyByUserIdAsync(user.Id);
var response = new ProfileResponseModel(user, organizations);
return response; return response;
} }
@ -165,7 +170,7 @@ namespace Bit.Api.Controllers
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
await _userService.SaveUserAsync(model.ToUser(user)); await _userService.SaveUserAsync(model.ToUser(user));
var response = new ProfileResponseModel(user); var response = new ProfileResponseModel(user, null);
return response; return response;
} }

View File

@ -9,7 +9,7 @@ namespace Bit.Api.Models
: base("authToken") : base("authToken")
{ {
Token = token; Token = token;
Profile = user == null ? null : new ProfileResponseModel(user); Profile = user == null ? null : new ProfileResponseModel(user, null);
} }
public string Token { get; set; } public string Token { get; set; }

View File

@ -1,11 +1,13 @@
using System; using System;
using Bit.Core.Domains; using Bit.Core.Domains;
using System.Collections.Generic;
using System.Linq;
namespace Bit.Api.Models namespace Bit.Api.Models
{ {
public class ProfileResponseModel : ResponseModel public class ProfileResponseModel : ResponseModel
{ {
public ProfileResponseModel(User user) public ProfileResponseModel(User user, IEnumerable<Organization> organizations)
: base("profile") : base("profile")
{ {
if(user == null) if(user == null)
@ -19,6 +21,7 @@ namespace Bit.Api.Models
MasterPasswordHint = string.IsNullOrWhiteSpace(user.MasterPasswordHint) ? null : user.MasterPasswordHint; MasterPasswordHint = string.IsNullOrWhiteSpace(user.MasterPasswordHint) ? null : user.MasterPasswordHint;
Culture = user.Culture; Culture = user.Culture;
TwoFactorEnabled = user.TwoFactorEnabled; TwoFactorEnabled = user.TwoFactorEnabled;
Organizations = organizations?.Select(o => new OrganizationResponseModel(o));
} }
public string Id { get; set; } public string Id { get; set; }
@ -27,5 +30,18 @@ namespace Bit.Api.Models
public string MasterPasswordHint { get; set; } public string MasterPasswordHint { get; set; }
public string Culture { get; set; } public string Culture { get; set; }
public bool TwoFactorEnabled { get; set; } public bool TwoFactorEnabled { get; set; }
public IEnumerable<OrganizationResponseModel> Organizations { get; set; }
public class OrganizationResponseModel
{
public OrganizationResponseModel(Organization organization)
{
Id = organization.Id.ToString();
Name = organization.Name;
}
public string Id { get; set; }
public string Name { get; set; }
}
} }
} }

View File

@ -37,7 +37,7 @@ namespace Bit.Core.Repositories.SqlServer
using(var connection = new SqlConnection(ConnectionString)) using(var connection = new SqlConnection(ConnectionString))
{ {
var results = await connection.QueryAsync<Organization>( var results = await connection.QueryAsync<Organization>(
"[dbo].[Organization_ReadUserId]", "[dbo].[Organization_ReadByUserId]",
new { UserId = userId }, new { UserId = userId },
commandType: CommandType.StoredProcedure); commandType: CommandType.StoredProcedure);