feat: list shared albums (editor access) in workflow add/remove-album picker
Closes #286. The album picker for add_to_album/remove_from_album only showed albums owned by the current user. Add an opt-in ?includeShared param to /api/albums/list that also includes albums where the user has 'editor' role (upload access), and group the picker into 'My Albums' / 'Shared Albums' sections. Other callers of listAlbums() don't pass includeShared, so they keep the existing owner-only behavior unchanged.
This commit is contained in:
1 parent
58bb1d0e9d
commit
1afe0c858c
4 files changed
+42
-22
No files matched your search
@@ -25,7 +25,9 @@ function AlbumPicker({ value, onChange }: { value: string | undefined; onChange:
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
listAlbums()
|
||||
// Shared albums are included so this action can add assets to albums the
|
||||
// user has editor (upload) access to, not just ones they own.
|
||||
listAlbums({ includeShared: true })
|
||||
.then((data) => {
|
||||
setAlbums(data);
|
||||
if (value) {
|
||||
@@ -36,6 +38,25 @@ function AlbumPicker({ value, onChange }: { value: string | undefined; onChange:
|
||||
.finally(() => setLoading(false));
|
||||
}, []);
|
||||
|
||||
const ownedAlbums = albums.filter((a) => a.myRole !== "editor");
|
||||
const sharedAlbums = albums.filter((a) => a.myRole === "editor");
|
||||
|
||||
const renderItem = (album: IAlbum) => (
|
||||
<CommandItem
|
||||
key={album.id}
|
||||
value={album.albumName}
|
||||
onSelect={() => {
|
||||
setSelectedAlbum(album);
|
||||
onChange(album.id, album.albumName);
|
||||
setOpen(false);
|
||||
}}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<span className="text-xs truncate flex-1">{album.albumName}</span>
|
||||
<Check className={cn("h-3 w-3", value === album.id ? "opacity-100" : "opacity-0")} />
|
||||
</CommandItem>
|
||||
);
|
||||
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
@@ -52,23 +73,16 @@ function AlbumPicker({ value, onChange }: { value: string | undefined; onChange:
|
||||
<CommandInput placeholder="Search albums..." className="text-xs" />
|
||||
<CommandList>
|
||||
<CommandEmpty>{loading ? "Loading..." : "No albums found."}</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{albums.map((album) => (
|
||||
<CommandItem
|
||||
key={album.id}
|
||||
value={album.albumName}
|
||||
onSelect={() => {
|
||||
setSelectedAlbum(album);
|
||||
onChange(album.id, album.albumName);
|
||||
setOpen(false);
|
||||
}}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<span className="text-xs truncate flex-1">{album.albumName}</span>
|
||||
<Check className={cn("h-3 w-3", value === album.id ? "opacity-100" : "opacity-0")} />
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
{ownedAlbums.length > 0 && (
|
||||
<CommandGroup heading="My Albums">
|
||||
{ownedAlbums.map(renderItem)}
|
||||
</CommandGroup>
|
||||
)}
|
||||
{sharedAlbums.length > 0 && (
|
||||
<CommandGroup heading="Shared Albums">
|
||||
{sharedAlbums.map(renderItem)}
|
||||
</CommandGroup>
|
||||
)}
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
|
||||
@@ -60,7 +60,7 @@ export const listPotentialTripAssets = async (
|
||||
return API.get(LIST_POTENTIAL_ALBUMS_ASSETS_PATH, params).then((assets) => assets.map(cleanUpAsset));
|
||||
}
|
||||
|
||||
export const listAlbums = async (filters?: { sortBy?: string, sortOrder?: string }) => {
|
||||
export const listAlbums = async (filters?: { sortBy?: string, sortOrder?: string, includeShared?: boolean }) => {
|
||||
return API.get(LIST_ALBUMS_PATH, filters);
|
||||
}
|
||||
export const getAlbumInfo = async (id: string) => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { db } from "@/config/db";
|
||||
import { getCurrentUser } from "@/handlers/serverUtils/user.utils";
|
||||
import { NextApiResponse } from "next";
|
||||
import { albums } from "@/schema/albums.schema";
|
||||
import { count, desc, eq, min, max, sql, and, sum, isNotNull } from "drizzle-orm";
|
||||
import { count, desc, eq, inArray, min, max, sql, and, sum, isNotNull } from "drizzle-orm";
|
||||
import { assets } from "@/schema/assets.schema";
|
||||
import { albumsAssetsAssets } from "@/schema/albumAssetsAssets.schema";
|
||||
import { albumUsers } from "@/schema/albumUsers.schema";
|
||||
@@ -50,7 +50,10 @@ export default async function handler(
|
||||
if (!currentUser) {
|
||||
return res.status(401).json({ error: "Unauthorized" });
|
||||
}
|
||||
const { sortBy = 'lastPhotoDate', sortOrder = 'desc' } = req.query as { sortBy: string, sortOrder: string };
|
||||
const { sortBy = 'lastPhotoDate', sortOrder = 'desc', includeShared } = req.query as { sortBy: string, sortOrder: string, includeShared?: string };
|
||||
// Shared albums grant "editor" role to collaborators, which is enough to
|
||||
// add/upload assets. "viewer" (read-only shares) is deliberately excluded.
|
||||
const roles = includeShared === 'true' ? ["owner", "editor"] : ["owner"];
|
||||
|
||||
const dbAlbums = await db.select({
|
||||
id: albums.id,
|
||||
@@ -65,12 +68,13 @@ export default async function handler(
|
||||
order: albums.order,
|
||||
isActivityEnabled: albums.isActivityEnabled,
|
||||
ownerId: albumUsers.userId,
|
||||
myRole: albumUsers.role,
|
||||
description: albums.description,
|
||||
lastModifiedAssetTimestamp: max(exif.dateTimeOriginal),
|
||||
faceCount: count(sql<string>`DISTINCT ${assetFaces.personId}`), // Ensure unique personId
|
||||
})
|
||||
.from(albums)
|
||||
.innerJoin(albumUsers, and(eq(albums.id, albumUsers.albumId), eq(albumUsers.role, "owner")))
|
||||
.innerJoin(albumUsers, and(eq(albums.id, albumUsers.albumId), inArray(albumUsers.role, roles)))
|
||||
.leftJoin(albumsAssetsAssets, eq(albums.id, albumsAssetsAssets.albumId))
|
||||
.leftJoin(assets, and(
|
||||
eq(albumsAssetsAssets.assetId, assets.id),
|
||||
|
||||
Vendored
+2
@@ -6,6 +6,8 @@ export interface IAlbum {
|
||||
updatedAt: Date;
|
||||
id: string;
|
||||
ownerId: string;
|
||||
/** Current user's role on this album ("owner" | "editor" | "viewer"), when returned by an endpoint that includes shared albums. */
|
||||
myRole?: string;
|
||||
owner?: IAlbumOwner;
|
||||
albumUsers?: any[];
|
||||
shared?: boolean;
|
||||
|
||||
Reference in new issue
Block a user