Skip to content

Commit

Permalink
Group sharing support (#1453)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored Feb 12, 2021
1 parent d8aa2eb commit d270f61
Show file tree
Hide file tree
Showing 48 changed files with 1,194 additions and 1,386 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/group-sharing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Add functionality to share resources with groups

https://github.com/cs3org/reva/pull/1453
10 changes: 7 additions & 3 deletions cmd/reva/ocm-share-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ func ocmShareCreateCommand() *command {
Permissions: perm,
Grantee: &provider.Grantee{
Type: gt,
Id: &userpb.UserId{
// For now, we only support user shares.
// TODO (ishank011): To be updated once this is decided.
Id: &provider.Grantee_UserId{UserId: &userpb.UserId{
Idp: *idp,
OpaqueId: *grantee,
},
}},
},
}

Expand Down Expand Up @@ -153,7 +155,9 @@ func ocmShareCreateCommand() *command {

s := shareRes.Share
t.AppendRows([]table.Row{
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), s.Grantee.Type.String(), s.Grantee.Id.Idp, s.Grantee.Id.OpaqueId, time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(),
s.Grantee.Type.String(), s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId,
time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
})
t.Render()

Expand Down
8 changes: 6 additions & 2 deletions cmd/reva/ocm-share-list-received.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ func ocmShareListReceivedCommand() *command {
if len(w) == 0 {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated", "State"})
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type",
"Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated", "State"})
for _, s := range shareRes.Shares {
t.AppendRows([]table.Row{
{s.Share.Id.OpaqueId, s.Share.Owner.Idp, s.Share.Owner.OpaqueId, s.Share.ResourceId.String(), s.Share.Permissions.String(), s.Share.Grantee.Type.String(), s.Share.Grantee.Id.Idp, s.Share.Grantee.Id.OpaqueId, time.Unix(int64(s.Share.Ctime.Seconds), 0), time.Unix(int64(s.Share.Mtime.Seconds), 0), s.State.String()},
{s.Share.Id.OpaqueId, s.Share.Owner.Idp, s.Share.Owner.OpaqueId, s.Share.ResourceId.String(),
s.Share.Permissions.String(), s.Share.Grantee.Type.String(), s.Share.Grantee.GetUserId().Idp,
s.Share.Grantee.GetUserId().OpaqueId, time.Unix(int64(s.Share.Ctime.Seconds), 0),
time.Unix(int64(s.Share.Mtime.Seconds), 0), s.State.String()},
})
}
t.Render()
Expand Down
7 changes: 5 additions & 2 deletions cmd/reva/ocm-share-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ func ocmShareListCommand() *command {
if len(w) == 0 {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"})
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type",
"Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"})

for _, s := range shareRes.Shares {
t.AppendRows([]table.Row{
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), s.Grantee.Type.String(), s.Grantee.Id.Idp, s.Grantee.Id.OpaqueId, time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(),
s.Grantee.Type.String(), s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId,
time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
})
}
t.Render()
Expand Down
30 changes: 25 additions & 5 deletions cmd/reva/share-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"time"

grouppb "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
Expand Down Expand Up @@ -89,12 +90,23 @@ func shareCreateCommand() *command {
},
Grantee: &provider.Grantee{
Type: gt,
Id: &userpb.UserId{
Idp: *idp,
OpaqueId: *grantee,
},
},
}
switch *grantType {
case "user":
grant.Grantee.Id = &provider.Grantee_UserId{UserId: &userpb.UserId{
Idp: *idp,
OpaqueId: *grantee,
}}
case "group":
grant.Grantee.Id = &provider.Grantee_GroupId{GroupId: &grouppb.GroupId{
Idp: *idp,
OpaqueId: *grantee,
}}
default:
return errors.New("Invalid grantee type argument: " + *grantType)
}

shareRequest := &collaboration.CreateShareRequest{
ResourceInfo: res.Info,
Grant: grant,
Expand All @@ -114,8 +126,16 @@ func shareCreateCommand() *command {
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"})

s := shareRes.Share
var idp, opaque string
if s.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_USER {
idp, opaque = s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId
} else if s.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_GROUP {
idp, opaque = s.Grantee.GetGroupId().Idp, s.Grantee.GetGroupId().OpaqueId
}
t.AppendRows([]table.Row{
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), s.Grantee.Type.String(), s.Grantee.Id.Idp, s.Grantee.Id.OpaqueId, time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(),
s.Grantee.Type.String(), idp, opaque,
time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
})
t.Render()

Expand Down
15 changes: 13 additions & 2 deletions cmd/reva/share-list-received.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/jedib0t/go-pretty/table"
)

