mirror of
https://github.com/bitwarden/server.git
synced 2025-07-04 01:22:50 -05:00
org context checks in org apis. remove depr. code
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Core
|
||||
{
|
||||
@ -10,5 +10,26 @@ namespace Bit.Core
|
||||
{
|
||||
public virtual User User { get; set; }
|
||||
public virtual string DeviceIdentifier { get; set; }
|
||||
public virtual List<CurrentContentOrganization> Organizations { get; set; } = new List<CurrentContentOrganization>();
|
||||
|
||||
public bool OrganizationUser(Guid orgId)
|
||||
{
|
||||
return Organizations.Any(o => o.Id == orgId);
|
||||
}
|
||||
public bool OrganizationAdmin(Guid orgId)
|
||||
{
|
||||
return Organizations.Any(o => o.Id == orgId &&
|
||||
(o.Type == OrganizationUserType.Owner || o.Type == OrganizationUserType.Admin));
|
||||
}
|
||||
public bool OrganizationOwner(Guid orgId)
|
||||
{
|
||||
return Organizations.Any(o => o.Id == orgId && o.Type == OrganizationUserType.Owner);
|
||||
}
|
||||
|
||||
public class CurrentContentOrganization
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public OrganizationUserType Type { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,24 +24,8 @@ namespace Bit.Core.Models.Api
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Plan { get; set; }
|
||||
public Core.Enums.PlanType PlanType { get; set; }
|
||||
public Enums.PlanType PlanType { get; set; }
|
||||
public bool PlanTrial { get; set; }
|
||||
public short MaxUsers { get; set; }
|
||||
}
|
||||
|
||||
public class OrganizationExtendedResponseModel : OrganizationResponseModel
|
||||
{
|
||||
public OrganizationExtendedResponseModel(Organization organization, OrganizationUser organizationUser)
|
||||
: base(organization, "organizationExtended")
|
||||
{
|
||||
if(organizationUser == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(organizationUser));
|
||||
}
|
||||
|
||||
Key = organizationUser.Key;
|
||||
}
|
||||
|
||||
public string Key { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ namespace Bit.Core.Repositories
|
||||
{
|
||||
public interface IOrganizationRepository : IRepository<Organization, Guid>
|
||||
{
|
||||
Task<Organization> GetByIdAsync(Guid id, Guid userId);
|
||||
Task<ICollection<Organization>> GetManyByUserIdAsync(Guid userId);
|
||||
}
|
||||
}
|
||||
|
@ -19,19 +19,6 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
: base(connectionString)
|
||||
{ }
|
||||
|
||||
public async Task<Organization> GetByIdAsync(Guid id, Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Organization>(
|
||||
"[dbo].[Organization_ReadByIdUserId]",
|
||||
new { Id = id, UserId = userId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<Organization>> GetManyByUserIdAsync(Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
|
Reference in New Issue
Block a user