feat: implement edit public link
This commit is contained in:
@@ -654,11 +654,18 @@ func (g Graph) UpdatePermission(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't implement updating link permissions yet
|
// This is a public link
|
||||||
if _, ok := oldPermission.GetLinkOk(); ok {
|
if _, ok := oldPermission.GetLinkOk(); ok {
|
||||||
errorcode.NotSupported.Render(w, r, http.StatusNotImplemented, "not implemented")
|
updatedPermission, err := g.updatePublicLinkPermission(ctx, permissionID, &itemID, permission)
|
||||||
|
if err != nil {
|
||||||
|
errorcode.RenderError(w, r, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
render.Status(r, http.StatusOK)
|
||||||
|
render.JSON(w, r, &updatedPermission)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a user share
|
// This is a user share
|
||||||
updatedPermission, err := g.updateUserShare(ctx, permissionID, oldPermission, permission)
|
updatedPermission, err := g.updateUserShare(ctx, permissionID, oldPermission, permission)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -248,7 +248,30 @@ func (g Graph) updatePublicLinkPassword(ctx context.Context, permissionID string
|
|||||||
return permission, nil
|
return permission, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g Graph) updatePublicLinkPermission(ctx context.Context, permissionID string, info *providerv1beta1.ResourceInfo, newPermission *libregraph.Permission) (perm *libregraph.Permission, err error) {
|
func (g Graph) updatePublicLinkPermission(ctx context.Context, permissionID string, itemID *providerv1beta1.ResourceId, newPermission *libregraph.Permission) (perm *libregraph.Permission, err error) {
|
||||||
|
gatewayClient, err := g.gatewaySelector.Next()
|
||||||
|
if err != nil {
|
||||||
|
g.logger.Error().Err(err).Msg("could not select next gateway client")
|
||||||
|
return nil, errorcode.New(errorcode.GeneralException, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
statResp, err := gatewayClient.Stat(
|
||||||
|
ctx,
|
||||||
|
&providerv1beta1.StatRequest{
|
||||||
|
Ref: &providerv1beta1.Reference{
|
||||||
|
ResourceId: itemID,
|
||||||
|
Path: ".",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
g.logger.Error().Err(err).Msg("transport error, could not stat resource")
|
||||||
|
return nil, errorcode.New(errorcode.GeneralException, err.Error())
|
||||||
|
}
|
||||||
|
if code := statResp.GetStatus().GetCode(); code != rpc.Code_CODE_OK {
|
||||||
|
g.logger.Debug().Interface("itemID", itemID).Msg(statResp.GetStatus().GetMessage())
|
||||||
|
return nil, errorcode.New(cs3StatusToErrCode(code), statResp.GetStatus().GetMessage())
|
||||||
|
}
|
||||||
|
|
||||||
if newPermission.HasExpirationDateTime() {
|
if newPermission.HasExpirationDateTime() {
|
||||||
expirationDate := newPermission.GetExpirationDateTime()
|
expirationDate := newPermission.GetExpirationDateTime()
|
||||||
update := &link.UpdatePublicShareRequest_Update{
|
update := &link.UpdatePublicShareRequest_Update{
|
||||||
@@ -279,7 +302,7 @@ func (g Graph) updatePublicLinkPermission(ctx context.Context, permissionID stri
|
|||||||
libregraph.DriveItemCreateLink{
|
libregraph.DriveItemCreateLink{
|
||||||
Type: &changedLink,
|
Type: &changedLink,
|
||||||
},
|
},
|
||||||
info.GetType(),
|
statResp.GetInfo().GetType(),
|
||||||
)
|
)
|
||||||
update := &link.UpdatePublicShareRequest_Update{
|
update := &link.UpdatePublicShareRequest_Update{
|
||||||
Type: link.UpdatePublicShareRequest_Update_TYPE_PERMISSIONS,
|
Type: link.UpdatePublicShareRequest_Update_TYPE_PERMISSIONS,
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ func permission(v *validator.Validate) {
|
|||||||
sl.ReportError(permission.Id, "Id", "Id", "readonly", "")
|
sl.ReportError(permission.Id, "Id", "Id", "readonly", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, ok := permission.GetHasPasswordOk(); ok {
|
||||||
|
sl.ReportError(permission.HasPassword, "hasPassword", "HasPassword", "readonly", "")
|
||||||
|
}
|
||||||
|
|
||||||
rolesAndActions(sl, permission.Roles, permission.LibreGraphPermissionsActions, true)
|
rolesAndActions(sl, permission.Roles, permission.LibreGraphPermissionsActions, true)
|
||||||
}, s)
|
}, s)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user