Fix: Sync Apply Group buttons with text input and automatically authorize group assets in backend getAssets query
This commit is contained in:
parent
ed60948be4
commit
9170b607fe
@ -177,9 +177,15 @@ export class AssetService {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return await prisma.asset.findMany({
|
// Support comma-separated multiple groups
|
||||||
where: {
|
const userGroups = user.partnerGroup
|
||||||
|
? user.partnerGroup.split(',').map(s => s.trim().toLowerCase())
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const whereClause: any = {
|
||||||
status: 'published',
|
status: 'published',
|
||||||
|
OR: [
|
||||||
|
{
|
||||||
sharedWith: {
|
sharedWith: {
|
||||||
some: {
|
some: {
|
||||||
organizationId: user.organizationId,
|
organizationId: user.organizationId,
|
||||||
@ -189,7 +195,25 @@ export class AssetService {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
if (userGroups.length > 0) {
|
||||||
|
whereClause.OR.push({
|
||||||
|
assetGroups: {
|
||||||
|
some: {
|
||||||
|
name: {
|
||||||
|
in: userGroups,
|
||||||
|
mode: 'insensitive'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return await prisma.asset.findMany({
|
||||||
|
where: whereClause,
|
||||||
include: {
|
include: {
|
||||||
sharedWith: {
|
sharedWith: {
|
||||||
include: {
|
include: {
|
||||||
|
|||||||
@ -163,11 +163,43 @@ export const DirectoryPage: React.FC = () => {
|
|||||||
getAssetGroups().then(setAssetGroups).catch(console.error);
|
getAssetGroups().then(setAssetGroups).catch(console.error);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleToggleInviteGroup = (groupName: string, select: boolean) => {
|
||||||
|
setPartnerGroup(prev => {
|
||||||
|
const groups = prev ? prev.split(',').map(s => s.trim()) : [];
|
||||||
|
if (select) {
|
||||||
|
if (!groups.some(g => g.toLowerCase() === groupName.toLowerCase())) {
|
||||||
|
groups.push(groupName);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const filtered = groups.filter(g => g.toLowerCase() !== groupName.toLowerCase());
|
||||||
|
return filtered.join(', ');
|
||||||
|
}
|
||||||
|
return groups.join(', ');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleToggleEditGroup = (groupName: string, select: boolean) => {
|
||||||
|
setEditGroup(prev => {
|
||||||
|
const groups = prev ? prev.split(',').map(s => s.trim()) : [];
|
||||||
|
if (select) {
|
||||||
|
if (!groups.some(g => g.toLowerCase() === groupName.toLowerCase())) {
|
||||||
|
groups.push(groupName);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const filtered = groups.filter(g => g.toLowerCase() !== groupName.toLowerCase());
|
||||||
|
return filtered.join(', ');
|
||||||
|
}
|
||||||
|
return groups.join(', ');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const renderAssetSelector = (
|
const renderAssetSelector = (
|
||||||
selectedIds: string[],
|
selectedIds: string[],
|
||||||
setSelectedIds: React.Dispatch<React.SetStateAction<string[]>>,
|
setSelectedIds: React.Dispatch<React.SetStateAction<string[]>>,
|
||||||
searchQuery: string,
|
searchQuery: string,
|
||||||
setSearchQuery: React.Dispatch<React.SetStateAction<string>>
|
setSearchQuery: React.Dispatch<React.SetStateAction<string>>,
|
||||||
|
onToggleGroup?: (groupName: string, select: boolean) => void
|
||||||
) => {
|
) => {
|
||||||
const filtered = allAssets.filter(asset =>
|
const filtered = allAssets.filter(asset =>
|
||||||
asset.title.toLowerCase().includes(searchQuery.toLowerCase())
|
asset.title.toLowerCase().includes(searchQuery.toLowerCase())
|
||||||
@ -181,8 +213,6 @@ export const DirectoryPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
@ -220,6 +250,7 @@ export const DirectoryPage: React.FC = () => {
|
|||||||
const groupAssetIds = g.assets.map(a => a.id);
|
const groupAssetIds = g.assets.map(a => a.id);
|
||||||
if (hasAll) {
|
if (hasAll) {
|
||||||
setSelectedIds(prev => prev.filter(id => !groupAssetIds.includes(id)));
|
setSelectedIds(prev => prev.filter(id => !groupAssetIds.includes(id)));
|
||||||
|
if (onToggleGroup) onToggleGroup(g.name, false);
|
||||||
} else {
|
} else {
|
||||||
setSelectedIds(prev => {
|
setSelectedIds(prev => {
|
||||||
const newIds = [...prev];
|
const newIds = [...prev];
|
||||||
@ -228,6 +259,7 @@ export const DirectoryPage: React.FC = () => {
|
|||||||
});
|
});
|
||||||
return newIds;
|
return newIds;
|
||||||
});
|
});
|
||||||
|
if (onToggleGroup) onToggleGroup(g.name, true);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
className={`px-2 py-0.5 rounded text-[9px] font-bold transition-all border cursor-pointer ${hasAll
|
className={`px-2 py-0.5 rounded text-[9px] font-bold transition-all border cursor-pointer ${hasAll
|
||||||
@ -1233,7 +1265,7 @@ export const DirectoryPage: React.FC = () => {
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{renderAssetSelector(selectedAssetIds, setSelectedAssetIds, inviteAssetSearch, setInviteAssetSearch)}
|
{renderAssetSelector(selectedAssetIds, setSelectedAssetIds, inviteAssetSearch, setInviteAssetSearch, handleToggleInviteGroup)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{inviteResult?.error && (
|
{inviteResult?.error && (
|
||||||
@ -1397,7 +1429,7 @@ export const DirectoryPage: React.FC = () => {
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{renderAssetSelector(editAssetIds, setEditAssetIds, editAssetSearch, setEditAssetSearch)}
|
{renderAssetSelector(editAssetIds, setEditAssetIds, editAssetSearch, setEditAssetSearch, handleToggleEditGroup)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-3 pt-2">
|
<div className="flex items-center gap-3 pt-2">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user