diff --git a/src/core/classes/site.ts b/src/core/classes/site.ts index ed6ee34c6..bc20704b5 100644 --- a/src/core/classes/site.ts +++ b/src/core/classes/site.ts @@ -2749,10 +2749,21 @@ export type CoreSiteConfigResponse = { warnings?: CoreWSExternalWarning[]; }; +/** + * Possible values for 'supportavailability' config. + */ +export const enum CoreSiteConfigSupportAvailability { + Disabled = 0, + Authenticated = 1, + Anyone = 2, +} + /** * Site config indexed by name. */ -export type CoreSiteConfig = {[name: string]: string}; +export type CoreSiteConfig = Record & { + supportavailability?: string; // String representation of CoreSiteConfigSupportAvailability. +}; /** * Result of WS tool_mobile_get_public_config. @@ -2784,6 +2795,7 @@ export type CoreSitePublicConfigResponse = { agedigitalconsentverification?: boolean; // Whether age digital consent verification is enabled. supportname?: string; // Site support contact name (only if age verification is enabled). supportemail?: string; // Site support contact email (only if age verification is enabled). + supportavailability?: CoreSiteConfigSupportAvailability; supportpage?: string; // Site support contact url. autolang?: number; // Whether to detect default language from browser setting. lang?: string; // Default language for the site. diff --git a/src/core/features/login/tests/behat/basic-usage-400.feature b/src/core/features/login/tests/behat/basic-usage-400.feature new file mode 100644 index 000000000..5e6f19148 --- /dev/null +++ b/src/core/features/login/tests/behat/basic-usage-400.feature @@ -0,0 +1,19 @@ +@auth @core_auth @app @javascript @lms_from4.0 @lms_upto4.0 +Feature: Test basic usage of login in app + I need basic login functionality to work + + Background: + Given the following "users" exist: + | username | firstname | lastname | + | student1 | david | student | + + Scenario: Forgot password + When I enter the app + And I press "Forgotten your username or password?" in the app + And I set the field "Enter either username or email address" to "student1" + And I press "Search" in the app + Then I should find "Success" in the app + + When I press "OK" in the app + And I press "Forgotten your username or password?" in the app + Then I should find "Contact support" in the app diff --git a/src/core/features/login/tests/behat/basic_usage.feature b/src/core/features/login/tests/behat/basic_usage.feature index 5dbea5ed4..0aef46f28 100755 --- a/src/core/features/login/tests/behat/basic_usage.feature +++ b/src/core/features/login/tests/behat/basic_usage.feature @@ -135,8 +135,10 @@ Feature: Test basic usage of login in app When I press "Reconnect" in the app Then I should find "Acceptance test site" in the app - @lms_from4.0 + @lms_from4.1 Scenario: Forgot password + Given the following config values are set as admin: + | supportavailability | 2 | When I enter the app And I press "Forgotten your username or password?" in the app And I set the field "Enter either username or email address" to "student1" diff --git a/src/core/features/user/classes/support/authenticated-support-config.ts b/src/core/features/user/classes/support/authenticated-support-config.ts index 509b30c9f..36b87a446 100644 --- a/src/core/features/user/classes/support/authenticated-support-config.ts +++ b/src/core/features/user/classes/support/authenticated-support-config.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { CoreSite } from '@classes/site'; +import { CoreSite, CoreSiteConfigSupportAvailability } from '@classes/site'; import { CoreSites } from '@services/sites'; import { CoreUserSupportConfig } from './support-config'; @@ -42,8 +42,28 @@ export class CoreUserAuthenticatedSupportConfig extends CoreUserSupportConfig { * @inheritdoc */ canContactSupport(): boolean { - return this.site.isVersionGreaterEqualThan('4.0') - && !this.site.isFeatureDisabled('NoDelegate_CoreUserSupport'); + if (this.site.isFeatureDisabled('NoDelegate_CoreUserSupport')) { + return false; + } + + if (this.site.isVersionGreaterEqualThan('4.1')) { + if (!this.site.config || !('supportavailability' in this.site.config)) { + return false; + } + + const supportAvailability = Number(this.site.config.supportavailability); + + return supportAvailability === CoreSiteConfigSupportAvailability.Authenticated + || supportAvailability === CoreSiteConfigSupportAvailability.Anyone; + } + + if (this.site.isVersionGreaterEqualThan('4.0')) { + // This feature was always available in 4.0. + return true; + } + + // This feature wasn't available before 4.0. + return false; } /** diff --git a/src/core/features/user/classes/support/guest-support-config.ts b/src/core/features/user/classes/support/guest-support-config.ts index e48af2ee0..2c4462478 100644 --- a/src/core/features/user/classes/support/guest-support-config.ts +++ b/src/core/features/user/classes/support/guest-support-config.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { CoreSitePublicConfigResponse } from '@classes/site'; +import { CoreSiteConfigSupportAvailability, CoreSitePublicConfigResponse } from '@classes/site'; import { CoreUserNullSupportConfig } from '@features/user/classes/support/null-support-config'; import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; @@ -51,6 +51,12 @@ export class CoreUserGuestSupportConfig extends CoreUserSupportConfig { * @inheritdoc */ canContactSupport(): boolean { + // This config was introduced in 4.1, if it's missing we can assume the site is 4.0 or lower. + if ('supportavailability' in this.config) { + return this.config.supportavailability === CoreSiteConfigSupportAvailability.Anyone; + } + + // This config is only available to guests since 4.0, if it's missing we can assume guests can't contact support. return 'supportpage' in this.config; } diff --git a/src/core/features/user/tests/behat/support.feature b/src/core/features/user/tests/behat/support.feature index 5f6166135..0f4c9018d 100644 --- a/src/core/features/user/tests/behat/support.feature +++ b/src/core/features/user/tests/behat/support.feature @@ -5,6 +5,7 @@ Feature: Site support Given the following "users" exist: | username | firstname | lastname | | student1 | Student | Student | + And I am logged in as "student1" Scenario: Uses default support page Given I entered the app as "student1"