-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: add graph beta listPermissions endpoint
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
Showing
30 changed files
with
2,918 additions
and
343 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
changelog/unreleased/enhancement-sharing-ng-list-permissions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.