diff --git a/Topcoder/class.topcoder.plugin.php b/Topcoder/class.topcoder.plugin.php index af258f1..0d034c5 100644 --- a/Topcoder/class.topcoder.plugin.php +++ b/Topcoder/class.topcoder.plugin.php @@ -187,6 +187,10 @@ public function settingsController_topcoder_create($sender) { $cf->form()->validateRule('Plugins.Topcoder.RoleApiURI', 'ValidateRequired', t('You must provide Role API URI.')); $cf->form()->validateRule('Plugins.Topcoder.ResourceRolesApiURI', 'ValidateRequired', t('You must provide Resource Roles API URI.')); $cf->form()->validateRule('Plugins.Topcoder.ResourcesApiURI', 'ValidateRequired', t('You must provide Resources API URI.')); + $isEmbedded = (bool) c('Garden.Embed.Allow'); + if ($isEmbedded) { + $cf->form()->validateRule('Plugins.Topcoder.MicroFrontendsForumsURL', 'ValidateRequired', t('You must provide Micro-Frontends Forums URL.')); + } $cf->form()->validateRule('Plugins.Topcoder.MemberProfileURL', 'ValidateRequired', t('You must provide Member Profile URL.')); if($cf->form()->getFormValue('Plugins.Topcoder.UseTopcoderAuthToken') == 1) { $cf->form()->validateRule('AuthenticationProvider.SignInUrl', 'ValidateRequired', t('You must provide SignIn URL.')); @@ -209,6 +213,7 @@ public function settingsController_topcoder_create($sender) { 'Plugins.Topcoder.RoleApiURI' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Role API URI'], 'Plugins.Topcoder.ResourceRolesApiURI' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Resource Roles API URI'], 'Plugins.Topcoder.ResourcesApiURI' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Resources API URI'], + 'Plugins.Topcoder.MicroFrontendsForumsURL' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Micro-Frontends Forums URL'], 'Plugins.Topcoder.MemberProfileURL' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Member Profile URL'], 'Plugins.Topcoder.UseTopcoderAuthToken' => ['Control' => 'CheckBox', 'Default' => false, 'Description' => 'Use Topcoder access token to log in to Vanilla'], 'AuthenticationProvider.SignInUrl' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder SignIn URL'], @@ -284,6 +289,8 @@ public function gdn_auth_startAuthenticator_handler() { if(!c('Garden.Installed')) { return; } + self::log('Embedded Settings', ['Garden.Embed.Allow' => c('Garden.Embed.Allow')]); + self::log('Cache', ['Active Cache' => Gdn_Cache::activeCache(), 'Type' =>Gdn::cache()->type()]); if(!$this->isDefault()) { @@ -1955,11 +1962,69 @@ private static function topcoderUserCache($userFields) { return $cached; } - // TODO: Debugging issues-108 + // Support Micro-frontends forums app public function gdn_dispatcher_beforeDispatch_handler($sender, $args) { - self::log('gdn_dispatcher_beforeDispatch_handler', [ + $mfeUrl = c("Plugins.Topcoder.MicroFrontendsForumsURL"); + $deliveryType = Gdn::request()->getQueryItem("DeliveryType"); + $remoteUrl = Gdn::request()->getQueryItem("remote")? urldecode(Gdn::request()->getQueryItem("remote")):""; + $isEmbedded = (bool) c('Garden.Embed.Allow', false); + + $data = array( + 'Garden.Embed.Allow' => c('Garden.Embed.Allow'), + 'MFEUrl' => $mfeUrl, + 'RemoteQueryParam("remote")' => $remoteUrl, + 'RemoteQueryParam("remote") == mfeUrl' => strcmp($mfeUrl, $remoteUrl) === 0, + 'Request(current fullPath)' => Gdn::request()->getFullPath(), + 'Request(current url)'=> Gdn::request()->getUrl(), + 'currentUrl == mfeUrl' => strcmp($mfeUrl, Gdn::request()->getUrl()) === 0, + 'Request(pathAndQuery)' => Gdn::request()->pathAndQuery(), + 'Request(Method)'=> Gdn::request()->getMethod(), + 'Request(DeliveryType)' =>Gdn::request()->getQueryItem("DeliveryType"), + 'Request(DeliveryType calculated)'=> !($deliveryType == "" || $deliveryType == DELIVERY_TYPE_ALL), 'Permissions' => Gdn::session()->getPermissionsArray(), - ]); + ); + logMessage(__FILE__, __LINE__, 'TopcoderPlugin', "Data", json_encode($data )); + + self::log('gdn_dispatcher_beforeDispatch_handler', $data); + + + if(!$isEmbedded) { + return; + } + + if(Gdn::request()->getMethod() != Gdn::request()::METHOD_GET) { + return; + } + if(stringBeginsWith(Gdn::request()->getPath(), '/api/') || stringBeginsWith(Gdn::request()->getPath(), '/dashboard') + || stringBeginsWith(Gdn::request()->getPath(), '/settings') + || stringBeginsWith(Gdn::request()->getPath(), '/embed/') + || stringBeginsWith(Gdn::request()->getPath(), '/social/') + || stringBeginsWith(Gdn::request()->getPath(), '/vanilla/') + || stringBeginsWith(Gdn::request()->getPath(), '/utility/') || stringBeginsWith(Gdn::request()->getPath(), '/notifications/') + || stringBeginsWith(Gdn::request()->getPath(), '/js/') + || stringBeginsWith(Gdn::request()->getPath(), '/applications/') + || stringBeginsWith(Gdn::request()->getPath(), '/themes/') + || stringBeginsWith(Gdn::request()->getPath(), '/dist/') + || stringBeginsWith(Gdn::request()->getPath(), '/css/') + || stringBeginsWith(Gdn::request()->getPath(), '/plugins/') + || stringBeginsWith(Gdn::request()->getPath(), '/resources/')) { + return; + } + + if(!($deliveryType == "" || $deliveryType == DELIVERY_TYPE_ALL)) { + return; + } + if(stringBeginsWith(Gdn::request()->getUrl(), $mfeUrl)) { + return; + } + + if(strlen($remoteUrl) > 0){ + return; + } else { + safeHeader("HTTP/1.1 301 Moved Permanently"); + safeHeader("Location: " . url($mfeUrl."/#/" . Gdn::request()->pathAndQuery())); + exit(); + } } // Topcoder Cache is used for caching Topcoder Users by handle.