github.com/cs3org/reva/v2@v2.27.7/pkg/events/sharing.go (about)

     1  // Copyright 2018-2021 CERN
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  // In applying this license, CERN does not waive the privileges and immunities
    16  // granted to it by virtue of its status as an Intergovernmental Organization
    17  // or submit itself to any jurisdiction.
    18  
    19  package events
    20  
    21  import (
    22  	"encoding/json"
    23  	"time"
    24  
    25  	group "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1"
    26  	user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
    27  	rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
    28  	collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
    29  	link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
    30  	provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
    31  	types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
    32  )
    33  
    34  // ShareCreated is emitted when a share is created
    35  type ShareCreated struct {
    36  	ShareID   *collaboration.ShareId
    37  	Executant *user.UserId
    38  	Sharer    *user.UserId
    39  	// split the protobuf Grantee oneof so we can use stdlib encoding/json
    40  	GranteeUserID  *user.UserId
    41  	GranteeGroupID *group.GroupId
    42  	Sharee         *provider.Grantee
    43  	ItemID         *provider.ResourceId
    44  	ResourceName   string
    45  	Permissions    *collaboration.SharePermissions
    46  	CTime          *types.Timestamp
    47  }
    48  
    49  // Unmarshal to fulfill umarshaller interface
    50  func (ShareCreated) Unmarshal(v []byte) (interface{}, error) {
    51  	e := ShareCreated{}
    52  	err := json.Unmarshal(v, &e)
    53  	return e, err
    54  }
    55  
    56  // ShareRemoved is emitted when a share is removed
    57  type ShareRemoved struct {
    58  	Executant *user.UserId
    59  	// split protobuf Spec
    60  	ShareID  *collaboration.ShareId
    61  	ShareKey *collaboration.ShareKey
    62  	// split the protobuf Grantee oneof so we can use stdlib encoding/json
    63  	GranteeUserID  *user.UserId
    64  	GranteeGroupID *group.GroupId
    65  
    66  	ItemID       *provider.ResourceId
    67  	ResourceName string
    68  	Timestamp    time.Time
    69  }
    70  
    71  // Unmarshal to fulfill umarshaller interface
    72  func (ShareRemoved) Unmarshal(v []byte) (interface{}, error) {
    73  	e := ShareRemoved{}
    74  	err := json.Unmarshal(v, &e)
    75  	return e, err
    76  }
    77  
    78  // ShareUpdated is emitted when a share is updated
    79  type ShareUpdated struct {
    80  	Executant      *user.UserId
    81  	ShareID        *collaboration.ShareId
    82  	ItemID         *provider.ResourceId
    83  	ResourceName   string
    84  	Permissions    *collaboration.SharePermissions
    85  	GranteeUserID  *user.UserId
    86  	GranteeGroupID *group.GroupId
    87  	Sharer         *user.UserId
    88  	MTime          *types.Timestamp
    89  
    90  	Updated string // Deprecated
    91  	// indicates what was updated
    92  	UpdateMask []string
    93  }
    94  
    95  // Unmarshal to fulfill umarshaller interface
    96  func (ShareUpdated) Unmarshal(v []byte) (interface{}, error) {
    97  	e := ShareUpdated{}
    98  	err := json.Unmarshal(v, &e)
    99  	return e, err
   100  }
   101  
   102  // ShareExpired is emitted when a share expires
   103  type ShareExpired struct {
   104  	ShareID    *collaboration.ShareId
   105  	ShareOwner *user.UserId
   106  	ItemID     *provider.ResourceId
   107  	Path       string
   108  	ExpiredAt  time.Time
   109  	// split the protobuf Grantee oneof so we can use stdlib encoding/json
   110  	GranteeUserID  *user.UserId
   111  	GranteeGroupID *group.GroupId
   112  }
   113  
   114  // Unmarshal to fulfill umarshaller interface
   115  func (ShareExpired) Unmarshal(v []byte) (interface{}, error) {
   116  	e := ShareExpired{}
   117  	err := json.Unmarshal(v, &e)
   118  	return e, err
   119  }
   120  
   121  // ReceivedShareUpdated is emitted when a received share is accepted or declined
   122  type ReceivedShareUpdated struct {
   123  	Executant      *user.UserId
   124  	ShareID        *collaboration.ShareId
   125  	ItemID         *provider.ResourceId
   126  	Path           string
   127  	Permissions    *collaboration.SharePermissions
   128  	GranteeUserID  *user.UserId
   129  	GranteeGroupID *group.GroupId
   130  	Sharer         *user.UserId
   131  	MTime          *types.Timestamp
   132  
   133  	State string
   134  }
   135  
   136  // Unmarshal to fulfill umarshaller interface
   137  func (ReceivedShareUpdated) Unmarshal(v []byte) (interface{}, error) {
   138  	e := ReceivedShareUpdated{}
   139  	err := json.Unmarshal(v, &e)
   140  	return e, err
   141  }
   142  
   143  // LinkCreated is emitted when a public link is created
   144  type LinkCreated struct {
   145  	Executant         *user.UserId
   146  	ShareID           *link.PublicShareId
   147  	Sharer            *user.UserId
   148  	ItemID            *provider.ResourceId
   149  	ResourceName      string
   150  	Permissions       *link.PublicSharePermissions
   151  	DisplayName       string
   152  	Expiration        *types.Timestamp
   153  	PasswordProtected bool
   154  	CTime             *types.Timestamp
   155  	Token             string
   156  }
   157  
   158  // Unmarshal to fulfill umarshaller interface
   159  func (LinkCreated) Unmarshal(v []byte) (interface{}, error) {
   160  	e := LinkCreated{}
   161  	err := json.Unmarshal(v, &e)
   162  	return e, err
   163  }
   164  
   165  // LinkUpdated is emitted when a public link is updated
   166  type LinkUpdated struct {
   167  	Executant         *user.UserId
   168  	ShareID           *link.PublicShareId
   169  	Sharer            *user.UserId
   170  	ItemID            *provider.ResourceId
   171  	ResourceName      string
   172  	Permissions       *link.PublicSharePermissions
   173  	DisplayName       string
   174  	Expiration        *types.Timestamp
   175  	PasswordProtected bool
   176  	MTime             *types.Timestamp
   177  	Token             string
   178  
   179  	FieldUpdated string
   180  }
   181  
   182  // Unmarshal to fulfill umarshaller interface
   183  func (LinkUpdated) Unmarshal(v []byte) (interface{}, error) {
   184  	e := LinkUpdated{}
   185  	err := json.Unmarshal(v, &e)
   186  	return e, err
   187  }
   188  
   189  // LinkAccessed is emitted when a public link is accessed successfully (by token)
   190  type LinkAccessed struct {
   191  	Executant         *user.UserId
   192  	ShareID           *link.PublicShareId
   193  	Sharer            *user.UserId
   194  	ItemID            *provider.ResourceId
   195  	Path              string
   196  	Permissions       *link.PublicSharePermissions
   197  	DisplayName       string
   198  	Expiration        *types.Timestamp
   199  	PasswordProtected bool
   200  	CTime             *types.Timestamp
   201  	Token             string
   202  }
   203  
   204  // Unmarshal to fulfill umarshaller interface
   205  func (LinkAccessed) Unmarshal(v []byte) (interface{}, error) {
   206  	e := LinkAccessed{}
   207  	err := json.Unmarshal(v, &e)
   208  	return e, err
   209  }
   210  
   211  // LinkAccessFailed is emitted when an access to a public link has resulted in an error (by token)
   212  type LinkAccessFailed struct {
   213  	Executant *user.UserId
   214  	ShareID   *link.PublicShareId
   215  	Token     string
   216  	Status    rpc.Code
   217  	Message   string
   218  	Timestamp *types.Timestamp
   219  }
   220  
   221  // Unmarshal to fulfill umarshaller interface
   222  func (LinkAccessFailed) Unmarshal(v []byte) (interface{}, error) {
   223  	e := LinkAccessFailed{}
   224  	err := json.Unmarshal(v, &e)
   225  	return e, err
   226  }
   227  
   228  // LinkRemoved is emitted when a share is removed
   229  type LinkRemoved struct {
   230  	Executant *user.UserId
   231  	// split protobuf Ref
   232  	ShareID      *link.PublicShareId
   233  	ShareToken   string
   234  	Timestamp    *types.Timestamp
   235  	ItemID       *provider.ResourceId
   236  	ResourceName string
   237  }
   238  
   239  // Unmarshal to fulfill umarshaller interface
   240  func (LinkRemoved) Unmarshal(v []byte) (interface{}, error) {
   241  	e := LinkRemoved{}
   242  	err := json.Unmarshal(v, &e)
   243  	return e, err
   244  }