feat: Add isPrivate field to AdminProduct and update filtering logic in admin panels
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
This commit is contained in:
@@ -240,6 +240,7 @@ class AdminRepository {
|
|||||||
name: product.name,
|
name: product.name,
|
||||||
canonicalName: product.canonicalName,
|
canonicalName: product.canonicalName,
|
||||||
ownerId: product.ownerId,
|
ownerId: product.ownerId,
|
||||||
|
isPrivate: true,
|
||||||
categoryId: product.categoryId,
|
categoryId: product.categoryId,
|
||||||
categoryPath: product.categoryPath,
|
categoryPath: product.categoryPath,
|
||||||
status: 'private',
|
status: 'private',
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ class AdminProduct {
|
|||||||
final String? canonicalName;
|
final String? canonicalName;
|
||||||
final String? normalizedName;
|
final String? normalizedName;
|
||||||
final int? ownerId;
|
final int? ownerId;
|
||||||
|
final bool? isPrivate;
|
||||||
final int? categoryId;
|
final int? categoryId;
|
||||||
final String? categoryPath;
|
final String? categoryPath;
|
||||||
final bool? isActive;
|
final bool? isActive;
|
||||||
@@ -16,6 +17,7 @@ class AdminProduct {
|
|||||||
this.canonicalName,
|
this.canonicalName,
|
||||||
this.normalizedName,
|
this.normalizedName,
|
||||||
this.ownerId,
|
this.ownerId,
|
||||||
|
this.isPrivate,
|
||||||
this.categoryId,
|
this.categoryId,
|
||||||
this.categoryPath,
|
this.categoryPath,
|
||||||
this.isActive,
|
this.isActive,
|
||||||
@@ -46,6 +48,7 @@ class AdminProduct {
|
|||||||
canonicalName: json['canonicalName']?.toString(),
|
canonicalName: json['canonicalName']?.toString(),
|
||||||
normalizedName: json['normalizedName']?.toString(),
|
normalizedName: json['normalizedName']?.toString(),
|
||||||
ownerId: ((json['owner'] as Map<String, dynamic>?)?['id'] as num?)?.toInt(),
|
ownerId: ((json['owner'] as Map<String, dynamic>?)?['id'] as num?)?.toInt(),
|
||||||
|
isPrivate: json['isPrivate'] as bool?,
|
||||||
categoryId: (json['categoryId'] as num?)?.toInt(),
|
categoryId: (json['categoryId'] as num?)?.toInt(),
|
||||||
categoryPath: names.isEmpty ? null : names.join(' > '),
|
categoryPath: names.isEmpty ? null : names.join(' > '),
|
||||||
isActive: json['isActive'] as bool?,
|
isActive: json['isActive'] as bool?,
|
||||||
|
|||||||
@@ -38,13 +38,17 @@ List<AdminProduct> filterSelectableAdminProducts({
|
|||||||
required AdminProduct? selectedProduct,
|
required AdminProduct? selectedProduct,
|
||||||
}) {
|
}) {
|
||||||
final ownerFiltered = ownerUserId == null
|
final ownerFiltered = ownerUserId == null
|
||||||
? products.where((p) => p.ownerId == null).toList()
|
? products.where((p) => p.isPrivate != true).toList()
|
||||||
: products.where((p) => p.ownerId == null || p.ownerId == ownerUserId).toList();
|
: products
|
||||||
|
.where(
|
||||||
|
(p) => p.isPrivate != true || p.ownerId == ownerUserId,
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
|
||||||
final scopeFiltered = switch (scopeFilter) {
|
final scopeFiltered = switch (scopeFilter) {
|
||||||
ProductScopeFilter.all => ownerFiltered,
|
ProductScopeFilter.all => ownerFiltered,
|
||||||
ProductScopeFilter.globalOnly => ownerFiltered.where((p) => p.ownerId == null).toList(),
|
ProductScopeFilter.globalOnly => ownerFiltered.where((p) => p.isPrivate != true).toList(),
|
||||||
ProductScopeFilter.privateOnly => ownerFiltered.where((p) => p.ownerId != null).toList(),
|
ProductScopeFilter.privateOnly => ownerFiltered.where((p) => p.isPrivate == true).toList(),
|
||||||
};
|
};
|
||||||
|
|
||||||
final source = categoryId == null
|
final source = categoryId == null
|
||||||
@@ -64,7 +68,7 @@ List<ProductOption> toProductOptions(List<AdminProduct> products) {
|
|||||||
.map(
|
.map(
|
||||||
(p) => (
|
(p) => (
|
||||||
id: p.id,
|
id: p.id,
|
||||||
name: p.ownerId == null ? p.displayName : '${p.displayName} (privat)',
|
name: p.isPrivate == true ? '${p.displayName} (privat)' : p.displayName,
|
||||||
categoryId: p.categoryId,
|
categoryId: p.categoryId,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -854,6 +854,7 @@ class _InventoryFormDialogState extends State<_InventoryFormDialog> {
|
|||||||
name: initial.productName,
|
name: initial.productName,
|
||||||
canonicalName: initial.productCanonicalName,
|
canonicalName: initial.productCanonicalName,
|
||||||
ownerId: initial.userId,
|
ownerId: initial.userId,
|
||||||
|
isPrivate: null,
|
||||||
categoryId: initial.categoryId,
|
categoryId: initial.categoryId,
|
||||||
categoryPath: initial.categoryPath,
|
categoryPath: initial.categoryPath,
|
||||||
status: 'private',
|
status: 'private',
|
||||||
@@ -943,7 +944,7 @@ class _InventoryFormDialogState extends State<_InventoryFormDialog> {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
_productScopeFilter = ProductScopeFilter.globalOnly;
|
_productScopeFilter = ProductScopeFilter.globalOnly;
|
||||||
final selected = _productById(_productId);
|
final selected = _productById(_productId);
|
||||||
if (selected?.ownerId != null) {
|
if (selected?.isPrivate == true) {
|
||||||
_productId = null;
|
_productId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -565,6 +565,7 @@ class _PantryFormDialogState extends State<_PantryFormDialog> {
|
|||||||
name: initial.productName,
|
name: initial.productName,
|
||||||
canonicalName: initial.productCanonicalName,
|
canonicalName: initial.productCanonicalName,
|
||||||
ownerId: initial.userId,
|
ownerId: initial.userId,
|
||||||
|
isPrivate: null,
|
||||||
categoryId: initial.categoryId,
|
categoryId: initial.categoryId,
|
||||||
categoryPath: initial.categoryPath,
|
categoryPath: initial.categoryPath,
|
||||||
status: 'private',
|
status: 'private',
|
||||||
@@ -645,7 +646,7 @@ class _PantryFormDialogState extends State<_PantryFormDialog> {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
_productScopeFilter = ProductScopeFilter.globalOnly;
|
_productScopeFilter = ProductScopeFilter.globalOnly;
|
||||||
final selected = _productById(_productId);
|
final selected = _productById(_productId);
|
||||||
if (selected?.ownerId != null) {
|
if (selected?.isPrivate == true) {
|
||||||
_productId = null;
|
_productId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user