Expand Down Expand Up @@ -54,10 +55,20 @@ func shareListReceivedCommand() *command {
if len(w) == 0 {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated", "State"})
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type",
"Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated", "State"})
for _, s := range shareRes.Shares {
var idp, opaque string
if s.Share.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_USER {
idp, opaque = s.Share.Grantee.GetUserId().Idp, s.Share.Grantee.GetUserId().OpaqueId
} else if s.Share.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_GROUP {
idp, opaque = s.Share.Grantee.GetGroupId().Idp, s.Share.Grantee.GetGroupId().OpaqueId
}
t.AppendRows([]table.Row{
{s.Share.Id.OpaqueId, s.Share.Owner.Idp, s.Share.Owner.OpaqueId, s.Share.ResourceId.String(), s.Share.Permissions.String(), s.Share.Grantee.Type.String(), s.Share.Grantee.Id.Idp, s.Share.Grantee.Id.OpaqueId, time.Unix(int64(s.Share.Ctime.Seconds), 0), time.Unix(int64(s.Share.Mtime.Seconds), 0), s.State.String()},
{s.Share.Id.OpaqueId, s.Share.Owner.Idp, s.Share.Owner.OpaqueId, s.Share.ResourceId.String(),
s.Share.Permissions.String(), s.Share.Grantee.Type.String(), idp,
opaque, time.Unix(int64(s.Share.Ctime.Seconds), 0),
time.Unix(int64(s.Share.Mtime.Seconds), 0), s.State.String()},
})
}
t.Render()
Expand Down
13 changes: 11 additions & 2 deletions cmd/reva/share-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,20 @@ func shareListCommand() *command {
if len(w) == 0 {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"})
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type",
"Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"})

for _, s := range shareRes.Shares {
var idp, opaque string
if s.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_USER {
idp, opaque = s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId
} else if s.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_GROUP {
idp, opaque = s.Grantee.GetGroupId().Idp, s.Grantee.GetGroupId().OpaqueId
}
t.AppendRows([]table.Row{
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), s.Grantee.Type.String(), s.Grantee.Id.Idp, s.Grantee.Id.OpaqueId, time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(),
s.Grantee.Type.String(), idp, opaque,
time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
})
}
t.Render()
Expand Down
140 changes: 140 additions & 0 deletions examples/oc-phoenix/groups.demo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
[
{
"id": {
"opaque_id": "sailing-lovers",
"idp": "localhost:20080"
},
"group_name": "sailing-lovers",
"mail": "sailing-lovers@example.org",
"display_name": "Sailing Lovers",
"gid_number": 123,
"members": [
{
"id": {
"opaque_id": "4c510ada-c86b-4815-8820-42cdf82c3d51",
"idp": "localhost:20080"
}
}
]
},
{
"id": {
"opaque_id": "violin-haters",
"idp": "localhost:20080"
},
"group_name": "violin-haters",
"mail": "violin-haters@example.org",
"display_name": "Violin Haters",
"gid_number": 456,
"members": [
{
"id": {
"opaque_id": "4c510ada-c86b-4815-8820-42cdf82c3d51",
"idp": "localhost:20080"
}
}
]
},
{
"id": {
"opaque_id": "radium-lovers",
"idp": "localhost:20080"
},
"group_name": "radium-lovers",
"mail": "radium-lovers@example.org",
"display_name": "Radium Lovers",
"gid_number": 789,
"members": [
{
"id": {
"opaque_id": "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c",
"idp": "localhost:20080"
}
}
]
},
{
"id": {
"opaque_id": "polonium-lovers",
"idp": "localhost:20080"
},
"group_name": "polonium-lovers",
"mail": "polonium-lovers@example.org",
"display_name": "Polonium Lovers",
"gid_number": 987,
"members": [
{
"id": {
"opaque_id": "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c",
"idp": "localhost:20080"
}
}
]
},
{
"id": {
"opaque_id": "quantum-lovers",
"idp": "localhost:20080"
},
"group_name": "quantum-lovers",
"mail": "quantum-lovers@example.org",
"display_name": "Quantum Lovers",
"gid_number": 654,
"members": [
{
"id": {
"opaque_id": "932b4540-8d16-481e-8ef4-588e4b6b151c",
"idp": "localhost:20080"
}
}
]
},
{
"id": {
"opaque_id": "philosophy-haters",
"idp": "localhost:20080"
},
"group_name": "philosophy-haters",
"mail": "philosophy-haters@example.org",
"display_name": "Philosophy Haters",
"gid_number": 321,
"members": [
{
"id": {
"opaque_id": "932b4540-8d16-481e-8ef4-588e4b6b151c",
"idp": "localhost:20080"
}
}
]
},
{
"id": {
"opaque_id": "physics-lovers",
"idp": "localhost:20080"
},
"group_name": "physics-lovers",
"mail": "physics-lovers@example.org",
"display_name": "Physics Lovers",
"gid_number": 101,
"members": [
{
"id": {
"opaque_id": "4c510ada-c86b-4815-8820-42cdf82c3d51",
"idp": "localhost:20080"
}
},
{
"id": {
"opaque_id": "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c",
"idp": "localhost:20080"
}
},
{
"id": {
"opaque_id": "932b4540-8d16-481e-8ef4-588e4b6b151c",
"idp": "localhost:20080"
}
}
]
}
]
Loading

0 comments on commit d270f61

Please sign in to comment.