Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/api/plane/app/serializers/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ class Meta:
"asset",
"attributes",
# "issue_id",
"created_at",
"created_by",
"updated_at",
"updated_by",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2023-present Plane Software, Inc. and contributors
# SPDX-License-Identifier: AGPL-3.0-only
# See the LICENSE file for details.

from datetime import UTC, datetime
from uuid import uuid4

import pytest

from plane.app.serializers.issue import IssueAttachmentLiteSerializer, IssueAttachmentSerializer
from plane.db.models import FileAsset, Workspace


@pytest.mark.unit
@pytest.mark.parametrize("serializer", [IssueAttachmentLiteSerializer, IssueAttachmentSerializer])
def test_work_item_attachment_returns_original_timestamp(serializer):
uploaded = datetime(2026, 1, 1, 10, 30, tzinfo=UTC)
attachment = FileAsset(
workspace=Workspace(id=uuid4(), slug="example"),
project_id=uuid4(),
issue_id=uuid4(),
entity_type=FileAsset.EntityTypeContext.ISSUE_ATTACHMENT,
created_at=uploaded,
updated_at=datetime(2026, 2, 1, tzinfo=UTC),
)

assert datetime.fromisoformat(serializer(attachment).data["created_at"]) == uploaded
3 changes: 2 additions & 1 deletion apps/web/components/core/activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { useEffect } from "react";
import { getAttachmentUploadMessage } from "@/helpers/attachment-activity";
import { observer } from "mobx-react";
import { useParams } from "next/navigation";
// store hooks
Expand Down Expand Up @@ -204,7 +205,7 @@ const activityDetails: {
if (activity.verb === "created")
return (
<>
uploaded a new attachment
{getAttachmentUploadMessage(activity.new_value)}
{showIssue && (
<>
{" "}
Expand Down
9 changes: 5 additions & 4 deletions apps/web/components/issues/attachment/attachment-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export const IssueAttachmentsDetail = observer(function IssueAttachmentsDetail(p

if (!attachment) return <></>;

const uploadedAt = renderFormattedDate(new Date(attachment.created_at), "MMM dd, yyyy, HH:mm");

return (
<>
{isDeleteIssueAttachmentModalOpen && (
Expand All @@ -79,18 +81,17 @@ export const IssueAttachmentsDetail = observer(function IssueAttachmentsDetail(p
<Tooltip label={fileName} layout="stacked" disabled={isMobile}>
<span className="truncate text-body-xs-medium text-primary">{fileName}</span>
</Tooltip>
<div className="flex items-center gap-2 text-caption-sm-regular text-tertiary">
<div className="flex flex-wrap items-center gap-x-2 text-caption-sm-regular text-tertiary">
<span>{fileExtension.toUpperCase()}</span>
<span>{convertBytesToSize(attachment.attributes.size)}</span>
<time dateTime={attachment.created_at}>{uploadedAt}</time>
</div>
</div>
</Link>

<div className="flex shrink-0 items-center gap-1">
<Tooltip
label={`${
getUserDetails(attachment.updated_by)?.display_name ?? ""
} uploaded on ${renderFormattedDate(attachment.updated_at)}`}
label={`${getUserDetails(attachment.created_by)?.display_name ?? ""} uploaded on ${uploadedAt}`}
layout="stacked"
disabled={isMobile}
>
Expand Down
17 changes: 11 additions & 6 deletions apps/web/components/issues/attachment/attachment-list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const IssueAttachmentsListItem = observer(function IssueAttachmentsListIt

if (!attachment) return <></>;

const uploadedAt = renderFormattedDate(new Date(attachment.created_at), "MMM dd, yyyy, HH:mm");

return (
<>
<button
Expand All @@ -66,9 +68,14 @@ export const IssueAttachmentsListItem = observer(function IssueAttachmentsListIt
<div className="group flex h-11 items-center justify-between gap-3 pr-2 pl-3 hover:bg-surface-2">
<div className="flex items-center gap-3 truncate text-body-xs-regular">
<div className="flex items-center gap-3">{fileIcon}</div>
<Tooltip label={fileName} layout="stacked" disabled={isMobile}>
<p className="truncate font-medium text-secondary">{fileName}</p>
</Tooltip>
<div className="flex min-w-0 flex-col items-start">
<Tooltip label={fileName} layout="stacked" disabled={isMobile}>
<p className="max-w-full truncate font-medium text-secondary">{fileName}</p>
</Tooltip>
<time dateTime={attachment.created_at} className="text-caption-sm-regular text-tertiary">
{uploadedAt}
</time>
</div>
<span className="flex size-1.5 rounded-full bg-layer-1" />
<span className="shrink-0 text-placeholder">{convertBytesToSize(attachment.attributes.size)}</span>
</div>
Expand All @@ -77,9 +84,7 @@ export const IssueAttachmentsListItem = observer(function IssueAttachmentsListIt
{attachment?.created_by && (
<>
<Tooltip
label={`${
getUserDetails(attachment?.created_by)?.display_name ?? ""
} uploaded on ${renderFormattedDate(attachment.updated_at)}`}
label={`${getUserDetails(attachment?.created_by)?.display_name ?? ""} uploaded on ${uploadedAt}`}
layout="stacked"
disabled={isMobile}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* See the LICENSE file for details.
*/

import { getAttachmentUploadMessage } from "@/helpers/attachment-activity";
import { observer } from "mobx-react";
import { AttachOutline } from "@makeplane/propel/icons";
// hooks
Expand All @@ -30,7 +31,7 @@ export const IssueAttachmentActivity = observer(function IssueAttachmentActivity
ends={ends}
>
<>
{activity.verb === "created" ? `uploaded a new attachment` : `removed an attachment`}
{activity.verb === "created" ? getAttachmentUploadMessage(activity.new_value) : `removed an attachment`}
{showIssue && (activity.verb === "created" ? ` to ` : ` from `)}
{showIssue && <IssueLink activityId={activityId} />}.
</>
Expand Down
23 changes: 23 additions & 0 deletions apps/web/helpers/attachment-activity.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2023-present Plane Software, Inc. and contributors
* SPDX-License-Identifier: AGPL-3.0-only
* See the LICENSE file for details.
*/

import assert from "node:assert/strict";
import { test } from "node:test";
import { getAttachmentUploadMessage } from "./attachment-activity.ts";

const keyPrefix = "b807ccfa-f160-4ee3-af9c-f15cd7fc574d/c76f3ef65be54f83b15a8db228887ac2-";

test("upload activity preserves the filename exactly, including spaces, punctuation and non-ASCII characters", () => {
for (const name of ["Q4 – résumé (final)-2.pdf", "100% #1.csv", "README"]) {
assert.equal(getAttachmentUploadMessage(keyPrefix + name), `uploaded “${name}”`);
}
});

test("upload activity falls back to a generic message for missing and unrecognized asset keys", () => {
for (const asset of [null, undefined, "", keyPrefix, "https://storage.example.com/" + keyPrefix + "a.txt?sig=abc"]) {
assert.equal(getAttachmentUploadMessage(asset), "uploaded a new attachment");
}
});
11 changes: 11 additions & 0 deletions apps/web/helpers/attachment-activity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) 2023-present Plane Software, Inc. and contributors
* SPDX-License-Identifier: AGPL-3.0-only
* See the LICENSE file for details.
*/

export function getAttachmentUploadMessage(asset: string | null | undefined): string {
// Upload activities store the object key as <workspace UUID>/<random hex UUID>-<filename>.
const fileName = asset?.match(/^[\da-f-]{36}\/[\da-f]{32}-([^/]+)$/i)?.[1];
return fileName ? `uploaded “${fileName}”` : "uploaded a new attachment";
}
8 changes: 4 additions & 4 deletions apps/web/store/issue/issue-details/attachment.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See the LICENSE file for details.
*/

import { uniq, pull, set, debounce, update, concat } from "lodash-es";
import { uniq, pull, set, debounce, update, orderBy } from "lodash-es";
import { action, computed, makeObservable, observable, runInAction } from "mobx";
import { computedFn } from "mobx-utils";
import { v4 as uuidv4 } from "uuid";
Expand Down Expand Up @@ -121,8 +121,9 @@ export class IssueAttachmentStore implements IIssueAttachmentStore {
if (attachments && attachments.length > 0) {
const newAttachmentIds = attachments.map((attachment) => attachment.id);
runInAction(() => {
update(this.attachments, [issueId], (attachmentIds = []) => uniq(concat(attachmentIds, newAttachmentIds)));
attachments.forEach((attachment) => set(this.attachmentMap, attachment.id, attachment));
const ids = uniq([...(this.attachments[issueId] ?? []), ...newAttachmentIds]);
this.attachments[issueId] = orderBy(ids, (id) => Date.parse(this.attachmentMap[id].created_at), "desc");
});
}
};
Expand Down Expand Up @@ -165,8 +166,7 @@ export class IssueAttachmentStore implements IIssueAttachmentStore {

if (response && response.id) {
runInAction(() => {
update(this.attachments, [issueId], (attachmentIds = []) => uniq(concat(attachmentIds, [response.id])));
set(this.attachmentMap, response.id, response);
this.addAttachments(issueId, [response]);
this.rootIssueStore.issues.updateIssue(issueId, {
attachment_count: this.getAttachmentsCountByIssueId(issueId),
});
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/issues/issue_attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type TIssueAttachment = {
asset_url: string;
issue_id: string;
// required
created_at: string;
updated_at: string;
updated_by: string;
created_by: string;
Expand Down