Skip to content

Commit

Permalink
Merge branch 'main' into ac/pm-12490/create-organization-enable-command
Browse files Browse the repository at this point in the history
  • Loading branch information
r-tome committed Jan 29, 2025
2 parents 56d8794 + f1c94a1 commit 9a35fca
Show file tree
Hide file tree
Showing 23 changed files with 135 additions and 19 deletions.
23 changes: 19 additions & 4 deletions src/Api/AdminConsole/Controllers/OrganizationUsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,8 @@ public async Task Accept(Guid orgId, Guid organizationUserId, [FromBody] Organiz
throw new UnauthorizedAccessException();
}

var masterPasswordPolicy = await _policyRepository.GetByOrganizationIdTypeAsync(orgId, PolicyType.ResetPassword);
var useMasterPasswordPolicy = masterPasswordPolicy != null &&
masterPasswordPolicy.Enabled &&
masterPasswordPolicy.GetDataModel<ResetPasswordDataModel>().AutoEnrollEnabled;
var useMasterPasswordPolicy = await ShouldHandleResetPasswordAsync(orgId);

if (useMasterPasswordPolicy && string.IsNullOrWhiteSpace(model.ResetPasswordKey))
{
throw new BadRequestException(string.Empty, "Master Password reset is required, but not provided.");
Expand All @@ -328,6 +326,23 @@ public async Task Accept(Guid orgId, Guid organizationUserId, [FromBody] Organiz
}
}

private async Task<bool> ShouldHandleResetPasswordAsync(Guid orgId)
{
var organizationAbility = await _applicationCacheService.GetOrganizationAbilityAsync(orgId);

if (organizationAbility is not { UsePolicies: true })
{
return false;
}

var masterPasswordPolicy = await _policyRepository.GetByOrganizationIdTypeAsync(orgId, PolicyType.ResetPassword);
var useMasterPasswordPolicy = masterPasswordPolicy != null &&
masterPasswordPolicy.Enabled &&
masterPasswordPolicy.GetDataModel<ResetPasswordDataModel>().AutoEnrollEnabled;

return useMasterPasswordPolicy;
}

