@@ -31,6 +31,7 @@ import (
31
31
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
32
32
)
33
33
34
+ // DBShare stores information about user and public shares.
34
35
type DBShare struct {
35
36
ID string
36
37
UIDOwner string
@@ -48,6 +49,7 @@ type DBShare struct {
48
49
State int
49
50
}
50
51
52
+ // FormatGrantee formats a CS3API grantee to a string
51
53
func FormatGrantee (g * provider.Grantee ) (int , string ) {
52
54
var granteeType int
53
55
var formattedID string
@@ -64,6 +66,7 @@ func FormatGrantee(g *provider.Grantee) (int, string) {
64
66
return granteeType , formattedID
65
67
}
66
68
69
+ // ExtractGrantee retrieves the CS3API grantee from a formatted string
67
70
func ExtractGrantee (t int , g string ) * provider.Grantee {
68
71
var grantee * provider.Grantee
69
72
switch t {
@@ -79,6 +82,7 @@ func ExtractGrantee(t int, g string) *provider.Grantee {
79
82
return grantee
80
83
}
81
84
85
+ // ResourceTypeToItem maps a resource type to an integer
82
86
func ResourceTypeToItem (r provider.ResourceType ) string {
83
87
switch r {
84
88
case provider .ResourceType_RESOURCE_TYPE_FILE :
@@ -94,6 +98,7 @@ func ResourceTypeToItem(r provider.ResourceType) string {
94
98
}
95
99
}
96
100
101
+ // SharePermToInt maps read/write permissions to an integer
97
102
func SharePermToInt (p * provider.ResourcePermissions ) int {
98
103
var perm int
99
104
if p .CreateContainer {
@@ -104,6 +109,7 @@ func SharePermToInt(p *provider.ResourcePermissions) int {
104
109
return perm
105
110
}
106
111
112
+ // IntTosharePerm retrieves read/write permissions from an integer
107
113
func IntTosharePerm (p int ) * provider.ResourcePermissions {
108
114
switch p {
109
115
case 1 :
@@ -141,6 +147,7 @@ func IntTosharePerm(p int) *provider.ResourcePermissions {
141
147
}
142
148
}
143
149
150
+ // IntToShareState retrieves the received share state from an integer
144
151
func IntToShareState (g int ) collaboration.ShareState {
145
152
switch g {
146
153
case 0 :
@@ -152,13 +159,15 @@ func IntToShareState(g int) collaboration.ShareState {
152
159
}
153
160
}
154
161
162
+ // FormatUserID formats a CS3API user ID to a string
155
163
func FormatUserID (u * userpb.UserId ) string {
156
164
if u .Idp != "" {
157
165
return fmt .Sprintf ("%s:%s" , u .OpaqueId , u .Idp )
158
166
}
159
167
return u .OpaqueId
160
168
}
161
169
170
+ // ExtractUserID retrieves a CS3API user ID from a string
162
171
func ExtractUserID (u string ) * userpb.UserId {
163
172
parts := strings .Split (u , ":" )
164
173
if len (parts ) > 1 {
@@ -167,13 +176,15 @@ func ExtractUserID(u string) *userpb.UserId {
167
176
return & userpb.UserId {OpaqueId : parts [0 ]}
168
177
}
169
178
179
+ // FormatGroupID formats a CS3API group ID to a string
170
180
func FormatGroupID (u * grouppb.GroupId ) string {
171
181
if u .Idp != "" {
172
182
return fmt .Sprintf ("%s:%s" , u .OpaqueId , u .Idp )
173
183
}
174
184
return u .OpaqueId
175
185
}
176
186
187
+ // ExtractGroupID retrieves a CS3API group ID from a string
177
188
func ExtractGroupID (u string ) * grouppb.GroupId {
178
189
parts := strings .Split (u , ":" )
179
190
if len (parts ) > 1 {
@@ -182,6 +193,7 @@ func ExtractGroupID(u string) *grouppb.GroupId {
182
193
return & grouppb.GroupId {OpaqueId : parts [0 ]}
183
194
}
184
195
196
+ // ConvertToCS3Share converts a DBShare to a CS3API collaboration share
185
197
func ConvertToCS3Share (s DBShare ) * collaboration.Share {
186
198
ts := & typespb.Timestamp {
187
199
Seconds : uint64 (s .STime ),
@@ -200,6 +212,7 @@ func ConvertToCS3Share(s DBShare) *collaboration.Share {
200
212
}
201
213
}
202
214
215
+ // ConvertToCS3ReceivedShare converts a DBShare to a CS3API collaboration received share
203
216
func ConvertToCS3ReceivedShare (s DBShare ) * collaboration.ReceivedShare {
204
217
share := ConvertToCS3Share (s )
205
218
return & collaboration.ReceivedShare {
@@ -208,6 +221,7 @@ func ConvertToCS3ReceivedShare(s DBShare) *collaboration.ReceivedShare {
208
221
}
209
222
}
210
223
224
+ // ConvertToCS3PublicShare converts a DBShare to a CS3API public share
211
225
func ConvertToCS3PublicShare (s DBShare ) * link.PublicShare {
212
226
ts := & typespb.Timestamp {
213
227
Seconds : uint64 (s .STime ),
0 commit comments