feat: [OCISDEV-282] user type upgrade/downgrade (#11678)

* feat: [OCISDEV-282] user type upgrade/downgrade
* the storage utils pkg separated
* extended the test coverage
* the failures added to expected
This commit is contained in:
Roman Perekhod authored and GitHub committed 2025-09-26 17:04:01 +02:00
1 parent e4dec40f04
commit 2c7f57865f
10 files changed
+752 -30

No files matched your search

+26
View File
@@ -7,6 +7,7 @@ import (
"net/http"
"time"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/render"
libregraph "github.com/owncloud/libre-graph-api-go"
@@ -106,6 +107,11 @@ func New(e ErrorCode, msg string) Error {
}
}
// New errorcode.Error from cs3rpc Status Code
func NewFromStatusCode(code rpc.Code, msg string) Error {
return New(cs3StatusToErrCode(code), msg)
}
// Render writes a Graph ErrorCode object to the response writer
func (e ErrorCode) Render(w http.ResponseWriter, r *http.Request, status int, msg string) {
render.Status(r, status)
@@ -206,3 +212,23 @@ func ToError(err error) (Error, bool) {
return Error{}, false
}
func cs3StatusToErrCode(code rpc.Code) (errcode ErrorCode) {
switch code {
case rpc.Code_CODE_UNAUTHENTICATED:
errcode = Unauthenticated
case rpc.Code_CODE_PERMISSION_DENIED:
errcode = AccessDenied
case rpc.Code_CODE_NOT_FOUND:
errcode = ItemNotFound
case rpc.Code_CODE_LOCKED:
errcode = ItemIsLocked
case rpc.Code_CODE_INVALID_ARGUMENT:
errcode = InvalidRequest
case rpc.Code_CODE_FAILED_PRECONDITION:
errcode = InvalidRequest
default:
errcode = GeneralException
}
return errcode
}