Skip to content

Commit 8d8e038

Browse files
committed
Removed Permissions from unique index + another rename for consistency
1 parent 07afd6d commit 8d8e038

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

changelog/unreleased/ocm-model-refactor.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ some fields for better consistency:
1010
* `Type` has been renamed to `RecipientType` with
1111
type `OcmShareType`, and converted both ways
1212
* Unique index constraints have been created as follows:
13-
* For `Shares` on `(inode, instance, permissions, recipient, deletedAt)`
14-
* For `OcmShares` on `(storageId, fileId, shareWith, owner, deletedAt)`
13+
* For `Shares` on `(inode, instance, recipient, deletedAt)`
14+
* For `OcmShares` on `(inode, instance, shareWith, owner, deletedAt)`
1515
* The unique indexes have been renamed with a `u_`
1616
prefix for consistency: this affected `u_shareid_user`,
1717
`u_link_token`. The `i_share_with` was dropped
1818
as redundant.
1919
* The `(FileIdPrefix, ItemSource)` tuple is now
20-
`(StorageId, FileId)` in `OcmShare`, and it was
21-
removed from `OcmReceivedShare` as unused
20+
`(Instance, Inode)` in `OcmShare` to be consistent
21+
with the regular shares, and it was removed
22+
from `OcmReceivedShare` as unused
2223
* `Alias` and `Hidden` were added in `OcmReceivedShare`
2324

2425
https://github.com/cs3org/reva/pull/5402

pkg/share/manager/sql/conversions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ func convertToCS3OCMShare(s *model.OcmShare, am []*ocm.AccessMethod) *ocm.Share
8383
OpaqueId: strconv.Itoa(int(s.Id)),
8484
},
8585
ResourceId: &provider.ResourceId{
86-
StorageId: s.StorageId,
87-
OpaqueId: s.FileId,
86+
StorageId: s.Instance,
87+
OpaqueId: s.Inode,
8888
},
8989
Name: s.Name,
9090
Token: s.Token,

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,18 @@ type ProtoShare struct {
125125

126126
// Share is a regular share between users or groups. The unique index ensures that there
127127
// can only be one share per (inode, instance, permissions, recipient) tuple, unless the share is deleted:
128-
// for that, we redeclare the corresponding fields for GORM to define the unique index.
128+
// for that, we redeclare `DeletedAt`, `Inode`, and `Instance` for GORM to define the unique index.
129129
type Share struct {
130130
ProtoShare
131131
DeletedAt gorm.DeletedAt `gorm:"uniqueIndex:u_share"`
132132
Inode string `gorm:"size:32;uniqueIndex:u_share"`
133133
Instance string `gorm:"size:32;uniqueIndex:u_share"`
134-
Permissions uint8 `gorm:"uniqueIndex:u_share"`
135134
ShareWith string `gorm:"size:255;uniqueIndex:u_share"` // 255 because this can be an external account, which has a long representation
136135
SharedWithIsGroup bool
137136
Description string `gorm:"size:1024"`
138137
}
139138

140-
// PublicLink is a public link share.
141-
// TODO(lopresti) We could enforce a unique index on (UIDInitiator, Inode, Permissions, DeleteAt) but for now web allows
142-
// the creation of multiple links (with or without different names), so we only enforce a unique constraint on the token.
139+
// PublicLink is a public link share. We only enforce a unique constraint on the token.
143140
type PublicLink struct {
144141
ProtoShare
145142
Token string `gorm:"uniqueIndex:u_link_token;size:32"` // Current tokens are only 16 chars long, but old tokens used to be 32 characters
@@ -162,14 +159,14 @@ type ShareState struct {
162159
}
163160

164161
// OcmShare represents an OCM share for a remote user. The unique index ensures that there
165-
// can only be one share per (storageId, fileId, shareWith, owner) tuple, unless the share is deleted:
166-
// for that, we redeclare the DeletedAt as in Share. In addition, tokens must be unique.
162+
// can only be one share per (inode, instance, shareWith, owner) tuple, unless the share is deleted:
163+
// for that, we redeclare `DeletedAt`, `Inode`, and `Instance` as in Share. In addition, tokens must be unique.
167164
type OcmShare struct {
168165
BaseModel
169166
DeletedAt gorm.DeletedAt `gorm:"uniqueIndex:u_ocmshare"`
167+
Inode string `gorm:"size:64;not null;uniqueIndex:u_ocmshare"`
168+
Instance string `gorm:"size:64;not null;uniqueIndex:u_ocmshare"`
170169
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"`
173170
Name string `gorm:"type:text;not null"`
174171
ShareWith string `gorm:"size:255;not null;uniqueIndex:u_ocmshare"`
175172
Owner string `gorm:"size:255;not null;uniqueIndex:u_ocmshare"`

pkg/share/manager/sql/ocm_shares.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ func (m *mgr) StoreShare(ctx context.Context, s *ocm.Share) (*ocm.Share, error)
9090

9191
share := &model.OcmShare{
9292
Token: s.Token,
93-
StorageId: s.ResourceId.StorageId,
94-
FileId: s.ResourceId.OpaqueId,
93+
Instance: s.ResourceId.StorageId,
94+
Inode: s.ResourceId.OpaqueId,
9595
Name: s.Name,
9696
ShareWith: formatUserID(s.Grantee.GetUserId()),
9797
Owner: s.Owner.OpaqueId,

0 commit comments

Comments
 (0)