Fix group file metadata and access
This commit is contained in:
@@ -5187,6 +5187,13 @@ func (a *adapter) FileUserHasAccess(fid string, uid t.Uid) (bool, error) {
|
||||
AND d.low<=m.seqid AND (d.hi=0 OR d.hi>m.seqid)
|
||||
)
|
||||
)
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM im_group_files AS gf
|
||||
INNER JOIN im_subscriptions AS s
|
||||
ON s.topic=gf.topic AND s.userid=?
|
||||
WHERE (gf.file_id=? OR gf.file_id LIKE CONCAT(?,'.%')) AND gf.status='active'
|
||||
AND s.deletedat IS NULL AND INSTR(s.modewant,'R')>0 AND INSTR(s.modegiven,'R')>0
|
||||
)
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM im_meeting_note_files AS mnf
|
||||
INNER JOIN im_meetings AS mtg
|
||||
@@ -5205,6 +5212,7 @@ func (a *adapter) FileUserHasAccess(fid string, uid t.Uid) (bool, error) {
|
||||
)
|
||||
) LIMIT 1`,
|
||||
store.DecodeUid(fileID), t.UploadCompleted, store.DecodeUid(uid), store.DecodeUid(uid), store.DecodeUid(uid), store.DecodeUid(uid), store.DecodeUid(uid),
|
||||
store.DecodeUid(uid), fid, fid,
|
||||
fid, t.MeetingStateCanceled, store.DecodeUid(uid), store.DecodeUid(uid), store.DecodeUid(uid))
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
||||
@@ -7843,8 +7843,16 @@ func (a *adapter) TenantFileUserHasAccess(id t.TenantID, fid string, uid t.Uid)
|
||||
AND d.low<=m.seqid AND (d.hi=0 OR d.hi>m.seqid)
|
||||
)
|
||||
)
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM im_group_files AS gf
|
||||
INNER JOIN im_subscriptions AS s
|
||||
ON s.tenant_id=fu.tenant_id AND s.topic=gf.topic AND s.userid=?
|
||||
WHERE (gf.file_id=? OR gf.file_id LIKE CONCAT(?,'.%')) AND gf.status='active'
|
||||
AND s.deletedat IS NULL AND INSTR(s.modewant,'R')>0 AND INSTR(s.modegiven,'R')>0
|
||||
)
|
||||
) LIMIT 1`,
|
||||
id, decodeUID(fileID), t.UploadCompleted, decodeUID(uid), decodeUID(uid), decodeUID(uid), decodeUID(uid), decodeUID(uid))
|
||||
id, decodeUID(fileID), t.UploadCompleted, decodeUID(uid), decodeUID(uid), decodeUID(uid), decodeUID(uid), decodeUID(uid),
|
||||
decodeUID(uid), fid, fid)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -933,6 +933,7 @@ func (a *adapter) TenantGroupFileCreate(id t.TenantID, file *t.GroupFile) (*t.Gr
|
||||
if file.IdempotencyKey == "" {
|
||||
file.IdempotencyKey = file.GroupFileID
|
||||
}
|
||||
a.enrichGroupFileFromUpload(id, file)
|
||||
now := t.TimeNow()
|
||||
ctx, cancel := a.getContext()
|
||||
if cancel != nil {
|
||||
@@ -941,7 +942,12 @@ func (a *adapter) TenantGroupFileCreate(id t.TenantID, file *t.GroupFile) (*t.Gr
|
||||
_, err := a.db.ExecContext(ctx, `INSERT INTO im_group_files
|
||||
(group_file_id,topic,file_id,source_topic,source_seq,uploader_id,file_name,mime_type,file_type,file_size,status,idempotency_key,created_at,updated_at)
|
||||
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||
ON DUPLICATE KEY UPDATE updated_at=updated_at`,
|
||||
ON DUPLICATE KEY UPDATE
|
||||
file_name=IF(file_name='', VALUES(file_name), file_name),
|
||||
mime_type=IF(mime_type='', VALUES(mime_type), mime_type),
|
||||
file_size=IF(file_size=0, VALUES(file_size), file_size),
|
||||
file_type=IF(file_type='' OR file_type='file', VALUES(file_type), file_type),
|
||||
updated_at=updated_at`,
|
||||
file.GroupFileID, file.Topic, file.FileID, file.SourceTopic, file.SourceSeq, decodeUID(file.UploaderID),
|
||||
file.FileName, file.MIMEType, file.FileType, file.FileSize, file.Status, file.IdempotencyKey, now, now)
|
||||
if err != nil && !isDupe(err) {
|
||||
@@ -950,6 +956,32 @@ func (a *adapter) TenantGroupFileCreate(id t.TenantID, file *t.GroupFile) (*t.Gr
|
||||
return a.groupFileByQuery(ctx, "SELECT * FROM im_group_files WHERE topic=? AND file_id=?", file.Topic, file.FileID)
|
||||
}
|
||||
|
||||
func (a *adapter) enrichGroupFileFromUpload(id t.TenantID, file *t.GroupFile) {
|
||||
if file == nil || t.ParseUid(file.FileID).IsZero() {
|
||||
return
|
||||
}
|
||||
fd, err := a.TenantFileGet(id, file.FileID)
|
||||
if err != nil || fd == nil {
|
||||
if file.FileName == "" {
|
||||
file.FileName = file.FileID
|
||||
}
|
||||
return
|
||||
}
|
||||
if file.MIMEType == "" {
|
||||
file.MIMEType = strings.TrimSpace(fd.MimeType)
|
||||
}
|
||||
if file.FileSize <= 0 {
|
||||
file.FileSize = fd.Size
|
||||
}
|
||||
if file.FileName == "" {
|
||||
if original := strings.TrimSpace(fd.OriginalName); original != "" {
|
||||
file.FileName = original
|
||||
} else {
|
||||
file.FileName = file.FileID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a *adapter) TenantGroupFileDelete(id t.TenantID, topic, groupFileID string, actor t.Uid, canManage bool, now time.Time) (*t.GroupFile, error) {
|
||||
if tenantAdp, err := a.routeGroupTenant(id); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user