-
Notifications
You must be signed in to change notification settings - Fork 180
/
producer.go
170 lines (153 loc) · 4.51 KB
/
producer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* Copyright (c) 2018. Abstrium SAS <team (at) pydio.com>
* This file is part of Pydio Cells.
*
* Pydio Cells is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio Cells is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio Cells. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com>.
*/
package activity
import (
"time"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/pydio/cells/common/proto/activity"
"github.com/pydio/cells/common/proto/idm"
"github.com/pydio/cells/common/proto/tree"
)
func AclActivity(author string, workspace *idm.Workspace, permission string) (ac *activity.Object) {
ac = createObject()
ac.Type = activity.ObjectType_Share
t := activity.ObjectType_Workspace
if workspace.Scope == idm.WorkspaceScope_ROOM {
t = activity.ObjectType_Cell
}
ac.Object = &activity.Object{
Type: t,
Name: workspace.Label,
Id: workspace.UUID,
}
ac.Actor = &activity.Object{
Type: activity.ObjectType_Person,
Name: author,
Id: author,
}
ac.Updated = ×tamp.Timestamp{
Seconds: time.Now().Unix(),
}
return
}
func DocumentActivity(author string, event *tree.NodeChangeEvent) (ac *activity.Object, detectedNode *tree.Node) {
ac = createObject()
ac.Name = "File Event"
switch event.Type {
case tree.NodeChangeEvent_CREATE:
// log.Printf("CREATE %v", event.Type)
ac.Type = activity.ObjectType_Create
if event.Target.IsLeaf() {
ac.Object = &activity.Object{
Type: activity.ObjectType_Document,
}
} else {
ac.Object = &activity.Object{
Type: activity.ObjectType_Folder,
}
}
ac.Object.Name = event.Target.Path
ac.Object.Id = event.Target.Uuid
detectedNode = event.Target
case tree.NodeChangeEvent_READ:
// log.Printf("CREATE %v", event.Type)
ac.Type = activity.ObjectType_Read
if event.Target.IsLeaf() {
ac.Object = &activity.Object{
Type: activity.ObjectType_Document,
}
} else {
ac.Object = &activity.Object{
Type: activity.ObjectType_Folder,
}
}
ac.Object.Name = event.Target.Path
ac.Object.Id = event.Target.Uuid
detectedNode = event.Target
case tree.NodeChangeEvent_DELETE:
// log.Printf("DELETE %v", event.Type)
ac.Type = activity.ObjectType_Delete
if event.Source.IsLeaf() {
ac.Object = &activity.Object{
Type: activity.ObjectType_Document,
}
} else {
ac.Object = &activity.Object{
Type: activity.ObjectType_Folder,
}
}
ac.Object.Name = event.Source.Path
ac.Object.Id = event.Source.Uuid
detectedNode = event.Source
case tree.NodeChangeEvent_UPDATE_PATH:
// log.Printf("MOVE %v", event.Type)
ac.Type = activity.ObjectType_Move
ac.Object = &activity.Object{
Type: activity.ObjectType_Document,
Name: event.Target.Path,
Id: event.Target.Uuid,
}
ac.Origin = &activity.Object{
Type: activity.ObjectType_Document,
Name: event.Source.Path,
Id: event.Source.Uuid,
}
ac.Target = &activity.Object{
Type: activity.ObjectType_Document,
Name: event.Target.Path,
Id: event.Target.Uuid,
}
detectedNode = event.Target
case tree.NodeChangeEvent_UPDATE_CONTENT, tree.NodeChangeEvent_UPDATE_META:
// log.Printf("UPDATE %v", event.Type)
ac.Type = activity.ObjectType_Update
ac.Object = &activity.Object{
Type: activity.ObjectType_Document,
Name: event.Target.Path,
Id: event.Target.Uuid,
}
detectedNode = event.Target
case tree.NodeChangeEvent_UPDATE_USER_META:
// log.Printf("UPDATE %v", event.Type)
ac.Type = activity.ObjectType_UpdateMeta
ac.Object = &activity.Object{
Type: activity.ObjectType_Document,
Name: event.Target.Path,
Id: event.Target.Uuid,
}
if event.Target.GetStringMeta("comments") != "" {
ac.Type = activity.ObjectType_UpdateComment
ac.Items = []*activity.Object{{
Type: activity.ObjectType_Note,
Summary: event.Target.GetStringMeta("comments"),
}}
}
detectedNode = event.Target
}
ac.Actor = &activity.Object{
Type: activity.ObjectType_Person,
Name: author,
Id: author,
}
ac.Updated = ×tamp.Timestamp{
Seconds: time.Now().Unix(),
}
return ac, detectedNode
}