-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[PM-38749] Add endpoint to update SupportsConfirmation and inviteBlob #7999
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| ο»Ώusing System.ComponentModel.DataAnnotations; | ||
| using Bit.Core.AdminConsole.OrganizationFeatures.InviteLinks; | ||
| using Bit.Core.Utilities; | ||
|
|
||
| namespace Bit.Api.AdminConsole.Models.Request.Organizations; | ||
|
|
||
| public class UpdateInviteSupportConfirmRequestModel | ||
| { | ||
| /// <summary> | ||
| /// An opaque cryptographic blob. The server only stores and transports it, so its format is not | ||
| /// validated here. | ||
| /// </summary> | ||
| [Required] | ||
| [EncryptedStringLength(3000)] | ||
| public required string Invite { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Whether this invite link can be used to confirm a user. | ||
| /// </summary> | ||
| [Required] | ||
| public required bool SupportsConfirmation { get; set; } | ||
|
|
||
| public UpdateInviteSupportConfirmRequest ToCommandRequest(Guid organizationId) => new() | ||
| { | ||
| OrganizationId = organizationId, | ||
| Invite = Invite, | ||
| SupportsConfirmation = SupportsConfirmation, | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| ο»Ώusing Bit.Core.AdminConsole.Entities; | ||
| using Bit.Core.AdminConsole.Utilities.v2.Results; | ||
|
|
||
| namespace Bit.Core.AdminConsole.OrganizationFeatures.InviteLinks.Interfaces; | ||
|
|
||
| public interface IUpdateInviteSupportConfirmCommand | ||
| { | ||
| /// <summary> | ||
| /// Updates only the <see cref="OrganizationInviteLink.Invite"/> blob and | ||
| /// <see cref="OrganizationInviteLink.SupportsConfirmation"/> flag for the specified organization's invite link. | ||
| /// </summary> | ||
| /// <param name="request">The details for the invite link update.</param> | ||
| /// <returns>The updated <see cref="OrganizationInviteLink"/>, or an error if the organization does not support | ||
| /// invite links or a link does not exist.</returns> | ||
| Task<CommandResult<OrganizationInviteLink>> UpdateAsync(UpdateInviteSupportConfirmRequest request); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| ο»Ώusing Bit.Core.AdminConsole.AbilitiesCache; | ||
| using Bit.Core.AdminConsole.Entities; | ||
| using Bit.Core.AdminConsole.OrganizationFeatures.InviteLinks.Interfaces; | ||
| using Bit.Core.AdminConsole.Repositories; | ||
| using Bit.Core.AdminConsole.Utilities.v2.Results; | ||
|
|
||
| namespace Bit.Core.AdminConsole.OrganizationFeatures.InviteLinks; | ||
|
|
||
| public class UpdateInviteSupportConfirmCommand( | ||
| IOrganizationInviteLinkRepository organizationInviteLinkRepository, | ||
| IOrganizationAbilityCacheService organizationAbilityCacheService, | ||
| TimeProvider timeProvider) | ||
| : IUpdateInviteSupportConfirmCommand | ||
| { | ||
| public async Task<CommandResult<OrganizationInviteLink>> UpdateAsync( | ||
| UpdateInviteSupportConfirmRequest request) | ||
| { | ||
| if (!await OrganizationHasInviteLinksAbilityAsync(request.OrganizationId)) | ||
| { | ||
| return new InviteLinkNotAvailable(); | ||
| } | ||
|
|
||
| var inviteLink = await organizationInviteLinkRepository.GetByOrganizationIdAsync(request.OrganizationId); | ||
| if (inviteLink is null) | ||
| { | ||
| return new InviteLinkNotFound(); | ||
| } | ||
|
|
||
| inviteLink.Invite = request.Invite; | ||
| inviteLink.SupportsConfirmation = request.SupportsConfirmation; | ||
| inviteLink.RevisionDate = timeProvider.GetUtcNow().UtcDateTime; | ||
|
|
||
| await organizationInviteLinkRepository.ReplaceAsync(inviteLink); | ||
|
|
||
| return inviteLink; | ||
| } | ||
|
|
||
| private async Task<bool> OrganizationHasInviteLinksAbilityAsync(Guid organizationId) | ||
| { | ||
| var ability = await organizationAbilityCacheService.GetOrganizationAbilityAsync(organizationId); | ||
|
Comment on lines
+21
to
+40
Contributor
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. β QUESTION: This mutating command does not log an organization audit event, unlike every sibling invite-link command. Details
Is the missing audit event intentional (e.g., deferred to a follow-up, or intentionally out of scope), or should a new |
||
| return ability is not null && ability.UseInviteLinks; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| ο»Ώnamespace Bit.Core.AdminConsole.OrganizationFeatures.InviteLinks; | ||
|
|
||
| public record UpdateInviteSupportConfirmRequest | ||
| { | ||
| public required Guid OrganizationId { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// The invite link cryptographic blob. | ||
| /// </summary> | ||
| public required string Invite { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Whether this invite link can be used to confirm a user. | ||
| /// </summary> | ||
| public required bool SupportsConfirmation { get; init; } | ||
| } |
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.
I don't feel strongly about this route name. We have an endpoint with the base route that only updates the domain name, so we need to name this one something different. I'm happy to hear any suggestions.