Skip to content

Commit

Permalink
Return user type in the response of the ocs GET user call (#2256)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored Dec 1, 2021
1 parent 79fb299 commit e6d302e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
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),
})
}

0 comments on commit e6d302e

Please sign in to comment.