Skip to content

Commit 23385fc

Browse files
authored
Merge pull request #105 from topcoder-platform/mfe-issues-9
MFE-issues-9:redirect to mf forums
2 parents 710005f + 8897d38 commit 23385fc

File tree

1 file changed

+68
-3
lines changed

1 file changed

+68
-3
lines changed

Topcoder/class.topcoder.plugin.php

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ public function settingsController_topcoder_create($sender) {
187187
$cf->form()->validateRule('Plugins.Topcoder.RoleApiURI', 'ValidateRequired', t('You must provide Role API URI.'));
188188
$cf->form()->validateRule('Plugins.Topcoder.ResourceRolesApiURI', 'ValidateRequired', t('You must provide Resource Roles API URI.'));
189189
$cf->form()->validateRule('Plugins.Topcoder.ResourcesApiURI', 'ValidateRequired', t('You must provide Resources API URI.'));
190+
$isEmbedded = (bool) c('Garden.Embed.Allow');
191+
if ($isEmbedded) {
192+
$cf->form()->validateRule('Plugins.Topcoder.MicroFrontendsForumsURL', 'ValidateRequired', t('You must provide Micro-Frontends Forums URL.'));
193+
}
190194
$cf->form()->validateRule('Plugins.Topcoder.MemberProfileURL', 'ValidateRequired', t('You must provide Member Profile URL.'));
191195
if($cf->form()->getFormValue('Plugins.Topcoder.UseTopcoderAuthToken') == 1) {
192196
$cf->form()->validateRule('AuthenticationProvider.SignInUrl', 'ValidateRequired', t('You must provide SignIn URL.'));
@@ -209,6 +213,7 @@ public function settingsController_topcoder_create($sender) {
209213
'Plugins.Topcoder.RoleApiURI' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Role API URI'],
210214
'Plugins.Topcoder.ResourceRolesApiURI' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Resource Roles API URI'],
211215
'Plugins.Topcoder.ResourcesApiURI' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Resources API URI'],
216+
'Plugins.Topcoder.MicroFrontendsForumsURL' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Micro-Frontends Forums URL'],
212217
'Plugins.Topcoder.MemberProfileURL' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Member Profile URL'],
213218
'Plugins.Topcoder.UseTopcoderAuthToken' => ['Control' => 'CheckBox', 'Default' => false, 'Description' => 'Use Topcoder access token to log in to Vanilla'],
214219
'AuthenticationProvider.SignInUrl' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder SignIn URL'],
@@ -284,6 +289,8 @@ public function gdn_auth_startAuthenticator_handler() {
284289
if(!c('Garden.Installed')) {
285290
return;
286291
}
292+
self::log('Embedded Settings', ['Garden.Embed.Allow' => c('Garden.Embed.Allow')]);
293+
287294
self::log('Cache', ['Active Cache' => Gdn_Cache::activeCache(), 'Type' =>Gdn::cache()->type()]);
288295

289296
if(!$this->isDefault()) {
@@ -1955,11 +1962,69 @@ private static function topcoderUserCache($userFields) {
19551962
return $cached;
19561963
}
19571964

1958-
// TODO: Debugging issues-108
1965+
// Support Micro-frontends forums app
19591966
public function gdn_dispatcher_beforeDispatch_handler($sender, $args) {
1960-
self::log('gdn_dispatcher_beforeDispatch_handler', [
1967+
$mfeUrl = c("Plugins.Topcoder.MicroFrontendsForumsURL");
1968+
$deliveryType = Gdn::request()->getQueryItem("DeliveryType");
1969+
$remoteUrl = Gdn::request()->getQueryItem("remote")? urldecode(Gdn::request()->getQueryItem("remote")):"";
1970+
$isEmbedded = (bool) c('Garden.Embed.Allow', false);
1971+
1972+
$data = array(
1973+
'Garden.Embed.Allow' => c('Garden.Embed.Allow'),
1974+
'MFEUrl' => $mfeUrl,
1975+
'RemoteQueryParam("remote")' => $remoteUrl,
1976+
'RemoteQueryParam("remote") == mfeUrl' => strcmp($mfeUrl, $remoteUrl) === 0,
1977+
'Request(current fullPath)' => Gdn::request()->getFullPath(),
1978+
'Request(current url)'=> Gdn::request()->getUrl(),
1979+
'currentUrl == mfeUrl' => strcmp($mfeUrl, Gdn::request()->getUrl()) === 0,
1980+
'Request(pathAndQuery)' => Gdn::request()->pathAndQuery(),
1981+
'Request(Method)'=> Gdn::request()->getMethod(),
1982+
'Request(DeliveryType)' =>Gdn::request()->getQueryItem("DeliveryType"),
1983+
'Request(DeliveryType calculated)'=> !($deliveryType == "" || $deliveryType == DELIVERY_TYPE_ALL),
19611984
'Permissions' => Gdn::session()->getPermissionsArray(),
1962-
]);
1985+
);
1986+
logMessage(__FILE__, __LINE__, 'TopcoderPlugin', "Data", json_encode($data ));
1987+
1988+
self::log('gdn_dispatcher_beforeDispatch_handler', $data);
1989+
1990+
1991+
if(!$isEmbedded) {
1992+
return;
1993+
}
1994+
1995+
if(Gdn::request()->getMethod() != Gdn::request()::METHOD_GET) {
1996+
return;
1997+
}
1998+
if(stringBeginsWith(Gdn::request()->getPath(), '/api/') || stringBeginsWith(Gdn::request()->getPath(), '/dashboard')
1999+
|| stringBeginsWith(Gdn::request()->getPath(), '/settings')
2000+
|| stringBeginsWith(Gdn::request()->getPath(), '/embed/')
2001+
|| stringBeginsWith(Gdn::request()->getPath(), '/social/')
2002+
|| stringBeginsWith(Gdn::request()->getPath(), '/vanilla/')
2003+
|| stringBeginsWith(Gdn::request()->getPath(), '/utility/') || stringBeginsWith(Gdn::request()->getPath(), '/notifications/')
2004+
|| stringBeginsWith(Gdn::request()->getPath(), '/js/')
2005+
|| stringBeginsWith(Gdn::request()->getPath(), '/applications/')
2006+
|| stringBeginsWith(Gdn::request()->getPath(), '/themes/')
2007+
|| stringBeginsWith(Gdn::request()->getPath(), '/dist/')
2008+
|| stringBeginsWith(Gdn::request()->getPath(), '/css/')
2009+
|| stringBeginsWith(Gdn::request()->getPath(), '/plugins/')
2010+
|| stringBeginsWith(Gdn::request()->getPath(), '/resources/')) {
2011+
return;
2012+
}
2013+
2014+
if(!($deliveryType == "" || $deliveryType == DELIVERY_TYPE_ALL)) {
2015+
return;
2016+
}
2017+
if(stringBeginsWith(Gdn::request()->getUrl(), $mfeUrl)) {
2018+
return;
2019+
}
2020+
2021+
if(strlen($remoteUrl) > 0){
2022+
return;
2023+
} else {
2024+
safeHeader("HTTP/1.1 301 Moved Permanently");
2025+
safeHeader("Location: " . url($mfeUrl."/#/" . Gdn::request()->pathAndQuery()));
2026+
exit();
2027+
}
19632028
}
19642029

19652030
// Topcoder Cache is used for caching Topcoder Users by handle.

0 commit comments

Comments
 (0)