@@ -27,19 +27,20 @@ namespace Bit.Api.AdminConsole.Controllers;
2727[ Authorize ( "Application" ) ]
2828public class PoliciesController : Controller
2929{
30- private readonly IPolicyRepository _policyRepository ;
31- private readonly IOrganizationUserRepository _organizationUserRepository ;
32- private readonly IUserService _userService ;
3330 private readonly ICurrentContext _currentContext ;
31+ private readonly IFeatureService _featureService ;
3432 private readonly GlobalSettings _globalSettings ;
33+ private readonly IOrganizationHasVerifiedDomainsQuery _organizationHasVerifiedDomainsQuery ;
34+ private readonly IOrganizationRepository _organizationRepository ;
3535 private readonly IDataProtector _organizationServiceDataProtector ;
36+ private readonly IOrganizationUserRepository _organizationUserRepository ;
3637 private readonly IDataProtectorTokenFactory < OrgUserInviteTokenable > _orgUserInviteTokenDataFactory ;
37- private readonly IFeatureService _featureService ;
38- private readonly IOrganizationHasVerifiedDomainsQuery _organizationHasVerifiedDomainsQuery ;
38+ private readonly IPolicyRepository _policyRepository ;
39+ private readonly IUserService _userService ;
40+
3941 private readonly ISavePolicyCommand _savePolicyCommand ;
4042
41- public PoliciesController (
42- IPolicyRepository policyRepository ,
43+ public PoliciesController ( IPolicyRepository policyRepository ,
4344 IOrganizationUserRepository organizationUserRepository ,
4445 IUserService userService ,
4546 ICurrentContext currentContext ,
@@ -48,6 +49,7 @@ public PoliciesController(
4849 IDataProtectorTokenFactory < OrgUserInviteTokenable > orgUserInviteTokenDataFactory ,
4950 IFeatureService featureService ,
5051 IOrganizationHasVerifiedDomainsQuery organizationHasVerifiedDomainsQuery ,
52+ IOrganizationRepository organizationRepository ,
5153 ISavePolicyCommand savePolicyCommand )
5254 {
5355 _policyRepository = policyRepository ;
@@ -57,7 +59,7 @@ public PoliciesController(
5759 _globalSettings = globalSettings ;
5860 _organizationServiceDataProtector = dataProtectionProvider . CreateProtector (
5961 "OrganizationServiceDataProtector" ) ;
60-
62+ _organizationRepository = organizationRepository ;
6163 _orgUserInviteTokenDataFactory = orgUserInviteTokenDataFactory ;
6264 _featureService = featureService ;
6365 _organizationHasVerifiedDomainsQuery = organizationHasVerifiedDomainsQuery ;
@@ -104,6 +106,13 @@ public async Task<ListResponseModel<PolicyResponseModel>> Get(string orgId)
104106 public async Task < ListResponseModel < PolicyResponseModel > > GetByToken ( Guid orgId , [ FromQuery ] string email ,
105107 [ FromQuery ] string token , [ FromQuery ] Guid organizationUserId )
106108 {
109+ var organization = await _organizationRepository . GetByIdAsync ( orgId ) ;
110+
111+ if ( organization is not { UsePolicies : true } )
112+ {
113+ throw new NotFoundException ( ) ;
114+ }
115+
107116 // TODO: PM-4142 - remove old token validation logic once 3 releases of backwards compatibility are complete
108117 var newTokenValid = OrgUserInviteTokenable . ValidateOrgUserInviteStringToken (
109118 _orgUserInviteTokenDataFactory , token , organizationUserId , email ) ;
@@ -158,6 +167,13 @@ public async Task<ListResponseModel<PolicyResponseModel>> GetByInvitedUser(Guid
158167 [ HttpGet ( "master-password" ) ]
159168 public async Task < PolicyResponseModel > GetMasterPasswordPolicy ( Guid orgId )
160169 {
170+ var organization = await _organizationRepository . GetByIdAsync ( orgId ) ;
171+
172+ if ( organization is not { UsePolicies : true } )
173+ {
174+ throw new NotFoundException ( ) ;
175+ }
176+
161177 var userId = _userService . GetProperUserId ( User ) . Value ;
162178
163179 var orgUser = await _organizationUserRepository . GetByOrganizationAsync ( orgId , userId ) ;
0 commit comments