Skip to content

Commit c8a4f2a

Browse files
committed
fix - files distribution only to selected suborg
1 parent 9471d41 commit c8a4f2a

File tree

3 files changed

+71
-86
lines changed

3 files changed

+71
-86
lines changed

db-connector.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10070,18 +10070,17 @@ func GetAllFiles(ctx context.Context, orgId, namespace string) ([]File, error) {
1007010070
}
1007110071
}
1007210072

10073-
// Should check if it's a child org and get parent orgs files if that is distributed
10073+
// Should check if it's a child org and get parent orgs files if that is distributed to that child org
1007410074
foundOrg, err := GetOrg(ctx, orgId)
1007510075
if err == nil && len(foundOrg.ChildOrgs) == 0 && len(foundOrg.CreatorOrg) > 0 && foundOrg.CreatorOrg != orgId {
1007610076
parentOrg, err := GetOrg(ctx, foundOrg.CreatorOrg)
1007710077
if err == nil {
1007810078
parentFiles, err := GetAllFiles(ctx, parentOrg.Id, namespace)
1007910079
if err == nil {
1008010080
for _, f := range parentFiles {
10081-
if !f.SuborgDistributed {
10081+
if !ArrayContains(f.SuborgDistribution, orgId) {
1008210082
continue
1008310083
}
10084-
1008510084
files = append(files, f)
1008610085
}
1008710086
}

files.go

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -571,15 +571,15 @@ func HandleGetFileNamespace(resp http.ResponseWriter, request *http.Request) {
571571
// FIXME: This double control is silly
572572
fileResponse.Files = append(fileResponse.Files, file)
573573
fileResponse.List = append(fileResponse.List, BaseFile{
574-
Name: file.Filename,
575-
ID: file.Id,
576-
Type: file.Type,
577-
UpdatedAt: file.UpdatedAt,
578-
Md5Sum: file.Md5sum,
579-
Status: file.Status,
580-
FileSize: file.FileSize,
581-
OrgId: file.OrgId,
582-
SuborgDistributed: file.SuborgDistributed,
574+
Name: file.Filename,
575+
ID: file.Id,
576+
Type: file.Type,
577+
UpdatedAt: file.UpdatedAt,
578+
Md5Sum: file.Md5sum,
579+
Status: file.Status,
580+
FileSize: file.FileSize,
581+
OrgId: file.OrgId,
582+
SuborgDistribution: file.SuborgDistribution,
583583
})
584584
}
585585
}
@@ -592,21 +592,23 @@ func HandleGetFileNamespace(resp http.ResponseWriter, request *http.Request) {
592592
parentFiles, err := GetAllFiles(ctx, parentOrg.Id, namespace)
593593
if err == nil {
594594
for _, file := range parentFiles {
595-
if !file.SuborgDistributed {
595+
596+
if !ArrayContains(file.SuborgDistribution, user.ActiveOrg.Id) {
596597
continue
597598
}
599+
598600
if file.Namespace == namespace {
599601
fileResponse.Files = append(fileResponse.Files, file)
600602
fileResponse.List = append(fileResponse.List, BaseFile{
601-
Name: file.Filename,
602-
ID: file.Id,
603-
Type: file.Type,
604-
UpdatedAt: file.UpdatedAt,
605-
Md5Sum: file.Md5sum,
606-
Status: file.Status,
607-
FileSize: file.FileSize,
608-
OrgId: file.OrgId,
609-
SuborgDistributed: file.SuborgDistributed,
603+
Name: file.Filename,
604+
ID: file.Id,
605+
Type: file.Type,
606+
UpdatedAt: file.UpdatedAt,
607+
Md5Sum: file.Md5sum,
608+
Status: file.Status,
609+
FileSize: file.FileSize,
610+
OrgId: file.OrgId,
611+
SuborgDistribution: file.SuborgDistribution,
610612
})
611613
}
612614
}
@@ -2144,8 +2146,9 @@ func HandleSetFileConfig(resp http.ResponseWriter, request *http.Request) {
21442146
}
21452147

21462148
type configFile struct {
2147-
Id string `json:"id"`
2148-
Action string `json:"action"`
2149+
Id string `json:"id"`
2150+
Action string `json:"action"`
2151+
SelectedSuborg []string `json:"selected_suborgs"`
21492152
}
21502153

21512154
var config configFile
@@ -2173,27 +2176,11 @@ func HandleSetFileConfig(resp http.ResponseWriter, request *http.Request) {
21732176
}
21742177

21752178
if config.Action == "suborg_distribute" {
2176-
org, err := GetOrg(ctx, user.ActiveOrg.Id)
2177-
if err != nil {
2178-
log.Printf("[ERROR] Failed getting org %s: %s", file.OrgId, err)
2179-
resp.WriteHeader(403)
2180-
resp.Write([]byte(`{"success": false, "reason": "Failed getting org"}`))
2181-
return
2182-
}
2183-
2184-
// Check if org doesn't have a creator org
2185-
if len(org.CreatorOrg) != 0 {
2186-
log.Printf("[INFO] Org %s has creator org %s, can't distribute", org.Id, org.CreatorOrg)
2187-
resp.WriteHeader(400)
2188-
resp.Write([]byte(`{"success": false, "reason": "Can't distribute auth for suborgs"}`))
2189-
return
2190-
}
2191-
2192-
if file.SuborgDistributed {
2193-
file.SuborgDistributed = false
21942179

2180+
if len(config.SelectedSuborg) == 0 {
2181+
file.SuborgDistribution = []string{}
21952182
} else {
2196-
file.SuborgDistributed = true
2183+
file.SuborgDistribution = config.SelectedSuborg
21972184
}
21982185

21992186
err = SetFile(ctx, *file)
@@ -2211,7 +2198,6 @@ func HandleSetFileConfig(resp http.ResponseWriter, request *http.Request) {
22112198
if err == nil {
22122199
for _, childOrg := range foundOrg.ChildOrgs {
22132200
cacheKey := fmt.Sprintf("files_%s_%s", childOrg.Id, file.Namespace)
2214-
log.Printf("Clearing cache for %s", cacheKey)
22152201
DeleteCache(ctx, cacheKey)
22162202
}
22172203
}

structs.go

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,39 +1434,39 @@ type NotificationCached struct {
14341434
}
14351435

14361436
type File struct {
1437-
Id string `json:"id" datastore:"id"`
1438-
ReferenceFileId string `json:"reference_file_id" datastore:"reference_file_id"`
1439-
Type string `json:"type" datastore:"type"`
1440-
CreatedAt int64 `json:"created_at" datastore:"created_at"`
1441-
UpdatedAt int64 `json:"updated_at" datastore:"updated_at"`
1442-
MetaAccessAt int64 `json:"meta_access_at" datastore:"meta_access_at"`
1443-
DownloadAt int64 `json:"last_downloaded" datastore:"last_downloaded"`
1444-
Description string `json:"description" datastore:"description"`
1445-
ExpiresAt string `json:"expires_at" datastore:"expires_at"`
1446-
Status string `json:"status" datastore:"status"`
1447-
Filename string `json:"filename" datastore:"filename"`
1448-
URL string `json:"url" datastore:"org"`
1449-
OrgId string `json:"org_id" datastore:"org_id"`
1450-
WorkflowId string `json:"workflow_id" datastore:"workflow_id"`
1451-
Workflows []string `json:"workflows" datastore:"workflows"`
1452-
DownloadPath string `json:"download_path" datastore:"download_path"`
1453-
Md5sum string `json:"md5_sum" datastore:"md5_sum"`
1454-
Sha256sum string `json:"sha256_sum" datastore:"sha256_sum"`
1455-
FileSize int64 `json:"filesize" datastore:"filesize"`
1456-
Duplicate bool `json:"duplicate" datastore:"duplicate"`
1457-
Subflows []string `json:"subflows" datastore:"subflows"`
1458-
Tags []string `json:"tags" datastore:"tags"`
1459-
StorageArea string `json:"storage_area" datastore:"storage_area"`
1460-
Etag int `json:"etag" datastore:"etag"`
1461-
ContentType string `json:"content_type" datastore:"content_type"`
1462-
UpdatedBy string `json:"updated_by" datastore:"updated_by"`
1463-
CreatedBy string `json:"created_by" datastore:"created_by"`
1464-
Namespace string `json:"namespace" datastore:"namespace"`
1465-
Encrypted bool `json:"encrypted" datastore:"encrypted"`
1466-
IsEdited bool `json:"isedited" datastore:"isedited"`
1467-
LastEditor string `json:"lasteditor" datastore:"lasteditor"`
1468-
OriginalMd5sum string `json:"Originalmd5_sum" datastore:"Originalmd5_sum"`
1469-
SuborgDistributed bool `json:"suborg_distributed" datastore:"suborg_distributed"`
1437+
Id string `json:"id" datastore:"id"`
1438+
ReferenceFileId string `json:"reference_file_id" datastore:"reference_file_id"`
1439+
Type string `json:"type" datastore:"type"`
1440+
CreatedAt int64 `json:"created_at" datastore:"created_at"`
1441+
UpdatedAt int64 `json:"updated_at" datastore:"updated_at"`
1442+
MetaAccessAt int64 `json:"meta_access_at" datastore:"meta_access_at"`
1443+
DownloadAt int64 `json:"last_downloaded" datastore:"last_downloaded"`
1444+
Description string `json:"description" datastore:"description"`
1445+
ExpiresAt string `json:"expires_at" datastore:"expires_at"`
1446+
Status string `json:"status" datastore:"status"`
1447+
Filename string `json:"filename" datastore:"filename"`
1448+
URL string `json:"url" datastore:"org"`
1449+
OrgId string `json:"org_id" datastore:"org_id"`
1450+
WorkflowId string `json:"workflow_id" datastore:"workflow_id"`
1451+
Workflows []string `json:"workflows" datastore:"workflows"`
1452+
DownloadPath string `json:"download_path" datastore:"download_path"`
1453+
Md5sum string `json:"md5_sum" datastore:"md5_sum"`
1454+
Sha256sum string `json:"sha256_sum" datastore:"sha256_sum"`
1455+
FileSize int64 `json:"filesize" datastore:"filesize"`
1456+
Duplicate bool `json:"duplicate" datastore:"duplicate"`
1457+
Subflows []string `json:"subflows" datastore:"subflows"`
1458+
Tags []string `json:"tags" datastore:"tags"`
1459+
StorageArea string `json:"storage_area" datastore:"storage_area"`
1460+
Etag int `json:"etag" datastore:"etag"`
1461+
ContentType string `json:"content_type" datastore:"content_type"`
1462+
UpdatedBy string `json:"updated_by" datastore:"updated_by"`
1463+
CreatedBy string `json:"created_by" datastore:"created_by"`
1464+
Namespace string `json:"namespace" datastore:"namespace"`
1465+
Encrypted bool `json:"encrypted" datastore:"encrypted"`
1466+
IsEdited bool `json:"isedited" datastore:"isedited"`
1467+
LastEditor string `json:"lasteditor" datastore:"lasteditor"`
1468+
OriginalMd5sum string `json:"Originalmd5_sum" datastore:"Originalmd5_sum"`
1469+
SuborgDistribution []string `json:"suborg_distribution" datastore:"suborg_distribution"`
14701470
}
14711471

14721472
type DisabledRules struct {
@@ -2716,15 +2716,15 @@ type DataToSend struct {
27162716
}
27172717

27182718
type BaseFile struct {
2719-
Name string `json:"name"`
2720-
ID string `json:"id"`
2721-
Type string `json:"type"`
2722-
UpdatedAt int64 `json:"updated_at"`
2723-
Md5Sum string `json:"md5_sum"`
2724-
Status string `json:"status"`
2725-
FileSize int64 `json:"filesize"`
2726-
OrgId string `json:"org_id"`
2727-
SuborgDistributed bool `json:"suborg_distributed"`
2719+
Name string `json:"name"`
2720+
ID string `json:"id"`
2721+
Type string `json:"type"`
2722+
UpdatedAt int64 `json:"updated_at"`
2723+
Md5Sum string `json:"md5_sum"`
2724+
Status string `json:"status"`
2725+
FileSize int64 `json:"filesize"`
2726+
OrgId string `json:"org_id"`
2727+
SuborgDistribution []string `json:"suborg_distribution"`
27282728
}
27292729

27302730
type FileResponse struct {

0 commit comments

Comments
 (0)