Skip to content

Commit

Permalink
enhancement: add graph beta listPermissions endpoint
Browse files Browse the repository at this point in the history
besides the new api endpoint it includes several utilities to simplify the graph api development.

* resolve drive and item id from the request path
* generic pointer and value utilities
* space root detection
  • Loading branch information
fschade committed Nov 26, 2023
1 parent ed46fa9 commit f6b1bd5
Show file tree
Hide file tree
Showing 30 changed files with 2,918 additions and 343 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Add Sharing NG list permissions endpoint

We've added a new sharing ng endpoint which lists all permissions for a given item.

https://github.com/owncloud/ocis/pull/7805
https://github.com/owncloud/ocis/issues/6993
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ require (
github.com/onsi/gomega v1.29.0
github.com/open-policy-agent/opa v0.51.0
github.com/orcaman/concurrent-map v1.0.0
github.com/owncloud/libre-graph-api-go v1.0.5-0.20231113143725-09bf34dc9afb
github.com/owncloud/libre-graph-api-go v1.0.5-0.20231123060936-76fa32d91140
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.9
github.com/prometheus/client_golang v1.17.0
Expand All @@ -95,6 +95,7 @@ require (
go.opentelemetry.io/otel/sdk v1.21.0
go.opentelemetry.io/otel/trace v1.21.0
golang.org/x/crypto v0.15.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/image v0.14.0
golang.org/x/net v0.18.0
golang.org/x/oauth2 v0.13.0
Expand Down Expand Up @@ -328,7 +329,6 @@ require (
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.23.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1789,8 +1789,8 @@ github.com/oracle/oci-go-sdk v24.3.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35uk
github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HDbW65HOY=
github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
github.com/ovh/go-ovh v1.1.0/go.mod h1:AxitLZ5HBRPyUd+Zl60Ajaag+rNTdVXWIkzfrVuTXWA=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20231113143725-09bf34dc9afb h1:KFnmkGvHY+6k6IZ9I1w5Ia24VbALYms+Y6W7LrsUbsE=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20231113143725-09bf34dc9afb/go.mod h1:v2aAl5IwEI8t+GmcWvBd+bvJMYp9Vf1hekLuRf0UnEs=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20231123060936-76fa32d91140 h1:mM2gPv90HJ7BL58WMBa/tQ3r6PvSAfIMu9RaoUftE8E=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20231123060936-76fa32d91140/go.mod h1:v2aAl5IwEI8t+GmcWvBd+bvJMYp9Vf1hekLuRf0UnEs=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
Expand Down
38 changes: 38 additions & 0 deletions ocis-pkg/conversions/ptr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package conversions

// ToPointer converts a value to a pointer
func ToPointer[T any](val T) *T {
return &val
}

// ToValue converts a pointer to a value
func ToValue[T any](ptr *T) T {
if ptr == nil {
var t T
return t
}

return *ptr
}

// ToPointerSlice converts a slice of values to a slice of pointers
func ToPointerSlice[E any](s []E) []*E {
rs := make([]*E, len(s))

for i, v := range s {
rs[i] = ToPointer(v)
}

return rs
}

// ToValueSlice converts a slice of pointers to a slice of values
func ToValueSlice[E any](s []*E) []E {
rs := make([]E, len(s))

for i, v := range s {
rs[i] = ToValue(v)
}

return rs
}
113 changes: 113 additions & 0 deletions ocis-pkg/conversions/ptr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package conversions_test

import (
"fmt"
"testing"

libregraph "github.com/owncloud/libre-graph-api-go"

"github.com/owncloud/ocis/v2/ocis-pkg/conversions"
)

func checkIdentical[T any](t *testing.T, p T, want string) {
t.Helper()
got := fmt.Sprintf("%T", p)
if got != want {
t.Errorf("want:%q got:%q", want, got)
}
}

func TestToPointer2(t *testing.T) {
checkIdentical(t, conversions.ToPointer("a"), "*string")
checkIdentical(t, conversions.ToPointer(1), "*int")
checkIdentical(t, conversions.ToPointer(-1), "*int")
checkIdentical(t, conversions.ToPointer(float64(1)), "*float64")
checkIdentical(t, conversions.ToPointer(float64(-1)), "*float64")
checkIdentical(t, conversions.ToPointer(libregraph.UnifiedRoleDefinition{}), "*libregraph.UnifiedRoleDefinition")

checkIdentical(t, conversions.ToPointer([]string{"a"}), "*[]string")
checkIdentical(t, conversions.ToPointer([]int{1}), "*[]int")
checkIdentical(t, conversions.ToPointer([]float64{1}), "*[]float64")
checkIdentical(t, conversions.ToPointer([]libregraph.UnifiedRoleDefinition{{}}), "*[]libregraph.UnifiedRoleDefinition")

checkIdentical(t, conversions.ToPointer(conversions.ToPointer("a")), "**string")
checkIdentical(t, conversions.ToPointer(conversions.ToPointer(1)), "**int")
checkIdentical(t, conversions.ToPointer(conversions.ToPointer(-1)), "**int")
checkIdentical(t, conversions.ToPointer(conversions.ToPointer(float64(1))), "**float64")
checkIdentical(t, conversions.ToPointer(conversions.ToPointer(float64(-1))), "**float64")
checkIdentical(t, conversions.ToPointer(conversions.ToPointer(libregraph.UnifiedRoleDefinition{})), "**libregraph.UnifiedRoleDefinition")

checkIdentical(t, conversions.ToPointer(conversions.ToPointer([]string{"a"})), "**[]string")
checkIdentical(t, conversions.ToPointer(conversions.ToPointer([]int{1})), "**[]int")
checkIdentical(t, conversions.ToPointer(conversions.ToPointer([]float64{1})), "**[]float64")
checkIdentical(t, conversions.ToPointer(conversions.ToPointer([]libregraph.UnifiedRoleDefinition{{}})), "**[]libregraph.UnifiedRoleDefinition")
}

func TestToValue(t *testing.T) {
checkIdentical(t, conversions.ToValue((*int)(nil)), "int")
checkIdentical(t, conversions.ToValue((*string)(nil)), "string")
checkIdentical(t, conversions.ToValue((*float64)(nil)), "float64")
checkIdentical(t, conversions.ToValue((*libregraph.UnifiedRoleDefinition)(nil)), "libregraph.UnifiedRoleDefinition")
checkIdentical(t, conversions.ToValue((*[]string)(nil)), "[]string")
checkIdentical(t, conversions.ToValue((*[]libregraph.UnifiedRoleDefinition)(nil)), "[]libregraph.UnifiedRoleDefinition")

checkIdentical(t, conversions.ToValue(conversions.ToPointer("a")), "string")
checkIdentical(t, conversions.ToValue(conversions.ToPointer(1)), "int")
checkIdentical(t, conversions.ToValue(conversions.ToPointer(-1)), "int")
checkIdentical(t, conversions.ToValue(conversions.ToPointer(float64(1))), "float64")
checkIdentical(t, conversions.ToValue(conversions.ToPointer(float64(-1))), "float64")
checkIdentical(t, conversions.ToValue(conversions.ToPointer(libregraph.UnifiedRoleDefinition{})), "libregraph.UnifiedRoleDefinition")

checkIdentical(t, conversions.ToValue(conversions.ToPointer([]string{"a"})), "[]string")
checkIdentical(t, conversions.ToValue(conversions.ToPointer([]int{1})), "[]int")
checkIdentical(t, conversions.ToValue(conversions.ToPointer([]float64{1})), "[]float64")
checkIdentical(t, conversions.ToValue(conversions.ToPointer([]libregraph.UnifiedRoleDefinition{{}})), "[]libregraph.UnifiedRoleDefinition")

checkIdentical(t, conversions.ToValue(conversions.ToPointer(conversions.ToPointer("a"))), "*string")
checkIdentical(t, conversions.ToValue(conversions.ToPointer(conversions.ToPointer(1))), "*int")
checkIdentical(t, conversions.ToValue(conversions.ToPointer(conversions.ToPointer(-1))), "*int")
checkIdentical(t, conversions.ToValue(conversions.ToPointer(conversions.ToPointer(float64(1)))), "*float64")
checkIdentical(t, conversions.ToValue(conversions.ToPointer(conversions.ToPointer(float64(-1)))), "*float64")
checkIdentical(t, conversions.ToValue(conversions.ToPointer(conversions.ToPointer(libregraph.UnifiedRoleDefinition{}))), "*libregraph.UnifiedRoleDefinition")

checkIdentical(t, conversions.ToValue(conversions.ToPointer(conversions.ToPointer([]string{"a"}))), "*[]string")
checkIdentical(t, conversions.ToValue(conversions.ToPointer(conversions.ToPointer([]int{1}))), "*[]int")
checkIdentical(t, conversions.ToValue(conversions.ToPointer(conversions.ToPointer([]float64{1}))), "*[]float64")
checkIdentical(t, conversions.ToValue(conversions.ToPointer(conversions.ToPointer([]libregraph.UnifiedRoleDefinition{{}}))), "*[]libregraph.UnifiedRoleDefinition")
}

func TestToPointerSlice(t *testing.T) {
checkIdentical(t, conversions.ToPointerSlice([]string{"a"}), "[]*string")
checkIdentical(t, conversions.ToPointerSlice([]int{1}), "[]*int")
checkIdentical(t, conversions.ToPointerSlice([]libregraph.UnifiedRoleDefinition{{}}), "[]*libregraph.UnifiedRoleDefinition")

checkIdentical(t, conversions.ToPointerSlice(([]string)(nil)), "[]*string")
checkIdentical(t, conversions.ToPointerSlice(([]int)(nil)), "[]*int")
checkIdentical(t, conversions.ToPointerSlice(([]libregraph.UnifiedRoleDefinition)(nil)), "[]*libregraph.UnifiedRoleDefinition")

checkIdentical(t, conversions.ToPointerSlice([]*string{conversions.ToPointer("a")}), "[]**string")
checkIdentical(t, conversions.ToPointerSlice([]*int{conversions.ToPointer(1)}), "[]**int")
checkIdentical(t, conversions.ToPointerSlice(([]*libregraph.UnifiedRoleDefinition)(nil)), "[]**libregraph.UnifiedRoleDefinition")

checkIdentical(t, conversions.ToPointerSlice(([]*string)(nil)), "[]**string")
checkIdentical(t, conversions.ToPointerSlice(([]*int)(nil)), "[]**int")
checkIdentical(t, conversions.ToPointerSlice(([]*libregraph.UnifiedRoleDefinition)(nil)), "[]**libregraph.UnifiedRoleDefinition")
}

func TestToValueSlice(t *testing.T) {
checkIdentical(t, conversions.ToValueSlice(conversions.ToPointerSlice([]string{"a"})), "[]string")
checkIdentical(t, conversions.ToValueSlice(conversions.ToPointerSlice([]int{1})), "[]int")
checkIdentical(t, conversions.ToValueSlice(conversions.ToPointerSlice([]libregraph.UnifiedRoleDefinition{{}})), "[]libregraph.UnifiedRoleDefinition")

checkIdentical(t, conversions.ToValueSlice(conversions.ToPointerSlice(([]string)(nil))), "[]string")
checkIdentical(t, conversions.ToValueSlice(conversions.ToPointerSlice(([]int)(nil))), "[]int")
checkIdentical(t, conversions.ToValueSlice(conversions.ToPointerSlice(([]libregraph.UnifiedRoleDefinition)(nil))), "[]libregraph.UnifiedRoleDefinition")

checkIdentical(t, conversions.ToValueSlice(conversions.ToPointerSlice([]*string{conversions.ToPointer("a")})), "[]*string")
checkIdentical(t, conversions.ToValueSlice(conversions.ToPointerSlice([]*int{conversions.ToPointer(1)})), "[]*int")
checkIdentical(t, conversions.ToValueSlice(conversions.ToPointerSlice([]*libregraph.UnifiedRoleDefinition{conversions.ToPointer(libregraph.UnifiedRoleDefinition{})})), "[]*libregraph.UnifiedRoleDefinition")

checkIdentical(t, conversions.ToValueSlice(conversions.ToPointerSlice(([]*string)(nil))), "[]*string")
checkIdentical(t, conversions.ToValueSlice(conversions.ToPointerSlice(([]*int)(nil))), "[]*int")
checkIdentical(t, conversions.ToValueSlice(conversions.ToPointerSlice(([]*libregraph.UnifiedRoleDefinition)(nil))), "[]*libregraph.UnifiedRoleDefinition")
}
13 changes: 0 additions & 13 deletions ocis-pkg/conversions/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package conversions

import (
"strings"
"unicode/utf8"
)

// StringToSliceString splits a string into a slice string according to separator
Expand All @@ -15,15 +14,3 @@ func StringToSliceString(src string, sep string) []string {

return parts
}

// Reverse reverses a string
func Reverse(s string) string {
size := len(s)
buf := make([]byte, size)
for start := 0; start < size; {
r, n := utf8.DecodeRuneInString(s[start:])
start += n
utf8.EncodeRune(buf[size-start:], r)
}
return string(buf)
}
Loading

0 comments on commit f6b1bd5

Please sign in to comment.