Merge pull request #1823 from LalitDeore/license-1

add cloud sync data in cache
This commit is contained in:
Frikky
2025-10-06 12:21:30 +02:00
committed by GitHub
2 changed files with 70 additions and 11 deletions
+63 -11
View File
@@ -936,6 +936,58 @@ func handleInfo(resp http.ResponseWriter, request *http.Request) {
log.Printf("[DEBUG] Failed to get org during getinfo: %s", err)
}
childOrgs := []shuffle.Org{}
if len(org.CreatorOrg) > 0 {
childOrgs, err = shuffle.GetAllChildOrgs(ctx, org.CreatorOrg)
if err != nil {
log.Printf("[ERROR] Failed to get child orgs during getinfo: %s", err)
childOrgs = []shuffle.Org{}
}
}
failToLoadOrgs := []string{}
sort.Slice(childOrgs, func(i, j int) bool {
return childOrgs[i].Created < childOrgs[j].Created
})
for index, org := range childOrgs {
if index < 3 {
continue
}
failToLoadOrgs = append(failToLoadOrgs, org.Id)
}
if len(org.CreatorOrg) > 0 && len(childOrgs) > 3 && shuffle.ArrayContains(failToLoadOrgs, userInfo.ActiveOrg.Id) {
parentOrg, err := shuffle.GetOrg(ctx, org.CreatorOrg)
if err != nil {
log.Printf("[ERROR] Failed to get parent org during getinfo: %s", err)
} else {
parent := shuffle.HandleCheckLicense(ctx, *parentOrg)
parentOrg := &parent
if !parentOrg.SyncFeatures.MultiTenant.Active {
userInfo.ActiveOrg = shuffle.OrgMini{
Id: parentOrg.Id,
Name: parentOrg.Name,
Role: userInfo.Role,
Branding: parentOrg.Branding,
Image: parentOrg.Image,
}
log.Printf("[INFO] Parent org %s has more than 3 child orgs and is not licensed. Moving user %s to parent org %s", parentOrg.Name, userInfo.Username, parentOrg.Name)
err = shuffle.SetUser(ctx, &userInfo, false)
if err != nil {
log.Printf("[WARNING] Failed setting user to parent org: %s", err)
}
resp.WriteHeader(200)
resp.Write([]byte(`{"success": true, "reason": "Parent org has more than 3 child orgs and is not licensed. Moving to parent org. Contact support@shuffler.io for more information", "switch_parent": true}`))
return
}
}
}
//if err == nil {
if len(org.Id) > 0 {
if userInfo.Role == "" {
@@ -3895,15 +3947,7 @@ func remoteOrgJobController(org shuffle.Org, body []byte) error {
if err != nil {
log.Printf("[ERROR] Failed to marshal SyncFeatures for cache: %s", err)
} else {
shuffle.SetCache(ctx, cacheKey, featuresBytes, 30)
}
subscriptionCacheKey := fmt.Sprintf("org_subscriptions_%s", org.Id)
subscriptionsBytes, err := json.Marshal(responseData.Subscriptions)
if err != nil {
log.Printf("[ERROR] Failed to marshal Subscriptions for cache: %s", err)
} else {
shuffle.SetCache(ctx, subscriptionCacheKey, subscriptionsBytes, 1800)
shuffle.SetCache(ctx, cacheKey, featuresBytes, 1800)
}
for _, job := range responseData.Jobs {
@@ -4910,8 +4954,16 @@ func handleCloudSetup(resp http.ResponseWriter, request *http.Request) {
// 2. Add iterative sync schedule for interval seconds
// 3. Add another environment for the org's users
org.CloudSync = true
org.SyncFeatures = responseData.SyncFeatures
org.Subscriptions = responseData.Subscriptions
// set cache here for 30 min
cacheKey := fmt.Sprintf("org_sync_features_%s", org.Id)
featuresBytes, err := json.Marshal(responseData.SyncFeatures)
if err != nil {
log.Printf("[ERROR] Failed to marshal SyncFeatures for cache: %s", err)
} else {
shuffle.SetCache(ctx, cacheKey, featuresBytes, 1800)
}
org.SyncConfig = shuffle.SyncConfig{
Apikey: responseData.SessionKey,
Interval: responseData.IntervalSeconds,
+7
View File
@@ -180,6 +180,13 @@ const App = (message, props) => {
var userInfo = {};
if (responseJson.success === true) {
//console.log("USER: ", responseJson);
if (responseJson?.switch_parent === true) {
toast.info(responseJson.reason)
setTimeout(() => {
window.location.reload();
}, 3000);
return
}
userInfo = responseJson;
setIsLoggedIn(true);