Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9b566d0b5 | ||
|
|
db54ca993f |
No files matched your search
@@ -0,0 +1,5 @@
|
||||
Enhancement: Notify the user when an upload fails to finalize
|
||||
|
||||
When an async blob commit fails after postprocessing and the node is reverted, the uploading user now receives a persisted "Upload failed" notification identifying the file, and the stale upload row is removed from the file list instead of the failure being silent.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12987
|
||||
@@ -1,5 +1,12 @@
|
||||
package service
|
||||
|
||||
type PostprocessingOutcome string
|
||||
|
||||
const (
|
||||
OutcomeSuccess PostprocessingOutcome = ""
|
||||
OutcomeFailed PostprocessingOutcome = "failed"
|
||||
)
|
||||
|
||||
// FileEvent is emitted when a file is uploaded/renamed/deleted/...
|
||||
type FileEvent struct {
|
||||
ParentItemID string `json:"parentitemid"`
|
||||
@@ -8,6 +15,8 @@ type FileEvent struct {
|
||||
InitiatorID string `json:"initiatorid"`
|
||||
Etag string `json:"etag"`
|
||||
|
||||
Outcome PostprocessingOutcome `json:"outcome,omitempty"`
|
||||
|
||||
// Only in case of sharing (refactor this into separate struct when more fields are needed)
|
||||
AffectedUserIDs []string `json:"affecteduserids"`
|
||||
}
|
||||
|
||||
@@ -143,8 +143,16 @@ func (cl *ClientlogService) processEvent(event events.Event) {
|
||||
err = errors.New("unhandled event")
|
||||
case events.UploadReady:
|
||||
if e.Failed {
|
||||
// we don't inform about failed uploads yet
|
||||
return
|
||||
// node reverted, resource gone: build the payload from the event, not the gateway.
|
||||
evType = "postprocessing-finished"
|
||||
users = []string{e.ExecutingUser.GetId().GetOpaqueId()}
|
||||
data = FileEvent{
|
||||
ItemID: storagespace.FormatResourceID(e.ResourceID),
|
||||
SpaceID: storagespace.FormatStorageID(e.ResourceID.GetStorageId(), e.ResourceID.GetSpaceId()),
|
||||
InitiatorID: event.InitiatorID,
|
||||
Outcome: OutcomeFailed,
|
||||
}
|
||||
break
|
||||
}
|
||||
fileEv("postprocessing-finished", e.FileRef)
|
||||
case events.ItemTrashed:
|
||||
|
||||
@@ -33,6 +33,7 @@ import (
|
||||
var _registeredEvents = []events.Unmarshaller{
|
||||
// file related
|
||||
events.PostprocessingStepFinished{},
|
||||
events.UploadReady{},
|
||||
|
||||
// space related
|
||||
events.SpaceDisabled{},
|
||||
|
||||
@@ -97,6 +97,8 @@ func (c *Converter) ConvertEvent(eventid string, event interface{}) (OC10Notific
|
||||
default:
|
||||
return OC10Notification{}, fmt.Errorf("unknown postprocessing step: %s", ev.FinishedStep)
|
||||
}
|
||||
case events.UploadReady:
|
||||
return c.uploadFailedMessage(eventid, UploadFailed, ev.ExecutingUser, ev.ResourceID, ev.Filename, utils.TSToTime(ev.Timestamp))
|
||||
|
||||
// space related
|
||||
case events.SpaceDisabled:
|
||||
@@ -390,6 +392,36 @@ func (c *Converter) policiesMessage(eventid string, nt NotificationTemplate, exe
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Converter) uploadFailedMessage(eventid string, nt NotificationTemplate, executant *user.User, rid *storageprovider.ResourceId, filename string, ts time.Time) (OC10Notification, error) {
|
||||
// node reverted: compose from the event's filename, not a gateway lookup.
|
||||
subj, subjraw, msg, msgraw, err := composeMessage(nt, c.locale, c.defaultLanguage, c.translationPath, map[string]interface{}{
|
||||
"resourcename": filename,
|
||||
})
|
||||
if err != nil {
|
||||
return OC10Notification{}, err
|
||||
}
|
||||
|
||||
dets := map[string]interface{}{
|
||||
"resource": map[string]string{
|
||||
"name": filename,
|
||||
},
|
||||
}
|
||||
|
||||
return OC10Notification{
|
||||
EventID: eventid,
|
||||
Service: c.serviceName,
|
||||
UserName: executant.GetUsername(),
|
||||
Timestamp: ts.Format(time.RFC3339Nano),
|
||||
ResourceID: storagespace.FormatResourceID(rid),
|
||||
ResourceType: _resourceTypeResource,
|
||||
Subject: subj,
|
||||
SubjectRaw: subjraw,
|
||||
Message: msg,
|
||||
MessageRaw: msgraw,
|
||||
MessageDetails: dets,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Converter) deprovisionMessage(nt NotificationTemplate, deproDate string) (OC10Notification, error) {
|
||||
subj, subjraw, msg, msgraw, err := composeMessage(nt, c.locale, c.defaultLanguage, c.translationPath, map[string]interface{}{
|
||||
"date": deproDate,
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package service_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
"github.com/owncloud/reva/v2/pkg/events"
|
||||
|
||||
"github.com/owncloud/ocis/v2/services/userlog/pkg/service"
|
||||
)
|
||||
|
||||
// nil gateway selector proves the notification is built without a lookup.
|
||||
func TestConvertEventUploadFailed(t *testing.T) {
|
||||
c := service.NewConverter(context.Background(), "en", nil, "userlog", "", "en")
|
||||
|
||||
ev := events.UploadReady{
|
||||
Failed: true,
|
||||
Filename: "big-upload.iso",
|
||||
ExecutingUser: &user.User{
|
||||
Id: &user.UserId{OpaqueId: "user-1"},
|
||||
Username: "einstein",
|
||||
},
|
||||
ResourceID: &provider.ResourceId{
|
||||
StorageId: "storage-1",
|
||||
SpaceId: "space-1",
|
||||
OpaqueId: "item-1",
|
||||
},
|
||||
}
|
||||
|
||||
n, err := c.ConvertEvent("event-1", ev)
|
||||
if err != nil {
|
||||
t.Fatalf("ConvertEvent returned error: %v", err)
|
||||
}
|
||||
|
||||
if n.Subject != "Upload failed" {
|
||||
t.Errorf("unexpected subject: %q", n.Subject)
|
||||
}
|
||||
if want := "The upload of big-upload.iso could not be finalized. Please try again."; n.Message != want {
|
||||
t.Errorf("unexpected message: got %q want %q", n.Message, want)
|
||||
}
|
||||
if n.UserName != "einstein" {
|
||||
t.Errorf("unexpected username: %q", n.UserName)
|
||||
}
|
||||
if n.ResourceID != "storage-1$space-1!item-1" {
|
||||
t.Errorf("unexpected resource id: %q", n.ResourceID)
|
||||
}
|
||||
}
|
||||
@@ -162,6 +162,11 @@ func (ul *UserlogService) processEvent(event events.Event) {
|
||||
default:
|
||||
return
|
||||
}
|
||||
case events.UploadReady:
|
||||
if !e.Failed {
|
||||
return
|
||||
}
|
||||
users = append(users, e.ExecutingUser.GetId().GetOpaqueId())
|
||||
|
||||
// space related // TODO: how to find spaceadmins?
|
||||
case events.SpaceDisabled:
|
||||
|
||||
@@ -14,6 +14,11 @@ var (
|
||||
Message: l10n.Template("File {resource} was deleted because it violates the policies"),
|
||||
}
|
||||
|
||||
UploadFailed = NotificationTemplate{
|
||||
Subject: l10n.Template("Upload failed"),
|
||||
Message: l10n.Template("The upload of {resource} could not be finalized. Please try again."),
|
||||
}
|
||||
|
||||
SpaceShared = NotificationTemplate{
|
||||
Subject: l10n.Template("Space shared"),
|
||||
Message: l10n.Template("{user} added you to Space {space}"),
|
||||
|
||||
@@ -77,6 +77,15 @@ export const onSSEProcessingFinishedEvent = async ({
|
||||
previewService,
|
||||
processedItems
|
||||
}: SSEEventOptions) => {
|
||||
// finalize failed, node reverted: drop the optimistic row (incl. on the initiator).
|
||||
if (sseData.outcome === 'failed') {
|
||||
const failedResource = resourcesStore.resources.find((f) => f.id === sseData.itemid)
|
||||
if (failedResource) {
|
||||
resourcesStore.removeResources([failedResource])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (!isItemInCurrentFolder({ resourcesStore, parentFolderId: sseData.parentitemid })) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ export const eventSchema = z.object({
|
||||
spaceid: z.string().optional(),
|
||||
initiatorid: z.string().optional(),
|
||||
etag: z.string().optional(),
|
||||
affecteduserids: z.array(z.string()).optional().nullable()
|
||||
affecteduserids: z.array(z.string()).optional().nullable(),
|
||||
outcome: z.enum(['failed']).optional()
|
||||
})
|
||||
|
||||
export type EventSchemaType = z.infer<typeof eventSchema>
|
||||
|
||||
@@ -120,6 +120,50 @@ describe('file events', () => {
|
||||
expect(mocks.resourcesStore.upsertResource).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
describe('onSSEProcessingFinishedEvent', () => {
|
||||
it('removes the resource when the upload failed to finalize', async () => {
|
||||
const failedResource = mock<Resource>({
|
||||
id: 'file1',
|
||||
storageId: 'space1',
|
||||
parentFolderId: 'currenFolder!currentFolder'
|
||||
})
|
||||
const mocks = getMocks({ resources: [failedResource] })
|
||||
const sseData = mock<EventSchemaType>({
|
||||
itemid: failedResource.id,
|
||||
spaceid: failedResource.storageId,
|
||||
outcome: 'failed'
|
||||
})
|
||||
await onSSEProcessingFinishedEvent({ sseData, ...mocks })
|
||||
expect(mocks.resourcesStore.removeResources).toHaveBeenCalledWith([failedResource])
|
||||
expect(mocks.messageStore.showMessage).not.toHaveBeenCalled()
|
||||
})
|
||||
it('removes the failed resource even when initiated by the current client', async () => {
|
||||
const failedResource = mock<Resource>({
|
||||
id: 'file1',
|
||||
storageId: 'space1',
|
||||
parentFolderId: 'currenFolder!currentFolder'
|
||||
})
|
||||
const mocks = getMocks({ resources: [failedResource] })
|
||||
const sseData = mock<EventSchemaType>({
|
||||
itemid: failedResource.id,
|
||||
spaceid: failedResource.storageId,
|
||||
initiatorid: 'local1',
|
||||
outcome: 'failed'
|
||||
})
|
||||
await onSSEProcessingFinishedEvent({ sseData, ...mocks })
|
||||
expect(mocks.resourcesStore.removeResources).toHaveBeenCalledWith([failedResource])
|
||||
})
|
||||
it('does not remove anything when the failed resource is not in the store', async () => {
|
||||
const mocks = getMocks()
|
||||
const sseData = mock<EventSchemaType>({
|
||||
itemid: 'filesomewhereelse',
|
||||
spaceid: 'space1',
|
||||
outcome: 'failed'
|
||||
})
|
||||
await onSSEProcessingFinishedEvent({ sseData, ...mocks })
|
||||
expect(mocks.resourcesStore.removeResources).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
describe('onSSEItemTrashedEvent', () => {
|
||||
it('calls "removeResources" when resource has been trashed', async () => {
|
||||
const resourceToTrash = mock<Resource>({
|
||||
|
||||
Reference in new issue
Block a user