Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return user type in the response of the ocs GET user call #2256

Merged
merged 3 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/ocs-user-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Return user type in the response of the ocs GET user call

https://github.com/cs3org/reva/pull/2256
21 changes: 21 additions & 0 deletions internal/http/services/owncloud/ocs/conversions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,24 @@ func ParseTimestamp(timestampString string) (*types.Timestamp, error) {
Nanos: uint32(final % 1000000000),
}, nil
}

// UserTypeString returns human readable strings for various user types
func UserTypeString(userType userpb.UserType) string {
switch userType {
case userpb.UserType_USER_TYPE_PRIMARY:
return "primary"
case userpb.UserType_USER_TYPE_SECONDARY:
return "secondary"
case userpb.UserType_USER_TYPE_SERVICE:
return "service"
case userpb.UserType_USER_TYPE_APPLICATION:
return "application"
case userpb.UserType_USER_TYPE_GUEST:
return "guest"
case userpb.UserType_USER_TYPE_FEDERATED:
return "federated"
case userpb.UserType_USER_TYPE_LIGHTWEIGHT:
return "lightweight"
}
return "invalid"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"net/http"

"github.com/cs3org/reva/internal/http/services/owncloud/ocs/conversions"
"github.com/cs3org/reva/internal/http/services/owncloud/ocs/response"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
)
Expand All @@ -45,6 +46,7 @@ func (h *Handler) GetSelf(w http.ResponseWriter, r *http.Request) {
ID: u.Username,
DisplayName: u.DisplayName,
Email: u.Mail,
UserType: conversions.UserTypeString(u.Id.Type),
})
}

Expand All @@ -54,4 +56,5 @@ type User struct {
ID string `json:"id" xml:"id"`
DisplayName string `json:"display-name" xml:"display-name"`
Email string `json:"email" xml:"email"`
UserType string `json:"user-type" xml:"user-type"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/internal/http/services/owncloud/ocdav"
"github.com/cs3org/reva/internal/http/services/owncloud/ocs/config"
"github.com/cs3org/reva/internal/http/services/owncloud/ocs/conversions"
"github.com/cs3org/reva/internal/http/services/owncloud/ocs/response"
"github.com/cs3org/reva/pkg/appctx"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
Expand Down Expand Up @@ -65,6 +66,7 @@ type Users struct {
Quota *Quota `json:"quota" xml:"quota"`
Email string `json:"email" xml:"email"`
DisplayName string `json:"displayname" xml:"displayname"`
UserType string `json:"user-type" xml:"user-type"`
// FIXME home should never be exposed ... even in oc 10
// home
TwoFactorAuthEnabled bool `json:"two_factor_auth_enabled" xml:"two_factor_auth_enabled"`
Expand Down Expand Up @@ -145,5 +147,6 @@ func (h *Handler) GetUsers(w http.ResponseWriter, r *http.Request) {
},
DisplayName: u.DisplayName,
Email: u.Mail,
UserType: conversions.UserTypeString(u.Id.Type),
})
}