graph: Assign new user the default user role
Similar to what the accounts service is doing, all new users get the User role assigned now. Otherwise creating the user's personal space upon login is not working.
This commit is contained in:
1 parent
fe2501b083
commit
06ca18b1fb
3 files changed
+23
-4
No files matched your search
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/owncloud/ocis/graph/pkg/config"
|
"github.com/owncloud/ocis/graph/pkg/config"
|
||||||
"github.com/owncloud/ocis/graph/pkg/identity"
|
"github.com/owncloud/ocis/graph/pkg/identity"
|
||||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||||
|
settingssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/settings/v0"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -66,6 +67,7 @@ type Graph struct {
|
|||||||
identityBackend identity.Backend
|
identityBackend identity.Backend
|
||||||
gatewayClient GatewayClient
|
gatewayClient GatewayClient
|
||||||
httpClient HTTPClient
|
httpClient HTTPClient
|
||||||
|
roleService settingssvc.RoleService
|
||||||
spacePropertiesCache *ttlcache.Cache
|
spacePropertiesCache *ttlcache.Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,17 +116,19 @@ func NewService(opts ...Option) Service {
|
|||||||
svc.httpClient = options.HTTPClient
|
svc.httpClient = options.HTTPClient
|
||||||
}
|
}
|
||||||
|
|
||||||
roleService := options.RoleService
|
if options.RoleService == nil {
|
||||||
if roleService == nil {
|
svc.roleService = settingssvc.NewRoleService("com.owncloud.api.settings", grpc.DefaultClient)
|
||||||
roleService = settingssvc.NewRoleService("com.owncloud.api.settings", grpc.DefaultClient)
|
} else {
|
||||||
|
svc.roleService = options.RoleService
|
||||||
}
|
}
|
||||||
|
|
||||||
roleManager := options.RoleManager
|
roleManager := options.RoleManager
|
||||||
if roleManager == nil {
|
if roleManager == nil {
|
||||||
m := roles.NewManager(
|
m := roles.NewManager(
|
||||||
roles.CacheSize(1024),
|
roles.CacheSize(1024),
|
||||||
roles.CacheTTL(time.Hour),
|
roles.CacheTTL(time.Hour),
|
||||||
roles.Logger(options.Logger),
|
roles.Logger(options.Logger),
|
||||||
roles.RoleService(roleService),
|
roles.RoleService(svc.roleService),
|
||||||
)
|
)
|
||||||
roleManager = &m
|
roleManager = &m
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import (
|
|||||||
libregraph "github.com/owncloud/libre-graph-api-go"
|
libregraph "github.com/owncloud/libre-graph-api-go"
|
||||||
"github.com/owncloud/ocis/graph/pkg/identity"
|
"github.com/owncloud/ocis/graph/pkg/identity"
|
||||||
"github.com/owncloud/ocis/graph/pkg/service/v0/errorcode"
|
"github.com/owncloud/ocis/graph/pkg/service/v0/errorcode"
|
||||||
|
settings "github.com/owncloud/ocis/protogen/gen/ocis/services/settings/v0"
|
||||||
|
settingssvc "github.com/owncloud/ocis/settings/pkg/service/v0"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetMe implements the Service interface.
|
// GetMe implements the Service interface.
|
||||||
@@ -86,6 +88,19 @@ func (g Graph) PostUser(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// All users get the user role by default currently.
|
||||||
|
// to all new users for now, as create Account request does not have any role field
|
||||||
|
if g.roleService == nil {
|
||||||
|
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, "could not assign role to account: roleService not configured")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, err = g.roleService.AssignRoleToUser(r.Context(), &settings.AssignRoleToUserRequest{
|
||||||
|
AccountUuid: *u.Id,
|
||||||
|
RoleId: settingssvc.BundleUUIDRoleUser,
|
||||||
|
}); err != nil {
|
||||||
|
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, fmt.Sprintf("could not assign role to account %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
render.Status(r, http.StatusOK)
|
render.Status(r, http.StatusOK)
|
||||||
render.JSON(w, r, u)
|
render.JSON(w, r, u)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user