1
0
mirror of https://github.com/bitwarden/server synced 2026-02-26 17:33:40 +00:00

[PM-32131] Add UseMyItems organization ability (#7014)

Purpose: UseMyItems is a new organization ability / plan flag
which is automatically enabled where UsePolicies is enabled,
but can be selectively disabled to disable My Items creation
when the Organization Data Ownership policy is turned on.

- new organization table column with all sprocs and views updated
- data migration to enable the feature for all organizations that already use policies (replicating existing behaviour)
- data and api models updated
- added to organization license file so it can be preserved in self-hosted instances
- note that we don't have a plan feature defined for this yet, so it is set based on UsePolicies to match the migration logic. Billing Team have a ticket to add this
This commit is contained in:
Thomas Rittson
2026-02-25 12:52:28 +10:00
committed by GitHub
parent 8f54ac306c
commit e3c392badb
54 changed files with 22386 additions and 21 deletions

View File

@@ -247,6 +247,12 @@ public class OrganizationsController : Controller
[SelfHosted(NotSelfHostedOnly = true)]
public async Task<IActionResult> Edit(Guid id, OrganizationEditModel model)
{
if (!ModelState.IsValid)
{
TempData["Error"] = ModelState.GetErrorMessage();
return RedirectToAction("Edit", new { id });
}
var organization = await _organizationRepository.GetByIdAsync(id);
if (organization == null)
@@ -564,6 +570,7 @@ public class OrganizationsController : Controller
organization.UseAutomaticUserConfirmation = model.UseAutomaticUserConfirmation;
organization.UseDisableSmAdsForUsers = model.UseDisableSmAdsForUsers;
organization.UsePhishingBlocker = model.UsePhishingBlocker;
organization.UseMyItems = model.UseMyItems;
//secrets
organization.SmSeats = model.SmSeats;

View File

@@ -19,7 +19,7 @@ using Bit.SharedWeb.Utilities;
namespace Bit.Admin.AdminConsole.Models;
public class OrganizationEditModel : OrganizationViewModel
public class OrganizationEditModel : OrganizationViewModel, IValidatableObject
{
private readonly List<Plan> _plans;
@@ -109,6 +109,7 @@ public class OrganizationEditModel : OrganizationViewModel
UseAutomaticUserConfirmation = org.UseAutomaticUserConfirmation;
UseDisableSmAdsForUsers = org.UseDisableSmAdsForUsers;
UsePhishingBlocker = org.UsePhishingBlocker;
UseMyItems = org.UseMyItems;
_plans = plans;
}
@@ -202,6 +203,8 @@ public class OrganizationEditModel : OrganizationViewModel
[Display(Name = "Automatic User Confirmation")]
public bool UseAutomaticUserConfirmation { get; set; }
[Display(Name = "Create My Items for organization ownership")]
public bool UseMyItems { get; set; }
/**
* Creates a Plan[] object for use in Javascript
* This is mapped manually below to provide some type safety in case the plan objects change
@@ -335,6 +338,18 @@ public class OrganizationEditModel : OrganizationViewModel
existingOrganization.UseOrganizationDomains = UseOrganizationDomains;
existingOrganization.UseDisableSmAdsForUsers = UseDisableSmAdsForUsers;
existingOrganization.UsePhishingBlocker = UsePhishingBlocker;
existingOrganization.UseMyItems = UseMyItems;
return existingOrganization;
}
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (UseMyItems && !UsePolicies)
{
var displayName = nameof(UseMyItems).GetDisplayAttribute<OrganizationEditModel>()?.GetName() ?? nameof(UseMyItems);
yield return new ValidationResult(
$"The {displayName} feature requires Policies to be enabled.",
[nameof(UseMyItems)]);
}
}
}

View File

@@ -178,6 +178,10 @@
<input type="checkbox" class="form-check-input" asp-for="UsersGetPremium" disabled='@(canEditPlan ? null : "disabled")'>
<label class="form-check-label" asp-for="UsersGetPremium"></label>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" asp-for="UseMyItems" disabled='@(canEditPlan ? null : "disabled")'>
<label class="form-check-label" asp-for="UseMyItems"></label>
</div>
</div>
<div class="col-3">
<h3>Secrets Manager</h3>

View File

@@ -62,8 +62,8 @@
console.log(plan);
// General features
document.getElementById('@(nameof(Model.SelfHost))').checked = plan.hasSelfHost;
document.getElementById('@(nameof(Model.Use2fa))').checked = plan.has2fa;
document.getElementById('@(nameof(Model.UseApi))').checked = plan.hasApi;
document.getElementById('@(nameof(Model.UseGroups))').checked = plan.hasGroups;
@@ -77,8 +77,10 @@
document.getElementById('@(nameof(Model.UseCustomPermissions))').checked = plan.hasCustomPermissions;
// use key connector is intentionally omitted
// Password Manager features
document.getElementById('@(nameof(Model.UseTotp))').checked = plan.hasTotp;
document.getElementById('@(nameof(Model.UsersGetPremium))').checked = plan.usersGetPremium;
document.getElementById('@(nameof(Model.UseMyItems))').checked = plan.hasPolicies; // TODO: use the plan property when added (PM-32366)
document.getElementById('@(nameof(Model.MaxStorageGb))').value =
document.getElementById('@(nameof(Model.MaxStorageGb))').value ||

View File

@@ -51,6 +51,7 @@ public abstract class BaseProfileOrganizationResponseModel : ResponseModel
UsePhishingBlocker = organizationDetails.UsePhishingBlocker;
UseDisableSMAdsForUsers = organizationDetails.UseDisableSMAdsForUsers;
UsePasswordManager = organizationDetails.UsePasswordManager;
UseMyItems = organizationDetails.UseMyItems;
SelfHost = organizationDetails.SelfHost;
Seats = organizationDetails.Seats;
MaxCollections = organizationDetails.MaxCollections;
@@ -104,6 +105,7 @@ public abstract class BaseProfileOrganizationResponseModel : ResponseModel
public bool UseAutomaticUserConfirmation { get; set; }
public bool UseDisableSMAdsForUsers { get; set; }
public bool UsePhishingBlocker { get; set; }
public bool UseMyItems { get; set; }
public bool SelfHost { get; set; }
public int? Seats { get; set; }
public short? MaxCollections { get; set; }

View File

@@ -76,6 +76,7 @@ public class OrganizationResponseModel : ResponseModel
UseAutomaticUserConfirmation = organization.UseAutomaticUserConfirmation;
UseDisableSmAdsForUsers = organization.UseDisableSmAdsForUsers;
UsePhishingBlocker = organization.UsePhishingBlocker;
UseMyItems = organization.UseMyItems;
}
public Guid Id { get; set; }
@@ -127,6 +128,7 @@ public class OrganizationResponseModel : ResponseModel
public bool UseAutomaticUserConfirmation { get; set; }
public bool UseDisableSmAdsForUsers { get; set; }
public bool UsePhishingBlocker { get; set; }
public bool UseMyItems { get; set; }
}
public class OrganizationSubscriptionResponseModel : OrganizationResponseModel

View File

@@ -144,6 +144,12 @@ public class Organization : ITableObject<Guid>, IStorableSubscriber, IRevisable
/// </summary>
public bool UsePhishingBlocker { get; set; }
/// <summary>
/// If set to true, My Items collections will be created automatically when the Organization Data Ownership
/// policy is enabled.
/// </summary>
public bool UseMyItems { get; set; }
public void SetNewId()
{
if (Id == default(Guid))
@@ -324,6 +330,7 @@ public class Organization : ITableObject<Guid>, IStorableSubscriber, IRevisable
Use2fa = license.Use2fa;
UseApi = license.UseApi;
UsePolicies = license.UsePolicies;
UseMyItems = license.UseMyItems;
UseSso = license.UseSso;
UseKeyConnector = license.UseKeyConnector;
UseScim = license.UseScim;

View File

@@ -56,4 +56,5 @@ public interface IProfileOrganizationDetails
bool UseDisableSMAdsForUsers { get; set; }
bool UsePhishingBlocker { get; set; }
bool UseMyItems { get; set; }
}

View File

@@ -67,4 +67,5 @@ public class OrganizationUserOrganizationDetails : IProfileOrganizationDetails
public bool UseAutomaticUserConfirmation { get; set; }
public bool UseDisableSMAdsForUsers { get; set; }
public bool UsePhishingBlocker { get; set; }
public bool UseMyItems { get; set; }
}

View File

@@ -159,6 +159,7 @@ public class SelfHostedOrganizationDetails : Organization
UsePhishingBlocker = UsePhishingBlocker,
UseOrganizationDomains = UseOrganizationDomains,
UseAutomaticUserConfirmation = UseAutomaticUserConfirmation,
UseMyItems = UseMyItems,
};
}
}

View File

@@ -58,4 +58,5 @@ public class ProviderUserOrganizationDetails : IProfileOrganizationDetails
public string? ResetPasswordKey { get; set; }
public bool UseDisableSMAdsForUsers { get; set; }
public bool UsePhishingBlocker { get; set; }
public bool UseMyItems { get; set; }
}

View File

@@ -31,6 +31,7 @@ public class OrganizationAbility
UseAutomaticUserConfirmation = organization.UseAutomaticUserConfirmation;
UseDisableSmAdsForUsers = organization.UseDisableSmAdsForUsers;
UsePhishingBlocker = organization.UsePhishingBlocker;
UseMyItems = organization.UseMyItems;
}
public Guid Id { get; set; }
@@ -55,4 +56,5 @@ public class OrganizationAbility
public bool UseAutomaticUserConfirmation { get; set; }
public bool UseDisableSmAdsForUsers { get; set; }
public bool UsePhishingBlocker { get; set; }
public bool UseMyItems { get; set; }
}

View File

@@ -82,6 +82,7 @@ public class CloudOrganizationSignUpCommand(
MaxCollections = plan.PasswordManager.MaxCollections,
MaxStorageGb = (short)(plan.PasswordManager.BaseStorageGb + signup.AdditionalStorageGb),
UsePolicies = plan.HasPolicies,
UseMyItems = plan.HasPolicies, // TODO: use the plan property when added (PM-32366)
UseSso = plan.HasSso,
UseGroups = plan.HasGroups,
UseEvents = plan.HasEvents,

View File

@@ -75,6 +75,7 @@ public class ProviderClientOrganizationSignUpCommand : IProviderClientOrganizati
MaxCollections = plan.PasswordManager.MaxCollections,
MaxStorageGb = plan.PasswordManager.BaseStorageGb,
UsePolicies = plan.HasPolicies,
UseMyItems = plan.HasPolicies, // TODO: use the plan property when added (PM-32366)
UseSso = plan.HasSso,
UseOrganizationDomains = plan.HasOrganizationDomains,
UseGroups = plan.HasGroups,

View File

@@ -65,6 +65,7 @@ public static class OrganizationFactory
UseDisableSmAdsForUsers =
claimsPrincipal.GetValue<bool>(OrganizationLicenseConstants.UseDisableSmAdsForUsers),
UsePhishingBlocker = claimsPrincipal.GetValue<bool>(OrganizationLicenseConstants.UsePhishingBlocker),
UseMyItems = claimsPrincipal.GetValue<bool>(OrganizationLicenseConstants.UseMyItems),
};
public static Organization Create(
@@ -117,5 +118,6 @@ public static class OrganizationFactory
UseAutomaticUserConfirmation = license.UseAutomaticUserConfirmation,
UseDisableSmAdsForUsers = license.UseDisableSmAdsForUsers,
UsePhishingBlocker = license.UsePhishingBlocker,
UseMyItems = license.UseMyItems,
};
}

View File

@@ -46,6 +46,7 @@ public static class OrganizationLicenseConstants
public const string UseAutomaticUserConfirmation = nameof(UseAutomaticUserConfirmation);
public const string UseDisableSmAdsForUsers = nameof(UseDisableSmAdsForUsers);
public const string UsePhishingBlocker = nameof(UsePhishingBlocker);
public const string UseMyItems = nameof(UseMyItems);
}
public static class UserLicenseConstants

View File

@@ -59,6 +59,7 @@ public class OrganizationLicenseClaimsFactory : ILicenseClaimsFactory<Organizati
new(nameof(OrganizationLicenseConstants.UseAutomaticUserConfirmation), entity.UseAutomaticUserConfirmation.ToString()),
new(nameof(OrganizationLicenseConstants.UseDisableSmAdsForUsers), entity.UseDisableSmAdsForUsers.ToString()),
new(nameof(OrganizationLicenseConstants.UsePhishingBlocker), entity.UsePhishingBlocker.ToString()),
new(nameof(OrganizationLicenseConstants.UseMyItems), entity.UseMyItems.ToString()),
};
if (entity.Name is not null)

View File

@@ -88,6 +88,7 @@ public class UpdateOrganizationLicenseCommand : IUpdateOrganizationLicenseComman
license.UseAutomaticUserConfirmation = claimsPrincipal.GetValue<bool>(OrganizationLicenseConstants.UseAutomaticUserConfirmation);
license.UseDisableSmAdsForUsers = claimsPrincipal.GetValue<bool>(OrganizationLicenseConstants.UseDisableSmAdsForUsers);
license.UsePhishingBlocker = claimsPrincipal.GetValue<bool>(OrganizationLicenseConstants.UsePhishingBlocker);
license.UseMyItems = claimsPrincipal.GetValue<bool>(OrganizationLicenseConstants.UseMyItems);
license.MaxStorageGb = claimsPrincipal.GetValue<short?>(OrganizationLicenseConstants.MaxStorageGb);
license.InstallationId = claimsPrincipal.GetValue<Guid>(OrganizationLicenseConstants.InstallationId);
license.LicenseType = claimsPrincipal.GetValue<LicenseType>(OrganizationLicenseConstants.LicenseType);

View File

@@ -156,6 +156,7 @@ public class OrganizationLicense : ILicense
public bool UseAdminSponsoredFamilies { get; set; }
public bool UseAutomaticUserConfirmation { get; set; }
public bool UseDisableSmAdsForUsers { get; set; }
public bool UseMyItems { get; set; }
public string Hash { get; set; }
public string Signature { get; set; }
public string Token { get; set; }
@@ -232,7 +233,8 @@ public class OrganizationLicense : ILicense
!p.Name.Equals(nameof(UseOrganizationDomains)) &&
!p.Name.Equals(nameof(UseAutomaticUserConfirmation)) &&
!p.Name.Equals(nameof(UseDisableSmAdsForUsers)) &&
!p.Name.Equals(nameof(UsePhishingBlocker)))
!p.Name.Equals(nameof(UsePhishingBlocker)) &&
!p.Name.Equals(nameof(UseMyItems)))
.OrderBy(p => p.Name)
.Select(p => $"{p.Name}:{Core.Utilities.CoreHelpers.FormatLicenseSignatureValue(p.GetValue(this, null))}")
.Aggregate((c, n) => $"{c}|{n}");
@@ -428,6 +430,7 @@ public class OrganizationLicense : ILicense
var useOrganizationDomains = claimsPrincipal.GetValue<bool>(nameof(UseOrganizationDomains));
var useAutomaticUserConfirmation = claimsPrincipal.GetValue<bool>(nameof(UseAutomaticUserConfirmation));
var useDisableSmAdsForUsers = claimsPrincipal.GetValue<bool>(nameof(UseDisableSmAdsForUsers));
var useMyItems = claimsPrincipal.GetValue<bool>(nameof(UseMyItems));
var claimedPlanType = claimsPrincipal.GetValue<PlanType>(nameof(PlanType));
@@ -465,7 +468,8 @@ public class OrganizationLicense : ILicense
useAdminSponsoredFamilies == organization.UseAdminSponsoredFamilies &&
useOrganizationDomains == organization.UseOrganizationDomains &&
useAutomaticUserConfirmation == organization.UseAutomaticUserConfirmation &&
useDisableSmAdsForUsers == organization.UseDisableSmAdsForUsers;
useDisableSmAdsForUsers == organization.UseDisableSmAdsForUsers &&
useMyItems == organization.UseMyItems;
}

View File

@@ -148,6 +148,7 @@ public class UpgradePremiumToOrganizationCommand(
MaxCollections = targetPlan.PasswordManager.MaxCollections,
MaxStorageGb = targetPlan.PasswordManager.BaseStorageGb,
UsePolicies = targetPlan.HasPolicies,
UseMyItems = targetPlan.HasPolicies, // TODO: use the plan property when added (PM-32366)
UseSso = targetPlan.HasSso,
UseGroups = targetPlan.HasGroups,
UseEvents = targetPlan.HasEvents,

View File

@@ -82,6 +82,7 @@ public class RestartSubscriptionCommand(
organization.Plan = newPlan.Name;
organization.SelfHost = newPlan.HasSelfHost;
organization.UsePolicies = newPlan.HasPolicies;
organization.UseMyItems = newPlan.HasPolicies; // TODO: use the plan property when added (PM-32366)
organization.UseGroups = newPlan.HasGroups;
organization.UseDirectory = newPlan.HasDirectory;
organization.UseEvents = newPlan.HasEvents;

View File

@@ -259,6 +259,7 @@ public class UpgradeOrganizationPlanCommand : IUpgradeOrganizationPlanCommand
organization.UseApi = newPlan.HasApi;
organization.SelfHost = newPlan.HasSelfHost;
organization.UsePolicies = newPlan.HasPolicies;
organization.UseMyItems = newPlan.HasPolicies; // TODO: use the plan property when added (PM-32366)
organization.MaxStorageGb = (short)(newPlan.PasswordManager.BaseStorageGb + upgrade.AdditionalStorageGb);
organization.UseSso = newPlan.HasSso;
organization.UseOrganizationDomains = newPlan.HasOrganizationDomains;

View File

@@ -139,7 +139,8 @@ public class OrganizationRepository : Repository<Core.AdminConsole.Entities.Orga
UseAdminSponsoredFamilies = e.UseAdminSponsoredFamilies,
UseAutomaticUserConfirmation = e.UseAutomaticUserConfirmation,
UseDisableSmAdsForUsers = e.UseDisableSmAdsForUsers,
UsePhishingBlocker = e.UsePhishingBlocker
UsePhishingBlocker = e.UsePhishingBlocker,
UseMyItems = e.UseMyItems
}).ToListAsync();
}
}

View File

@@ -76,7 +76,8 @@ public class OrganizationUserOrganizationDetailsViewQuery : IQuery<OrganizationU
UseOrganizationDomains = o.UseOrganizationDomains,
UseAutomaticUserConfirmation = o.UseAutomaticUserConfirmation,
UseDisableSMAdsForUsers = o.UseDisableSmAdsForUsers,
UsePhishingBlocker = o.UsePhishingBlocker
UsePhishingBlocker = o.UsePhishingBlocker,
UseMyItems = o.UseMyItems
};
return query;
}

View File

@@ -62,7 +62,8 @@ public class ProviderUserOrganizationDetailsViewQuery : IQuery<ProviderUserOrgan
SsoEnabled = x.ss.Enabled,
SsoConfig = x.ss.Data,
UseDisableSMAdsForUsers = x.o.UseDisableSmAdsForUsers,
UsePhishingBlocker = x.o.UsePhishingBlocker
UsePhishingBlocker = x.o.UsePhishingBlocker,
UseMyItems = x.o.UseMyItems
});
}
}

View File

@@ -61,7 +61,8 @@ CREATE PROCEDURE [dbo].[Organization_Create]
@SyncSeats BIT = 0,
@UseAutomaticUserConfirmation BIT = 0,
@UsePhishingBlocker BIT = 0,
@UseDisableSmAdsForUsers BIT = 0
@UseDisableSmAdsForUsers BIT = 0,
@UseMyItems BIT = 0
AS
BEGIN
SET NOCOUNT ON
@@ -131,7 +132,8 @@ BEGIN
[UseAutomaticUserConfirmation],
[UsePhishingBlocker],
[MaxStorageGbIncreased],
[UseDisableSmAdsForUsers]
[UseDisableSmAdsForUsers],
[UseMyItems]
)
VALUES
(
@@ -198,6 +200,7 @@ BEGIN
@UseAutomaticUserConfirmation,
@UsePhishingBlocker,
@MaxStorageGb,
@UseDisableSmAdsForUsers
@UseDisableSmAdsForUsers,
@UseMyItems
);
END

View File

@@ -28,9 +28,10 @@ BEGIN
[LimitItemDeletion],
[UseOrganizationDomains],
[UseAdminSponsoredFamilies],
[UseAutomaticUserConfirmation],
[UseAutomaticUserConfirmation],
[UsePhishingBlocker],
[UseDisableSmAdsForUsers]
[UseDisableSmAdsForUsers],
[UseMyItems]
FROM
[dbo].[Organization]
END

View File

@@ -61,7 +61,8 @@ CREATE PROCEDURE [dbo].[Organization_Update]
@SyncSeats BIT = 0,
@UseAutomaticUserConfirmation BIT = 0,
@UsePhishingBlocker BIT = 0,
@UseDisableSmAdsForUsers BIT = 0
@UseDisableSmAdsForUsers BIT = 0,
@UseMyItems BIT = 0
AS
BEGIN
SET NOCOUNT ON
@@ -131,7 +132,8 @@ BEGIN
[UseAutomaticUserConfirmation] = @UseAutomaticUserConfirmation,
[UsePhishingBlocker] = @UsePhishingBlocker,
[MaxStorageGbIncreased] = @MaxStorageGb,
[UseDisableSmAdsForUsers] = @UseDisableSmAdsForUsers
[UseDisableSmAdsForUsers] = @UseDisableSmAdsForUsers,
[UseMyItems] = @UseMyItems
WHERE
[Id] = @Id;
END

View File

@@ -63,6 +63,7 @@ CREATE TABLE [dbo].[Organization] (
[MaxStorageGbIncreased] SMALLINT NULL,
[UsePhishingBlocker] BIT NOT NULL CONSTRAINT [DF_Organization_UsePhishingBlocker] DEFAULT (0),
[UseDisableSmAdsForUsers] BIT NOT NULL CONSTRAINT [DF_Organization_UseDisableSmAdsForUsers] DEFAULT (0),
[UseMyItems] BIT NOT NULL CONSTRAINT [DF_Organization_UseMyItems] DEFAULT (0),
CONSTRAINT [PK_Organization] PRIMARY KEY CLUSTERED ([Id] ASC)
);

View File

@@ -57,7 +57,8 @@ SELECT
OS.[IsAdminInitiated],
O.[UseAutomaticUserConfirmation],
O.[UsePhishingBlocker],
O.[UseDisableSmAdsForUsers]
O.[UseDisableSmAdsForUsers],
O.[UseMyItems]
FROM
[dbo].[OrganizationUser] OU
LEFT JOIN

View File

@@ -63,6 +63,7 @@ SELECT
[SyncSeats],
[UseAutomaticUserConfirmation],
[UsePhishingBlocker],
[UseDisableSmAdsForUsers]
[UseDisableSmAdsForUsers],
[UseMyItems]
FROM
[dbo].[Organization]

View File

@@ -46,7 +46,8 @@ SELECT
SS.[Enabled] SsoEnabled,
SS.[Data] SsoConfig,
O.[UsePhishingBlocker],
O.[UseDisableSmAdsForUsers]
O.[UseDisableSmAdsForUsers],
O.[UseMyItems]
FROM
[dbo].[ProviderUser] PU
INNER JOIN