[HttpPost("{id}/confirm")]
public async Task Confirm(string orgId, string id, [FromBody] OrganizationUserConfirmRequestModel model)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public OrganizationResponseModel(Organization organization, string obj = "organi
MaxAutoscaleSmServiceAccounts = organization.MaxAutoscaleSmServiceAccounts;
LimitCollectionCreation = organization.LimitCollectionCreation;
LimitCollectionDeletion = organization.LimitCollectionDeletion;
LimitItemDeletion = organization.LimitItemDeletion;
AllowAdminAccessToAllCollectionItems = organization.AllowAdminAccessToAllCollectionItems;
UseRiskInsights = organization.UseRiskInsights;
}
Expand Down Expand Up @@ -102,6 +103,7 @@ public OrganizationResponseModel(Organization organization, string obj = "organi
public int? MaxAutoscaleSmServiceAccounts { get; set; }
public bool LimitCollectionCreation { get; set; }
public bool LimitCollectionDeletion { get; set; }
public bool LimitItemDeletion { get; set; }
public bool AllowAdminAccessToAllCollectionItems { get; set; }
public bool UseRiskInsights { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public ProfileOrganizationResponseModel(
AccessSecretsManager = organization.AccessSecretsManager;
LimitCollectionCreation = organization.LimitCollectionCreation;
LimitCollectionDeletion = organization.LimitCollectionDeletion;
LimitItemDeletion = organization.LimitItemDeletion;
AllowAdminAccessToAllCollectionItems = organization.AllowAdminAccessToAllCollectionItems;
UserIsManagedByOrganization = organizationIdsManagingUser.Contains(organization.OrganizationId);
UseRiskInsights = organization.UseRiskInsights;
Expand Down Expand Up @@ -128,6 +129,7 @@ public ProfileOrganizationResponseModel(
public bool AccessSecretsManager { get; set; }
public bool LimitCollectionCreation { get; set; }
public bool LimitCollectionDeletion { get; set; }
public bool LimitItemDeletion { get; set; }
public bool AllowAdminAccessToAllCollectionItems { get; set; }
/// <summary>
/// Indicates if the organization manages the user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public ProfileProviderOrganizationResponseModel(ProviderUserOrganizationDetails
ProductTierType = StaticStore.GetPlan(organization.PlanType).ProductTier;
LimitCollectionCreation = organization.LimitCollectionCreation;
LimitCollectionDeletion = organization.LimitCollectionDeletion;
LimitItemDeletion = organization.LimitItemDeletion;
AllowAdminAccessToAllCollectionItems = organization.AllowAdminAccessToAllCollectionItems;
UseRiskInsights = organization.UseRiskInsights;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ public class OrganizationCollectionManagementUpdateRequestModel
{
public bool LimitCollectionCreation { get; set; }
public bool LimitCollectionDeletion { get; set; }
public bool LimitItemDeletion { get; set; }
public bool AllowAdminAccessToAllCollectionItems { get; set; }

public virtual Organization ToOrganization(Organization existingOrganization, IFeatureService featureService)
{
existingOrganization.LimitCollectionCreation = LimitCollectionCreation;
existingOrganization.LimitCollectionDeletion = LimitCollectionDeletion;
existingOrganization.LimitItemDeletion = LimitItemDeletion;
existingOrganization.AllowAdminAccessToAllCollectionItems = AllowAdminAccessToAllCollectionItems;
return existingOrganization;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Vault/Controllers/CiphersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ await _cipherService.CreateAttachmentShareAsync(cipher, stream, fileName, key,

[HttpDelete("{id}/attachment/{attachmentId}")]
[HttpPost("{id}/attachment/{attachmentId}/delete")]
public async Task DeleteAttachment(Guid id, string attachmentId)
public async Task<DeleteAttachmentResponseData> DeleteAttachment(Guid id, string attachmentId)
{
var userId = _userService.GetProperUserId(User).Value;
var cipher = await GetByIdAsync(id, userId);
Expand All @@ -1106,7 +1106,7 @@ public async Task DeleteAttachment(Guid id, string attachmentId)
throw new NotFoundException();
}

await _cipherService.DeleteAttachmentAsync(cipher, attachmentId, userId, false);
return await _cipherService.DeleteAttachmentAsync(cipher, attachmentId, userId, false);
}

[HttpDelete("{id}/attachment/{attachmentId}/admin")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public OrganizationAbility(Organization organization)
UsePolicies = organization.UsePolicies;
LimitCollectionCreation = organization.LimitCollectionCreation;
LimitCollectionDeletion = organization.LimitCollectionDeletion;
LimitItemDeletion = organization.LimitItemDeletion;
AllowAdminAccessToAllCollectionItems = organization.AllowAdminAccessToAllCollectionItems;
UseRiskInsights = organization.UseRiskInsights;
}
Expand All @@ -41,6 +42,7 @@ public OrganizationAbility(Organization organization)
public bool UsePolicies { get; set; }
public bool LimitCollectionCreation { get; set; }
public bool LimitCollectionDeletion { get; set; }
public bool LimitItemDeletion { get; set; }
public bool AllowAdminAccessToAllCollectionItems { get; set; }
public bool UseRiskInsights { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class OrganizationUserOrganizationDetails
public int? SmServiceAccounts { get; set; }
public bool LimitCollectionCreation { get; set; }
public bool LimitCollectionDeletion { get; set; }
public bool LimitItemDeletion { get; set; }
public bool AllowAdminAccessToAllCollectionItems { get; set; }
public bool UseRiskInsights { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public Organization ToOrganization()
OwnersNotifiedOfAutoscaling = OwnersNotifiedOfAutoscaling,
LimitCollectionCreation = LimitCollectionCreation,
LimitCollectionDeletion = LimitCollectionDeletion,
LimitItemDeletion = LimitItemDeletion,
AllowAdminAccessToAllCollectionItems = AllowAdminAccessToAllCollectionItems,
Status = Status
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class ProviderUserOrganizationDetails
public PlanType PlanType { get; set; }
public bool LimitCollectionCreation { get; set; }
public bool LimitCollectionDeletion { get; set; }
public bool LimitItemDeletion { get; set; }
public bool AllowAdminAccessToAllCollectionItems { get; set; }
public bool UseRiskInsights { get; set; }
public ProviderType ProviderType { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions src/Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ public static class FeatureFlagKeys
public const string EnablePasswordManagerSyncAndroid = "enable-password-manager-sync-android";
public const string EnablePasswordManagerSynciOS = "enable-password-manager-sync-ios";
public const string AccountDeprovisioningBanner = "pm-17120-account-deprovisioning-admin-console-banner";
public const string SingleTapPasskeyCreation = "single-tap-passkey-creation";
public const string SingleTapPasskeyAuthentication = "single-tap-passkey-authentication";
public const string EnableRiskInsightsNotifications = "enable-risk-insights-notifications";

public static List<string> GetAllKeys()
{
Expand Down
1 change: 1 addition & 0 deletions src/Core/Models/PushNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ public class OrganizationCollectionManagementPushNotification
public Guid OrganizationId { get; init; }
public bool LimitCollectionCreation { get; init; }
public bool LimitCollectionDeletion { get; init; }
public bool LimitItemDeletion { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ await SendPayloadToOrganizationAsync(
{
OrganizationId = organization.Id,
LimitCollectionCreation = organization.LimitCollectionCreation,
LimitCollectionDeletion = organization.LimitCollectionDeletion
LimitCollectionDeletion = organization.LimitCollectionDeletion,
LimitItemDeletion = organization.LimitItemDeletion
},
false
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ await SendMessageAsync(PushType.SyncOrganizationCollectionSettingChanged,
{
OrganizationId = organization.Id,
LimitCollectionCreation = organization.LimitCollectionCreation,
LimitCollectionDeletion = organization.LimitCollectionDeletion
LimitCollectionDeletion = organization.LimitCollectionDeletion,
LimitItemDeletion = organization.LimitItemDeletion
}, false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ await SendMessageAsync(PushType.SyncOrganizationCollectionSettingChanged,
{
OrganizationId = organization.Id,
LimitCollectionCreation = organization.LimitCollectionCreation,
LimitCollectionDeletion = organization.LimitCollectionDeletion
LimitCollectionDeletion = organization.LimitCollectionDeletion,
LimitItemDeletion = organization.LimitItemDeletion
}, false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ await SendPayloadToOrganizationAsync(
{
OrganizationId = organization.Id,
LimitCollectionCreation = organization.LimitCollectionCreation,
LimitCollectionDeletion = organization.LimitCollectionDeletion
LimitCollectionDeletion = organization.LimitCollectionDeletion,
LimitItemDeletion = organization.LimitItemDeletion
},
false
);
Expand Down
13 changes: 13 additions & 0 deletions src/Core/Vault/Models/Data/DeleteAttachmentReponseData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Bit.Core.Vault.Entities;

namespace Bit.Core.Vault.Models.Data;

public class DeleteAttachmentResponseData
{
public Cipher Cipher { get; set; }

public DeleteAttachmentResponseData(Cipher cipher)
{
Cipher = cipher;
}
}
2 changes: 1 addition & 1 deletion src/Core/Vault/Services/ICipherService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Task CreateAttachmentShareAsync(Cipher cipher, Stream stream, string fileName, s
string attachmentId, Guid organizationShareId);
Task DeleteAsync(Cipher cipher, Guid deletingUserId, bool orgAdmin = false);
Task DeleteManyAsync(IEnumerable<Guid> cipherIds, Guid deletingUserId, Guid? organizationId = null, bool orgAdmin = false);
Task DeleteAttachmentAsync(Cipher cipher, string attachmentId, Guid deletingUserId, bool orgAdmin = false);
Task<DeleteAttachmentResponseData> DeleteAttachmentAsync(Cipher cipher, string attachmentId, Guid deletingUserId, bool orgAdmin = false);
Task PurgeAsync(Guid organizationId);
Task MoveManyAsync(IEnumerable<Guid> cipherIds, Guid? destinationFolderId, Guid movingUserId);
Task SaveFolderAsync(Folder folder);
Expand Down
23 changes: 19 additions & 4 deletions src/Core/Vault/Services/Implementations/CipherService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ await _cipherRepository.UpdateAttachmentAsync(new CipherAttachment
AttachmentData = JsonSerializer.Serialize(data)
});
cipher.AddAttachment(attachmentId, data);

// Update the revision date when an attachment is added
cipher.RevisionDate = DateTime.UtcNow;
await _cipherRepository.ReplaceAsync((CipherDetails)cipher);

await _pushService.PushSyncCipherUpdateAsync(cipher, null);

return (attachmentId, uploadUrl);
Expand Down Expand Up @@ -259,6 +264,10 @@ public async Task CreateAttachmentAsync(Cipher cipher, Stream stream, string fil
throw;
}

// Update the revision date when an attachment is added
cipher.RevisionDate = DateTime.UtcNow;
await _cipherRepository.ReplaceAsync((CipherDetails)cipher);

// push
await _pushService.PushSyncCipherUpdateAsync(cipher, null);
}
Expand Down Expand Up @@ -441,7 +450,7 @@ public async Task DeleteManyAsync(IEnumerable<Guid> cipherIds, Guid deletingUser
await _pushService.PushSyncCiphersAsync(deletingUserId);
}

public async Task DeleteAttachmentAsync(Cipher cipher, string attachmentId, Guid deletingUserId,
public async Task<DeleteAttachmentResponseData> DeleteAttachmentAsync(Cipher cipher, string attachmentId, Guid deletingUserId,
bool orgAdmin = false)
{
if (!orgAdmin && !(await UserCanEditAsync(cipher, deletingUserId)))
Expand All @@ -454,7 +463,7 @@ public async Task DeleteAttachmentAsync(Cipher cipher, string attachmentId, Guid
throw new NotFoundException();
}

await DeleteAttachmentAsync(cipher, cipher.GetAttachments()[attachmentId]);
return await DeleteAttachmentAsync(cipher, cipher.GetAttachments()[attachmentId]);
}

public async Task PurgeAsync(Guid organizationId)
Expand Down Expand Up @@ -834,20 +843,26 @@ private void ValidateCipherLastKnownRevisionDateAsync(Cipher cipher, DateTime? l
}
}

private async Task DeleteAttachmentAsync(Cipher cipher, CipherAttachment.MetaData attachmentData)
private async Task<DeleteAttachmentResponseData> DeleteAttachmentAsync(Cipher cipher, CipherAttachment.MetaData attachmentData)
{
if (attachmentData == null || string.IsNullOrWhiteSpace(attachmentData.AttachmentId))
{
return;
return null;
}

await _cipherRepository.DeleteAttachmentAsync(cipher.Id, attachmentData.AttachmentId);
cipher.DeleteAttachment(attachmentData.AttachmentId);
await _attachmentStorageService.DeleteAttachmentAsync(cipher.Id, attachmentData);
await _eventService.LogCipherEventAsync(cipher, Bit.Core.Enums.EventType.Cipher_AttachmentDeleted);

// Update the revision date when an attachment is deleted
cipher.RevisionDate = DateTime.UtcNow;
await _cipherRepository.ReplaceAsync((CipherDetails)cipher);

// push
await _pushService.PushSyncCipherUpdateAsync(cipher, null);

return new DeleteAttachmentResponseData(cipher);
}

private async Task ValidateCipherEditForAttachmentAsync(Cipher cipher, Guid savingUserId, bool orgAdmin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public async Task<ICollection<OrganizationAbility>> GetManyAbilitiesAsync()
UsePolicies = e.UsePolicies,
LimitCollectionCreation = e.LimitCollectionCreation,
LimitCollectionDeletion = e.LimitCollectionDeletion,
LimitItemDeletion = e.LimitItemDeletion,
AllowAdminAccessToAllCollectionItems = e.AllowAdminAccessToAllCollectionItems,
UseRiskInsights = e.UseRiskInsights
}).ToListAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ from os in os_g.DefaultIfEmpty()
SmServiceAccounts = o.SmServiceAccounts,
LimitCollectionCreation = o.LimitCollectionCreation,
LimitCollectionDeletion = o.LimitCollectionDeletion,
LimitItemDeletion = o.LimitItemDeletion,
AllowAdminAccessToAllCollectionItems = o.AllowAdminAccessToAllCollectionItems,
UseRiskInsights = o.UseRiskInsights,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ join p in dbContext.Providers on pu.ProviderId equals p.Id
PlanType = x.o.PlanType,
LimitCollectionCreation = x.o.LimitCollectionCreation,
LimitCollectionDeletion = x.o.LimitCollectionDeletion,
LimitItemDeletion = x.o.LimitItemDeletion,
AllowAdminAccessToAllCollectionItems = x.o.AllowAdminAccessToAllCollectionItems,
UseRiskInsights = x.o.UseRiskInsights,
ProviderType = x.p.Type
Expand Down
Loading

0 comments on commit 9a35fca

Please sign in to comment.