-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[PM-40514] Add UseRiskInsights Org ability check in all Access Intelligence v1 endpoints #8258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lastbestdev
wants to merge
6
commits into
main
Choose a base branch
from
PM-40514/dirt/check-use-risk-insights-ai-v1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+300
β113
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
32859cf
cover access intelligence v1 endpoints with org UseRiskInsights abiliβ¦
lastbestdev 2f1b1a7
update tests
lastbestdev af22d69
remove unused single add critical application endpoint
lastbestdev 3d5249f
Merge branch 'main' into PM-40514/dirt/check-use-risk-insights-ai-v1
lastbestdev b58a4b8
format
lastbestdev 842ee69
Merge branch 'main' into PM-40514/dirt/check-use-risk-insights-ai-v1
lastbestdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| using Bit.Api.Dirt.Models.Response; | ||
| using Bit.Api.Tools.Models.Response; | ||
| using Bit.Core; | ||
| using Bit.Core.AdminConsole.AbilitiesCache; | ||
| using Bit.Core.Context; | ||
| using Bit.Core.Dirt.Entities; | ||
| using Bit.Core.Dirt.Reports.Models.Data; | ||
|
|
@@ -26,6 +27,7 @@ public class ReportsController : Controller | |
| private readonly IGetPasswordHealthReportApplicationQuery _getPwdHealthReportAppQuery; | ||
| private readonly IDropPasswordHealthReportApplicationCommand _dropPwdHealthReportAppCommand; | ||
| private readonly IGetPasskeyDirectoryQuery _getPasskeyDirectoryQuery; | ||
| private readonly IOrganizationAbilityCacheService _organizationAbilityCacheService; | ||
| private readonly ILogger<ReportsController> _logger; | ||
|
|
||
| public ReportsController( | ||
|
|
@@ -36,6 +38,7 @@ public ReportsController( | |
| IGetPasswordHealthReportApplicationQuery getPasswordHealthReportApplicationQuery, | ||
| IDropPasswordHealthReportApplicationCommand dropPwdHealthReportAppCommand, | ||
| IGetPasskeyDirectoryQuery getPasskeyDirectoryQuery, | ||
| IOrganizationAbilityCacheService organizationAbilityCacheService, | ||
| ILogger<ReportsController> logger | ||
| ) | ||
| { | ||
|
|
@@ -46,6 +49,7 @@ ILogger<ReportsController> logger | |
| _getPwdHealthReportAppQuery = getPasswordHealthReportApplicationQuery; | ||
| _dropPwdHealthReportAppCommand = dropPwdHealthReportAppCommand; | ||
| _getPasskeyDirectoryQuery = getPasskeyDirectoryQuery; | ||
| _organizationAbilityCacheService = organizationAbilityCacheService; | ||
| _logger = logger; | ||
| } | ||
|
|
||
|
|
@@ -59,12 +63,7 @@ ILogger<ReportsController> logger | |
| [HttpGet("member-cipher-details/{orgId}")] | ||
| public async Task<IEnumerable<MemberCipherDetailsResponseModel>> GetMemberCipherDetails(Guid orgId) | ||
| { | ||
| // Using the AccessReports permission here until new permissions | ||
| // are needed for more control over reports | ||
| if (!await _currentContext.AccessReports(orgId)) | ||
| { | ||
| throw new NotFoundException(); | ||
| } | ||
| await AuthorizeAsync(orgId); | ||
|
|
||
| var riskDetails = await GetRiskInsightsReportDetails(new RiskInsightsReportRequest { OrganizationId = orgId }); | ||
|
|
||
|
|
@@ -125,39 +124,11 @@ private async Task<IEnumerable<RiskInsightsReportDetail>> GetRiskInsightsReportD | |
| [HttpGet("password-health-report-applications/{orgId}")] | ||
| public async Task<IEnumerable<PasswordHealthReportApplication>> GetPasswordHealthReportApplications(Guid orgId) | ||
| { | ||
| if (!await _currentContext.AccessReports(orgId)) | ||
| { | ||
| throw new NotFoundException(); | ||
| } | ||
| await AuthorizeAsync(orgId); | ||
|
|
||
| return await _getPwdHealthReportAppQuery.GetPasswordHealthReportApplicationAsync(orgId); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds a new record into PasswordHealthReportApplication | ||
| /// </summary> | ||
| /// <param name="request">A single instance of PasswordHealthReportApplication Model</param> | ||
| /// <returns>A single instance of PasswordHealthReportApplication</returns> | ||
| /// <exception cref="BadRequestException">If the organization Id is not valid</exception> | ||
| /// <exception cref="NotFoundException">If the user lacks access</exception> | ||
| [HttpPost("password-health-report-application")] | ||
| public async Task<PasswordHealthReportApplication> AddPasswordHealthReportApplication( | ||
| [FromBody] PasswordHealthReportApplicationModel request) | ||
| { | ||
| if (!await _currentContext.AccessReports(request.OrganizationId)) | ||
| { | ||
| throw new NotFoundException(); | ||
| } | ||
|
|
||
| var commandRequest = new AddPasswordHealthReportApplicationRequest | ||
| { | ||
| OrganizationId = request.OrganizationId, | ||
| Url = request.Url | ||
| }; | ||
|
|
||
| return await _addPwdHealthReportAppCommand.AddPasswordHealthReportApplicationAsync(commandRequest); | ||
| } | ||
|
Comment on lines
-136
to
-159
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this endpoint is removed as it is never called in the |
||
|
|
||
| /// <summary> | ||
| /// Adds multiple records into PasswordHealthReportApplication | ||
| /// </summary> | ||
|
|
@@ -169,9 +140,9 @@ public async Task<PasswordHealthReportApplication> AddPasswordHealthReportApplic | |
| public async Task<IEnumerable<PasswordHealthReportApplication>> AddPasswordHealthReportApplications( | ||
| [FromBody] IEnumerable<PasswordHealthReportApplicationModel> request) | ||
| { | ||
| if (request.Any(_ => _currentContext.AccessReports(_.OrganizationId).Result == false)) | ||
| foreach (var item in request) | ||
| { | ||
| throw new NotFoundException(); | ||
| await AuthorizeAsync(item.OrganizationId); | ||
| } | ||
|
|
||
| var commandRequests = request.Select(request => new AddPasswordHealthReportApplicationRequest | ||
|
|
@@ -197,10 +168,7 @@ public async Task<IEnumerable<PasswordHealthReportApplication>> AddPasswordHealt | |
| public async Task DropPasswordHealthReportApplication( | ||
| [FromBody] DropPasswordHealthReportApplicationRequest request) | ||
| { | ||
| if (!await _currentContext.AccessReports(request.OrganizationId)) | ||
| { | ||
| throw new NotFoundException(); | ||
| } | ||
| await AuthorizeAsync(request.OrganizationId); | ||
|
|
||
| await _dropPwdHealthReportAppCommand.DropPasswordHealthReportApplicationAsync(request); | ||
| } | ||
|
|
@@ -222,4 +190,18 @@ public async Task<IEnumerable<PasskeyDirectoryResponseModel>> GetPasskeyDirector | |
| Instructions = e.Instructions | ||
| }); | ||
| } | ||
|
|
||
| private async Task AuthorizeAsync(Guid organizationId) | ||
| { | ||
| if (!await _currentContext.AccessReports(organizationId)) | ||
| { | ||
| throw new NotFoundException(); | ||
| } | ||
|
|
||
| var orgAbility = await _organizationAbilityCacheService.GetOrganizationAbilityAsync(organizationId); | ||
| if (orgAbility is null || !orgAbility.UseRiskInsights) | ||
| { | ||
| throw new BadRequestException("Your organization's plan does not support this feature."); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: all the same logic here, just moved private methods to the bottom of file to improve order