fix persanal space creating
This commit is contained in:
1 parent
b44091a077
commit
0151111d59
2 files changed
+34
-34
No files matched your search
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/v2/services/graph/pkg/errorcode"
|
||||
revactx "github.com/owncloud/reva/v2/pkg/ctx"
|
||||
"github.com/owncloud/reva/v2/pkg/rgrpc/status"
|
||||
"github.com/owncloud/reva/v2/pkg/rgrpc/todo/pool"
|
||||
"github.com/owncloud/reva/v2/pkg/utils"
|
||||
"google.golang.org/grpc/metadata"
|
||||
@@ -73,40 +72,41 @@ func (m createHome) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
createHomeRes, err := client.CreateHome(ctx, createHomeReq)
|
||||
if err != nil {
|
||||
m.logger.Err(err).Msg("error calling CreateHome")
|
||||
} else if createHomeRes.Status.Code != rpc.Code_CODE_OK {
|
||||
err := status.NewErrorFromCode(createHomeRes.Status.Code, "gateway")
|
||||
if createHomeRes.Status.Code != rpc.Code_CODE_ALREADY_EXISTS {
|
||||
m.logger.Err(err).Msg("error when calling Createhome")
|
||||
}
|
||||
switch {
|
||||
case createHomeRes.GetStatus().GetCode() == rpc.Code_CODE_OK:
|
||||
m.logger.Info().Interface("userID", u.GetId().GetOpaqueId()).Msg("personal space created")
|
||||
case createHomeRes.GetStatus().GetCode() != rpc.Code_CODE_ALREADY_EXISTS:
|
||||
m.logger.Error().Interface("userID", u.GetId().GetOpaqueId()).Interface("status", createHomeRes.GetStatus()).Msg("personal space creation failed")
|
||||
}
|
||||
|
||||
if spaceID := u.GetId().GetOpaqueId(); spaceID != "" {
|
||||
// Create the "protected-personal" space.
|
||||
// Use the user ID as the space ID if it is a valid uuid or generate a new one.
|
||||
// Replace last 4 chars of the space id with "0000" to make it visible.
|
||||
if err := uuid.Validate(spaceID); err != nil {
|
||||
spaceID = uuid.New().String()
|
||||
}
|
||||
} else if createHomeRes.Status.Code == rpc.Code_CODE_OK {
|
||||
if u != nil {
|
||||
// Create the "protected-personal" space.
|
||||
// Use the user ID as the space ID if it is a valid uuid or generate a new one.
|
||||
// Replace last 4 chars of the space id with "0000" to make it visible.
|
||||
spaceID := u.Id.OpaqueId
|
||||
if err := uuid.Validate(spaceID); err != nil {
|
||||
spaceID = uuid.New().String()
|
||||
}
|
||||
spaceID = spaceID[:len(spaceID)-4] + "0000"
|
||||
spaceID = spaceID[:len(spaceID)-4] + "0000"
|
||||
|
||||
createProtectedSpaceReq := &provider.CreateStorageSpaceRequest{
|
||||
Type: "protected-personal",
|
||||
Name: "Protected Personal",
|
||||
Owner: &userv1beta1.User{
|
||||
Id: u.Id,
|
||||
},
|
||||
Opaque: utils.AppendPlainToOpaque(nil, "spaceid", spaceID),
|
||||
}
|
||||
createProtectedSpaceReq := &provider.CreateStorageSpaceRequest{
|
||||
Type: "protected-personal",
|
||||
Name: "Protected Personal",
|
||||
Owner: &userv1beta1.User{
|
||||
Id: u.Id,
|
||||
},
|
||||
Opaque: utils.AppendPlainToOpaque(nil, "spaceid", spaceID),
|
||||
}
|
||||
|
||||
createProtectedSpaceRes, err := client.CreateStorageSpace(ctx, createProtectedSpaceReq)
|
||||
if err != nil {
|
||||
m.logger.Err(err).Msg("error calling CreateStorageSpace for protected-personal")
|
||||
} else if createProtectedSpaceRes.Status.Code != rpc.Code_CODE_OK && createProtectedSpaceRes.Status.Code != rpc.Code_CODE_ALREADY_EXISTS {
|
||||
m.logger.Error().
|
||||
Interface("status", createProtectedSpaceRes.Status).
|
||||
Str("userid", u.Id.OpaqueId).
|
||||
Msg("error when creating protected-personal space")
|
||||
}
|
||||
cpsRes, err := client.CreateStorageSpace(ctx, createProtectedSpaceReq)
|
||||
if err != nil {
|
||||
m.logger.Err(err).Msg("error calling CreateStorageSpace for protected-personal")
|
||||
}
|
||||
switch {
|
||||
case cpsRes.GetStatus().GetCode() == rpc.Code_CODE_OK:
|
||||
m.logger.Info().Interface("userID", u.GetId().GetOpaqueId()).Msg("protected-personal space created")
|
||||
case cpsRes.GetStatus().GetCode() != rpc.Code_CODE_ALREADY_EXISTS:
|
||||
m.logger.Error().Interface("userID", u.GetId().GetOpaqueId()).Interface("status", cpsRes.GetStatus()).Msg("protected-personal space creation failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ const (
|
||||
_spaceTypeMountpoint = "mountpoint"
|
||||
_spaceTypePersonal = "personal"
|
||||
_spaceTypeProject = "project"
|
||||
_spaceTypeProtectedPersonal = "protected_personal"
|
||||
_spaceTypeProtectedProject = "protected_project"
|
||||
_spaceTypeProtectedPersonal = "protected-personal"
|
||||
_spaceTypeProtectedProject = "protected-project"
|
||||
_spaceTypeGrant = "grant"
|
||||
_slowQueryDuration = 500 * time.Millisecond
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user