Fix: Sync Apply Group buttons with text input and automatically authorize group assets in backend getAssets query

This commit is contained in:
kenilkb 2026-07-16 12:52:26 +05:30
parent ed60948be4
commit 9170b607fe
2 changed files with 72 additions and 16 deletions

View File

@ -177,19 +177,43 @@ export class AssetService {
return [];
}
return await prisma.asset.findMany({
where: {
status: 'published',
sharedWith: {
some: {
organizationId: user.organizationId,
OR: [
{ userId: null },
{ userId: user.id }
]
// Support comma-separated multiple groups
const userGroups = user.partnerGroup
? user.partnerGroup.split(',').map(s => s.trim().toLowerCase())
: [];
const whereClause: any = {
status: 'published',
OR: [
{
sharedWith: {
some: {
organizationId: user.organizationId,
OR: [
{ userId: null },
{ userId: user.id }
]
}
}
}
},
]
};
if (userGroups.length > 0) {
whereClause.OR.push({
assetGroups: {
some: {
name: {
in: userGroups,
mode: 'insensitive'
}
}
}
});
}
return await prisma.asset.findMany({
where: whereClause,
include: {
sharedWith: {
include: {

View File

@ -163,11 +163,43 @@ export const DirectoryPage: React.FC = () => {
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 = (
selectedIds: string[],
setSelectedIds: React.Dispatch<React.SetStateAction<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 =>
asset.title.toLowerCase().includes(searchQuery.toLowerCase())
@ -181,8 +213,6 @@ export const DirectoryPage: React.FC = () => {
}
};
return (
<div className="space-y-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);
if (hasAll) {
setSelectedIds(prev => prev.filter(id => !groupAssetIds.includes(id)));
if (onToggleGroup) onToggleGroup(g.name, false);
} else {
setSelectedIds(prev => {
const newIds = [...prev];
@ -228,6 +259,7 @@ export const DirectoryPage: React.FC = () => {
});
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
@ -1233,7 +1265,7 @@ export const DirectoryPage: React.FC = () => {
</span>
)}
</div>
{renderAssetSelector(selectedAssetIds, setSelectedAssetIds, inviteAssetSearch, setInviteAssetSearch)}
{renderAssetSelector(selectedAssetIds, setSelectedAssetIds, inviteAssetSearch, setInviteAssetSearch, handleToggleInviteGroup)}
</div>
{inviteResult?.error && (
@ -1397,7 +1429,7 @@ export const DirectoryPage: React.FC = () => {
</span>
)}
</div>
{renderAssetSelector(editAssetIds, setEditAssetIds, editAssetSearch, setEditAssetSearch)}
{renderAssetSelector(editAssetIds, setEditAssetIds, editAssetSearch, setEditAssetSearch, handleToggleEditGroup)}
</div>
<div className="flex items-center gap-3 pt-2">