@@ -47,6 +47,28 @@ func (c *Client) GetUserPermissions(ctx context.Context, requestUserID string, t
4747 return permission .FixOwnerPermissions (result ), nil
4848}
4949
50+ // GroupsForUser returns what users have shared permissions with the user with an id of granteeUserID.
51+ // The GroupedPermissions are keyed by the id of the user who shared their permissions with granteeUserID.
52+ func (c * Client ) GroupsForUser (ctx context.Context , granteeUserID string ) (permission.GroupedPermissions , error ) {
53+ if ctx == nil {
54+ return nil , errors .New ("context is missing" )
55+ }
56+ if granteeUserID == "" {
57+ return nil , errors .New ("user id is missing" )
58+ }
59+
60+ url := c .client .ConstructURL ("access" , "groups" , granteeUserID )
61+ result := permission.GroupedPermissions {}
62+ if err := c .client .RequestData (ctx , "GET" , url , nil , nil , & result ); err != nil {
63+ if request .IsErrorResourceNotFound (err ) {
64+ return nil , request .ErrorUnauthorized ()
65+ }
66+ return nil , err
67+ }
68+
69+ return permission .FixGroupedOwnerPermissions (result ), nil
70+ }
71+
5072func (c * Client ) HasMembershipRelationship (ctx context.Context , granteeUserID , grantorUserID string ) (has bool , err error ) {
5173 fromTo , err := c .GetUserPermissions (ctx , granteeUserID , grantorUserID )
5274 if err != nil {
0 commit comments