Skip to content

Commit

Permalink
Merge pull request #8909 from owncloud/graph-ocm-fixes
Browse files Browse the repository at this point in the history
SharingNG: initial OCM support
  • Loading branch information
butonic authored Jun 28, 2024
2 parents 82f8be0 + b529eb8 commit dc68bbb
Show file tree
Hide file tree
Showing 14 changed files with 892 additions and 78 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/initial-ocm-support-for-graph.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Rudimentary OCM support in graph

We now allow creating and accepting OCM shares.

https://github.com/owncloud/ocis/pull/8909
61 changes: 61 additions & 0 deletions services/graph/mocks/base_graph_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions services/graph/mocks/drives_drive_item_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions services/graph/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ type Config struct {
TokenManager *TokenManager `yaml:"token_manager"`
GRPCClientTLS *shared.GRPCClientTLS `yaml:"grpc_client_tls"`

Application Application `yaml:"application"`
Spaces Spaces `yaml:"spaces"`
Identity Identity `yaml:"identity"`
Events Events `yaml:"events"`
Application Application `yaml:"application"`
Spaces Spaces `yaml:"spaces"`
Identity Identity `yaml:"identity"`
IncludeOCMSharees bool `yaml:"include_ocm_sharees" env:"GRAPH_INCLUDE_OCM_SHAREES" desc:"Include OCM sharees when listing users." introductionVersion:"5.0"`
Events Events `yaml:"events"`

Keycloak Keycloak `yaml:"keycloak"`
ServiceAccount ServiceAccount `yaml:"service_account"`
Expand Down
6 changes: 6 additions & 0 deletions services/graph/pkg/identity/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ func CreateUserModelFromCS3(u *cs3user.User) *libregraph.User {
u.Id = &cs3user.UserId{}
}
return &libregraph.User{
Identities: []libregraph.ObjectIdentity{
{
Issuer: &u.GetId().Idp,
IssuerAssignedId: &u.GetId().OpaqueId,
},
},
DisplayName: &u.DisplayName,
Mail: &u.Mail,
OnPremisesSamAccountName: &u.Username,
Expand Down
30 changes: 30 additions & 0 deletions services/graph/pkg/identity/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,41 @@ func (cache IdentityCache) GetUser(ctx context.Context, userid string) (libregra
return user, nil
}

// GetAcceptedUser looks up a user by id, if the user is not cached, yet it will do a lookup via the CS3 API
func (cache IdentityCache) GetAcceptedUser(ctx context.Context, userid string) (libregraph.User, error) {
var user libregraph.User
if item := cache.users.Get(userid); item == nil {
gatewayClient, err := cache.gatewaySelector.Next()
if err != nil {
return libregraph.User{}, errorcode.New(errorcode.GeneralException, err.Error())
}
cs3UserID := &cs3User.UserId{
OpaqueId: userid,
}
u, err := revautils.GetAcceptedUserWithContext(ctx, cs3UserID, gatewayClient)
if err != nil {
if revautils.IsErrNotFound(err) {
return libregraph.User{}, ErrNotFound
}
return libregraph.User{}, errorcode.New(errorcode.GeneralException, err.Error())
}
user = *CreateUserModelFromCS3(u)
cache.users.Set(userid, user, ttlcache.DefaultTTL)

} else {
user = item.Value()
}
return user, nil
}

// GetGroup looks up a group by id, if the group is not cached, yet it will do a lookup via the CS3 API
func (cache IdentityCache) GetGroup(ctx context.Context, groupID string) (libregraph.Group, error) {
var group libregraph.Group
if item := cache.groups.Get(groupID); item == nil {
gatewayClient, err := cache.gatewaySelector.Next()
if err != nil {
return group, errorcode.New(errorcode.GeneralException, err.Error())
}
cs3GroupID := &cs3Group.GroupId{
OpaqueId: groupID,
}
Expand Down
Loading

0 comments on commit dc68bbb

Please sign in to comment.