Skip to content

Commit

Permalink
Add user type to /cloud/users/ as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Nov 12, 2021
1 parent 4cc6eef commit 48fb8ec
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
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"
}
24 changes: 2 additions & 22 deletions internal/http/services/owncloud/ocs/handlers/cloud/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"fmt"
"net/http"

userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
"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 @@ -46,7 +46,7 @@ func (h *Handler) GetSelf(w http.ResponseWriter, r *http.Request) {
ID: u.Username,
DisplayName: u.DisplayName,
Email: u.Mail,
UserType: userTypeString(u.Id.Type),
UserType: conversions.UserTypeString(u.Id.Type),
})
}

Expand All @@ -58,23 +58,3 @@ type User struct {
Email string `json:"email" xml:"email"`
UserType string `json:"user-type" xml:"user-type"`
}

func userTypeString(userType userv1beta1.UserType) string {
switch userType {
case userv1beta1.UserType_USER_TYPE_PRIMARY:
return "primary"
case userv1beta1.UserType_USER_TYPE_SECONDARY:
return "secondary"
case userv1beta1.UserType_USER_TYPE_SERVICE:
return "service"
case userv1beta1.UserType_USER_TYPE_APPLICATION:
return "application"
case userv1beta1.UserType_USER_TYPE_GUEST:
return "guest"
case userv1beta1.UserType_USER_TYPE_FEDERATED:
return "federated"
case userv1beta1.UserType_USER_TYPE_LIGHTWEIGHT:
return "lightweight"
}
return "invalid"
}
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 48fb8ec

Please sign in to comment.