Skip to content

Commit 8a79b2a

Browse files
committed
Renamed Type to RecipientType in OCM shares and used it where missing
1 parent 66af487 commit 8a79b2a

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

pkg/share/manager/sql/conversions.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ func convertFromCS3OCMShareType(shareType ocm.ShareType) model.OcmShareType {
4242
return -1
4343
}
4444

45+
func convertToCS3OCMShareType(recipientType model.OcmShareType) ocm.ShareType {
46+
switch recipientType {
47+
case model.OcmShareTypeUser:
48+
return ocm.ShareType_SHARE_TYPE_USER
49+
case model.OcmShareTypeGroup:
50+
return ocm.ShareType_SHARE_TYPE_GROUP
51+
}
52+
return ocm.ShareType_SHARE_TYPE_INVALID
53+
}
54+
4555
func convertFromCS3OCMShareState(shareState ocm.ShareState) model.OcmShareState {
4656
switch shareState {
4757
case ocm.ShareState_SHARE_STATE_ACCEPTED:
@@ -96,7 +106,7 @@ func convertToCS3OCMShare(s *model.OcmShare, am []*ocm.AccessMethod) *ocm.Share
96106
Mtime: &types.Timestamp{
97107
Seconds: uint64(s.Mtime),
98108
},
99-
ShareType: ocm.ShareType_SHARE_TYPE_USER,
109+
ShareType: convertToCS3OCMShareType(s.RecipientType),
100110
AccessMethods: am,
101111
}
102112
if s.Expiration.Valid {
@@ -133,7 +143,7 @@ func convertToCS3OCMReceivedShare(s *model.OcmReceivedShare, p []*ocm.Protocol)
133143
Seconds: uint64(s.Mtime),
134144
},
135145
ResourceType: convertToCS3ResourceType(s.ItemType),
136-
ShareType: ocm.ShareType_SHARE_TYPE_USER,
146+
ShareType: convertToCS3OCMShareType(s.RecipientType),
137147
State: convertToCS3OCMShareState(s.State),
138148
Protocols: p,
139149
}

pkg/share/manager/sql/model/model.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,19 @@ type ShareState struct {
166166
// for that, we redeclare the DeletedAt as in Share. In addition, tokens must be unique.
167167
type OcmShare struct {
168168
BaseModel
169-
DeletedAt gorm.DeletedAt `gorm:"uniqueIndex:u_ocmshare"`
170-
Token string `gorm:"size:255;not null;uniqueIndex:u_ocmshare_token"`
171-
StorageId string `gorm:"size:64;not null;uniqueIndex:u_ocmshare"`
172-
FileId string `gorm:"size:64;not null;uniqueIndex:u_ocmshare"`
173-
Name string `gorm:"type:text;not null"`
174-
ShareWith string `gorm:"size:255;not null;uniqueIndex:u_ocmshare"`
175-
Owner string `gorm:"size:255;not null;uniqueIndex:u_ocmshare"`
176-
Initiator string `gorm:"type:text;not null"`
177-
Ctime uint64 `gorm:"not null"`
178-
Mtime uint64 `gorm:"not null"`
179-
Expiration sql.NullInt64 `gorm:"default:null"`
180-
Type OcmShareType `gorm:"not null"`
181-
Protocols []OcmShareProtocol `gorm:"constraint:OnDelete:CASCADE;"`
169+
DeletedAt gorm.DeletedAt `gorm:"uniqueIndex:u_ocmshare"`
170+
Token string `gorm:"size:255;not null;uniqueIndex:u_ocmshare_token"`
171+
StorageId string `gorm:"size:64;not null;uniqueIndex:u_ocmshare"`
172+
FileId string `gorm:"size:64;not null;uniqueIndex:u_ocmshare"`
173+
Name string `gorm:"type:text;not null"`
174+
ShareWith string `gorm:"size:255;not null;uniqueIndex:u_ocmshare"`
175+
Owner string `gorm:"size:255;not null;uniqueIndex:u_ocmshare"`
176+
Initiator string `gorm:"type:text;not null"`
177+
Ctime uint64 `gorm:"not null"`
178+
Mtime uint64 `gorm:"not null"`
179+
Expiration sql.NullInt64 `gorm:"default:null"`
180+
RecipientType OcmShareType `gorm:"not null"`
181+
Protocols []OcmShareProtocol `gorm:"constraint:OnDelete:CASCADE;"`
182182
}
183183

184184
// OcmShareProtocol represents the protocol used to access an OCM share, named AccessMethod in the OCM CS3 APIs.
@@ -201,7 +201,7 @@ type OcmReceivedShare struct {
201201
Ctime uint64 `gorm:"not null"`
202202
Mtime uint64 `gorm:"not null"`
203203
Expiration sql.NullInt64 `gorm:"default:null"`
204-
Type OcmShareType `gorm:"index:i_ocmrecshare_type;not null"`
204+
RecipientType OcmShareType `gorm:"index:i_ocmrecshare_type;not null"`
205205
State OcmShareState `gorm:"index:i_ocmrecshare_state;not null"`
206206
Alias string `gorm:"size:64"`
207207
Hidden bool

pkg/share/manager/sql/ocm_shares.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,16 @@ func (m *mgr) StoreShare(ctx context.Context, s *ocm.Share) (*ocm.Share, error)
8989
err = m.db.Transaction(func(tx *gorm.DB) error {
9090

9191
share := &model.OcmShare{
92-
Token: s.Token,
93-
StorageId: s.ResourceId.StorageId,
94-
FileId: s.ResourceId.OpaqueId,
95-
Name: s.Name,
96-
ShareWith: formatUserID(s.Grantee.GetUserId()),
97-
Owner: s.Owner.OpaqueId,
98-
Initiator: s.Creator.OpaqueId,
99-
Ctime: s.Ctime.Seconds,
100-
Mtime: s.Mtime.Seconds,
101-
Type: convertFromCS3OCMShareType(s.ShareType),
92+
Token: s.Token,
93+
StorageId: s.ResourceId.StorageId,
94+
FileId: s.ResourceId.OpaqueId,
95+
Name: s.Name,
96+
ShareWith: formatUserID(s.Grantee.GetUserId()),
97+
Owner: s.Owner.OpaqueId,
98+
Initiator: s.Creator.OpaqueId,
99+
Ctime: s.Ctime.Seconds,
100+
Mtime: s.Mtime.Seconds,
101+
RecipientType: convertFromCS3OCMShareType(s.ShareType),
102102
}
103103
if s.Expiration != nil {
104104
share.Expiration.Int64 = int64(s.Expiration.Seconds)
@@ -271,7 +271,7 @@ func (m *mgr) StoreReceivedShare(ctx context.Context, s *ocm.ReceivedShare) (*oc
271271
Initiator: formatUserID(s.Creator),
272272
Ctime: s.Ctime.Seconds,
273273
Mtime: s.Mtime.Seconds,
274-
Type: convertFromCS3OCMShareType(s.ShareType),
274+
RecipientType: convertFromCS3OCMShareType(s.ShareType),
275275
State: convertFromCS3OCMShareState(s.State),
276276
}
277277

0 commit comments

Comments
 (0)