Skip to content

Commit 208eaaa

Browse files
authored
Merge pull request #7564 from tanmoysrt/fix/trial-wait-until-site-reachable
fix(product-trial): Wait until the site answers before login redirect
2 parents 01d1b19 + ae37f68 commit 208eaaa

2 files changed

Lines changed: 65 additions & 39 deletions

File tree

‎dashboard/src/pages/signup/LoginToSite.vue‎

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
</div>
6363
</template>
6464
<script>
65-
import LoginBox from '../../components/auth/LoginBox.vue';
66-
import { Progress } from 'frappe-ui';
65+
import { Progress } from 'frappe-ui'
66+
import LoginBox from '../../components/auth/LoginBox.vue'
6767
6868
export default {
6969
name: 'SignupLoginToSite',
@@ -77,7 +77,7 @@ export default {
7777
product_trial_request: this.$route.query.product_trial_request,
7878
progressCount: 0,
7979
currentBuildStep: 'Configuring your setup',
80-
};
80+
}
8181
},
8282
resources: {
8383
saasProduct() {
@@ -86,7 +86,7 @@ export default {
8686
doctype: 'Product Trial',
8787
name: this.productId,
8888
auto: true,
89-
};
89+
}
9090
},
9191
siteRequest() {
9292
return {
@@ -97,12 +97,12 @@ export default {
9797
auto: true,
9898
onSuccess(doc) {
9999
if (doc.status === 'Site Created') {
100-
this.showCompleteProgress();
100+
this.showCompleteProgress()
101101
setTimeout(() => {
102-
this.loginToSite();
103-
}, 500);
102+
this.loginToSite()
103+
}, 500)
104104
} else if (this.isSiteProvisioning(doc.status)) {
105-
this.$resources.siteRequest.getProgress.reload();
105+
this.$resources.siteRequest.getProgress.reload()
106106
}
107107
},
108108
whitelistedMethods: {
@@ -111,15 +111,15 @@ export default {
111111
makeParams() {
112112
return {
113113
current_progress: this.progressCount,
114-
};
114+
}
115115
},
116116
onSuccess: (data) => {
117117
if (data.current_step === 'Site Created') {
118-
this.showCompleteProgress();
118+
this.showCompleteProgress()
119119
setTimeout(() => {
120-
this.loginToSite();
121-
}, 500);
122-
return;
120+
this.loginToSite()
121+
}, 500)
122+
return
123123
}
124124
125125
const currentStepMap = {
@@ -128,13 +128,13 @@ export default {
128128
'Prefilling Setup Wizard': 'Configuring your site',
129129
'Adding Domain': 'Configuring your site',
130130
'Site Created': 'Almost there',
131-
};
131+
}
132132
133133
this.currentBuildStep =
134134
currentStepMap[data.current_step] ||
135135
data.current_step ||
136-
this.currentBuildStep;
137-
const nextProgress = Number(data.progress || 0);
136+
this.currentBuildStep
137+
const nextProgress = Number(data.progress || 0)
138138
139139
if (
140140
!(
@@ -145,73 +145,86 @@ export default {
145145
const visibleProgress = Math.min(
146146
Math.max(nextProgress, this.progressCount + 0.2),
147147
95,
148-
);
149-
this.progressCount = Math.round(visibleProgress * 10) / 10;
148+
)
149+
this.progressCount = Math.round(visibleProgress * 10) / 10
150150
setTimeout(() => {
151151
if (
152152
['Site Created', 'Error'].includes(
153153
this.$resources.siteRequest.doc.status,
154154
)
155155
)
156-
return;
156+
return
157157
158-
this.$resources.siteRequest.getProgress.reload();
159-
}, 2000);
158+
this.$resources.siteRequest.getProgress.reload()
159+
}, 2000)
160160
}
161161
},
162162
},
163+
isSiteReachable: {
164+
method: 'is_site_reachable',
165+
onError() {},
166+
},
163167
getLoginSid: {
164168
method: 'get_login_sid',
165169
onSuccess(loginURL) {
166-
window.open(loginURL, '_self');
170+
window.open(loginURL, '_self')
167171
},
168172
},
169173
},
170-
};
174+
}
171175
},
172176
},
173177
computed: {
174178
saasProduct() {
175-
return this.$resources.saasProduct.doc;
179+
return this.$resources.saasProduct.doc
176180
},
177181
siteRequestDoc() {
178-
return this.$resources?.siteRequest?.doc;
182+
return this.$resources?.siteRequest?.doc
179183
},
180184
currentHelpText() {
181185
const defaultHelpTexts = [
182186
'Find anything with the Awesome bar',
183187
'All Frappe apps are open-source',
184188
'You can install more apps later',
185-
];
189+
]
186190
187191
const productHelpTexts = this.saasProduct?.help_texts
188192
? this.saasProduct.help_texts.map((t) => t.help_text)
189-
: [];
193+
: []
190194
const helpTexts = productHelpTexts.length
191195
? productHelpTexts
192-
: defaultHelpTexts;
193-
const helpTextIndex = Math.floor(this.progressCount) % helpTexts.length;
196+
: defaultHelpTexts
197+
const helpTextIndex = Math.floor(this.progressCount) % helpTexts.length
194198
195-
return helpTexts[helpTextIndex] || defaultHelpTexts[0];
199+
return helpTexts[helpTextIndex] || defaultHelpTexts[0]
196200
},
197201
},
198202
methods: {
199203
showCompleteProgress() {
200-
this.progressCount = 100;
201-
this.currentBuildStep = 'Almost there';
204+
this.progressCount = 100
205+
this.currentBuildStep = 'Almost there'
202206
},
203207
isSiteProvisioning(status) {
204-
return ['Wait for Site', 'Prefilling Setup Wizard', 'Adding Domain'].includes(
205-
status,
206-
);
208+
return [
209+
'Wait for Site',
210+
'Prefilling Setup Wizard',
211+
'Adding Domain',
212+
].includes(status)
207213
},
208-
loginToSite() {
214+
async loginToSite() {
209215
this.$pulse?.capture('trial_redirected_to_site', {
210216
product: this.productId,
211217
site: this.siteRequestDoc?.site,
212-
});
213-
this.$resources.siteRequest.getLoginSid.submit();
218+
})
219+
for (let attempt = 0; attempt < 30; attempt++) {
220+
const reachable = await this.$resources.siteRequest.isSiteReachable
221+
.submit()
222+
.catch(() => false)
223+
if (reachable) break
224+
await new Promise((resolve) => setTimeout(resolve, 3000))
225+
}
226+
this.$resources.siteRequest.getLoginSid.submit()
214227
},
215228
},
216-
};
229+
}
217230
</script>

‎press/saas/doctype/product_trial_request/product_trial_request.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,19 @@ def prefill_setup_wizard_data(self):
520520
reference_name=self.name,
521521
)
522522

523+
@dashboard_whitelist()
524+
def is_site_reachable(self) -> bool:
525+
# A proxy that doesn't know the domain yet redirects to the dashboard instead
526+
import requests
527+
528+
try:
529+
response = requests.get(
530+
f"https://{self.domain or self.site}/api/method/ping", allow_redirects=False, timeout=5
531+
)
532+
except requests.RequestException:
533+
return False
534+
return response.status_code == 200
535+
523536
@dashboard_whitelist()
524537
def get_login_sid(self):
525538
site: Site = frappe.get_doc("Site", self.site)

0 commit comments

Comments
 (0)