11960: Fix permission checking for events on trashed collections.
[arvados.git] / services / ws / session_v0.go
index 1cb302170b9f68dcff48f50e435c750a2c50adc5..daa5208d0fef564e4b02759e2f8665f6447b8fa9 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 package main
 
 import (
@@ -8,6 +12,7 @@ import (
        "sync/atomic"
        "time"
 
+       "git.curoverse.com/arvados.git/sdk/go/arvados"
        "github.com/Sirupsen/logrus"
 )
 
@@ -15,13 +20,23 @@ var (
        errQueueFull   = errors.New("client queue full")
        errFrameTooBig = errors.New("frame too big")
 
-       sendObjectAttributes = []string{"state", "name"}
+       // Send clients only these keys from the
+       // log.properties.old_attributes and
+       // log.properties.new_attributes hashes.
+       sendObjectAttributes = []string{
+               "is_trashed",
+               "name",
+               "owner_uuid",
+               "portable_data_hash",
+               "state",
+       }
 
        v0subscribeOK   = []byte(`{"status":200}`)
        v0subscribeFail = []byte(`{"status":400}`)
 )
 
 type v0session struct {
+       ac            *arvados.Client
        ws            wsConn
        sendq         chan<- interface{}
        db            *sql.DB
@@ -33,11 +48,15 @@ type v0session struct {
        setupOnce     sync.Once
 }
 
-func newSessionV0(ws wsConn, sendq chan<- interface{}, db *sql.DB, pc permChecker) (session, error) {
+// newSessionV0 returns a v0 session: a partial port of the Rails/puma
+// implementation, with just enough functionality to support Workbench
+// and arv-mount.
+func newSessionV0(ws wsConn, sendq chan<- interface{}, db *sql.DB, pc permChecker, ac *arvados.Client) (session, error) {
        sess := &v0session{
                sendq:       sendq,
                ws:          ws,
                db:          db,
+               ac:          ac,
                permChecker: pc,
                log:         logger(ws.Request().Context()),
        }
@@ -85,13 +104,16 @@ func (sess *v0session) EventMessage(e *event) ([]byte, error) {
                return nil, err
        }
 
+       kind, _ := sess.ac.KindForUUID(detail.ObjectUUID)
        msg := map[string]interface{}{
                "msgID":             atomic.AddUint64(&sess.lastMsgID, 1),
                "id":                detail.ID,
                "uuid":              detail.UUID,
                "object_uuid":       detail.ObjectUUID,
                "object_owner_uuid": detail.ObjectOwnerUUID,
+               "object_kind":       kind,
                "event_type":        detail.EventType,
+               "event_at":          detail.EventAt,
        }
        if detail.Properties != nil && detail.Properties["text"] != nil {
                msg["properties"] = detail.Properties
@@ -148,6 +170,7 @@ func (sub *v0subscribe) sendOldEvents(sess *v0session) {
                sess.log.WithError(err).Error("db.Query failed")
                return
        }
+       defer rows.Close()
        for rows.Next() {
                var id uint64
                err := rows.Scan(&id)