diff --git a/scripts/langindex.json b/scripts/langindex.json index 009ac93f8..d3cf2c75f 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -2155,11 +2155,6 @@ "core.login.passwordforgotten": "moodle", "core.login.passwordforgotteninstructions2": "moodle", "core.login.passwordrequired": "local_moodlemobileapp", - "core.login.policyaccept": "moodle", - "core.login.policyacceptmandatory": "local_moodlemobileapp", - "core.login.policyagree": "moodle", - "core.login.policyagreement": "moodle", - "core.login.policyagreementclick": "moodle", "core.login.potentialidps": "auth", "core.login.profileinvaliddata": "admin", "core.login.recaptchachallengeimage": "local_moodlemobileapp", @@ -2183,7 +2178,6 @@ "core.login.sitehasredirect": "local_moodlemobileapp", "core.login.siteinmaintenance": "local_moodlemobileapp", "core.login.sitenotallowed": "local_moodlemobileapp", - "core.login.sitepolicynotagreederror": "local_moodlemobileapp", "core.login.siteurl": "local_moodlemobileapp", "core.login.siteurlrequired": "local_moodlemobileapp", "core.login.startsignup": "moodle", @@ -2288,6 +2282,12 @@ "core.phone": "moodle", "core.pictureof": "moodle", "core.play": "local_moodlemobileapp", + "core.policy.policyaccept": "moodle", + "core.policy.policyacceptmandatory": "local_moodlemobileapp", + "core.policy.policyagree": "moodle", + "core.policy.policyagreement": "moodle", + "core.policy.policyagreementclick": "moodle", + "core.policy.sitepolicynotagreederror": "local_moodlemobileapp", "core.previous": "moodle", "core.proceed": "moodle", "core.publicprofile": "moodle", diff --git a/src/core/classes/sites/authenticated-site.ts b/src/core/classes/sites/authenticated-site.ts index ed6f6b43d..7db3ad6a9 100644 --- a/src/core/classes/sites/authenticated-site.ts +++ b/src/core/classes/sites/authenticated-site.ts @@ -669,7 +669,7 @@ export class CoreAuthenticatedSite extends CoreUnauthenticatedSite { } else if (error.errorcode === 'sitepolicynotagreed') { // Site policy not agreed, trigger event. this.triggerSiteEvent(CoreEvents.SITE_POLICY_NOT_AGREED, {}); - error.message = Translate.instant('core.login.sitepolicynotagreederror'); + error.message = Translate.instant('core.policy.sitepolicynotagreederror'); throw new CoreWSError(error); } else if (error.errorcode === 'dmlwriteexception' && CoreTextUtils.hasUnicodeData(data)) { diff --git a/src/core/features/features.module.ts b/src/core/features/features.module.ts index 6a38207d8..a6acf68ce 100644 --- a/src/core/features/features.module.ts +++ b/src/core/features/features.module.ts @@ -46,6 +46,7 @@ import { CoreUserToursModule } from './usertours/user-tours.module'; import { CoreViewerModule } from './viewer/viewer.module'; import { CoreXAPIModule } from './xapi/xapi.module'; import { CoreReportBuilderModule } from './reportbuilder/reportbuilder.module'; +import { CorePolicyModule } from './policy/policy.module'; @NgModule({ imports: [ @@ -80,6 +81,7 @@ import { CoreReportBuilderModule } from './reportbuilder/reportbuilder.module'; CoreViewerModule, CoreXAPIModule, CoreReportBuilderModule, + CorePolicyModule, // Import last to allow overrides. CoreEmulatorModule, diff --git a/src/core/features/login/lang.json b/src/core/features/login/lang.json index 2642ca11e..edbf0c44c 100644 --- a/src/core/features/login/lang.json +++ b/src/core/features/login/lang.json @@ -90,11 +90,6 @@ "passwordforgotten": "Forgotten password", "passwordforgotteninstructions2": "To reset your password, submit your username or your email address below. If we can find you in the database, an email will be sent to your email address, with instructions how to get access again.", "passwordrequired": "Password required", - "policyaccept": "I understand and agree", - "policyacceptmandatory": "I understand and agree to the mandatory site policies", - "policyagree": "You must agree to this policy to continue using this site. Do you agree?", - "policyagreement": "Site policy agreement", - "policyagreementclick": "Link to site policy agreement", "potentialidps": "Log in using your account on:", "profileinvaliddata": "Invalid value", "recaptchachallengeimage": "reCAPTCHA challenge image", @@ -118,7 +113,6 @@ "sitehasredirect": "Your site contains at least one HTTP redirect. The app cannot follow redirects, this could be the issue that's preventing the app from connecting to your site.", "siteinmaintenance": "Your site is in maintenance mode", "sitenotallowed": "This site is no longer available.", - "sitepolicynotagreederror": "Site policy not agreed.", "siteurl": "Site URL", "siteurlrequired": "Site URL required i.e https://campus.example.edu", "startsignup": "Create new account", diff --git a/src/core/features/login/login-lazy.module.ts b/src/core/features/login/login-lazy.module.ts index 0a575f5e7..13e05d136 100644 --- a/src/core/features/login/login-lazy.module.ts +++ b/src/core/features/login/login-lazy.module.ts @@ -20,7 +20,6 @@ import { hasSitesGuard } from './guards/has-sites'; import { CoreLoginComponentsModule } from './components/components.module'; import { CoreLoginHelper } from './services/login-helper'; import { CoreLoginForgottenPasswordPage } from '@features/login/pages/forgotten-password/forgotten-password'; -import { CoreLoginSitePolicyPage } from '@features/login/pages/site-policy/site-policy'; import { CoreUserComponentsModule } from '@features/user/components/components.module'; import { CoreLoginEmailSignupPage } from '@features/login/pages/email-signup/email-signup'; import { CoreLoginSitePage } from '@features/login/pages/site/site'; @@ -54,10 +53,6 @@ const routes: Routes = [ path: 'changepassword', component: CoreLoginChangePasswordPage, }, - { - path: 'sitepolicy', - component: CoreLoginSitePolicyPage, - }, { path: 'emailsignup', component: CoreLoginEmailSignupPage, @@ -77,7 +72,6 @@ const routes: Routes = [ ], declarations: [ CoreLoginForgottenPasswordPage, - CoreLoginSitePolicyPage, CoreLoginSitePage, CoreLoginSitesPage, CoreLoginChangePasswordPage, diff --git a/src/core/features/login/pages/email-signup/email-signup.html b/src/core/features/login/pages/email-signup/email-signup.html index 1c7216376..d59e5b999 100644 --- a/src/core/features/login/pages/email-signup/email-signup.html +++ b/src/core/features/login/pages/email-signup/email-signup.html @@ -183,19 +183,19 @@ -

{{ 'core.login.policyagreement' | translate }}

+

{{ 'core.policy.policyagreement' | translate }}

- {{ 'core.login.policyagreementclick' | translate }} + {{ 'core.policy.policyagreementclick' | translate }} -

{{ 'core.login.policyacceptmandatory' | translate }}

+

{{ 'core.policy.policyacceptmandatory' | translate }}

diff --git a/src/core/features/login/pages/email-signup/email-signup.ts b/src/core/features/login/pages/email-signup/email-signup.ts index 186ba464c..5a05c71b2 100644 --- a/src/core/features/login/pages/email-signup/email-signup.ts +++ b/src/core/features/login/pages/email-signup/email-signup.ts @@ -118,7 +118,7 @@ export class CoreLoginEmailSignupPage implements OnInit { }; this.passwordErrors = { required: 'core.login.passwordrequired' }; this.emailErrors = { required: 'core.login.missingemail' }; - this.policyErrors = { required: 'core.login.policyagree' }; + this.policyErrors = { required: 'core.policy.policyagree' }; this.email2Errors = { required: 'core.login.missingemail', pattern: 'core.login.emailnotmatch', @@ -215,11 +215,7 @@ export class CoreLoginEmailSignupPage implements OnInit { * @returns Promise resolved when done. */ protected async getSignupSettings(): Promise { - this.settings = await CoreWS.callAjax( - 'auth_email_get_signup_settings', - {}, - { siteUrl: this.site.getURL() }, - ); + this.settings = await CoreLoginHelper.getEmailSignupSettings(this.site.getURL()); if (CoreUserProfileFieldDelegate.hasRequiredUnsupportedField(this.settings.profilefields)) { this.allRequiredSupported = false; diff --git a/src/core/features/login/services/login-helper.ts b/src/core/features/login/services/login-helper.ts index c80fc521e..a2aded067 100644 --- a/src/core/features/login/services/login-helper.ts +++ b/src/core/features/login/services/login-helper.ts @@ -57,6 +57,7 @@ import { IDENTITY_PROVIDER_FEATURE_NAME_PREFIX, } from '../constants'; import { LazyRoutesModule } from '@/app/app-routing.module'; +import { CorePolicy } from '@features/policy/services/policy'; /** * Helper provider that provides some common features regarding authentication. @@ -87,30 +88,10 @@ export class CoreLoginHelperProvider { * * @param siteId Site ID. If not defined, current site. * @returns Promise resolved if success, rejected if failure. + * @deprecated since 4.4. Use CorePolicy.acceptMandatoryPolicies instead. */ async acceptSitePolicy(siteId?: string): Promise { - const site = await CoreSites.getSite(siteId); - - const result = await site.write('core_user_agree_site_policy', {}); - - if (result.status) { - return; - } - - if (!result.warnings?.length) { - throw new CoreError('Cannot agree site policy'); - } - - // Check if there is a warning 'alreadyagreed'. - const found = result.warnings.some((warning) => warning.warningcode === 'alreadyagreed'); - if (found) { - // Policy already agreed, treat it as a success. - return; - } - - // Another warning, reject. - throw new CoreWSError(result.warnings[0]); - + return CorePolicy.acceptMandatorySitePolicies(siteId); } /** @@ -286,36 +267,25 @@ export class CoreLoginHelperProvider { return params && params.oauthsso !== undefined ? Number(params.oauthsso) : undefined; } + /** + * Get email signup settings. + * + * @param siteUrl Site URL. + * @returns Signup settings. + */ + async getEmailSignupSettings(siteUrl: string): Promise { + return await CoreWS.callAjax('auth_email_get_signup_settings', {}, { siteUrl }); + } + /** * Get the site policy. * * @param siteId Site ID. If not defined, current site. * @returns Promise resolved with the site policy. + * @deprecated since 4.4. Use CorePolicy.getSitePoliciesURL instead. */ async getSitePolicy(siteId?: string): Promise { - const site = await CoreSites.getSite(siteId); - - let sitePolicy: string | undefined; - - try { - // Try to get the latest config, maybe the site policy was just added or has changed. - sitePolicy = await site.getConfig('sitepolicy', true); - } catch (error) { - // Cannot get config, try to get the site policy using auth_email_get_signup_settings. - const settings = await CoreWS.callAjax( - 'auth_email_get_signup_settings', - {}, - { siteUrl: site.getURL() }, - ); - - sitePolicy = settings.sitepolicy; - } - - if (!sitePolicy) { - throw new CoreError('Cannot retrieve site policy'); - } - - return sitePolicy; + return CorePolicy.getSitePoliciesURL(siteId); } /** @@ -1067,20 +1037,11 @@ export class CoreLoginHelperProvider { * Function called when site policy is not agreed. Reserved for core use. * * @param siteId Site ID. If not defined, current site. + * @returns void + * @deprecated since 4.4. Use CorePolicy.goToAcceptSitePolicies instead. */ sitePolicyNotAgreed(siteId?: string): void { - siteId = siteId || CoreSites.getCurrentSiteId(); - if (!siteId || siteId != CoreSites.getCurrentSiteId()) { - // Only current site allowed. - return; - } - - // If current page is already site policy, stop. - if (CoreNavigator.isCurrent('/login/sitepolicy')) { - return; - } - - CoreNavigator.navigate('/login/sitepolicy', { params: { siteId }, reset: true }); + return CorePolicy.goToAcceptSitePolicies(siteId); } /** @@ -1535,14 +1496,6 @@ export type CoreLoginSSOData = CoreRedirectPayload & { ssoUrlParams?: CoreUrlParams; // Other params added to the login url. }; -/** - * Result of WS core_user_agree_site_policy. - */ -type AgreeSitePolicyResult = { - status: boolean; // Status: true only if we set the policyagreed to 1 for the user. - warnings?: CoreWSExternalWarning[]; -}; - /** * Result of WS auth_email_get_signup_settings. */ diff --git a/src/core/features/policy/constants.ts b/src/core/features/policy/constants.ts new file mode 100644 index 000000000..c341a326a --- /dev/null +++ b/src/core/features/policy/constants.ts @@ -0,0 +1,17 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Routing. +export const POLICY_PAGE_NAME = 'policy'; +export const SITE_POLICY_PAGE_NAME = 'sitepolicy'; diff --git a/src/core/features/policy/lang.json b/src/core/features/policy/lang.json new file mode 100644 index 000000000..66fdf8295 --- /dev/null +++ b/src/core/features/policy/lang.json @@ -0,0 +1,8 @@ +{ + "policyaccept": "I understand and agree", + "policyacceptmandatory": "I understand and agree to the mandatory site policies", + "policyagree": "You must agree to this policy to continue using this site. Do you agree?", + "policyagreement": "Site policy agreement", + "policyagreementclick": "Link to site policy agreement", + "sitepolicynotagreederror": "Site policy not agreed." +} diff --git a/src/core/features/login/pages/site-policy/site-policy.html b/src/core/features/policy/pages/site-policy/site-policy.html similarity index 78% rename from src/core/features/login/pages/site-policy/site-policy.html rename to src/core/features/policy/pages/site-policy/site-policy.html index 76ca02525..b17608f30 100644 --- a/src/core/features/login/pages/site-policy/site-policy.html +++ b/src/core/features/policy/pages/site-policy/site-policy.html @@ -5,7 +5,7 @@ -

{{ 'core.login.policyagreement' | translate }}

+

{{ 'core.policy.policyagreement' | translate }}

@@ -14,13 +14,13 @@ -

{{ 'core.login.policyagree' | translate }}

+

{{ 'core.policy.policyagree' | translate }}

- {{ 'core.login.policyagreementclick' | translate }} + {{ 'core.policy.policyagreementclick' | translate }}

@@ -28,10 +28,10 @@ - {{ 'core.login.policyacceptmandatory' | translate }} + {{ 'core.policy.policyacceptmandatory' | translate }} - {{ 'core.login.cancel' | translate }} + {{ 'core.cancel' | translate }}
diff --git a/src/core/features/login/pages/site-policy/site-policy.scss b/src/core/features/policy/pages/site-policy/site-policy.scss similarity index 100% rename from src/core/features/login/pages/site-policy/site-policy.scss rename to src/core/features/policy/pages/site-policy/site-policy.scss diff --git a/src/core/features/login/pages/site-policy/site-policy.ts b/src/core/features/policy/pages/site-policy/site-policy.ts similarity index 91% rename from src/core/features/login/pages/site-policy/site-policy.ts rename to src/core/features/policy/pages/site-policy/site-policy.ts index 3d28649b4..55997cbcc 100644 --- a/src/core/features/login/pages/site-policy/site-policy.ts +++ b/src/core/features/policy/pages/site-policy/site-policy.ts @@ -18,22 +18,22 @@ import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; -import { CoreLoginHelper } from '@features/login/services/login-helper'; import { CoreSite } from '@classes/sites/site'; import { CoreNavigator } from '@services/navigator'; import { CoreEvents } from '@singletons/events'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { Translate } from '@singletons'; +import { CorePolicy } from '@features/policy/services/policy'; /** * Page to accept a site policy. */ @Component({ - selector: 'page-core-login-site-policy', + selector: 'page-core-policy-site-policy', templateUrl: 'site-policy.html', styleUrls: ['site-policy.scss'], }) -export class CoreLoginSitePolicyPage implements OnInit { +export class CorePolicySitePolicyPage implements OnInit { sitePolicy?: string; showInline?: boolean; @@ -76,7 +76,7 @@ export class CoreLoginSitePolicyPage implements OnInit { */ protected async fetchSitePolicy(): Promise { try { - this.sitePolicy = await CoreLoginHelper.getSitePolicy(this.siteId); + this.sitePolicy = await CorePolicy.getSitePoliciesURL(this.siteId); } catch (error) { CoreDomUtils.showErrorModalDefault(error, 'Error getting site policy.'); this.cancel(); @@ -100,7 +100,7 @@ export class CoreLoginSitePolicyPage implements OnInit { CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM, ws: 'auth_email_get_signup_settings', - name: Translate.instant('core.login.policyagreement'), + name: Translate.instant('core.policy.policyagreement'), data: { category: 'policy' }, url: '/user/policy.php', }); @@ -126,7 +126,7 @@ export class CoreLoginSitePolicyPage implements OnInit { const modal = await CoreDomUtils.showModalLoading('core.sending', true); try { - await CoreLoginHelper.acceptSitePolicy(this.siteId); + await CorePolicy.acceptMandatorySitePolicies(this.siteId); // Success accepting, go to site initial page. // Invalidate cache since some WS don't return error if site policy is not accepted. diff --git a/src/core/features/policy/policy-lazy.module.ts b/src/core/features/policy/policy-lazy.module.ts new file mode 100644 index 000000000..fd9bca426 --- /dev/null +++ b/src/core/features/policy/policy-lazy.module.ts @@ -0,0 +1,38 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; + +import { CoreSharedModule } from '@/core/shared.module'; +import { CorePolicySitePolicyPage } from '@features/policy/pages/site-policy/site-policy'; +import { SITE_POLICY_PAGE_NAME } from './constants'; + +const routes: Routes = [ + { + path: SITE_POLICY_PAGE_NAME, + component: CorePolicySitePolicyPage, + }, +]; + +@NgModule({ + imports: [ + CoreSharedModule, + RouterModule.forChild(routes), + ], + declarations: [ + CorePolicySitePolicyPage, + ], +}) +export class CorePolicyLazyModule {} diff --git a/src/core/features/policy/policy.module.ts b/src/core/features/policy/policy.module.ts new file mode 100644 index 000000000..b8c79184d --- /dev/null +++ b/src/core/features/policy/policy.module.ts @@ -0,0 +1,60 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { APP_INITIALIZER, NgModule, Type } from '@angular/core'; +import { Routes } from '@angular/router'; + +import { AppRoutingModule } from '@/app/app-routing.module'; +import { CoreEvents } from '@singletons/events'; +import { POLICY_PAGE_NAME } from './constants'; + +/** + * Get policy services. + * + * @returns Policy services. + */ +export async function getPolicyServices(): Promise[]> { + const { CorePolicyService } = await import('@features/policy/services/policy'); + + return [ + CorePolicyService, + ]; +} + +const routes: Routes = [ + { + path: POLICY_PAGE_NAME, + loadChildren: () => import('./policy-lazy.module').then(m => m.CorePolicyLazyModule), + }, +]; + +@NgModule({ + imports: [ + AppRoutingModule.forChild(routes), + ], + providers: [ + { + provide: APP_INITIALIZER, + multi: true, + useValue: async () => { + CoreEvents.on(CoreEvents.SITE_POLICY_NOT_AGREED, async (data) => { + const { CorePolicy } = await import('@features/policy/services/policy'); + + CorePolicy.goToAcceptSitePolicies(data.siteId); + }); + }, + }, + ], +}) +export class CorePolicyModule {} diff --git a/src/core/features/policy/services/policy.ts b/src/core/features/policy/services/policy.ts new file mode 100644 index 000000000..b77363700 --- /dev/null +++ b/src/core/features/policy/services/policy.ts @@ -0,0 +1,121 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Injectable } from '@angular/core'; +import { CoreError } from '@classes/errors/error'; +import { CoreWSError } from '@classes/errors/wserror'; +import { CoreLoginHelper } from '@features/login/services/login-helper'; +import { CoreNavigator } from '@services/navigator'; +import { CoreSites } from '@services/sites'; +import { CoreWSExternalWarning } from '@services/ws'; +import { makeSingleton } from '@singletons'; +import { POLICY_PAGE_NAME, SITE_POLICY_PAGE_NAME } from '../constants'; + +/** + * Service that provides some common features regarding policies. + */ +@Injectable({ providedIn: 'root' }) +export class CorePolicyService { + + /** + * Accept all mandatory site policies. + * + * @param siteId Site ID. If not defined, current site. + * @returns Promise resolved if success, rejected if failure. + */ + async acceptMandatorySitePolicies(siteId?: string): Promise { + const site = await CoreSites.getSite(siteId); + + const result = await site.write('core_user_agree_site_policy', {}); + + if (result.status) { + return; + } + + if (!result.warnings?.length) { + throw new CoreError('Cannot agree site policy'); + } + + // Check if there is a warning 'alreadyagreed'. + const found = result.warnings.some((warning) => warning.warningcode === 'alreadyagreed'); + if (found) { + // Policy already agreed, treat it as a success. + return; + } + + // Another warning, reject. + throw new CoreWSError(result.warnings[0]); + } + + /** + * Get the URL to view the site policy (or all the site policies in a single page if there's more than one). + * + * @param siteId Site ID. If not defined, current site. + * @returns Promise resolved with the site policy. + */ + async getSitePoliciesURL(siteId?: string): Promise { + const site = await CoreSites.getSite(siteId); + + let sitePolicy: string | undefined; + + try { + // Try to get the latest config, maybe the site policy was just added or has changed. + sitePolicy = await site.getConfig('sitepolicy', true); + } catch (error) { + // Cannot get config, try to get the site policy using signup settings. + const settings = await CoreLoginHelper.getEmailSignupSettings(site.getURL()); + + sitePolicy = settings.sitepolicy; + } + + if (!sitePolicy) { + throw new CoreError('Cannot retrieve site policy'); + } + + return sitePolicy; + } + + /** + * Open page to accept site policies. + * + * @param siteId Site ID. If not defined, current site. + */ + goToAcceptSitePolicies(siteId?: string): void { + siteId = siteId || CoreSites.getCurrentSiteId(); + if (!siteId || siteId != CoreSites.getCurrentSiteId()) { + // Only current site allowed. + return; + } + + const routePath = `/${POLICY_PAGE_NAME}/${SITE_POLICY_PAGE_NAME}`; + + // If current page is already site policy, stop. + if (CoreNavigator.isCurrent(routePath)) { + return; + } + + CoreNavigator.navigate(routePath, { params: { siteId }, reset: true }); + } + +} + +export const CorePolicy = makeSingleton(CorePolicyService); + +/** + * Result of WS core_user_agree_site_policy. + */ +type AgreeSitePolicyResult = { + status: boolean; // Status: true only if we set the policyagreed to 1 for the user. + warnings?: CoreWSExternalWarning[]; +};