the code duplication was reduced
This commit is contained in:
@@ -80,15 +80,7 @@ func WithResource(ref *provider.Reference, addSpace bool) ActivityOption {
|
|||||||
vars["resource"] = Resource{
|
vars["resource"] = Resource{
|
||||||
Name: filepath.Base(ref.GetPath()),
|
Name: filepath.Base(ref.GetPath()),
|
||||||
}
|
}
|
||||||
n := filepath.Base(filepath.Dir(ref.GetPath()))
|
n := getFolderName(ctx, gwc, ref)
|
||||||
if n == "." || n == "/" {
|
|
||||||
s, err := utils.GetSpace(ctx, toSpace(ref).GetOpaqueId(), gwc)
|
|
||||||
if err == nil {
|
|
||||||
n = s.GetName()
|
|
||||||
} else {
|
|
||||||
n = "root"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vars["folder"] = Resource{
|
vars["folder"] = Resource{
|
||||||
Name: n,
|
Name: n,
|
||||||
}
|
}
|
||||||
@@ -137,15 +129,7 @@ func WithTrashedResource(ref *provider.Reference, rid *provider.ResourceId) Acti
|
|||||||
vars["resource"] = Resource{
|
vars["resource"] = Resource{
|
||||||
Name: filepath.Base(ref.GetPath()),
|
Name: filepath.Base(ref.GetPath()),
|
||||||
}
|
}
|
||||||
n := filepath.Base(filepath.Dir(ref.GetPath()))
|
n := getFolderName(ctx, gwc, ref)
|
||||||
if n == "." || n == "/" {
|
|
||||||
s, err := utils.GetSpace(ctx, toSpace(ref).GetOpaqueId(), gwc)
|
|
||||||
if err == nil {
|
|
||||||
n = s.GetName()
|
|
||||||
} else {
|
|
||||||
n = "root"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vars["folder"] = Resource{
|
vars["folder"] = Resource{
|
||||||
Name: n,
|
Name: n,
|
||||||
}
|
}
|
||||||
@@ -334,6 +318,19 @@ func (s *ActivitylogService) GetVars(ctx context.Context, opts ...ActivityOption
|
|||||||
return vars, nil
|
return vars, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getFolderName(ctx context.Context, gwc gateway.GatewayAPIClient, ref *provider.Reference) string {
|
||||||
|
n := filepath.Base(filepath.Dir(ref.GetPath()))
|
||||||
|
if n == "." || n == "/" {
|
||||||
|
s, err := utils.GetSpace(ctx, toSpace(ref).GetOpaqueId(), gwc)
|
||||||
|
if err == nil {
|
||||||
|
n = s.GetName()
|
||||||
|
} else {
|
||||||
|
n = "root"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
func mapField(val string) string {
|
func mapField(val string) string {
|
||||||
switch val {
|
switch val {
|
||||||
case "TYPE_PERMISSIONS", "permission":
|
case "TYPE_PERMISSIONS", "permission":
|
||||||
|
|||||||
Reference in New Issue
Block a user