feat: add cross-album search, auto-rules, album UI redesign, editorial archiving and pdf download
This commit is contained in:
1 parent
9c0d43b1ec
commit
375e5b8b7d
23 files changed
+1153
-43
No files matched your search
@@ -50,6 +50,7 @@ export type EditorialServiceRepository = {
|
||||
to: AccountStatus;
|
||||
adminUserId: string;
|
||||
}): Promise<void>;
|
||||
archiveEditorial(input: { editorialId: string; adminUserId: string }): Promise<void>;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -151,6 +152,10 @@ export function createEditorialService({
|
||||
}
|
||||
await repository.transitionStatus(input);
|
||||
},
|
||||
|
||||
async archiveEditorial(input: { editorialId: string; adminUserId: string }): Promise<void> {
|
||||
await repository.archiveEditorial(input);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -416,6 +421,95 @@ export function createEditorialServiceRepository(
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
async archiveEditorial({ editorialId, adminUserId }) {
|
||||
await database.transaction(async (transaction) => {
|
||||
await lockEditorialForMutation(transaction, editorialId);
|
||||
|
||||
const [editorial] = await transaction
|
||||
.select({
|
||||
id: editorialAccounts.id,
|
||||
status: editorialAccounts.status,
|
||||
archivedAt: editorialAccounts.archivedAt,
|
||||
})
|
||||
.from(editorialAccounts)
|
||||
.where(eq(editorialAccounts.id, editorialId))
|
||||
.for("update")
|
||||
.limit(1);
|
||||
|
||||
if (!editorial) {
|
||||
throw new EditorialServiceError("EDITORIAL_NOT_FOUND");
|
||||
}
|
||||
|
||||
if (editorial.archivedAt) {
|
||||
return;
|
||||
}
|
||||
|
||||
const activeGrants = await transaction
|
||||
.select({ id: albumGrants.id, immichAlbumId: albumGrants.immichAlbumId })
|
||||
.from(albumGrants)
|
||||
.where(
|
||||
and(
|
||||
eq(albumGrants.editorialAccountId, editorialId),
|
||||
isNull(albumGrants.revokedAt),
|
||||
),
|
||||
)
|
||||
.for("update");
|
||||
|
||||
const changedAt = new Date();
|
||||
const newStatus = editorial.status === "active" ? "suspended" : editorial.status;
|
||||
|
||||
await transaction
|
||||
.update(editorialAccounts)
|
||||
.set({
|
||||
archivedAt: changedAt,
|
||||
archivedByUserId: adminUserId,
|
||||
status: newStatus,
|
||||
updatedAt: changedAt,
|
||||
})
|
||||
.where(eq(editorialAccounts.id, editorialId));
|
||||
|
||||
if (activeGrants.length > 0) {
|
||||
const grantIds = activeGrants.map((g) => g.id);
|
||||
await transaction
|
||||
.update(albumGrants)
|
||||
.set({ revokedAt: changedAt })
|
||||
.where(inArray(albumGrants.id, grantIds));
|
||||
|
||||
for (const grant of activeGrants) {
|
||||
await transaction.insert(auditEvents).values({
|
||||
eventType: "album_revoked",
|
||||
actorUserId: adminUserId,
|
||||
actorType: "admin",
|
||||
entityType: "album_grant",
|
||||
entityId: grant.immichAlbumId,
|
||||
previousValues: {
|
||||
editorialId: editorialId,
|
||||
immichAlbumId: grant.immichAlbumId,
|
||||
granted: true,
|
||||
},
|
||||
newValues: {
|
||||
editorialId: editorialId,
|
||||
immichAlbumId: grant.immichAlbumId,
|
||||
granted: false,
|
||||
},
|
||||
occurredAt: changedAt,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await transaction.insert(auditEvents).values({
|
||||
eventType: "editorial_archived",
|
||||
actorUserId: adminUserId,
|
||||
actorType: "admin",
|
||||
entityType: "editorial_account",
|
||||
entityId: editorialId,
|
||||
previousValues: { status: editorial.status, archived: false },
|
||||
newValues: { status: newStatus, archived: true },
|
||||
occurredAt: changedAt,
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user