@@ -106,6 +106,17 @@ func (m *publicShareMgr) CreatePublicShare(ctx context.Context, u *user.User, md
106
106
NotifyUploadsExtraRecipients : notifyUploadsExtraRecipients ,
107
107
}
108
108
109
+ // Create Shared ID
110
+ id , err := createID (m .db )
111
+ if err != nil {
112
+ return nil , errors .Wrap (err , "failed to create id for PublicShare" )
113
+ }
114
+
115
+ publiclink .BaseModel = model.BaseModel {
116
+ Id : id ,
117
+ ShareId : model.ShareID {ID : id },
118
+ }
119
+
109
120
publiclink .UIDOwner = conversions .FormatUserID (md .Owner )
110
121
publiclink .UIDInitiator = conversions .FormatUserID (user .Id )
111
122
publiclink .InitialPath = md .Path
@@ -155,30 +166,46 @@ func (m *publicShareMgr) UpdatePublicShare(ctx context.Context, u *user.User, re
155
166
var res * gorm.DB
156
167
switch req .GetUpdate ().GetType () {
157
168
case link .UpdatePublicShareRequest_Update_TYPE_DISPLAYNAME :
158
- res = m .db .Model (& publiclink ).Update ("link_name" , req .Update .GetDisplayName ())
169
+ res = m .db .Model (& publiclink ).
170
+ Where ("id = ?" , publiclink .Id ).
171
+ Update ("link_name" , req .Update .GetDisplayName ())
159
172
case link .UpdatePublicShareRequest_Update_TYPE_PERMISSIONS :
160
173
permissions := conversions .SharePermToInt (req .Update .GetGrant ().GetPermissions ().Permissions )
161
- res = m .db .Model (& publiclink ).Update ("permissions" , uint8 (permissions ))
174
+ res = m .db .Model (& publiclink ).
175
+ Where ("id = ?" , publiclink .Id ).
176
+ Update ("permissions" , uint8 (permissions ))
162
177
case link .UpdatePublicShareRequest_Update_TYPE_EXPIRATION :
163
- res = m .db .Model (& publiclink ).Update ("expiration" , time .Unix (int64 (req .Update .GetGrant ().Expiration .Seconds ), 0 ))
178
+ res = m .db .Model (& publiclink ).
179
+ Where ("id = ?" , publiclink .Id ).
180
+ Update ("expiration" , time .Unix (int64 (req .Update .GetGrant ().Expiration .Seconds ), 0 ))
164
181
case link .UpdatePublicShareRequest_Update_TYPE_PASSWORD :
165
182
if req .Update .GetGrant ().Password == "" {
166
183
// Remove the password
167
- res = m .db .Model (& publiclink ).Update ("password" , "" )
184
+ res = m .db .Model (& publiclink ).
185
+ Where ("id = ?" , publiclink .Id ).
186
+ Update ("password" , "" )
168
187
} else {
169
188
// Update the password
170
189
hashedPwd , err := hashPassword (req .Update .GetGrant ().Password , m .c .LinkPasswordHashCost )
171
190
if err != nil {
172
191
return nil , errors .Wrap (err , "could not hash share password" )
173
192
}
174
- res = m .db .Model (& publiclink ).Update ("password" , hashedPwd )
193
+ res = m .db .Model (& publiclink ).
194
+ Where ("id = ?" , publiclink .Id ).
195
+ Update ("password" , hashedPwd )
175
196
}
176
197
case link .UpdatePublicShareRequest_Update_TYPE_DESCRIPTION :
177
- res = m .db .Model (& publiclink ).Update ("description" , req .Update .GetDescription ())
198
+ res = m .db .Model (& publiclink ).
199
+ Where ("id = ?" , publiclink .Id ).
200
+ Update ("description" , req .Update .GetDescription ())
178
201
case link .UpdatePublicShareRequest_Update_TYPE_NOTIFYUPLOADS :
179
- res = m .db .Model (& publiclink ).Update ("notify_uploads" , req .Update .GetNotifyUploads ())
202
+ res = m .db .Model (& publiclink ).
203
+ Where ("id = ?" , publiclink .Id ).
204
+ Update ("notify_uploads" , req .Update .GetNotifyUploads ())
180
205
case link .UpdatePublicShareRequest_Update_TYPE_NOTIFYUPLOADSEXTRARECIPIENTS :
181
- res = m .db .Model (& publiclink ).Update ("notify_uploads_extra_recipients" , req .Update .GetNotifyUploadsExtraRecipients ())
206
+ res = m .db .Model (& publiclink ).
207
+ Where ("id = ?" , publiclink .Id ).
208
+ Update ("notify_uploads_extra_recipients" , req .Update .GetNotifyUploadsExtraRecipients ())
182
209
default :
183
210
return nil , fmt .Errorf ("invalid update type: %v" , req .GetUpdate ().GetType ())
184
211
}
@@ -249,7 +276,7 @@ func (m *publicShareMgr) RevokePublicShare(ctx context.Context, u *user.User, re
249
276
if err != nil {
250
277
return err
251
278
}
252
- res := m .db .Delete (& publiclink )
279
+ res := m .db .Where ( "id = ?" , publiclink . Id ). Delete (& publiclink )
253
280
return res .Error
254
281
255
282
}
@@ -284,7 +311,7 @@ func (m *publicShareMgr) GetPublicShareByToken(ctx context.Context, token string
284
311
// Get Link by ID. Does not return orphans or expired links.
285
312
func (m * publicShareMgr ) getLinkByID (ctx context.Context , id * link.PublicShareId ) (* model.PublicLink , error ) {
286
313
var link model.PublicLink
287
- res := m .db .First ( & link , id .OpaqueId )
314
+ res := m .db .Where ( "id = ?" , id .OpaqueId ). First ( & link )
288
315
289
316
if res .RowsAffected == 0 || link .Orphan || isExpired (link ) {
290
317
return nil , errtypes .NotFound (id .OpaqueId )
@@ -375,8 +402,8 @@ func emptyLinkWithId(id string) (*model.PublicLink, error) {
375
402
}
376
403
share := & model.PublicLink {
377
404
ProtoShare : model.ProtoShare {
378
- Model : gorm. Model {
379
- ID : uint (intId ),
405
+ BaseModel : model. BaseModel {
406
+ Id : uint (intId ),
380
407
},
381
408
},
382
409
}
0 commit comments